Skip to content

Commit

Permalink
move conventions for MergeTinyTask, MergeTinyV2Task, and MergeInterme…
Browse files Browse the repository at this point in the history
…diaryTask to MappingsPlugin

refine their and their superclass' properties
  • Loading branch information
supersaiyansubtlety committed Oct 1, 2024
1 parent 3d15b0e commit 6391a20
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 84 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
76 changes: 59 additions & 17 deletions buildSrc/src/main/java/quilt/internal/MappingsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ public abstract class MappingsPlugin implements Plugin<Project> {
public static Provider<RegularFile> provideMappingsDestFile(
Provider<Directory> 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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,20 @@

public abstract class AbstractTinyMergeTask extends DefaultMappingsTask {
@InputFile
protected abstract RegularFileProperty getInput();
public abstract RegularFileProperty getInput();

@OutputFile
public abstract RegularFileProperty getOutputMappings();

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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,34 @@

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;

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6391a20

Please sign in to comment.