From e20993daf86a4716b8b28d1c51806ddffcae71d0 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Mon, 21 Dec 2020 20:42:23 +0000 Subject: [PATCH] Allow setting the RemapJarTask classpath. Closes #307 --- .../net/fabricmc/loom/task/RemapJarTask.java | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/src/main/java/net/fabricmc/loom/task/RemapJarTask.java b/src/main/java/net/fabricmc/loom/task/RemapJarTask.java index af0e503..3a8b271 100644 --- a/src/main/java/net/fabricmc/loom/task/RemapJarTask.java +++ b/src/main/java/net/fabricmc/loom/task/RemapJarTask.java @@ -29,11 +29,10 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.util.LinkedHashSet; -import java.util.Set; import com.google.common.base.Preconditions; import org.gradle.api.Project; +import org.gradle.api.file.FileCollection; import org.gradle.api.file.RegularFileProperty; import org.gradle.api.provider.Property; import org.gradle.api.tasks.Input; @@ -61,6 +60,7 @@ public class RemapJarTask extends Jar { private final Property addNestedDependencies; private final Property remapAccessWidener; public JarRemapper jarRemapper; + private FileCollection classpath; public RemapJarTask() { super(); @@ -95,10 +95,7 @@ public class RemapJarTask extends Jar { String fromM = "named"; String toM = "intermediary"; - Set classpathFiles = new LinkedHashSet<>( - project.getConfigurations().getByName("compileClasspath").getFiles() - ); - Path[] classpath = classpathFiles.stream().map(File::toPath).filter((p) -> !input.equals(p) && Files.exists(p)).toArray(Path[]::new); + Path[] classpath = getRemapClasspath(); TinyRemapper.Builder remapperBuilder = TinyRemapper.newRemapper(); @@ -173,16 +170,7 @@ public class RemapJarTask extends Jar { String toM = "intermediary"; if (extension.isRootProject()) { - Set classpathFiles = new LinkedHashSet<>( - project.getConfigurations().getByName("compileClasspath").getFiles() - ); - - Path[] classpath = classpathFiles.stream() - .map(File::toPath) - .filter(Files::exists) - .toArray(Path[]::new); - - jarRemapper.addToClasspath(classpath); + jarRemapper.addToClasspath(getRemapClasspath()); jarRemapper.addMappings(TinyRemapperMappingsHelper.create(mappingsProvider.getMappings(), fromM, toM, false)); } @@ -235,6 +223,19 @@ public class RemapJarTask extends Jar { }); } + private Path[] getRemapClasspath() { + FileCollection files = this.classpath; + + if (files == null) { + files = getProject().getConfigurations().getByName("compileClasspath"); + } + + return files.getFiles().stream() + .map(File::toPath) + .filter(Files::exists) + .toArray(Path[]::new); + } + @InputFile public RegularFileProperty getInput() { return input; @@ -249,4 +250,14 @@ public class RemapJarTask extends Jar { public Property getRemapAccessWidener() { return remapAccessWidener; } + + public RemapJarTask classpath(FileCollection collection) { + if (this.classpath == null) { + this.classpath = collection; + } else { + this.classpath = this.classpath.plus(collection); + } + + return this; + } }