From a6f7e2cbbbfc6b55d7acb842067635e49b8b84e2 Mon Sep 17 00:00:00 2001 From: Jaideep Singh Heer Date: Mon, 27 Jul 2020 01:38:48 +0530 Subject: [PATCH] Fix issue #243 by using ResolvedConfiguration and ResolvedDependency. (#244) * Fix issue #243 by using ResolvedConfiguration and ResolvedDependency. * Fix AvoidStarImport build error. --- .../net/fabricmc/loom/util/NestedJars.java | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/fabricmc/loom/util/NestedJars.java b/src/main/java/net/fabricmc/loom/util/NestedJars.java index 1c13298..fbab104 100644 --- a/src/main/java/net/fabricmc/loom/util/NestedJars.java +++ b/src/main/java/net/fabricmc/loom/util/NestedJars.java @@ -32,6 +32,7 @@ import java.util.Collection; import java.util.List; import java.util.Locale; import java.util.Set; +import java.util.stream.Collectors; import java.util.zip.ZipEntry; import com.google.gson.Gson; @@ -39,6 +40,13 @@ import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import org.apache.commons.io.FileUtils; +import org.gradle.api.artifacts.ResolvedConfiguration; +import org.gradle.api.artifacts.Configuration; +import org.gradle.api.artifacts.ResolvedDependency; +import org.gradle.api.artifacts.Dependency; +import org.gradle.api.artifacts.ProjectDependency; +import org.gradle.api.artifacts.ResolvedArtifact; +import org.gradle.api.artifacts.DependencySet; import org.zeroturnaround.zip.FileSource; import org.zeroturnaround.zip.ZipEntrySource; import org.zeroturnaround.zip.ZipUtil; @@ -46,10 +54,6 @@ import org.zeroturnaround.zip.transform.StringZipEntryTransformer; import org.zeroturnaround.zip.transform.ZipEntryTransformerEntry; import org.gradle.api.Project; import org.gradle.api.Task; -import org.gradle.api.artifacts.Configuration; -import org.gradle.api.artifacts.Dependency; -import org.gradle.api.artifacts.DependencySet; -import org.gradle.api.artifacts.ProjectDependency; import org.gradle.api.tasks.bundling.AbstractArchiveTask; import net.fabricmc.loom.LoomGradleExtension; @@ -95,10 +99,10 @@ public class NestedJars { private static List getContainedJars(Project project) { List fileList = new ArrayList<>(); - Configuration configuration = project.getConfigurations().getByName(Constants.INCLUDE); - DependencySet dependencies = configuration.getDependencies(); + ResolvedConfiguration configuration = project.getConfigurations().getByName(Constants.INCLUDE).getResolvedConfiguration(); + Set dependencies = configuration.getFirstLevelModuleDependencies(); - for (Dependency dependency : dependencies) { + for (ResolvedDependency dependency : dependencies) { if (dependency instanceof ProjectDependency) { ProjectDependency projectDependency = (ProjectDependency) dependency; Project dependencyProject = projectDependency.getDependencyProject(); @@ -115,7 +119,14 @@ public class NestedJars { } } } else { - fileList.addAll(prepareForNesting(configuration.files(dependency), dependency, project)); + fileList.addAll(prepareForNesting( + dependency + .getModuleArtifacts() + .stream() + .map(ResolvedArtifact::getFile) + .collect(Collectors.toSet()), + dependency, project) + ); } } @@ -156,7 +167,7 @@ public class NestedJars { } //This is a good place to do pre-nesting operations, such as adding a fabric.mod.json to a library - private static List prepareForNesting(Set files, Dependency dependency, Project project) { + private static List prepareForNesting(Set files, ResolvedDependency dependency, Project project) { List fileList = new ArrayList<>(); for (File file : files) { @@ -193,12 +204,12 @@ public class NestedJars { } //Generates a barebones mod for a dependency - private static String getMod(Dependency dependency) { + private static String getMod(ResolvedDependency dependency) { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("schemaVersion", 1); - jsonObject.addProperty("id", (dependency.getGroup() + "_" + dependency.getName()).replaceAll("\\.", "_").toLowerCase(Locale.ENGLISH)); - jsonObject.addProperty("version", dependency.getVersion()); - jsonObject.addProperty("name", dependency.getName()); + jsonObject.addProperty("id", (dependency.getModuleGroup() + "_" + dependency.getModuleName()).replaceAll("\\.", "_").toLowerCase(Locale.ENGLISH)); + jsonObject.addProperty("version", dependency.getModuleVersion()); + jsonObject.addProperty("name", dependency.getModuleName()); return GSON.toJson(jsonObject); }