From c8ef934bdaf5632ff4953afc37fad75d840837f5 Mon Sep 17 00:00:00 2001 From: liach <7806504+liach@users.noreply.github.com> Date: Mon, 11 Nov 2019 10:52:13 -0600 Subject: [PATCH] Add mixin ap to projects in a "better way" (#144) * Add mixin ap to projects in a "better way" Signed-off-by: liach * Remove obsolete bad code Signed-off-by: liach * Use a field in constants instead Signed-off-by: liach * String format does not work Signed-off-by: liach --- build.gradle | 1 - .../net/fabricmc/loom/AbstractPlugin.java | 60 +------------------ .../net/fabricmc/loom/util/Constants.java | 12 +++- 3 files changed, 12 insertions(+), 61 deletions(-) diff --git a/build.gradle b/build.gradle index b92c14a..4e6261c 100644 --- a/build.gradle +++ b/build.gradle @@ -47,7 +47,6 @@ dependencies { implementation ('net.fabricmc:tiny-remapper:0.2.0.56') { transitive = false } - implementation ('net.fabricmc:fabric-mixin-compile-extensions:0.2.0.3') // decompilers implementation ('net.fabricmc:procyon-fabric-compilertools:0.5.35.+') diff --git a/src/main/java/net/fabricmc/loom/AbstractPlugin.java b/src/main/java/net/fabricmc/loom/AbstractPlugin.java index 88e135a..85d43d3 100644 --- a/src/main/java/net/fabricmc/loom/AbstractPlugin.java +++ b/src/main/java/net/fabricmc/loom/AbstractPlugin.java @@ -30,7 +30,6 @@ import java.util.HashSet; import java.util.Map; import java.util.Optional; import java.util.Set; -import java.util.function.Predicate; import com.google.common.collect.ImmutableMap; import groovy.util.Node; @@ -40,10 +39,7 @@ import org.gradle.api.Task; import org.gradle.api.UnknownTaskException; import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Dependency; -import org.gradle.api.artifacts.component.ModuleComponentIdentifier; import org.gradle.api.artifacts.repositories.MavenArtifactRepository; -import org.gradle.api.artifacts.result.DependencyResult; -import org.gradle.api.artifacts.result.ResolvedDependencyResult; import org.gradle.api.plugins.JavaPlugin; import org.gradle.api.plugins.JavaPluginConvention; import org.gradle.api.publish.Publication; @@ -199,8 +195,8 @@ public class AbstractPlugin implements Plugin { * Permit to add a Maven repository to a target project. * * @param target The garget project - * @param name The name of the repository - * @param url The URL of the repository + * @param name The name of the repository + * @param url The URL of the repository * @return An object containing the name and the URL of the repository that can be modified later */ public MavenArtifactRepository addMavenRepo(Project target, final String name, final String url) { @@ -226,42 +222,6 @@ public class AbstractPlugin implements Plugin { EclipseModel eclipseModel = (EclipseModel) project.getExtensions().getByName("eclipse"); } - private void addModule(Project proj, String configuration, DependencyResult module) { - if (module instanceof ResolvedDependencyResult) { - if (module.getFrom().getId() instanceof ModuleComponentIdentifier) { - ModuleComponentIdentifier mci = ((ModuleComponentIdentifier) module.getFrom().getId()); - String moduleId = mci.getGroup() + ":" + mci.getModule() + ":" + mci.getVersion(); - proj.getDependencies().add(configuration, proj.getDependencies().module(moduleId)); - proj.getLogger().debug("Loom addModule " + moduleId + " to " + configuration); - } - - for (DependencyResult child : ((ResolvedDependencyResult) module).getSelected().getDependencies()) { - addModule(proj, configuration, child); - } - } - } - - private boolean findAndAddModule(Project project, String configuration, DependencyResult dep, Predicate predicate) { - boolean found = false; - - if (dep instanceof ResolvedDependencyResult) { - if (dep.getFrom().getId() instanceof ModuleComponentIdentifier) { - ModuleComponentIdentifier mci = ((ModuleComponentIdentifier) dep.getFrom().getId()); - - if (predicate.test(mci)) { - addModule(project, configuration, dep); - found = true; - } - } - - for (DependencyResult child : ((ResolvedDependencyResult) dep).getSelected().getDependencies()) { - findAndAddModule(project, configuration, child, predicate); - } - } - - return found; - } - /** * Add Minecraft dependencies to compile time. */ @@ -275,21 +235,7 @@ public class AbstractPlugin implements Plugin { javadoc.setClasspath(main.getOutput().plus(main.getCompileClasspath())); // Add Mixin dependencies - Project p = project; - - while (true) { - boolean found = false; - - for (DependencyResult dep : p.getBuildscript().getConfigurations().getByName("classpath").getIncoming().getResolutionResult().getRoot().getDependencies()) { - found = findAndAddModule(project, "annotationProcessor", dep, (mci) -> ("net.fabricmc".equals(mci.getGroup()) && "fabric-mixin-compile-extensions".equals(mci.getModule()))); - } - - if (found || AbstractPlugin.isRootProject(p)) { - break; - } - - p = p.getRootProject(); - } + project.getDependencies().add(JavaPlugin.ANNOTATION_PROCESSOR_CONFIGURATION_NAME, "net.fabricmc:fabric-mixin-compile-extensions:" + Constants.MIXIN_COMPILE_EXTENSIONS_VERSION); project.afterEvaluate(project1 -> { LoomGradleExtension extension = project1.getExtensions().getByType(LoomGradleExtension.class); diff --git a/src/main/java/net/fabricmc/loom/util/Constants.java b/src/main/java/net/fabricmc/loom/util/Constants.java index 26aa4ff..a1502d0 100644 --- a/src/main/java/net/fabricmc/loom/util/Constants.java +++ b/src/main/java/net/fabricmc/loom/util/Constants.java @@ -39,9 +39,13 @@ public class Constants { public static final String MOD_COMPILE_CLASSPATH = "modCompileClasspath"; public static final String MOD_COMPILE_CLASSPATH_MAPPED = "modCompileClasspathMapped"; - public static final List MOD_COMPILE_ENTRIES = ImmutableList.of(new RemappedConfigurationEntry("modCompile", "compile", true, "compile"), new RemappedConfigurationEntry("modApi", "api", true, "compile"), - new RemappedConfigurationEntry("modImplementation", "implementation", true, "runtime"), new RemappedConfigurationEntry("modRuntime", "runtimeOnly", false, ""), - new RemappedConfigurationEntry("modCompileOnly", "compileOnly", true, "")); + public static final List MOD_COMPILE_ENTRIES = ImmutableList.of( + new RemappedConfigurationEntry("modCompile", "compile", true, "compile"), + new RemappedConfigurationEntry("modApi", "api", true, "compile"), + new RemappedConfigurationEntry("modImplementation", "implementation", true, "runtime"), + new RemappedConfigurationEntry("modRuntime", "runtimeOnly", false, ""), + new RemappedConfigurationEntry("modCompileOnly", "compileOnly", true, "") + ); public static final String INCLUDE = "include"; public static final String MINECRAFT = "minecraft"; @@ -51,4 +55,6 @@ public class Constants { public static final String MINECRAFT_LINEMAPPED = "minecraftLinemapped"; public static final String MAPPINGS = "mappings"; public static final String MAPPINGS_FINAL = "mappingsFinal"; + + public static final String MIXIN_COMPILE_EXTENSIONS_VERSION = "0.2.0.3"; }