Skip to content

Commit

Permalink
AbstractDownloadMappingsTask -> DownloadMappingsTask, reworked its pr…
Browse files Browse the repository at this point in the history
…operties, and separated ExtractTinyMappingsTask

added ExtractTinyMappingsTasks for hashed and intermediary
removed DownloadIntermediaryMappingsTask class, it's just a DownloadMappingsTask now
added Constants.INTERMEDIARY_MAPPINGS_NAME, but haven't replaced duplicates yet
made some convensions in MappingsPlugin to use flatMap instead of lambdas
move MappingsExtension's getEnigmaProfileFile convension to MappingsPlugin
  • Loading branch information
supersaiyansubtlety committed Oct 1, 2024
1 parent 5616c3a commit afcb886
Show file tree
Hide file tree
Showing 13 changed files with 210 additions and 109 deletions.
4 changes: 4 additions & 0 deletions buildSrc/src/main/java/quilt/internal/Constants.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package quilt.internal;

// TODO consider moving these to MappingsExtension
public class Constants {
public static final String MINECRAFT_VERSION = "24w38a";

public static final String MAPPINGS_NAME = "quilt-mappings";

public static final String PER_VERSION_MAPPINGS_NAME = "hashed";

// TODO replace duplicates with this
public static final String INTERMEDIARY_MAPPINGS_NAME = "intermediary";

public static final String MAPPINGS_VERSION = MINECRAFT_VERSION + "+build." + System.getenv().getOrDefault("BUILD_NUMBER", "local");

public static final class Groups {
Expand Down
8 changes: 0 additions & 8 deletions buildSrc/src/main/java/quilt/internal/MappingsExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ public static MappingsExtension get(Project project) {
public MappingsExtension(Project project) {
this.fileConstants = new FileConstants(project);

// provide an informative error message if no profile is specified
this.getEnigmaProfileFile().convention(() -> {
throw new GradleException(
"No enigma profile specified. " +
"A profile must be specified to use an EnigmaProfileConsumingTask."
);
});

this.enigmaProfile = this.getEnigmaProfileFile()
.map(RegularFile::getAsFile)
.map(File::toPath)
Expand Down
132 changes: 110 additions & 22 deletions buildSrc/src/main/java/quilt/internal/MappingsPlugin.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package quilt.internal;

import org.gradle.api.GradleException;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.file.Directory;
import org.gradle.api.file.RegularFile;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.TaskContainer;
import org.jetbrains.annotations.NotNull;
import quilt.internal.tasks.EnigmaProfileConsumingTask;
Expand All @@ -27,34 +31,60 @@
import quilt.internal.tasks.lint.MappingLintTask;
import quilt.internal.tasks.setup.CheckIntermediaryMappingsTask;
import quilt.internal.tasks.setup.DownloadIntermediaryMappingsTask;
import quilt.internal.tasks.setup.DownloadMappingsTask;
import quilt.internal.tasks.setup.DownloadMinecraftJarsTask;
import quilt.internal.tasks.setup.DownloadMinecraftLibrariesTask;
import quilt.internal.tasks.setup.DownloadPerVersionMappingsTask;
import quilt.internal.tasks.setup.DownloadVersionsManifestTask;
import quilt.internal.tasks.setup.DownloadWantedVersionManifestTask;
import quilt.internal.tasks.setup.ExtractServerJarTask;
import quilt.internal.tasks.setup.ExtractTinyMappingsTask;
import quilt.internal.tasks.setup.MergeJarsTask;
import quilt.internal.tasks.unpick.CombineUnpickDefinitionsTask;
import quilt.internal.tasks.unpick.RemapUnpickDefinitionsTask;
import quilt.internal.tasks.unpick.gen.OpenGlConstantUnpickGeneratorTask;

import java.io.File;

import static quilt.internal.util.ProviderUtil.projectDirProviderOf;
import static quilt.internal.util.ProviderUtil.provideProjectDir;

// TODO extract common providers, possibly convert FileConstants to providers instead of files
public abstract class MappingsPlugin implements Plugin<Project> {
public static final String INSERT_AUTO_GENERATED_MAPPINGS_TASK_NAME = "insertAutoGeneratedMappings";
public static final String DOWNLOAD_PER_VERSION_MAPPINGS_TASK_NAME = "downloadPerVersionMappings";
public static final String EXTRACT_TINY_PER_VERSION_MAPPINGS_TASK_NAME = "extractTinyPerVersionMappings";
public static final String EXTRACT_TINY_INTERMEDIARY_MAPPINGS_TASK_NAME = "extractTinyIntermediaryMappings";

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;
}

@Override
public void apply(@NotNull Project project) {
final var ext = project.getExtensions().create("mappings", MappingsExtension.class, project);

final TaskContainer tasks = project.getTasks();

final Provider<Directory> mappingsDestDir =
provideProjectDir(project, ext.getFileConstants().cacheFilesMinecraft);

tasks.withType(EnigmaProfileConsumingTask.class).configureEach(task ->
task.getEnigmaProfile().convention(ext.enigmaProfile)
);

// provide an informative error message if no profile is specified
ext.getEnigmaProfileFile().convention(() -> {
throw new GradleException(
"No enigma profile specified. " +
"A profile must be specified to use an EnigmaProfileConsumingTask."
);
});

final var downloadVersionsManifest = tasks.register(
DownloadVersionsManifestTask.TASK_NAME, DownloadVersionsManifestTask.class,
task -> {
Expand All @@ -68,7 +98,9 @@ public void apply(@NotNull Project project) {
final var downloadWantedVersionManifest = tasks.register(
DownloadWantedVersionManifestTask.TASK_NAME, DownloadWantedVersionManifestTask.class,
task -> {
task.getManifest().convention(downloadVersionsManifest.get().getManifestFile());
task.getManifest().convention(
downloadVersionsManifest.flatMap(DownloadVersionsManifestTask::getManifestFile)
);

task.getVersionFile().convention(() ->
new File(ext.getFileConstants().cacheFilesMinecraft, Constants.MINECRAFT_VERSION + ".json")
Expand All @@ -79,7 +111,9 @@ public void apply(@NotNull Project project) {
final var downloadMinecraftJars = tasks.register(
DownloadMinecraftJarsTask.TASK_NAME, DownloadMinecraftJarsTask.class,
task -> {
task.getVersionFile().convention(downloadWantedVersionManifest.get().getVersionFile());
task.getVersionFile().convention(
downloadWantedVersionManifest.flatMap(DownloadWantedVersionManifestTask::getVersionFile)
);

task.getClientJar().convention(() -> new File(
ext.getFileConstants().cacheFilesMinecraft,
Expand All @@ -95,7 +129,9 @@ public void apply(@NotNull Project project) {
final var extractServerJarTask = tasks.register(
ExtractServerJarTask.TASK_NAME, ExtractServerJarTask.class,
task -> {
task.getServerBootstrapJar().convention(downloadMinecraftJars.get().getServerBootstrapJar());
task.getServerBootstrapJar().convention(
downloadMinecraftJars.flatMap(DownloadMinecraftJarsTask::getServerBootstrapJar)
);

task.getServerJar().convention(() -> new File(
ext.getFileConstants().cacheFilesMinecraft,
Expand All @@ -106,25 +142,48 @@ public void apply(@NotNull Project project) {

tasks.register(MergeJarsTask.TASK_NAME, MergeJarsTask.class, task -> {
task.getClientJar().convention(downloadMinecraftJars.get().getClientJar());
task.getServerJar().convention(extractServerJarTask.get().getServerJar());
task.getServerJar().convention(extractServerJarTask.flatMap(ExtractServerJarTask::getServerJar));

// TODO see if output jars like this can all go in a directory (build/minecraftJars/?)
task.getMergedFile().convention(() -> project.file(Constants.MINECRAFT_VERSION + "-merged.jar"));
});
final var downloadMinecraftLibraries = tasks.register(DownloadMinecraftLibrariesTask.TASK_NAME, DownloadMinecraftLibrariesTask.class, task -> {
task.getVersionFile().convention(downloadWantedVersionManifest.get().getVersionFile());
task.getLibrariesDir().convention(projectDirProviderOf(project, ext.getFileConstants().libraries));
});
final var downloadMinecraftLibraries = tasks.register(
DownloadMinecraftLibrariesTask.TASK_NAME, DownloadMinecraftLibrariesTask.class,
task -> {
task.getVersionFile().convention(
downloadWantedVersionManifest.flatMap(DownloadWantedVersionManifestTask::getVersionFile)
);
task.getLibrariesDir().convention(provideProjectDir(project, ext.getFileConstants().libraries));
}
);

final var downloadPerVersionMappings =
tasks.register(DownloadPerVersionMappingsTask.TASK_NAME, DownloadPerVersionMappingsTask.class);
final var downloadPerVersionMappings = tasks.register(
DOWNLOAD_PER_VERSION_MAPPINGS_TASK_NAME, DownloadMappingsTask.class,
task -> {
task.getMappingsConfiguration().convention(
project.getConfigurations().named(Constants.PER_VERSION_MAPPINGS_NAME)
);
task.getJarFile().convention(
provideMappingsDestFile(mappingsDestDir, Constants.PER_VERSION_MAPPINGS_NAME, "jar")
);
}
);
tasks.register(
EXTRACT_TINY_PER_VERSION_MAPPINGS_TASK_NAME, ExtractTinyMappingsTask.class,
task -> {
task.getJarFile().convention(downloadPerVersionMappings.flatMap(DownloadMappingsTask::getJarFile));
task.getTinyFile().convention(
provideMappingsDestFile(mappingsDestDir, Constants.INTERMEDIARY_MAPPINGS_NAME, "tiny")
);
}
);
tasks.register(InvertPerVersionMappingsTask.TASK_NAME, InvertPerVersionMappingsTask.class);
final var buildMappingsTiny = tasks.create(BuildMappingsTinyTask.TASK_NAME, BuildMappingsTinyTask.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);

task.getInputJar().convention(() -> ext.getFileConstants().perVersionMappingsJar);
task.getInputMappings().convention(buildMappingsTiny.getOutputMappings());
task.getInputMappings().convention(buildMappingsTiny.flatMap(BuildMappingsTinyTask::getOutputMappings));
});

tasks.register(MergeTinyTask.TASK_NAME, MergeTinyTask.class);
Expand All @@ -142,12 +201,14 @@ public void apply(@NotNull Project project) {
// TODO eliminate this
task.dependsOn(MapPerVersionMappingsJarTask.TASK_NAME);

task.getVersionFile().convention(downloadMinecraftLibraries.get().getVersionFile());
task.getVersionFile()
.convention(downloadMinecraftLibraries.flatMap(DownloadMinecraftLibrariesTask::getVersionFile));

task.getPerVersionMappingsJar().convention(() -> ext.getFileConstants().perVersionMappingsJar);

// TODO make sure this works even after MapPerVersionMappingsJarTask is updated
task.getArtifactsByUrl().convention(downloadMinecraftLibraries.get().artifactsByUrl);
task.getArtifactsByUrl()
.convention(downloadMinecraftLibraries.flatMap(downloadTask -> downloadTask.artifactsByUrl));

task.getUnpickGlStateManagerDefinitions().convention(() ->
ext.getFileConstants().unpickGlStateManagerDefinitions
Expand All @@ -159,13 +220,40 @@ public void apply(@NotNull Project project) {
tasks.register(GeneratePackageInfoMappingsTask.TASK_NAME, GeneratePackageInfoMappingsTask.class);
tasks.register(DownloadDictionaryFileTask.TASK_NAME, DownloadDictionaryFileTask.class);
final var mappingLint = tasks.register(MappingLintTask.TASK_NAME, MappingLintTask.class);
tasks.register(FindDuplicateMappingFilesTask.TASK_NAME, FindDuplicateMappingFilesTask.class, task -> {
task.getMappingDirectory().set(mappingLint.get().getMappingDirectory());
mappingLint.get().dependsOn(task);
});
tasks.register(FindDuplicateMappingFilesTask.TASK_NAME, FindDuplicateMappingFilesTask.class,
task -> {
task.getMappingDirectory().convention(mappingLint.get().getMappingDirectory());
mappingLint.get().dependsOn(task);
}
);

final var checkIntermediaryMappings =
tasks.register(CheckIntermediaryMappingsTask.TASK_NAME, CheckIntermediaryMappingsTask.class);
final var downloadIntermediaryMappings = tasks.register(
DownloadIntermediaryMappingsTask.TASK_NAME, DownloadIntermediaryMappingsTask.class,
task -> {
task.getMappingsConfiguration().convention(
project.getConfigurations().named(Constants.INTERMEDIARY_MAPPINGS_NAME)
);
task.getJarFile().convention(
provideMappingsDestFile(mappingsDestDir, Constants.INTERMEDIARY_MAPPINGS_NAME, "jar")
);

tasks.register(CheckIntermediaryMappingsTask.TASK_NAME, CheckIntermediaryMappingsTask.class);
tasks.register(DownloadIntermediaryMappingsTask.TASK_NAME, DownloadIntermediaryMappingsTask.class);
task.dependsOn(checkIntermediaryMappings);
task.onlyIf(unused ->
checkIntermediaryMappings.get().isPresent()
);
}
);
tasks.register(
EXTRACT_TINY_INTERMEDIARY_MAPPINGS_TASK_NAME, ExtractTinyMappingsTask.class,
task -> {
task.getJarFile().convention(downloadIntermediaryMappings.flatMap(DownloadMappingsTask::getJarFile));
task.getTinyFile().convention(
provideMappingsDestFile(mappingsDestDir, Constants.INTERMEDIARY_MAPPINGS_NAME, "tiny")
);
}
);
tasks.register(MergeIntermediaryTask.TASK_NAME, MergeIntermediaryTask.class);
tasks.register(RemoveIntermediaryTask.TASK_NAME, RemoveIntermediaryTask.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import org.gradle.api.tasks.TaskAction;
import org.jetbrains.annotations.VisibleForTesting;
import quilt.internal.Constants;
import quilt.internal.MappingsPlugin;
import quilt.internal.tasks.DefaultMappingsTask;
import quilt.internal.tasks.setup.DownloadPerVersionMappingsTask;
import quilt.internal.tasks.setup.DownloadMappingsTask;
import quilt.internal.tasks.setup.ExtractTinyMappingsTask;

import net.fabricmc.stitch.commands.tinyv2.CommandReorderTinyV2;

Expand All @@ -24,15 +26,15 @@ public abstract class InvertPerVersionMappingsTask extends DefaultMappingsTask {

public InvertPerVersionMappingsTask() {
super(Constants.Groups.BUILD_MAPPINGS_GROUP);
this.dependsOn(DownloadPerVersionMappingsTask.TASK_NAME);
this.dependsOn(MappingsPlugin.DOWNLOAD_PER_VERSION_MAPPINGS_TASK_NAME);

this.getInvertedTinyFile().convention(() -> new File(
this.fileConstants.cacheFilesMinecraft,
"%s-%s-inverted.tiny".formatted(Constants.MINECRAFT_VERSION, Constants.PER_VERSION_MAPPINGS_NAME)
));

this.getInput().convention(
this.getTaskNamed(DownloadPerVersionMappingsTask.TASK_NAME, DownloadPerVersionMappingsTask.class)
this.getTaskNamed(MappingsPlugin.EXTRACT_TINY_PER_VERSION_MAPPINGS_TASK_NAME, ExtractTinyMappingsTask.class)
.getTinyFile()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import net.fabricmc.mappingio.adapter.MappingDstNsReorder;
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;
Expand All @@ -33,8 +35,9 @@ public MergeIntermediaryTask() {
);

this.getInput().convention(
this.getTaskNamed(DownloadIntermediaryMappingsTask.TASK_NAME, DownloadIntermediaryMappingsTask.class)
.getTinyFile()
this.getTaskNamed(
MappingsPlugin.EXTRACT_TINY_INTERMEDIARY_MAPPINGS_TASK_NAME, ExtractTinyMappingsTask.class
).getTinyFile()
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package quilt.internal.tasks.jarmapping;

import quilt.internal.Constants;
import quilt.internal.MappingsPlugin;
import quilt.internal.tasks.setup.DownloadMinecraftLibrariesTask;
import quilt.internal.tasks.setup.DownloadPerVersionMappingsTask;
import quilt.internal.tasks.setup.ExtractTinyMappingsTask;
import quilt.internal.tasks.setup.MergeJarsTask;

public abstract class MapPerVersionMappingsJarTask extends MapJarTask {
Expand All @@ -12,13 +13,13 @@ public MapPerVersionMappingsJarTask() {
super(Constants.Groups.MAP_JAR_GROUP, "official", Constants.PER_VERSION_MAPPINGS_NAME);
this.dependsOn(
DownloadMinecraftLibrariesTask.TASK_NAME,
DownloadPerVersionMappingsTask.TASK_NAME,
MappingsPlugin.DOWNLOAD_PER_VERSION_MAPPINGS_TASK_NAME,
MergeJarsTask.TASK_NAME
);

this.getInputJar().convention(this.getTaskNamed(MergeJarsTask.TASK_NAME, MergeJarsTask.class).getMergedFile());
this.getMappingsFile().convention(
this.getTaskNamed(DownloadPerVersionMappingsTask.TASK_NAME, DownloadPerVersionMappingsTask.class)
this.getTaskNamed(MappingsPlugin.EXTRACT_TINY_PER_VERSION_MAPPINGS_TASK_NAME, ExtractTinyMappingsTask.class)
.getTinyFile()
);
this.getOutputJar().convention(() -> this.fileConstants.perVersionMappingsJar);
Expand Down
Loading

0 comments on commit afcb886

Please sign in to comment.