diff --git a/src/main/java/net/fabricmc/loom/api/LoomGradleExtensionAPI.java b/src/main/java/net/fabricmc/loom/api/LoomGradleExtensionAPI.java index efec199..98cf6db 100644 --- a/src/main/java/net/fabricmc/loom/api/LoomGradleExtensionAPI.java +++ b/src/main/java/net/fabricmc/loom/api/LoomGradleExtensionAPI.java @@ -25,7 +25,6 @@ package net.fabricmc.loom.api; import org.gradle.api.Action; -import org.gradle.api.DomainObjectCollection; import org.gradle.api.NamedDomainObjectContainer; import org.gradle.api.artifacts.Dependency; import org.gradle.api.file.ConfigurableFileCollection; @@ -35,7 +34,7 @@ import org.gradle.api.provider.Property; import org.gradle.api.publish.maven.MavenPublication; import org.jetbrains.annotations.ApiStatus; -import net.fabricmc.loom.api.decompilers.LoomDecompiler; +import net.fabricmc.loom.api.decompilers.DecompilerOptions; import net.fabricmc.loom.api.mappings.layered.spec.LayeredMappingSpecBuilder; import net.fabricmc.loom.configuration.ide.RunConfigSettings; import net.fabricmc.loom.configuration.processors.JarProcessor; @@ -56,11 +55,9 @@ public interface LoomGradleExtensionAPI { getShareRemapCaches().set(true); } - DomainObjectCollection getGameDecompilers(); + NamedDomainObjectContainer getDecompilerOptions(); - default void addDecompiler(LoomDecompiler decompiler) { - getGameDecompilers().add(decompiler); - } + void decompilers(Action> action); ListProperty getGameJarProcessors(); diff --git a/src/main/java/net/fabricmc/loom/api/decompilers/DecompilerOptions.java b/src/main/java/net/fabricmc/loom/api/decompilers/DecompilerOptions.java new file mode 100644 index 0000000..5f278f5 --- /dev/null +++ b/src/main/java/net/fabricmc/loom/api/decompilers/DecompilerOptions.java @@ -0,0 +1,81 @@ +/* + * This file is part of fabric-loom, licensed under the MIT License (MIT). + * + * Copyright (c) 2022 FabricMC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package net.fabricmc.loom.api.decompilers; + +import java.io.Serializable; +import java.util.Map; + +import com.google.common.base.Preconditions; +import org.gradle.api.Named; +import org.gradle.api.file.ConfigurableFileCollection; +import org.gradle.api.provider.MapProperty; +import org.gradle.api.provider.Property; + +public abstract class DecompilerOptions implements Named { + /** + * Class name for to the {@link LoomDecompiler}. + */ + public abstract Property getDecompilerClassname(); + + /** + * Additional classpath entries for the decompiler jvm. + */ + public abstract ConfigurableFileCollection getClasspath(); + + /** + * Additional options to be passed to the decompiler. + */ + public abstract MapProperty getOptions(); + + /** + * Memory used for forked JVM in megabytes. + */ + public abstract Property getMemory(); + + /** + * Maximum number of threads the decompiler is allowed to use. + */ + public abstract Property getMaxThreads(); + + public DecompilerOptions() { + getDecompilerClassname().finalizeValueOnRead(); + getClasspath().finalizeValueOnRead(); + getOptions().finalizeValueOnRead(); + getMemory().convention(4096L).finalizeValueOnRead(); + getMaxThreads().convention(Runtime.getRuntime().availableProcessors()).finalizeValueOnRead(); + } + + // Done to work around weird issues with the workers, possibly https://github.com/gradle/gradle/issues/13422 + public record Dto(String className, Map options, int maxThreads) implements Serializable { } + + public Dto toDto() { + Preconditions.checkArgument(getDecompilerClassname().isPresent(), "No decompiler classname specified for decompiler: " + getName()); + return new Dto( + getDecompilerClassname().get(), + getOptions().get(), + getMaxThreads().get() + ); + } +} diff --git a/src/main/java/net/fabricmc/loom/api/decompilers/LoomDecompiler.java b/src/main/java/net/fabricmc/loom/api/decompilers/LoomDecompiler.java index d903fd9..c69a433 100644 --- a/src/main/java/net/fabricmc/loom/api/decompilers/LoomDecompiler.java +++ b/src/main/java/net/fabricmc/loom/api/decompilers/LoomDecompiler.java @@ -26,13 +26,7 @@ package net.fabricmc.loom.api.decompilers; import java.nio.file.Path; -import org.gradle.api.Project; -import org.gradle.api.file.FileCollection; -import org.jetbrains.annotations.Nullable; - public interface LoomDecompiler { - String name(); - /** * @param sourcesDestination Decompiled sources jar * @param linemapDestination A byproduct of decompilation that lines up the compiled jar's line numbers with the decompiled @@ -41,12 +35,4 @@ public interface LoomDecompiler { * @param metaData Additional information that may or may not be needed while decompiling */ void decompile(Path compiledJar, Path sourcesDestination, Path linemapDestination, DecompilationMetadata metaData); - - /** - * Add additional classpath entries to the decompiler classpath, can return a configuration. - */ - @Nullable - default FileCollection getBootstrapClasspath(Project project) { - return null; - } } diff --git a/src/main/java/net/fabricmc/loom/api/mappings/layered/spec/LayeredMappingSpecBuilder.java b/src/main/java/net/fabricmc/loom/api/mappings/layered/spec/LayeredMappingSpecBuilder.java index f4e5d37..e3faef1 100644 --- a/src/main/java/net/fabricmc/loom/api/mappings/layered/spec/LayeredMappingSpecBuilder.java +++ b/src/main/java/net/fabricmc/loom/api/mappings/layered/spec/LayeredMappingSpecBuilder.java @@ -42,7 +42,7 @@ public interface LayeredMappingSpecBuilder { LayeredMappingSpecBuilder addLayer(MappingsSpec mappingSpec); /** - * Add a layer that uses the official mappings provided by Mojang with the default options. + * Add a layer that uses the official mappings provided by Mojang with the default decompilerOptions. */ default LayeredMappingSpecBuilder officialMojangMappings() { return officialMojangMappings(builder -> { }); diff --git a/src/main/java/net/fabricmc/loom/configuration/decompile/MergedDecompileConfiguration.java b/src/main/java/net/fabricmc/loom/configuration/decompile/MergedDecompileConfiguration.java index c0ae75c..a0b0793 100644 --- a/src/main/java/net/fabricmc/loom/configuration/decompile/MergedDecompileConfiguration.java +++ b/src/main/java/net/fabricmc/loom/configuration/decompile/MergedDecompileConfiguration.java @@ -65,15 +65,16 @@ public final class MergedDecompileConfiguration { final File inputJar = mappedJar; - LoomGradleExtension.get(project).getGameDecompilers().forEach(decompiler -> { - String taskName = "genSourcesWith" + decompiler.name(); + LoomGradleExtension.get(project).getDecompilerOptions().forEach(options -> { + final String decompilerName = options.getName().substring(0, 1).toUpperCase() + options.getName().substring(1); + String taskName = "genSourcesWith" + decompilerName; // Decompiler will be passed to the constructor of GenerateSourcesTask - project.getTasks().register(taskName, GenerateSourcesTask.class, decompiler).configure(task -> { + project.getTasks().register(taskName, GenerateSourcesTask.class, options).configure(task -> { task.getInputJar().set(inputJar); task.getRuntimeJar().set(minecraftProvider.getMergedJar().toFile()); task.dependsOn(project.getTasks().named("validateAccessWidener")); - task.setDescription("Decompile minecraft using %s.".formatted(decompiler.name())); + task.setDescription("Decompile minecraft using %s.".formatted(decompilerName)); task.setGroup(Constants.TaskGroup.FABRIC); if (mappingsProvider.hasUnpickDefinitions()) { diff --git a/src/main/java/net/fabricmc/loom/configuration/decompile/SplitDecompileConfiguration.java b/src/main/java/net/fabricmc/loom/configuration/decompile/SplitDecompileConfiguration.java index d02574e..8c2dde5 100644 --- a/src/main/java/net/fabricmc/loom/configuration/decompile/SplitDecompileConfiguration.java +++ b/src/main/java/net/fabricmc/loom/configuration/decompile/SplitDecompileConfiguration.java @@ -111,13 +111,14 @@ public final class SplitDecompileConfiguration { } private TaskProvider createDecompileTasks(String name, Action configureAction) { - extension.getGameDecompilers().forEach(decompiler -> { - final String taskName = "gen%sSourcesWith%s".formatted(name, decompiler.name()); + extension.getDecompilerOptions().forEach(options -> { + final String decompilerName = options.getName().substring(0, 1).toUpperCase() + options.getName().substring(1); + final String taskName = "gen%sSourcesWith%s".formatted(decompilerName, options.getName()); - project.getTasks().register(taskName, GenerateSourcesTask.class, decompiler).configure(task -> { + project.getTasks().register(taskName, GenerateSourcesTask.class, options).configure(task -> { configureAction.execute(task); task.dependsOn(project.getTasks().named("validateAccessWidener")); - task.setDescription("Decompile minecraft using %s.".formatted(decompiler.name())); + task.setDescription("Decompile minecraft using %s.".formatted(decompilerName)); task.setGroup(Constants.TaskGroup.FABRIC); }); }); diff --git a/src/main/java/net/fabricmc/loom/decompilers/DecompilerConfiguration.java b/src/main/java/net/fabricmc/loom/decompilers/DecompilerConfiguration.java index 0c58e5c..3a75bfd 100644 --- a/src/main/java/net/fabricmc/loom/decompilers/DecompilerConfiguration.java +++ b/src/main/java/net/fabricmc/loom/decompilers/DecompilerConfiguration.java @@ -27,6 +27,7 @@ package net.fabricmc.loom.decompilers; import org.gradle.api.Project; import net.fabricmc.loom.LoomGradleExtension; +import net.fabricmc.loom.api.decompilers.LoomDecompiler; import net.fabricmc.loom.decompilers.cfr.LoomCFRDecompiler; import net.fabricmc.loom.decompilers.fernflower.FabricFernFlowerDecompiler; @@ -35,8 +36,11 @@ public final class DecompilerConfiguration { } public static void setup(Project project) { - LoomGradleExtension extension = LoomGradleExtension.get(project); - extension.getGameDecompilers().add(new FabricFernFlowerDecompiler()); - extension.getGameDecompilers().add(new LoomCFRDecompiler()); + registerDecompiler(project, "fernFlower", FabricFernFlowerDecompiler.class); + registerDecompiler(project, "cfr", LoomCFRDecompiler.class); + } + + private static void registerDecompiler(Project project, String name, Class decompilerClass) { + LoomGradleExtension.get(project).getDecompilerOptions().register(name, options -> options.getDecompilerClassname().set(decompilerClass.getName())); } } diff --git a/src/main/java/net/fabricmc/loom/decompilers/cfr/LoomCFRDecompiler.java b/src/main/java/net/fabricmc/loom/decompilers/cfr/LoomCFRDecompiler.java index cb71513..faf53b1 100644 --- a/src/main/java/net/fabricmc/loom/decompilers/cfr/LoomCFRDecompiler.java +++ b/src/main/java/net/fabricmc/loom/decompilers/cfr/LoomCFRDecompiler.java @@ -30,8 +30,6 @@ import java.io.Writer; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.jar.Attributes; @@ -48,20 +46,14 @@ import org.benf.cfr.reader.util.output.SinkDumperFactory; import net.fabricmc.loom.api.decompilers.DecompilationMetadata; import net.fabricmc.loom.api.decompilers.LoomDecompiler; -import net.fabricmc.loom.decompilers.LineNumberRemapper; -public class LoomCFRDecompiler implements LoomDecompiler { +public final class LoomCFRDecompiler implements LoomDecompiler { private static final Map DECOMPILE_OPTIONS = Map.of( "renameillegalidents", "true", "trackbytecodeloc", "true", "comments", "false" ); - @Override - public String name() { - return "Cfr"; - } - @Override public void decompile(Path compiledJar, Path sourcesDestination, Path linemapDestination, DecompilationMetadata metaData) { final String path = compiledJar.toAbsolutePath().toString(); @@ -132,21 +124,4 @@ public class LoomCFRDecompiler implements LoomDecompiler { throw new UncheckedIOException("Failed to write line map", e); } } - - // A test main class to make it quicker/easier to debug with minimal jars - public static void main(String[] args) throws IOException { - LoomCFRDecompiler decompiler = new LoomCFRDecompiler(); - - Path lineMap = Paths.get("linemap.txt"); - - decompiler.decompile(Paths.get("input.jar"), - Paths.get("output-sources.jar"), - lineMap, - new DecompilationMetadata(4, null, Collections.emptyList(), null, Collections.emptyMap()) - ); - - LineNumberRemapper lineNumberRemapper = new LineNumberRemapper(); - lineNumberRemapper.readMappings(lineMap.toFile()); - lineNumberRemapper.process(null, Paths.get("input.jar"), Paths.get("output.jar")); - } } diff --git a/src/main/java/net/fabricmc/loom/decompilers/fernflower/FabricFernFlowerDecompiler.java b/src/main/java/net/fabricmc/loom/decompilers/fernflower/FabricFernFlowerDecompiler.java index 9ad8111..18d5545 100644 --- a/src/main/java/net/fabricmc/loom/decompilers/fernflower/FabricFernFlowerDecompiler.java +++ b/src/main/java/net/fabricmc/loom/decompilers/fernflower/FabricFernFlowerDecompiler.java @@ -37,11 +37,6 @@ import net.fabricmc.loom.api.decompilers.DecompilationMetadata; import net.fabricmc.loom.api.decompilers.LoomDecompiler; public final class FabricFernFlowerDecompiler implements LoomDecompiler { - @Override - public String name() { - return "FernFlower"; - } - @Override public void decompile(Path compiledJar, Path sourcesDestination, Path linemapDestination, DecompilationMetadata metaData) { final Map options = new HashMap<>( diff --git a/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionApiImpl.java b/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionApiImpl.java index f581567..053614b 100644 --- a/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionApiImpl.java +++ b/src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionApiImpl.java @@ -25,7 +25,6 @@ package net.fabricmc.loom.extension; import org.gradle.api.Action; -import org.gradle.api.DomainObjectCollection; import org.gradle.api.NamedDomainObjectContainer; import org.gradle.api.Project; import org.gradle.api.artifacts.Dependency; @@ -37,7 +36,7 @@ import org.gradle.api.publish.maven.MavenPublication; import net.fabricmc.loom.api.LoomGradleExtensionAPI; import net.fabricmc.loom.api.MixinExtensionAPI; -import net.fabricmc.loom.api.decompilers.LoomDecompiler; +import net.fabricmc.loom.api.decompilers.DecompilerOptions; import net.fabricmc.loom.api.mappings.layered.spec.LayeredMappingSpecBuilder; import net.fabricmc.loom.configuration.ide.RunConfigSettings; import net.fabricmc.loom.configuration.mods.ModVersionParser; @@ -53,7 +52,6 @@ import net.fabricmc.loom.util.DeprecationHelper; */ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionAPI { protected final DeprecationHelper deprecationHelper; - protected final DomainObjectCollection decompilers; protected final ListProperty jarProcessors; protected final ConfigurableFileCollection log4jConfigs; protected final RegularFileProperty accessWidener; @@ -67,12 +65,10 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA private final ModVersionParser versionParser; - private NamedDomainObjectContainer runConfigs; + private final NamedDomainObjectContainer runConfigs; + private final NamedDomainObjectContainer decompilers; protected LoomGradleExtensionApiImpl(Project project, LoomFiles directories) { - this.runConfigs = project.container(RunConfigSettings.class, - baseName -> new RunConfigSettings(project, baseName)); - this.decompilers = project.getObjects().domainObjectSet(LoomDecompiler.class); this.jarProcessors = project.getObjects().listProperty(JarProcessor.class) .empty(); this.log4jConfigs = project.files(directories.getDefaultLog4jConfigFile()); @@ -97,6 +93,10 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA this.deprecationHelper = new DeprecationHelper.ProjectBased(project); + this.runConfigs = project.container(RunConfigSettings.class, + baseName -> new RunConfigSettings(project, baseName)); + this.decompilers = project.getObjects().domainObjectContainer(DecompilerOptions.class); + this.accessWidener.finalizeValueOnRead(); this.getGameJarProcessors().finalizeValueOnRead(); } @@ -117,10 +117,15 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA } @Override - public DomainObjectCollection getGameDecompilers() { + public NamedDomainObjectContainer getDecompilerOptions() { return decompilers; } + @Override + public void decompilers(Action> action) { + action.execute(decompilers); + } + @Override public ListProperty getGameJarProcessors() { return jarProcessors; diff --git a/src/main/java/net/fabricmc/loom/task/GenerateSourcesTask.java b/src/main/java/net/fabricmc/loom/task/GenerateSourcesTask.java index c932418..38e743f 100644 --- a/src/main/java/net/fabricmc/loom/task/GenerateSourcesTask.java +++ b/src/main/java/net/fabricmc/loom/task/GenerateSourcesTask.java @@ -42,13 +42,9 @@ import java.util.stream.Collectors; import javax.inject.Inject; import org.gradle.api.file.ConfigurableFileCollection; -import org.gradle.api.file.FileCollection; import org.gradle.api.file.RegularFileProperty; -import org.gradle.api.provider.MapProperty; import org.gradle.api.provider.Property; -import org.gradle.api.tasks.Input; import org.gradle.api.tasks.InputFile; -import org.gradle.api.tasks.InputFiles; import org.gradle.api.tasks.TaskAction; import org.gradle.workers.WorkAction; import org.gradle.workers.WorkParameters; @@ -58,6 +54,7 @@ import org.gradle.workers.internal.WorkerDaemonClientsManager; import org.jetbrains.annotations.Nullable; import net.fabricmc.loom.api.decompilers.DecompilationMetadata; +import net.fabricmc.loom.api.decompilers.DecompilerOptions; import net.fabricmc.loom.api.decompilers.LoomDecompiler; import net.fabricmc.loom.configuration.accesswidener.AccessWidenerFile; import net.fabricmc.loom.configuration.accesswidener.TransitiveAccessWidenerMappingsProcessor; @@ -73,7 +70,7 @@ import net.fabricmc.loom.util.ipc.IPCClient; import net.fabricmc.loom.util.ipc.IPCServer; public abstract class GenerateSourcesTask extends AbstractLoomTask { - public final LoomDecompiler decompiler; + private final DecompilerOptions decompilerOptions; /** * The jar to decompile, can be the unpick jar. @@ -87,18 +84,6 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask { @InputFile public abstract RegularFileProperty getRuntimeJar(); - /** - * Max memory for forked JVM in megabytes. - */ - @Input - public abstract Property getMaxMemory(); - - @Input - public abstract MapProperty getOptions(); - - @InputFiles - public abstract ConfigurableFileCollection getClasspath(); - @Inject public abstract WorkerExecutor getWorkerExecutor(); @@ -106,21 +91,10 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask { public abstract WorkerDaemonClientsManager getWorkerDaemonClientsManager(); @Inject - public GenerateSourcesTask(LoomDecompiler decompiler) { - this.decompiler = decompiler; - - Objects.requireNonNull(getDecompilerConstructor(this.decompiler.getClass().getCanonicalName()), - "%s must have a no args constructor".formatted(this.decompiler.getClass().getCanonicalName())); - - FileCollection decompilerClasspath = decompiler.getBootstrapClasspath(getProject()); - - if (decompilerClasspath != null) { - getClasspath().from(decompilerClasspath); - } + public GenerateSourcesTask(DecompilerOptions decompilerOptions) { + this.decompilerOptions = decompilerOptions; getOutputs().upToDateWhen((o) -> false); - getMaxMemory().convention(4096L).finalizeValueOnRead(); - getOptions().finalizeValueOnRead(); } @TaskAction @@ -140,9 +114,9 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask { final Path ipcPath = Files.createTempFile("loom", "ipc"); Files.deleteIfExists(ipcPath); - try (ThreadedProgressLoggerConsumer loggerConsumer = new ThreadedProgressLoggerConsumer(getProject(), decompiler.name(), "Decompiling minecraft sources"); + try (ThreadedProgressLoggerConsumer loggerConsumer = new ThreadedProgressLoggerConsumer(getProject(), decompilerOptions.getName(), "Decompiling minecraft sources"); IPCServer logReceiver = new IPCServer(ipcPath, loggerConsumer)) { - doWork(ipcPath); + doWork(logReceiver); } catch (InterruptedException e) { throw new RuntimeException("Failed to shutdown log receiver", e); } finally { @@ -150,14 +124,12 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask { } } - private void doWork(@Nullable Path ipcPath) { + private void doWork(@Nullable IPCServer ipcServer) { final String jvmMarkerValue = UUID.randomUUID().toString(); final WorkQueue workQueue = createWorkQueue(jvmMarkerValue); workQueue.submit(DecompileAction.class, params -> { - params.getDecompilerClass().set(decompiler.getClass().getCanonicalName()); - - params.getOptions().set(getOptions()); + params.getDecompilerOptions().set(decompilerOptions.toDto()); params.getInputJar().set(getInputJar()); params.getRuntimeJar().set(getRuntimeJar()); @@ -166,8 +138,8 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask { params.getLinemapJar().set(getMappedJarFileWithSuffix("-linemapped.jar")); params.getMappings().set(getMappings().toFile()); - if (ipcPath != null) { - params.getIPCPath().set(ipcPath.toFile()); + if (ipcServer != null) { + params.getIPCPath().set(ipcServer.getPath().toFile()); } params.getClassPath().setFrom(getProject().getConfigurations().getByName(Constants.Configurations.MINECRAFT_DEPENDENCIES)); @@ -176,10 +148,10 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask { try { workQueue.await(); } finally { - if (useProcessIsolation()) { + if (ipcServer != null) { boolean stopped = WorkerDaemonClientsManagerHelper.stopIdleJVM(getWorkerDaemonClientsManager(), jvmMarkerValue); - if (!stopped) { + if (!stopped && ipcServer.hasReceivedMessage()) { throw new RuntimeException("Failed to stop decompile worker JVM"); } } @@ -193,9 +165,9 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask { return getWorkerExecutor().processIsolation(spec -> { spec.forkOptions(forkOptions -> { - forkOptions.setMaxHeapSize("%dm".formatted(getMaxMemory().get())); + forkOptions.setMaxHeapSize("%dm".formatted(decompilerOptions.getMemory().get())); forkOptions.systemProperty(WorkerDaemonClientsManagerHelper.MARKER_PROP, jvmMarkerValue); - forkOptions.bootstrapClasspath(getClasspath()); + forkOptions.bootstrapClasspath(decompilerOptions.getClasspath()); }); }); } @@ -206,9 +178,7 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask { } public interface DecompileParams extends WorkParameters { - Property getDecompilerClass(); - - MapProperty getOptions(); + Property getDecompilerOptions(); RegularFileProperty getInputJar(); RegularFileProperty getRuntimeJar(); @@ -247,20 +217,26 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask { final Path linemapJar = getParameters().getLinemapJar().get().getAsFile().toPath(); final Path runtimeJar = getParameters().getRuntimeJar().get().getAsFile().toPath(); + final DecompilerOptions.Dto decompilerOptions = getParameters().getDecompilerOptions().get(); + final LoomDecompiler decompiler; try { - decompiler = getDecompilerConstructor(getParameters().getDecompilerClass().get()).newInstance(); + final String className = decompilerOptions.className(); + final Constructor decompilerConstructor = getDecompilerConstructor(className); + Objects.requireNonNull(decompilerConstructor, "%s must have a no args constructor".formatted(className)); + + decompiler = decompilerConstructor.newInstance(); } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException("Failed to create decompiler", e); } DecompilationMetadata metadata = new DecompilationMetadata( - Runtime.getRuntime().availableProcessors(), + decompilerOptions.maxThreads(), getParameters().getMappings().get().getAsFile().toPath(), getLibraries(), logger, - getParameters().getOptions().get() + decompilerOptions.options() ); decompiler.decompile( diff --git a/src/main/java/net/fabricmc/loom/util/ipc/IPCServer.java b/src/main/java/net/fabricmc/loom/util/ipc/IPCServer.java index 7c8158a..d481083 100644 --- a/src/main/java/net/fabricmc/loom/util/ipc/IPCServer.java +++ b/src/main/java/net/fabricmc/loom/util/ipc/IPCServer.java @@ -46,6 +46,8 @@ public class IPCServer implements AutoCloseable { private final CountDownLatch startupLock = new CountDownLatch(1); + private boolean receivedMessage = false; + public IPCServer(Path path, Consumer consumer) { this.path = path; this.consumer = consumer; @@ -71,6 +73,7 @@ public class IPCServer implements AutoCloseable { Scanner scanner = new Scanner(clientChannel, StandardCharsets.UTF_8)) { while (!Thread.currentThread().isInterrupted()) { if (scanner.hasNextLine()) { + receivedMessage = true; this.consumer.accept(scanner.nextLine()); } } @@ -85,4 +88,12 @@ public class IPCServer implements AutoCloseable { loggerReceiverService.shutdownNow(); loggerReceiverService.awaitTermination(10, TimeUnit.SECONDS); } + + public boolean hasReceivedMessage() { + return receivedMessage; + } + + public Path getPath() { + return path; + } } diff --git a/src/test/resources/projects/decompile/build.gradle b/src/test/resources/projects/decompile/build.gradle index 934a832..993ac66 100644 --- a/src/test/resources/projects/decompile/build.gradle +++ b/src/test/resources/projects/decompile/build.gradle @@ -8,6 +8,13 @@ dependencies { modImplementation "net.fabricmc:fabric-loader:0.11.7" } -tasks.named("genSourcesWithCfr") { - options.put("test", "value") +loom { + decompilers { + cfr { + options.put("test", "value") + } + fernflower { + options.put("test", "value") + } + } } \ No newline at end of file