diff --git a/src/main/java/net/fabricmc/loom/LoomGradleExtension.java b/src/main/java/net/fabricmc/loom/LoomGradleExtension.java index a93a0c3..a15623c 100644 --- a/src/main/java/net/fabricmc/loom/LoomGradleExtension.java +++ b/src/main/java/net/fabricmc/loom/LoomGradleExtension.java @@ -47,6 +47,7 @@ import org.gradle.api.file.ConfigurableFileCollection; import org.gradle.api.plugins.BasePluginConvention; import net.fabricmc.loom.api.decompilers.LoomDecompiler; +import net.fabricmc.loom.processors.JarProcessor; import net.fabricmc.loom.processors.JarProcessorManager; import net.fabricmc.loom.providers.MappingsProvider; import net.fabricmc.loom.providers.MinecraftMappedProvider; @@ -67,6 +68,7 @@ public class LoomGradleExtension { private final ConfigurableFileCollection unmappedMods; final List decompilers = new ArrayList<>(); + private final List jarProcessors = new ArrayList<>(); // Not to be set in the build.gradle private final Project project; @@ -84,6 +86,17 @@ public class LoomGradleExtension { 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 factory) { return srcMappingCache[id] != null ? srcMappingCache[id] : (srcMappingCache[id] = factory.get()); } @@ -338,6 +351,10 @@ public class LoomGradleExtension { this.jarProcessorManager = jarProcessorManager; } + public List getJarProcessors() { + return jarProcessors; + } + public String getRefmapName() { if (refmapName == null || refmapName.isEmpty()) { String defaultRefmapName = project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName() + "-refmap.json"; diff --git a/src/main/java/net/fabricmc/loom/processors/JarProcessor.java b/src/main/java/net/fabricmc/loom/processors/JarProcessor.java index 59bd548..0a02894 100644 --- a/src/main/java/net/fabricmc/loom/processors/JarProcessor.java +++ b/src/main/java/net/fabricmc/loom/processors/JarProcessor.java @@ -26,12 +26,16 @@ package net.fabricmc.loom.processors; import java.io.File; -import org.gradle.api.Project; - public interface JarProcessor { - void setup(Project project); + void setup(); + /** + * Currently this is a destructive process that replaces the existing jar. + */ 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); } diff --git a/src/main/java/net/fabricmc/loom/processors/JarProcessorManager.java b/src/main/java/net/fabricmc/loom/processors/JarProcessorManager.java index 579296c..ab0d86d 100644 --- a/src/main/java/net/fabricmc/loom/processors/JarProcessorManager.java +++ b/src/main/java/net/fabricmc/loom/processors/JarProcessorManager.java @@ -25,37 +25,17 @@ package net.fabricmc.loom.processors; import java.io.File; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import org.gradle.api.Project; - -import net.fabricmc.loom.util.accesswidener.AccessWidenerJarProcessor; -import net.fabricmc.loom.LoomGradleExtension; - public class JarProcessorManager { - private final Project project; - private final LoomGradleExtension extension; - private final List jarProcessors; - public JarProcessorManager(Project project) { - this.project = project; - this.extension = project.getExtensions().getByType(LoomGradleExtension.class); - jarProcessors = setupProcessors(); + public JarProcessorManager(List jarProcessors) { + this.jarProcessors = jarProcessors; } - //TODO possibly expand via an API? - private List setupProcessors() { - List jarProcessors = new ArrayList<>(); - - if (extension.accessWidener != null) { - jarProcessors.add(new AccessWidenerJarProcessor()); - } - - jarProcessors.forEach(jarProcessor -> jarProcessor.setup(project)); - return Collections.unmodifiableList(jarProcessors); + public void setupProcessors() { + jarProcessors.forEach(JarProcessor::setup); } public boolean active() { diff --git a/src/main/java/net/fabricmc/loom/providers/MappingsProvider.java b/src/main/java/net/fabricmc/loom/providers/MappingsProvider.java index 17b4daa..21c9b1f 100644 --- a/src/main/java/net/fabricmc/loom/providers/MappingsProvider.java +++ b/src/main/java/net/fabricmc/loom/providers/MappingsProvider.java @@ -44,18 +44,20 @@ import org.zeroturnaround.zip.FileSource; import org.zeroturnaround.zip.ZipEntrySource; 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.DeletingFileVisitor; import net.fabricmc.loom.util.DependencyProvider; import net.fabricmc.loom.util.DownloadUtil; +import net.fabricmc.loom.util.accesswidener.AccessWidenerJarProcessor; import net.fabricmc.mapping.reader.v2.TinyV2Factory; import net.fabricmc.mapping.tree.TinyTree; import net.fabricmc.stitch.Command; import net.fabricmc.stitch.commands.CommandProposeFieldNames; import net.fabricmc.stitch.commands.tinyv2.CommandMergeTinyV2; 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 MinecraftMappedProvider mappedProvider; @@ -140,8 +142,15 @@ public class MappingsProvider extends DependencyProvider { addDependency(tinyMappingsJar, Constants.MAPPINGS_FINAL); - JarProcessorManager processorManager = new JarProcessorManager(getProject()); - getExtension().setJarProcessorManager(processorManager); + LoomGradleExtension extension = getExtension(); + + if (extension.accessWidener != null) { + extension.addJarProcessor(new AccessWidenerJarProcessor(getProject())); + } + + JarProcessorManager processorManager = new JarProcessorManager(extension.getJarProcessors()); + extension.setJarProcessorManager(processorManager); + processorManager.setupProcessors(); if (processorManager.active()) { mappedProvider = new MinecraftProcessedProvider(getProject(), processorManager); diff --git a/src/main/java/net/fabricmc/loom/util/accesswidener/AccessWidenerJarProcessor.java b/src/main/java/net/fabricmc/loom/util/accesswidener/AccessWidenerJarProcessor.java index ede382b..4770c38 100644 --- a/src/main/java/net/fabricmc/loom/util/accesswidener/AccessWidenerJarProcessor.java +++ b/src/main/java/net/fabricmc/loom/util/accesswidener/AccessWidenerJarProcessor.java @@ -50,20 +50,23 @@ import org.zeroturnaround.zip.transform.ByteArrayZipEntryTransformer; import org.zeroturnaround.zip.transform.ZipEntryTransformer; import org.zeroturnaround.zip.transform.ZipEntryTransformerEntry; -import net.fabricmc.mappings.EntryTriple; import net.fabricmc.loom.LoomGradleExtension; -import net.fabricmc.loom.util.Checksum; import net.fabricmc.loom.processors.JarProcessor; +import net.fabricmc.loom.util.Checksum; +import net.fabricmc.mappings.EntryTriple; import net.fabricmc.tinyremapper.TinyRemapper; public class AccessWidenerJarProcessor implements JarProcessor { private AccessWidener accessWidener = new AccessWidener(); - private Project project; + private final Project project; private byte[] inputHash; - @Override - public void setup(Project project) { + public AccessWidenerJarProcessor(Project project) { this.project = project; + } + + @Override + public void setup() { LoomGradleExtension loomGradleExtension = project.getExtensions().getByType(LoomGradleExtension.class); if (!loomGradleExtension.accessWidener.exists()) {