Allow adding additional jar processors (#247)

* processors

* cleanup

* oops

* make changes

* blargh
dev/0.11
Fudge 2020-08-24 22:10:21 +03:00 committed by GitHub
parent 032ee6f9f1
commit c4f25622a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 37 deletions

View File

@ -47,6 +47,7 @@ import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.plugins.BasePluginConvention; import org.gradle.api.plugins.BasePluginConvention;
import net.fabricmc.loom.api.decompilers.LoomDecompiler; import net.fabricmc.loom.api.decompilers.LoomDecompiler;
import net.fabricmc.loom.processors.JarProcessor;
import net.fabricmc.loom.processors.JarProcessorManager; import net.fabricmc.loom.processors.JarProcessorManager;
import net.fabricmc.loom.providers.MappingsProvider; import net.fabricmc.loom.providers.MappingsProvider;
import net.fabricmc.loom.providers.MinecraftMappedProvider; import net.fabricmc.loom.providers.MinecraftMappedProvider;
@ -67,6 +68,7 @@ public class LoomGradleExtension {
private final ConfigurableFileCollection unmappedMods; private final ConfigurableFileCollection unmappedMods;
final List<LoomDecompiler> decompilers = new ArrayList<>(); final List<LoomDecompiler> decompilers = new ArrayList<>();
private final List<JarProcessor> jarProcessors = new ArrayList<>();
// Not to be set in the build.gradle // Not to be set in the build.gradle
private final Project project; private final Project project;
@ -84,6 +86,17 @@ public class LoomGradleExtension {
decompilers.add(decompiler); decompilers.add(decompiler);
} }
/**
* Add a transformation over the mapped mc jar.
* Adding any jar processor will cause mapped mc jars to be stored per-project so that
* different transformation can be applied in different projects.
* This means remapping will need to be done individually per-project, which is slower when developing
* more than one project using the same minecraft version.
*/
public void addJarProcessor(JarProcessor processor) {
jarProcessors.add(processor);
}
public MappingSet getOrCreateSrcMappingCache(int id, Supplier<MappingSet> factory) { public MappingSet getOrCreateSrcMappingCache(int id, Supplier<MappingSet> factory) {
return srcMappingCache[id] != null ? srcMappingCache[id] : (srcMappingCache[id] = factory.get()); return srcMappingCache[id] != null ? srcMappingCache[id] : (srcMappingCache[id] = factory.get());
} }
@ -338,6 +351,10 @@ public class LoomGradleExtension {
this.jarProcessorManager = jarProcessorManager; this.jarProcessorManager = jarProcessorManager;
} }
public List<JarProcessor> getJarProcessors() {
return jarProcessors;
}
public String getRefmapName() { public String getRefmapName() {
if (refmapName == null || refmapName.isEmpty()) { if (refmapName == null || refmapName.isEmpty()) {
String defaultRefmapName = project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName() + "-refmap.json"; String defaultRefmapName = project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName() + "-refmap.json";

View File

@ -26,12 +26,16 @@ package net.fabricmc.loom.processors;
import java.io.File; import java.io.File;
import org.gradle.api.Project;
public interface JarProcessor { public interface JarProcessor {
void setup(Project project); void setup();
/**
* Currently this is a destructive process that replaces the existing jar.
*/
void process(File file); void process(File file);
/**
* Return true to make all jar processors run again, return false to use the existing results of jar processing.
*/
boolean isInvalid(File file); boolean isInvalid(File file);
} }

View File

@ -25,37 +25,17 @@
package net.fabricmc.loom.processors; package net.fabricmc.loom.processors;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.gradle.api.Project;
import net.fabricmc.loom.util.accesswidener.AccessWidenerJarProcessor;
import net.fabricmc.loom.LoomGradleExtension;
public class JarProcessorManager { public class JarProcessorManager {
private final Project project;
private final LoomGradleExtension extension;
private final List<JarProcessor> jarProcessors; private final List<JarProcessor> jarProcessors;
public JarProcessorManager(Project project) { public JarProcessorManager(List<JarProcessor> jarProcessors) {
this.project = project; this.jarProcessors = jarProcessors;
this.extension = project.getExtensions().getByType(LoomGradleExtension.class);
jarProcessors = setupProcessors();
} }
//TODO possibly expand via an API? public void setupProcessors() {
private List<JarProcessor> setupProcessors() { jarProcessors.forEach(JarProcessor::setup);
List<JarProcessor> jarProcessors = new ArrayList<>();
if (extension.accessWidener != null) {
jarProcessors.add(new AccessWidenerJarProcessor());
}
jarProcessors.forEach(jarProcessor -> jarProcessor.setup(project));
return Collections.unmodifiableList(jarProcessors);
} }
public boolean active() { public boolean active() {

View File

@ -44,18 +44,20 @@ import org.zeroturnaround.zip.FileSource;
import org.zeroturnaround.zip.ZipEntrySource; import org.zeroturnaround.zip.ZipEntrySource;
import org.zeroturnaround.zip.ZipUtil; import org.zeroturnaround.zip.ZipUtil;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.processors.JarProcessorManager;
import net.fabricmc.loom.processors.MinecraftProcessedProvider;
import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.DeletingFileVisitor;
import net.fabricmc.loom.util.DependencyProvider; import net.fabricmc.loom.util.DependencyProvider;
import net.fabricmc.loom.util.DownloadUtil; import net.fabricmc.loom.util.DownloadUtil;
import net.fabricmc.loom.util.accesswidener.AccessWidenerJarProcessor;
import net.fabricmc.mapping.reader.v2.TinyV2Factory; import net.fabricmc.mapping.reader.v2.TinyV2Factory;
import net.fabricmc.mapping.tree.TinyTree; import net.fabricmc.mapping.tree.TinyTree;
import net.fabricmc.stitch.Command; import net.fabricmc.stitch.Command;
import net.fabricmc.stitch.commands.CommandProposeFieldNames; import net.fabricmc.stitch.commands.CommandProposeFieldNames;
import net.fabricmc.stitch.commands.tinyv2.CommandMergeTinyV2; import net.fabricmc.stitch.commands.tinyv2.CommandMergeTinyV2;
import net.fabricmc.stitch.commands.tinyv2.CommandReorderTinyV2; import net.fabricmc.stitch.commands.tinyv2.CommandReorderTinyV2;
import net.fabricmc.loom.processors.JarProcessorManager;
import net.fabricmc.loom.processors.MinecraftProcessedProvider;
import net.fabricmc.loom.util.DeletingFileVisitor;
public class MappingsProvider extends DependencyProvider { public class MappingsProvider extends DependencyProvider {
public MinecraftMappedProvider mappedProvider; public MinecraftMappedProvider mappedProvider;
@ -140,8 +142,15 @@ public class MappingsProvider extends DependencyProvider {
addDependency(tinyMappingsJar, Constants.MAPPINGS_FINAL); addDependency(tinyMappingsJar, Constants.MAPPINGS_FINAL);
JarProcessorManager processorManager = new JarProcessorManager(getProject()); LoomGradleExtension extension = getExtension();
getExtension().setJarProcessorManager(processorManager);
if (extension.accessWidener != null) {
extension.addJarProcessor(new AccessWidenerJarProcessor(getProject()));
}
JarProcessorManager processorManager = new JarProcessorManager(extension.getJarProcessors());
extension.setJarProcessorManager(processorManager);
processorManager.setupProcessors();
if (processorManager.active()) { if (processorManager.active()) {
mappedProvider = new MinecraftProcessedProvider(getProject(), processorManager); mappedProvider = new MinecraftProcessedProvider(getProject(), processorManager);

View File

@ -50,20 +50,23 @@ import org.zeroturnaround.zip.transform.ByteArrayZipEntryTransformer;
import org.zeroturnaround.zip.transform.ZipEntryTransformer; import org.zeroturnaround.zip.transform.ZipEntryTransformer;
import org.zeroturnaround.zip.transform.ZipEntryTransformerEntry; import org.zeroturnaround.zip.transform.ZipEntryTransformerEntry;
import net.fabricmc.mappings.EntryTriple;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.Checksum;
import net.fabricmc.loom.processors.JarProcessor; import net.fabricmc.loom.processors.JarProcessor;
import net.fabricmc.loom.util.Checksum;
import net.fabricmc.mappings.EntryTriple;
import net.fabricmc.tinyremapper.TinyRemapper; import net.fabricmc.tinyremapper.TinyRemapper;
public class AccessWidenerJarProcessor implements JarProcessor { public class AccessWidenerJarProcessor implements JarProcessor {
private AccessWidener accessWidener = new AccessWidener(); private AccessWidener accessWidener = new AccessWidener();
private Project project; private final Project project;
private byte[] inputHash; private byte[] inputHash;
@Override public AccessWidenerJarProcessor(Project project) {
public void setup(Project project) {
this.project = project; this.project = project;
}
@Override
public void setup() {
LoomGradleExtension loomGradleExtension = project.getExtensions().getByType(LoomGradleExtension.class); LoomGradleExtension loomGradleExtension = project.getExtensions().getByType(LoomGradleExtension.class);
if (!loomGradleExtension.accessWidener.exists()) { if (!loomGradleExtension.accessWidener.exists()) {