Allow setting the RemapJarTask classpath. Closes #307
parent
36954809ec
commit
e20993daf8
|
@ -29,11 +29,10 @@ import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import org.gradle.api.Project;
|
import org.gradle.api.Project;
|
||||||
|
import org.gradle.api.file.FileCollection;
|
||||||
import org.gradle.api.file.RegularFileProperty;
|
import org.gradle.api.file.RegularFileProperty;
|
||||||
import org.gradle.api.provider.Property;
|
import org.gradle.api.provider.Property;
|
||||||
import org.gradle.api.tasks.Input;
|
import org.gradle.api.tasks.Input;
|
||||||
|
@ -61,6 +60,7 @@ public class RemapJarTask extends Jar {
|
||||||
private final Property<Boolean> addNestedDependencies;
|
private final Property<Boolean> addNestedDependencies;
|
||||||
private final Property<Boolean> remapAccessWidener;
|
private final Property<Boolean> remapAccessWidener;
|
||||||
public JarRemapper jarRemapper;
|
public JarRemapper jarRemapper;
|
||||||
|
private FileCollection classpath;
|
||||||
|
|
||||||
public RemapJarTask() {
|
public RemapJarTask() {
|
||||||
super();
|
super();
|
||||||
|
@ -95,10 +95,7 @@ public class RemapJarTask extends Jar {
|
||||||
String fromM = "named";
|
String fromM = "named";
|
||||||
String toM = "intermediary";
|
String toM = "intermediary";
|
||||||
|
|
||||||
Set<File> classpathFiles = new LinkedHashSet<>(
|
Path[] classpath = getRemapClasspath();
|
||||||
project.getConfigurations().getByName("compileClasspath").getFiles()
|
|
||||||
);
|
|
||||||
Path[] classpath = classpathFiles.stream().map(File::toPath).filter((p) -> !input.equals(p) && Files.exists(p)).toArray(Path[]::new);
|
|
||||||
|
|
||||||
TinyRemapper.Builder remapperBuilder = TinyRemapper.newRemapper();
|
TinyRemapper.Builder remapperBuilder = TinyRemapper.newRemapper();
|
||||||
|
|
||||||
|
@ -173,16 +170,7 @@ public class RemapJarTask extends Jar {
|
||||||
String toM = "intermediary";
|
String toM = "intermediary";
|
||||||
|
|
||||||
if (extension.isRootProject()) {
|
if (extension.isRootProject()) {
|
||||||
Set<File> classpathFiles = new LinkedHashSet<>(
|
jarRemapper.addToClasspath(getRemapClasspath());
|
||||||
project.getConfigurations().getByName("compileClasspath").getFiles()
|
|
||||||
);
|
|
||||||
|
|
||||||
Path[] classpath = classpathFiles.stream()
|
|
||||||
.map(File::toPath)
|
|
||||||
.filter(Files::exists)
|
|
||||||
.toArray(Path[]::new);
|
|
||||||
|
|
||||||
jarRemapper.addToClasspath(classpath);
|
|
||||||
|
|
||||||
jarRemapper.addMappings(TinyRemapperMappingsHelper.create(mappingsProvider.getMappings(), fromM, toM, false));
|
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
|
@InputFile
|
||||||
public RegularFileProperty getInput() {
|
public RegularFileProperty getInput() {
|
||||||
return input;
|
return input;
|
||||||
|
@ -249,4 +250,14 @@ public class RemapJarTask extends Jar {
|
||||||
public Property<Boolean> getRemapAccessWidener() {
|
public Property<Boolean> getRemapAccessWidener() {
|
||||||
return remapAccessWidener;
|
return remapAccessWidener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RemapJarTask classpath(FileCollection collection) {
|
||||||
|
if (this.classpath == null) {
|
||||||
|
this.classpath = collection;
|
||||||
|
} else {
|
||||||
|
this.classpath = this.classpath.plus(collection);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue