diff --git a/build.gradle b/build.gradle index 81b5b549a4..68aafd4b88 100644 --- a/build.gradle +++ b/build.gradle @@ -190,6 +190,7 @@ task mappings(type: EnigmaMappingsTask, dependsOn: "mapPerVersionMappingsJar") { build.dependsOn constantsJar, generatePackageInfoMappings +// TODO despaghetify this task v2UnmergedMappingsJar(type: MappingsV2JarTask, dependsOn: [insertAutoGeneratedMappings, combineUnpickDefinitions]) { archiveFileName = "${Constants.MAPPINGS_NAME}-${Constants.MAPPINGS_VERSION}-v2.jar" mappings = insertAutoGeneratedMappings.outputMappings diff --git a/buildSrc/src/main/java/quilt/internal/MappingsPlugin.java b/buildSrc/src/main/java/quilt/internal/MappingsPlugin.java index 5a2b76350b..d945fadb1a 100644 --- a/buildSrc/src/main/java/quilt/internal/MappingsPlugin.java +++ b/buildSrc/src/main/java/quilt/internal/MappingsPlugin.java @@ -57,11 +57,7 @@ public abstract class MappingsPlugin implements Plugin { public static Provider provideMappingsDestFile( Provider destDir, String mappingsName, String fileExt ) { - return destDir.map(dir -> dir.file(destFileNameOf(mappingsName, fileExt))); - } - - public static String destFileNameOf(String mappingsName, String fileExt) { - return Constants.MINECRAFT_VERSION + "-" + mappingsName + "." + fileExt; + return destDir.map(dir -> dir.file(Constants.MINECRAFT_VERSION + "-" + mappingsName + "." + fileExt)); } @Override @@ -177,17 +173,50 @@ public void apply(@NotNull Project project) { ); } ); - tasks.register(InvertPerVersionMappingsTask.TASK_NAME, InvertPerVersionMappingsTask.class); + final var invertPerVersionMappings = + tasks.register(InvertPerVersionMappingsTask.TASK_NAME, InvertPerVersionMappingsTask.class); final var buildMappingsTiny = tasks.register(BuildMappingsTinyTask.TASK_NAME, BuildMappingsTinyTask.class); - tasks.register(INSERT_AUTO_GENERATED_MAPPINGS_TASK_NAME, AddProposedMappingsTask.class, task -> { - task.dependsOn(downloadPerVersionMappings); + final var insertAutoGeneratedMappings = tasks.register( + INSERT_AUTO_GENERATED_MAPPINGS_TASK_NAME, AddProposedMappingsTask.class, + task -> { + // TODO eliminate this + task.dependsOn(downloadPerVersionMappings); + + task.getInputJar().convention(() -> ext.getFileConstants().perVersionMappingsJar); - task.getInputJar().convention(() -> ext.getFileConstants().perVersionMappingsJar); - task.getInputMappings().convention(buildMappingsTiny.flatMap(BuildMappingsTinyTask::getOutputMappings)); + task.getInputMappings().convention(buildMappingsTiny.flatMap(BuildMappingsTinyTask::getOutputMappings)); + + task.getOutputMappings().convention(() -> + new File(ext.getFileConstants().buildDir, INSERT_AUTO_GENERATED_MAPPINGS_TASK_NAME + ".tiny") + ); }); - tasks.register(MergeTinyTask.TASK_NAME, MergeTinyTask.class); - tasks.register(MergeTinyV2Task.TASK_NAME, MergeTinyV2Task.class); + tasks.register( + MergeTinyTask.TASK_NAME, MergeTinyTask.class, + task -> { + task.getInput().convention(buildMappingsTiny.flatMap(BuildMappingsTinyTask::getOutputMappings)); + + task.getHashedTinyMappings().convention( + invertPerVersionMappings.flatMap(InvertPerVersionMappingsTask::getInvertedTinyFile) + ); + + task.getOutputMappings().convention(() -> new File(ext.getFileConstants().buildDir, "mappings.tiny")); + } + ); + final var mergeTinyV2 = tasks.register(MergeTinyV2Task.TASK_NAME, MergeTinyV2Task.class, task -> { + // TODO eliminate this + task.dependsOn("v2UnmergedMappingsJar"); + + task.getInput().convention( + insertAutoGeneratedMappings.flatMap(AddProposedMappingsTask::getOutputMappings) + ); + + task.getHashedTinyMappings().convention( + invertPerVersionMappings.flatMap(InvertPerVersionMappingsTask::getInvertedTinyFile) + ); + + task.getOutputMappings().convention(() -> new File(ext.getFileConstants().buildDir, "merged2.tiny")); + }); tasks.register(TinyJarTask.TASK_NAME, TinyJarTask.class); tasks.register(CompressTinyTask.TASK_NAME, CompressTinyTask.class); tasks.register(DropInvalidMappingsTask.TASK_NAME, DropInvalidMappingsTask.class); @@ -240,12 +269,10 @@ public void apply(@NotNull Project project) { ); task.dependsOn(checkIntermediaryMappings); - task.onlyIf(unused -> - checkIntermediaryMappings.get().isPresent() - ); + task.onlyIf(unused -> checkIntermediaryMappings.get().isPresent()); } ); - tasks.register( + final var extractTinyIntermediaryMappings = tasks.register( EXTRACT_TINY_INTERMEDIARY_MAPPINGS_TASK_NAME, ExtractTinyMappingsTask.class, task -> { task.getJarFile().convention(downloadIntermediaryMappings.flatMap(DownloadMappingsTask::getJarFile)); @@ -254,7 +281,22 @@ public void apply(@NotNull Project project) { ); } ); - tasks.register(MergeIntermediaryTask.TASK_NAME, MergeIntermediaryTask.class); + tasks.register( + MergeIntermediaryTask.TASK_NAME, MergeIntermediaryTask.class, + task -> { + task.onlyIf(unused -> checkIntermediaryMappings.get().isPresent()); + + task.getInput().convention( + extractTinyIntermediaryMappings.flatMap(ExtractTinyMappingsTask::getTinyFile) + ); + + task.getMergedTinyMappings().convention(mergeTinyV2.flatMap(MergeTinyV2Task::getOutputMappings)); + + task.getOutputMappings().convention(() -> + new File(ext.getFileConstants().buildDir, "mappings-intermediaryMerged.tiny") + ); + } + ); tasks.register(RemoveIntermediaryTask.TASK_NAME, RemoveIntermediaryTask.class); tasks.register(CheckTargetVersionExistsTask.TASK_NAME, CheckTargetVersionExistsTask.class); diff --git a/buildSrc/src/main/java/quilt/internal/tasks/build/AbstractHashedMergeTask.java b/buildSrc/src/main/java/quilt/internal/tasks/build/AbstractHashedMergeTask.java index 897b59f87f..bb132a2678 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/build/AbstractHashedMergeTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/build/AbstractHashedMergeTask.java @@ -1,20 +1,19 @@ package quilt.internal.tasks.build; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.tasks.InputFile; import quilt.internal.Constants; -import java.io.File; - public abstract class AbstractHashedMergeTask extends AbstractTinyMergeTask { - public AbstractHashedMergeTask(String outputMappings) { - super(outputMappings, Constants.PER_VERSION_MAPPINGS_NAME); + @InputFile + public abstract RegularFileProperty getHashedTinyMappings(); + + public AbstractHashedMergeTask() { + super(Constants.PER_VERSION_MAPPINGS_NAME); } @Override public void mergeMappings() throws Exception { - final File hashedTinyInput = - this.getTaskNamed(InvertPerVersionMappingsTask.TASK_NAME, InvertPerVersionMappingsTask.class) - .getInvertedTinyFile().get().getAsFile(); - - this.mergeMappings(hashedTinyInput); + this.mergeMappings(this.getHashedTinyMappings().get().getAsFile()); } } diff --git a/buildSrc/src/main/java/quilt/internal/tasks/build/AbstractTinyMergeTask.java b/buildSrc/src/main/java/quilt/internal/tasks/build/AbstractTinyMergeTask.java index 29a9032a43..ac2d46e6be 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/build/AbstractTinyMergeTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/build/AbstractTinyMergeTask.java @@ -24,7 +24,7 @@ public abstract class AbstractTinyMergeTask extends DefaultMappingsTask { @InputFile - protected abstract RegularFileProperty getInput(); + public abstract RegularFileProperty getInput(); @OutputFile public abstract RegularFileProperty getOutputMappings(); @@ -32,16 +32,12 @@ public abstract class AbstractTinyMergeTask extends DefaultMappingsTask { protected final String mergeName; protected final String fillName; - public AbstractTinyMergeTask(String outputMappings, String mergeName) { - this(outputMappings, mergeName, mergeName); + public AbstractTinyMergeTask(String mergeName) { + this(mergeName, mergeName); } - public AbstractTinyMergeTask(String outputMappings, String mergeName, String fillName) { + public AbstractTinyMergeTask(String mergeName, String fillName) { super(Constants.Groups.BUILD_MAPPINGS_GROUP); - this.getOutputMappings().convention(() -> new File(this.fileConstants.buildDir, outputMappings)); - this.getOutputs().file(this.getOutputMappings()); - - this.getInput().convention(this.getProject().getObjects().fileProperty()); this.mergeName = mergeName; this.fillName = fillName; diff --git a/buildSrc/src/main/java/quilt/internal/tasks/build/AddProposedMappingsTask.java b/buildSrc/src/main/java/quilt/internal/tasks/build/AddProposedMappingsTask.java index dd6ce01542..48b52c6d91 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/build/AddProposedMappingsTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/build/AddProposedMappingsTask.java @@ -1,7 +1,6 @@ package quilt.internal.tasks.build; import java.io.BufferedWriter; -import java.io.File; import java.io.PrintWriter; import java.io.Reader; import java.nio.charset.StandardCharsets; @@ -41,18 +40,17 @@ import quilt.internal.util.ProviderUtil; public abstract class AddProposedMappingsTask extends EnigmaProfileConsumingTask { - @OutputFile - public abstract RegularFileProperty getOutputMappings(); - @InputFile public abstract RegularFileProperty getInputJar(); @InputFile public abstract RegularFileProperty getInputMappings(); + @OutputFile + public abstract RegularFileProperty getOutputMappings(); + public AddProposedMappingsTask() { super(Constants.Groups.BUILD_MAPPINGS_GROUP); - this.getOutputMappings().convention(() -> new File(this.fileConstants.buildDir, this.getName() + ".tiny")); } @TaskAction diff --git a/buildSrc/src/main/java/quilt/internal/tasks/build/MergeIntermediaryTask.java b/buildSrc/src/main/java/quilt/internal/tasks/build/MergeIntermediaryTask.java index 389a4c606e..8bfd1de972 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/build/MergeIntermediaryTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/build/MergeIntermediaryTask.java @@ -2,16 +2,14 @@ import net.fabricmc.mappingio.MappingVisitor; import net.fabricmc.mappingio.adapter.MappingDstNsReorder; + +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.tasks.InputFile; import org.jetbrains.annotations.VisibleForTesting; import quilt.internal.Constants; -import quilt.internal.MappingsPlugin; import quilt.internal.mappingio.DoubleNsCompleterVisitor; import quilt.internal.mappingio.UnmappedNameRemoverVisitor; -import quilt.internal.tasks.setup.CheckIntermediaryMappingsTask; -import quilt.internal.tasks.setup.DownloadIntermediaryMappingsTask; -import quilt.internal.tasks.setup.ExtractTinyMappingsTask; -import java.io.File; import java.io.IOException; import java.nio.file.Path; import java.util.List; @@ -19,33 +17,19 @@ public abstract class MergeIntermediaryTask extends AbstractTinyMergeTask { public static final String TASK_NAME = "mergeIntermediary"; + @InputFile + public abstract RegularFileProperty getMergedTinyMappings(); + public MergeIntermediaryTask() { super( - "mappings-intermediaryMerged.tiny", - "intermediary", + Constants.INTERMEDIARY_MAPPINGS_NAME, Constants.PER_VERSION_MAPPINGS_NAME ); - this.dependsOn( - CheckIntermediaryMappingsTask.TASK_NAME, - DownloadIntermediaryMappingsTask.TASK_NAME, - MergeTinyV2Task.TASK_NAME - ); - this.onlyIf(task -> - this.getTaskNamed(CheckIntermediaryMappingsTask.TASK_NAME, CheckIntermediaryMappingsTask.class).isPresent() - ); - - this.getInput().convention( - this.getTaskNamed( - MappingsPlugin.EXTRACT_TINY_INTERMEDIARY_MAPPINGS_TASK_NAME, ExtractTinyMappingsTask.class - ).getTinyFile() - ); } @Override public void mergeMappings() throws Exception { - final File tinyInput = this.getTaskNamed(MergeTinyV2Task.TASK_NAME, MergeTinyV2Task.class) - .getOutputMappings().get().getAsFile(); - this.mergeMappings(tinyInput); + this.mergeMappings(this.getMergedTinyMappings().get().getAsFile()); } @Override diff --git a/buildSrc/src/main/java/quilt/internal/tasks/build/MergeTinyTask.java b/buildSrc/src/main/java/quilt/internal/tasks/build/MergeTinyTask.java index e271e6deef..365ea3b46c 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/build/MergeTinyTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/build/MergeTinyTask.java @@ -9,15 +9,6 @@ public abstract class MergeTinyTask extends AbstractHashedMergeTask { public static final String TASK_NAME = "mergeTiny"; - public MergeTinyTask() { - super("mappings.tiny"); - this.dependsOn(InvertPerVersionMappingsTask.TASK_NAME, BuildMappingsTinyTask.TASK_NAME); - - this.getInput().convention( - this.getTaskNamed(BuildMappingsTinyTask.TASK_NAME, BuildMappingsTinyTask.class).getOutputMappings() - ); - } - @VisibleForTesting public static void mergeMappings( Path buildMappingsTiny, Path invertedPerVersionsMappings, Path outputMappings diff --git a/buildSrc/src/main/java/quilt/internal/tasks/build/MergeTinyV2Task.java b/buildSrc/src/main/java/quilt/internal/tasks/build/MergeTinyV2Task.java index 8437b534b0..3b8b84d94e 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/build/MergeTinyV2Task.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/build/MergeTinyV2Task.java @@ -6,21 +6,9 @@ import java.nio.file.Path; import java.util.function.Function; -import static quilt.internal.MappingsPlugin.INSERT_AUTO_GENERATED_MAPPINGS_TASK_NAME; - public abstract class MergeTinyV2Task extends AbstractHashedMergeTask { public static final String TASK_NAME = "mergeTinyV2"; - public MergeTinyV2Task() { - super("merged2.tiny"); - this.dependsOn(InvertPerVersionMappingsTask.TASK_NAME, "v2UnmergedMappingsJar"); - - this.getInput().convention( - this.getTaskNamed(INSERT_AUTO_GENERATED_MAPPINGS_TASK_NAME, AddProposedMappingsTask.class) - .getOutputMappings() - ); - } - @VisibleForTesting public static void mergeMappings( Path insertAutoGeneratedMappingsOutput, Path invertedPerVersionsMappings, Path outputMappings