Skip to content
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

Draft
wants to merge 26 commits into
base: dev/0.2.6
Choose a base branch
from

Conversation

marchermans
Copy link

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.

@liach
Copy link
Contributor

liach commented Nov 30, 2019

must you get the project in such nasty ways?

@marchermans
Copy link
Author

@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.

@marchermans
Copy link
Author

For everybody reading this: This PR needs a bug fix in TinyRemapper to be usefull: FabricMC/tiny-remapper#7 is the hanging issue.

Copy link
Contributor

@natanfudge natanfudge left a 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"))
Copy link
Contributor

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.

Copy link
Author

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();
Copy link
Contributor

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)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong formatting

{

private FabricModUtils()
{
Copy link
Contributor

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 -> {
Copy link
Contributor

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

Copy link
Contributor

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();
Copy link
Contributor

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

Copy link
Author

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) {
Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Author

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;
Copy link
Contributor

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.

Copy link
Author

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++) {
Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would iterate over JsonElements rather than JsonObjects so it's hardly much better

Copy link
Contributor

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();

Copy link
Author

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())//
Copy link
Contributor

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();
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okey will do.

@@ -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}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:O

Copy link
Author

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

Copy link
Contributor

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

@modmuss50
Copy link
Member

is this ready for reviews and testing?

@marchermans
Copy link
Author

I am still working on it.
That damn IDEA task is kind of difficult to deal with. Also christmas, and 3 birthdays in one week kind of took its toll.
Getting back on my horse though.

@modmuss50
Copy link
Member

No, dont rush or worry at all. I was just checking you werent waiting on me or something stupid 👍

@natanfudge
Copy link
Contributor

I wouldn't worry too much about the IDEA task. You can still just import Gradle instead.

jpenilla pushed a commit to jpenilla/fabric-loom that referenced this pull request Nov 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants