Add ability to specify additional tiny remapper options in remapJar (#292)

* Add ability to specify additional tiny remapper options in remapJar

* Imports go brr

* Fix checkstyle

Co-authored-by: modmuss50 <modmuss50@gmail.com>
This commit is contained in:
i509VCB
2020-12-21 15:02:39 -06:00
committed by GitHub
parent e20993daf8
commit b0860c36d6
2 changed files with 28 additions and 0 deletions

View File

@@ -29,8 +29,11 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import com.google.common.base.Preconditions;
import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.RegularFileProperty;
@@ -59,6 +62,7 @@ public class RemapJarTask extends Jar {
private final RegularFileProperty input;
private final Property<Boolean> addNestedDependencies;
private final Property<Boolean> remapAccessWidener;
private final List<Action<TinyRemapper.Builder>> remapOptions = new ArrayList<>();
public JarRemapper jarRemapper;
private FileCollection classpath;
@@ -107,6 +111,11 @@ public class RemapJarTask extends Jar {
}
}
// Apply any requested options to tiny remapper
for (Action<TinyRemapper.Builder> remapOption : this.remapOptions) {
remapOption.execute(remapperBuilder);
}
project.getLogger().lifecycle(":remapping " + input.getFileName());
StringBuilder rc = new StringBuilder("Remap classpath: ");
@@ -181,6 +190,9 @@ public class RemapJarTask extends Jar {
}
}
// Add remap options to the jar remapper
jarRemapper.addOptions(this.remapOptions);
jarRemapper.scheduleRemap(input, output)
.supplyAccessWidener((remapData, remapper) -> {
if (getRemapAccessWidener().getOrElse(false) && extension.accessWidener != null) {
@@ -251,6 +263,10 @@ public class RemapJarTask extends Jar {
return remapAccessWidener;
}
public void remapOptions(Action<TinyRemapper.Builder> action) {
this.remapOptions.add(action);
}
public RemapJarTask classpath(FileCollection collection) {
if (this.classpath == null) {
this.classpath = collection;