Allow adding additional jar processors (#247)
* processors * cleanup * oops * make changes * blargh
This commit is contained in:
parent
032ee6f9f1
commit
c4f25622a2
5 changed files with 50 additions and 37 deletions
|
@ -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<LoomDecompiler> decompilers = new ArrayList<>();
|
||||
private final List<JarProcessor> 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<MappingSet> factory) {
|
||||
return srcMappingCache[id] != null ? srcMappingCache[id] : (srcMappingCache[id] = factory.get());
|
||||
}
|
||||
|
@ -338,6 +351,10 @@ public class LoomGradleExtension {
|
|||
this.jarProcessorManager = jarProcessorManager;
|
||||
}
|
||||
|
||||
public List<JarProcessor> getJarProcessors() {
|
||||
return jarProcessors;
|
||||
}
|
||||
|
||||
public String getRefmapName() {
|
||||
if (refmapName == null || refmapName.isEmpty()) {
|
||||
String defaultRefmapName = project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName() + "-refmap.json";
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<JarProcessor> jarProcessors;
|
||||
|
||||
public JarProcessorManager(Project project) {
|
||||
this.project = project;
|
||||
this.extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||
jarProcessors = setupProcessors();
|
||||
public JarProcessorManager(List<JarProcessor> jarProcessors) {
|
||||
this.jarProcessors = jarProcessors;
|
||||
}
|
||||
|
||||
//TODO possibly expand via an API?
|
||||
private List<JarProcessor> setupProcessors() {
|
||||
List<JarProcessor> 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() {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()) {
|
||||
|
|
Loading…
Reference in a new issue