mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-30 13:05:27 -05:00
Add getMappingsFile and getDecompileTask APIs for use by the MC Dev plugin. (#697)
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
|
||||
package net.fabricmc.loom.api;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.gradle.api.Action;
|
||||
@@ -45,6 +46,7 @@ import net.fabricmc.loom.configuration.ide.RunConfigSettings;
|
||||
import net.fabricmc.loom.configuration.processors.JarProcessor;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.NoOpIntermediateMappingsProvider;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftJarConfiguration;
|
||||
import net.fabricmc.loom.task.GenerateSourcesTask;
|
||||
import net.fabricmc.loom.util.DeprecationHelper;
|
||||
|
||||
/**
|
||||
@@ -162,6 +164,17 @@ public interface LoomGradleExtensionAPI {
|
||||
setIntermediateMappingsProvider(NoOpIntermediateMappingsProvider.class, p -> { });
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tiny mappings file used to remap the game and mods.
|
||||
*/
|
||||
File getMappingsFile();
|
||||
|
||||
/**
|
||||
* Returns the {@link GenerateSourcesTask} for the given {@link DecompilerOptions}.
|
||||
* When env source sets are split and the client param is true the decompile task for the client jar will be returned.
|
||||
*/
|
||||
GenerateSourcesTask getDecompileTask(DecompilerOptions options, boolean client);
|
||||
|
||||
/**
|
||||
* Use "%1$s" as a placeholder for the minecraft version.
|
||||
*
|
||||
|
||||
@@ -67,6 +67,10 @@ public abstract class DecompilerOptions implements Named {
|
||||
getMaxThreads().convention(Runtime.getRuntime().availableProcessors()).finalizeValueOnRead();
|
||||
}
|
||||
|
||||
public String getFormattedName() {
|
||||
return getName().substring(0, 1).toUpperCase() + getName().substring(1);
|
||||
}
|
||||
|
||||
// Done to work around weird issues with the workers, possibly https://github.com/gradle/gradle/issues/13422
|
||||
public record Dto(String className, Map<String, String> options, int maxThreads) implements Serializable { }
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ public class SingleJarDecompileConfiguration extends DecompileConfiguration<Mapp
|
||||
final File inputJar = mappedJar;
|
||||
|
||||
LoomGradleExtension.get(project).getDecompilerOptions().forEach(options -> {
|
||||
final String decompilerName = options.getName().substring(0, 1).toUpperCase() + options.getName().substring(1);
|
||||
final String decompilerName = options.getFormattedName();
|
||||
String taskName = "genSourcesWith" + decompilerName;
|
||||
// Decompiler will be passed to the constructor of GenerateSourcesTask
|
||||
project.getTasks().register(taskName, GenerateSourcesTask.class, options).configure(task -> {
|
||||
|
||||
@@ -86,7 +86,7 @@ public final class SplitDecompileConfiguration extends DecompileConfiguration<Ma
|
||||
});
|
||||
|
||||
for (DecompilerOptions options : extension.getDecompilerOptions()) {
|
||||
final String decompilerName = options.getName().substring(0, 1).toUpperCase() + options.getName().substring(1);
|
||||
final String decompilerName = options.getFormattedName();
|
||||
|
||||
project.getTasks().register("genSourcesWith" + decompilerName, task -> {
|
||||
task.setDescription("Decompile minecraft using %s.".formatted(decompilerName));
|
||||
@@ -108,7 +108,7 @@ public final class SplitDecompileConfiguration extends DecompileConfiguration<Ma
|
||||
|
||||
private TaskProvider<Task> createDecompileTasks(String name, Action<GenerateSourcesTask> configureAction) {
|
||||
extension.getDecompilerOptions().forEach(options -> {
|
||||
final String decompilerName = options.getName().substring(0, 1).toUpperCase() + options.getName().substring(1);
|
||||
final String decompilerName = options.getFormattedName();
|
||||
final String taskName = "gen%sSourcesWith%s".formatted(name, decompilerName);
|
||||
|
||||
project.getTasks().register(taskName, GenerateSourcesTask.class, options).configure(task -> {
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
|
||||
package net.fabricmc.loom.extension;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.NamedDomainObjectContainer;
|
||||
import org.gradle.api.NamedDomainObjectList;
|
||||
@@ -36,6 +38,7 @@ import org.gradle.api.provider.Property;
|
||||
import org.gradle.api.publish.maven.MavenPublication;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.api.InterfaceInjectionExtensionAPI;
|
||||
import net.fabricmc.loom.api.LoomGradleExtensionAPI;
|
||||
import net.fabricmc.loom.api.MixinExtensionAPI;
|
||||
@@ -53,6 +56,7 @@ import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpecBuil
|
||||
import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingsDependency;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftJarConfiguration;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftSourceSets;
|
||||
import net.fabricmc.loom.task.GenerateSourcesTask;
|
||||
import net.fabricmc.loom.util.DeprecationHelper;
|
||||
import net.fabricmc.loom.util.gradle.SourceSetHelper;
|
||||
|
||||
@@ -253,6 +257,25 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
|
||||
intermediateMappingsProvider.set(provider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getMappingsFile() {
|
||||
return LoomGradleExtension.get(getProject()).getMappingsProvider().tinyMappings.toFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenerateSourcesTask getDecompileTask(DecompilerOptions options, boolean client) {
|
||||
final String decompilerName = options.getFormattedName();
|
||||
final String taskName;
|
||||
|
||||
if (areEnvironmentSourceSetsSplit()) {
|
||||
taskName = "gen%sSourcesWith%s".formatted(client ? "ClientOnly" : "Common", decompilerName);
|
||||
} else {
|
||||
taskName = "genSourcesWith" + decompilerName;
|
||||
}
|
||||
|
||||
return (GenerateSourcesTask) getProject().getTasks().getByName(taskName);
|
||||
}
|
||||
|
||||
protected abstract <T extends IntermediateMappingsProvider> void configureIntermediateMappingsProviderInternal(T provider);
|
||||
|
||||
@Override
|
||||
|
||||
@@ -50,7 +50,9 @@ import org.gradle.api.file.RegularFileProperty;
|
||||
import org.gradle.api.provider.Property;
|
||||
import org.gradle.api.tasks.InputFile;
|
||||
import org.gradle.api.tasks.InputFiles;
|
||||
import org.gradle.api.tasks.OutputFile;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
import org.gradle.work.DisableCachingByDefault;
|
||||
import org.gradle.workers.WorkAction;
|
||||
import org.gradle.workers.WorkParameters;
|
||||
import org.gradle.workers.WorkQueue;
|
||||
@@ -80,6 +82,7 @@ import net.fabricmc.mappingio.adapter.MappingSourceNsSwitch;
|
||||
import net.fabricmc.mappingio.format.Tiny2Writer;
|
||||
import net.fabricmc.mappingio.tree.MemoryMappingTree;
|
||||
|
||||
@DisableCachingByDefault
|
||||
public abstract class GenerateSourcesTask extends AbstractLoomTask {
|
||||
private final DecompilerOptions decompilerOptions;
|
||||
|
||||
@@ -98,6 +101,9 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
|
||||
@InputFiles
|
||||
public abstract ConfigurableFileCollection getClasspath();
|
||||
|
||||
@OutputFile
|
||||
public abstract RegularFileProperty getOutputJar();
|
||||
|
||||
@Inject
|
||||
public abstract WorkerExecutor getWorkerExecutor();
|
||||
|
||||
@@ -111,6 +117,8 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
|
||||
getOutputs().upToDateWhen((o) -> false);
|
||||
getClasspath().from(decompilerOptions.getClasspath()).finalizeValueOnRead();
|
||||
dependsOn(decompilerOptions.getClasspath().getBuiltBy());
|
||||
|
||||
getOutputJar().fileProvider(getProject().provider(() -> getMappedJarFileWithSuffix("-sources.jar")));
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
@@ -149,7 +157,7 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
|
||||
|
||||
params.getInputJar().set(getInputJar());
|
||||
params.getRuntimeJar().set(getRuntimeJar());
|
||||
params.getSourcesDestinationJar().set(getMappedJarFileWithSuffix("-sources.jar"));
|
||||
params.getSourcesDestinationJar().set(getOutputJar());
|
||||
params.getLinemap().set(getMappedJarFileWithSuffix("-sources.lmap"));
|
||||
params.getLinemapJar().set(getMappedJarFileWithSuffix("-linemapped.jar"));
|
||||
params.getMappings().set(getMappings().toFile());
|
||||
|
||||
Reference in New Issue
Block a user