-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DRAFT] Adding transformer support to be able to use remapped dependencies in any configuration. #156
base: dev/0.2.6
Are you sure you want to change the base?
Conversation
…ld code but adapted.
…ied by the transformer, or use none if a dependency is being extracted.
must you get the project in such nasty ways? |
@liach Sadly yes, gradle uses a custom injector system to inject data into the transformers itself, as such what can be injected is extremely limited. (Basically only its inputs). Additionally Transformers need to perform a pure action and their parameters need to be isolateble. In this context that means that the entire parameter set needs to be serializable. In the current context this means that to get the external data (the data needed to remap, for example the MC dependency or the mapping data) from the project config there is literally only one way. That said I am currently looking into a technology stack which would pass all of that information through to us without having to use the project at all. But yeah as of right now this PR also needs an update of TinyRemapper since that can not handle being uses in a multithreaded environment. And just crashes. Hence it being a draft as well. |
For everybody reading this: This PR needs a bug fix in TinyRemapper to be usefull: FabricMC/tiny-remapper#7 is the hanging issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remember to rebase
|
||
//Rudimentary check for sources. Which need to be remapped separately. | ||
//Potentially we need to check zip file contents. | ||
if (inputFile.getName().contains("-sources")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering this one and the sources jar one are extremely similiar, I think some common code can be extracted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep totally agree.
Some lambda logic and a builder would probably go a long way.
But I would love to write this up a bit better so that it works in nearly all cases perfectly before I go mayham on cleaning loom up and making it more stable.
|
||
public class TransformerProjectManager | ||
{ | ||
private static final TransformerProjectManager INSTANCE = new TransformerProjectManager(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a private constructor if you plan on keeping this
private Map<String, Project> projects = Maps.newConcurrentMap(); | ||
|
||
public void register(Project project) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong formatting
{ | ||
|
||
private FabricModUtils() | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting
*/ | ||
public static boolean isFabricMod(Project project, Logger logger, File artifact, String notation) { | ||
AtomicBoolean fabricMod = new AtomicBoolean(false); | ||
project.zipTree(artifact).visit(f -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming this lambda param file
would be beneficial in my opinion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stop using project here. Use java 8 zip file sysstem api or zip entry. also for project logger use sys out println instead
JsonObject jsonObject = GSON.fromJson(jsonStr, JsonObject.class); | ||
return jsonObject; | ||
} catch (IOException e) { | ||
e.printStackTrace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want something better than this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again original code does this. Will fix it.
throw new IllegalStateException("Tried to initialize: InstallerUtils but this is a Utility class."); | ||
} | ||
|
||
static JsonObject readInstallerJson(File file, Project project) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentionally package private?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's package private in ModProcessor
so is probably just a holdover from copy-pasting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep.
InstallerUtils comes from the ModProcessor class, so yeah I will need to give These Kinds of Things a brush over.
int priority = 0; | ||
|
||
try (JarFile jarFile = new JarFile(file)) { | ||
ZipEntry entry = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like how much mutable state is in this code, but I don't see an easy way around it so don't worry about it too much.
Also formatting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way we do this is really nasty. TBH The installer dependencies should not be retroactively injected in the classpath based on some weird spec nobody knows.
I will see what I can do to propose a Change here in the future, then this will probably Change as well.
|
||
File nestedFile = new File(extension.getNestedModCache(), fileName.substring(fileName.lastIndexOf("/"))); | ||
for (int i = 0; i < jsonArray.size(); i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't you use a for :
(foreach) loop here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would iterate over JsonElement
s rather than JsonObject
s so it's hardly much better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would have the same benefits as in any other for loop,
JsonObject jsonObject = jsonElement.getAsJsonObject();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH This is original code, i did not change this. But I plan to go over all of this and clean this kind of stuff up in an upcoming PR later on. This will probably stay in this PR, getting this to behave is already kind of difficult.
|
||
public static File findSources(DependencyHandler dependencies, ResolvedArtifact artifact) { | ||
@SuppressWarnings("unchecked") ArtifactResolutionQuery query = dependencies.createArtifactResolutionQuery()// | ||
.forComponents(artifact.getId().getComponentIdentifier())// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IDK why but the formatting here looks awful on github
|
||
private static RegularFileProperty getfilePropertyLegacy(Project project) { | ||
return project.getLayout().fileProperty(); | ||
return project.getObjects().fileProperty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class could be removed completely if there's no backwards compatibility being gained from it anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, should remove this completely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okey will do.
Next up implement the tooling lookup.
@@ -24,10 +24,10 @@ dependencies { | |||
//to change the versions see the gradle.properties file | |||
minecraft "com.mojang:minecraft:\${project.minecraft_version}" | |||
mappings "net.fabricmc:yarn:\${project.yarn_mappings}" | |||
modCompile "net.fabricmc:fabric-loader:\${project.loader_version}" | |||
compile "net.fabricmc:fabric-loader:\${project.loader_version}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:O
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What?
That is the goal of this whole ordeal :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, this should have been compile
in the example mod, given how the loader touches no minecraft code at all
TODO: Add reflective override to the tooling provider.
One more to go for idea and ofcourse the idea gradle task.... Fun.
Now on to patching dep resolution.
is this ready for reviews and testing? |
I am still working on it. |
No, dont rush or worry at all. I was just checking you werent waiting on me or something stupid 👍 |
I wouldn't worry too much about the IDEA task. You can still just import Gradle instead. |
Current situation
In the current situation a custom configuration is used to adapt and remap the mod dependencies to the mapping as defined by the user.
Even though this works as intended it is not entirely compatible with Gradle spec.
New situation
This implements transformers that interact with all dependencies added to the project and will transform them accordingly.
The transformers call the old methods, which where previously looping over a configuration.
Each transformer will initially detect if the artifact passed in a valid Fabric Mod before performing either a remap of a library jar, or a sources jar.