From afcb886ae64981b6727d9e74ecd8955b22a17d60 Mon Sep 17 00:00:00 2001 From: supersaiyansubtlety Date: Mon, 30 Sep 2024 00:42:54 -0700 Subject: [PATCH] AbstractDownloadMappingsTask -> DownloadMappingsTask, reworked its properties, 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 --- .../main/java/quilt/internal/Constants.java | 4 + .../quilt/internal/MappingsExtension.java | 8 -- .../java/quilt/internal/MappingsPlugin.java | 132 +++++++++++++++--- .../build/InvertPerVersionMappingsTask.java | 8 +- .../tasks/build/MergeIntermediaryTask.java | 7 +- .../MapPerVersionMappingsJarTask.java | 7 +- .../setup/AbstractDownloadMappingsTask.java | 57 -------- .../setup/CheckIntermediaryMappingsTask.java | 3 + .../DownloadIntermediaryMappingsTask.java | 3 +- .../tasks/setup/DownloadMappingsTask.java | 33 +++++ .../setup/DownloadPerVersionMappingsTask.java | 11 -- .../tasks/setup/ExtractTinyMappingsTask.java | 44 ++++++ .../quilt/internal/util/ProviderUtil.java | 2 +- 13 files changed, 210 insertions(+), 109 deletions(-) delete mode 100644 buildSrc/src/main/java/quilt/internal/tasks/setup/AbstractDownloadMappingsTask.java create mode 100644 buildSrc/src/main/java/quilt/internal/tasks/setup/DownloadMappingsTask.java delete mode 100644 buildSrc/src/main/java/quilt/internal/tasks/setup/DownloadPerVersionMappingsTask.java create mode 100644 buildSrc/src/main/java/quilt/internal/tasks/setup/ExtractTinyMappingsTask.java diff --git a/buildSrc/src/main/java/quilt/internal/Constants.java b/buildSrc/src/main/java/quilt/internal/Constants.java index 0ac11f6296..92d67763b9 100644 --- a/buildSrc/src/main/java/quilt/internal/Constants.java +++ b/buildSrc/src/main/java/quilt/internal/Constants.java @@ -1,5 +1,6 @@ package quilt.internal; +// TODO consider moving these to MappingsExtension public class Constants { public static final String MINECRAFT_VERSION = "24w38a"; @@ -7,6 +8,9 @@ public class Constants { 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 { diff --git a/buildSrc/src/main/java/quilt/internal/MappingsExtension.java b/buildSrc/src/main/java/quilt/internal/MappingsExtension.java index b367b37026..ef4f5a06c1 100644 --- a/buildSrc/src/main/java/quilt/internal/MappingsExtension.java +++ b/buildSrc/src/main/java/quilt/internal/MappingsExtension.java @@ -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) diff --git a/buildSrc/src/main/java/quilt/internal/MappingsPlugin.java b/buildSrc/src/main/java/quilt/internal/MappingsPlugin.java index 98aee6e96f..4027f01ae5 100644 --- a/buildSrc/src/main/java/quilt/internal/MappingsPlugin.java +++ b/buildSrc/src/main/java/quilt/internal/MappingsPlugin.java @@ -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; @@ -27,12 +31,13 @@ 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; @@ -40,10 +45,24 @@ 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 { 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 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; + } @Override public void apply(@NotNull Project project) { @@ -51,10 +70,21 @@ public void apply(@NotNull Project project) { final TaskContainer tasks = project.getTasks(); + final Provider 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 -> { @@ -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") @@ -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, @@ -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, @@ -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); @@ -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 @@ -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); diff --git a/buildSrc/src/main/java/quilt/internal/tasks/build/InvertPerVersionMappingsTask.java b/buildSrc/src/main/java/quilt/internal/tasks/build/InvertPerVersionMappingsTask.java index 326fbc6efd..4c14f3fead 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/build/InvertPerVersionMappingsTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/build/InvertPerVersionMappingsTask.java @@ -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; @@ -24,7 +26,7 @@ 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, @@ -32,7 +34,7 @@ public InvertPerVersionMappingsTask() { )); this.getInput().convention( - this.getTaskNamed(DownloadPerVersionMappingsTask.TASK_NAME, DownloadPerVersionMappingsTask.class) + this.getTaskNamed(MappingsPlugin.EXTRACT_TINY_PER_VERSION_MAPPINGS_TASK_NAME, ExtractTinyMappingsTask.class) .getTinyFile() ); } 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 854233e5d3..389a4c606e 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/build/MergeIntermediaryTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/build/MergeIntermediaryTask.java @@ -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; @@ -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() ); } diff --git a/buildSrc/src/main/java/quilt/internal/tasks/jarmapping/MapPerVersionMappingsJarTask.java b/buildSrc/src/main/java/quilt/internal/tasks/jarmapping/MapPerVersionMappingsJarTask.java index be6a66f3f8..2c217ed74a 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/jarmapping/MapPerVersionMappingsJarTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/jarmapping/MapPerVersionMappingsJarTask.java @@ -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 { @@ -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); diff --git a/buildSrc/src/main/java/quilt/internal/tasks/setup/AbstractDownloadMappingsTask.java b/buildSrc/src/main/java/quilt/internal/tasks/setup/AbstractDownloadMappingsTask.java deleted file mode 100644 index 12875e80b8..0000000000 --- a/buildSrc/src/main/java/quilt/internal/tasks/setup/AbstractDownloadMappingsTask.java +++ /dev/null @@ -1,57 +0,0 @@ -package quilt.internal.tasks.setup; - -import org.apache.commons.io.FileUtils; -import org.gradle.api.file.RegularFileProperty; -import org.gradle.api.tasks.OutputFile; -import org.gradle.api.tasks.TaskAction; -import quilt.internal.Constants; -import quilt.internal.tasks.DefaultMappingsTask; - -import java.io.File; -import java.io.IOException; - -public abstract class AbstractDownloadMappingsTask extends DefaultMappingsTask { - @OutputFile - public abstract RegularFileProperty getJarFile(); - - @OutputFile - public abstract RegularFileProperty getTinyFile(); - - private final String mappingsName; - - public AbstractDownloadMappingsTask(String mappingsName) { - super(Constants.Groups.SETUP_GROUP); - this.getJarFile().convention(() -> new File( - this.fileConstants.cacheFilesMinecraft, - "%s-%s.jar".formatted(Constants.MINECRAFT_VERSION, mappingsName) - )); - this.getTinyFile().convention(() -> new File( - this.fileConstants.cacheFilesMinecraft, - "%s-%s.tiny".formatted(Constants.MINECRAFT_VERSION, mappingsName) - )); - - this.mappingsName = mappingsName; - } - - @TaskAction - public void downloadMappings() throws IOException { - this.startDownload() - // TODO eliminate project access in task action - .src(this.getProject().getConfigurations().getByName(this.mappingsName).resolve().iterator().next().toURI().toString()) - .dest(this.getJarFile().get().getAsFile()) - .overwrite(false) - .download(); - - FileUtils.copyFile( - // TODO eliminate project access in task action - this.getProject() - .zipTree(this.getJarFile().get().getAsFile()) - .getFiles() - .stream() - .filter(file -> file.getName().endsWith("mappings.tiny")) - .findFirst() - .orElseThrow(), - this.getTinyFile().get().getAsFile() - ); - } -} diff --git a/buildSrc/src/main/java/quilt/internal/tasks/setup/CheckIntermediaryMappingsTask.java b/buildSrc/src/main/java/quilt/internal/tasks/setup/CheckIntermediaryMappingsTask.java index b5b48472de..57689143e9 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/setup/CheckIntermediaryMappingsTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/setup/CheckIntermediaryMappingsTask.java @@ -9,6 +9,9 @@ import java.io.File; import java.util.Set; +// TODO eliminate this task (or make it a super class of tasks that currently depend on it) +// Tasks that depend on it should instead take the intermediary configuration as input and check if it exists and +// can be resolved public abstract class CheckIntermediaryMappingsTask extends DefaultMappingsTask { public static final String TASK_NAME = "checkIntermediaryMappings"; diff --git a/buildSrc/src/main/java/quilt/internal/tasks/setup/DownloadIntermediaryMappingsTask.java b/buildSrc/src/main/java/quilt/internal/tasks/setup/DownloadIntermediaryMappingsTask.java index bbbfbecae3..add6638b59 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/setup/DownloadIntermediaryMappingsTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/setup/DownloadIntermediaryMappingsTask.java @@ -1,10 +1,9 @@ package quilt.internal.tasks.setup; -public abstract class DownloadIntermediaryMappingsTask extends AbstractDownloadMappingsTask { +public abstract class DownloadIntermediaryMappingsTask extends DownloadMappingsTask { public static final String TASK_NAME = "downloadIntermediaryMappings"; public DownloadIntermediaryMappingsTask() { - super("intermediary"); this.dependsOn(CheckIntermediaryMappingsTask.TASK_NAME); this.onlyIf(task -> this.getTaskNamed(CheckIntermediaryMappingsTask.TASK_NAME, CheckIntermediaryMappingsTask.class).isPresent() diff --git a/buildSrc/src/main/java/quilt/internal/tasks/setup/DownloadMappingsTask.java b/buildSrc/src/main/java/quilt/internal/tasks/setup/DownloadMappingsTask.java new file mode 100644 index 0000000000..6b3b4c4984 --- /dev/null +++ b/buildSrc/src/main/java/quilt/internal/tasks/setup/DownloadMappingsTask.java @@ -0,0 +1,33 @@ +package quilt.internal.tasks.setup; + +import org.gradle.api.artifacts.Configuration; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.provider.Property; +import org.gradle.api.tasks.InputFiles; +import org.gradle.api.tasks.OutputFile; +import org.gradle.api.tasks.TaskAction; +import quilt.internal.Constants; +import quilt.internal.tasks.DefaultMappingsTask; + +import java.io.IOException; + +public abstract class DownloadMappingsTask extends DefaultMappingsTask { + @InputFiles + public abstract Property getMappingsConfiguration(); + + @OutputFile + public abstract RegularFileProperty getJarFile(); + + public DownloadMappingsTask() { + super(Constants.Groups.SETUP_GROUP); + } + + @TaskAction + public void downloadMappings() throws IOException { + this.startDownload() + .src(this.getMappingsConfiguration().get().resolve().iterator().next().toURI().toString()) + .dest(this.getJarFile().get().getAsFile()) + .overwrite(false) + .download(); + } +} diff --git a/buildSrc/src/main/java/quilt/internal/tasks/setup/DownloadPerVersionMappingsTask.java b/buildSrc/src/main/java/quilt/internal/tasks/setup/DownloadPerVersionMappingsTask.java deleted file mode 100644 index bdc9e113fe..0000000000 --- a/buildSrc/src/main/java/quilt/internal/tasks/setup/DownloadPerVersionMappingsTask.java +++ /dev/null @@ -1,11 +0,0 @@ -package quilt.internal.tasks.setup; - -import quilt.internal.Constants; - -public abstract class DownloadPerVersionMappingsTask extends AbstractDownloadMappingsTask { - public static final String TASK_NAME = "downloadPerVersionMappings"; - - public DownloadPerVersionMappingsTask() { - super(Constants.PER_VERSION_MAPPINGS_NAME); - } -} diff --git a/buildSrc/src/main/java/quilt/internal/tasks/setup/ExtractTinyMappingsTask.java b/buildSrc/src/main/java/quilt/internal/tasks/setup/ExtractTinyMappingsTask.java new file mode 100644 index 0000000000..6afab2cdaf --- /dev/null +++ b/buildSrc/src/main/java/quilt/internal/tasks/setup/ExtractTinyMappingsTask.java @@ -0,0 +1,44 @@ +package quilt.internal.tasks.setup; + +import org.apache.commons.io.FileUtils; +import org.gradle.api.file.FileTree; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.tasks.InputFile; +import org.gradle.api.tasks.OutputFile; +import org.gradle.api.tasks.TaskAction; +import quilt.internal.Constants; +import quilt.internal.tasks.DefaultMappingsTask; + +import java.io.IOException; + +public abstract class ExtractTinyMappingsTask extends DefaultMappingsTask { + public static final String TINY_MAPPINGS_FILE_NAME_SUFFIX = "mappings.tiny"; + + @InputFile + public abstract RegularFileProperty getJarFile(); + + @OutputFile + public abstract RegularFileProperty getTinyFile(); + + private final FileTree jarZipTree; + + public ExtractTinyMappingsTask() { + super(Constants.Groups.SETUP_GROUP); + + // zipTree accesses the passed path lazily so passing jarFile here is ok + this.jarZipTree = this.getProject().zipTree(this.getJarFile()); + } + + @TaskAction + public void extractTinyMappings() throws IOException { + FileUtils.copyFile( + this.jarZipTree + .getFiles() + .stream() + .filter(file -> file.getName().endsWith(TINY_MAPPINGS_FILE_NAME_SUFFIX)) + .findFirst() + .orElseThrow(), + this.getTinyFile().get().getAsFile() + ); + } +} diff --git a/buildSrc/src/main/java/quilt/internal/util/ProviderUtil.java b/buildSrc/src/main/java/quilt/internal/util/ProviderUtil.java index 01b679899e..53adba5236 100644 --- a/buildSrc/src/main/java/quilt/internal/util/ProviderUtil.java +++ b/buildSrc/src/main/java/quilt/internal/util/ProviderUtil.java @@ -15,7 +15,7 @@ public static Path getPath(RegularFileProperty file) { return file.get().getAsFile().toPath(); } - public static Provider projectDirProviderOf(Project project, File directory) { + public static Provider provideProjectDir(Project project, File directory) { return project.getLayout().dir(project.provider(() -> directory)); } }