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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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;

View file

@ -34,6 +34,7 @@ import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import org.gradle.api.Action;
import org.objectweb.asm.commons.Remapper;
import net.fabricmc.stitch.util.Pair;
@ -46,6 +47,7 @@ public class JarRemapper {
private final List<IMappingProvider> mappingProviders = new ArrayList<>();
private final Set<Path> classPath = new HashSet<>();
private final List<RemapData> remapData = new ArrayList<>();
private List<Action<TinyRemapper.Builder>> remapOptions;
public void addMappings(IMappingProvider mappingProvider) {
mappingProviders.add(mappingProvider);
@ -65,6 +67,12 @@ public class JarRemapper {
TinyRemapper.Builder remapperBuilder = TinyRemapper.newRemapper();
mappingProviders.forEach(remapperBuilder::withMappings);
if (remapOptions != null) {
for (Action<TinyRemapper.Builder> remapOption : remapOptions) {
remapOption.execute(remapperBuilder);
}
}
TinyRemapper remapper = remapperBuilder.build();
Path[] remapClasspath = classPath.stream()
@ -102,6 +110,10 @@ public class JarRemapper {
remapData.forEach(RemapData::complete);
}
public void addOptions(List<Action<TinyRemapper.Builder>> remapOptions) {
this.remapOptions = remapOptions;
}
public static class RemapData {
public final Path input;
public final Path output;