diff --git a/build.gradle b/build.gradle index 68aafd4b88..4bdd8f950e 100644 --- a/build.gradle +++ b/build.gradle @@ -105,6 +105,7 @@ import quilt.internal.tasks.build.AddProposedMappingsTask import quilt.internal.tasks.build.MappingsV2JarTask import quilt.internal.tasks.build.TransformJarClassesTask import quilt.internal.tasks.decompile.DecompileTask +import quilt.internal.tasks.diff.ExtractTargetMappingJarTask import quilt.internal.tasks.jarmapping.MapPerVersionMappingsJarTask import quilt.internal.tasks.mappings.EnigmaMappingsTask import quilt.internal.tasks.unpick.RemapUnpickDefinitionsTask @@ -169,6 +170,7 @@ task sourcesJar(type: Jar, dependsOn: classes) { from sourceSets.constants.allSource } +// TODO despaghetify this task unpickHashedJar(type: UnpickJarTask) { inputFile.set mappings.fileConstants.perVersionMappingsJar outputFile.set mappings.fileConstants.unpickedJar @@ -301,50 +303,6 @@ task decompileVineflower(type: DecompileTask, dependsOn: [mapNamedJar]) { } } -task remapTargetUnpickDefinitions(type: RemapUnpickDefinitionsTask) { - dependsOn "checkUnpickVersionsMatch", "downloadTargetMappingsJar" - output.set downloadTargetMappingsJar.targetUnpickRemappedDefinitionsFile - mappings.set downloadTargetMappingsJar.targetMappingsFile - input.set downloadTargetMappingsJar.targetUnpickDefinitionsFile - - onlyIf { - checkUnpickVersionsMatch.match - } -} - -task unpickTargetJar(type: UnpickJarTask) { - dependsOn "checkUnpickVersionsMatch", "downloadMinecraftLibraries", "remapTargetUnpickDefinitions", "mapPerVersionMappingsJar" - - inputFile.set mappings.fileConstants.perVersionMappingsJar - outputFile.set remapTargetMinecraftJar.inputJar - unpickDefinition.set remapTargetUnpickDefinitions.output - unpickConstantsJar.set downloadTargetMappingsJar.targetUnpickConstantsFile - - onlyIf { - checkUnpickVersionsMatch.match - } -} - -task decompileTargetVineflower(type: DecompileTask, dependsOn: [remapTargetMinecraftJar]) { - input.set remapTargetMinecraftJar.outputJar - output.set file("namedTargetSrc") - decompiler = Decompilers.VINEFLOWER - libraries = files(configurations.decompileClasspath) - - doFirst { - file("namedTargetSrc").deleteDir() - - def javadocProvider = new MappingsJavadocProvider(downloadTargetMappingsJar.targetMappingsFile.get().getAsFile(), "named") - classJavadocProvider(javadocProvider) - fieldJavadocProvider(javadocProvider) - methodJavadocProvider(javadocProvider) - } - - onlyIf { - checkUnpickVersionsMatch.match - } -} - javadoc { dependsOn genFakeSource dependsOn downloadMinecraftLibraries diff --git a/buildSrc/src/main/java/quilt/internal/MappingsExtension.java b/buildSrc/src/main/java/quilt/internal/MappingsExtension.java index ef4f5a06c1..7c21e65caf 100644 --- a/buildSrc/src/main/java/quilt/internal/MappingsExtension.java +++ b/buildSrc/src/main/java/quilt/internal/MappingsExtension.java @@ -11,6 +11,11 @@ import java.io.IOException; public abstract class MappingsExtension { + // TODO see if this can use a BuildService + /** + * {@link MappingsPlugin} configures all + * {@link quilt.internal.tasks.EnigmaProfileConsumingTask EnigmaProfileConsumingTask}s to use this profile. + */ public final Provider enigmaProfile; private final FileConstants fileConstants; diff --git a/buildSrc/src/main/java/quilt/internal/MappingsPlugin.java b/buildSrc/src/main/java/quilt/internal/MappingsPlugin.java index d945fadb1a..3810e0c826 100644 --- a/buildSrc/src/main/java/quilt/internal/MappingsPlugin.java +++ b/buildSrc/src/main/java/quilt/internal/MappingsPlugin.java @@ -8,6 +8,7 @@ import org.gradle.api.provider.Provider; import org.gradle.api.tasks.TaskContainer; import org.jetbrains.annotations.NotNull; +import quilt.internal.decompile.Decompilers; import quilt.internal.tasks.EnigmaProfileConsumingTask; import quilt.internal.tasks.build.AddProposedMappingsTask; import quilt.internal.tasks.build.BuildMappingsTinyTask; @@ -20,10 +21,18 @@ import quilt.internal.tasks.build.MergeTinyV2Task; import quilt.internal.tasks.build.RemoveIntermediaryTask; import quilt.internal.tasks.build.TinyJarTask; +import quilt.internal.tasks.decompile.DecompileTask; import quilt.internal.tasks.diff.CheckTargetVersionExistsTask; import quilt.internal.tasks.diff.CheckUnpickVersionsMatchTask; +import quilt.internal.tasks.diff.DecompileTargetTask; import quilt.internal.tasks.diff.DownloadTargetMappingJarTask; +import quilt.internal.tasks.diff.ExtractTargetMappingJarTask; import quilt.internal.tasks.diff.RemapTargetMinecraftJarTask; +import quilt.internal.tasks.diff.RemapTargetUnpickDefinitionsTask; +import quilt.internal.tasks.diff.TargetVersionConsumingTask; +import quilt.internal.tasks.diff.UnpickTargetJarTask; +import quilt.internal.tasks.diff.UnpickVersionsMatchConsumingTask; +import quilt.internal.tasks.jarmapping.MapJarTask; import quilt.internal.tasks.jarmapping.MapNamedJarTask; import quilt.internal.tasks.jarmapping.MapPerVersionMappingsJarTask; import quilt.internal.tasks.lint.DownloadDictionaryFileTask; @@ -41,9 +50,12 @@ import quilt.internal.tasks.setup.MergeJarsTask; import quilt.internal.tasks.unpick.CombineUnpickDefinitionsTask; import quilt.internal.tasks.unpick.RemapUnpickDefinitionsTask; +import quilt.internal.tasks.unpick.UnpickJarTask; import quilt.internal.tasks.unpick.gen.OpenGlConstantUnpickGeneratorTask; +import quilt.internal.util.MappingsJavadocProvider; import java.io.File; +import java.nio.file.Path; import static quilt.internal.util.ProviderUtil.provideProjectDir; @@ -54,6 +66,12 @@ public abstract class MappingsPlugin implements Plugin { public static final String EXTRACT_TINY_PER_VERSION_MAPPINGS_TASK_NAME = "extractTinyPerVersionMappings"; public static final String EXTRACT_TINY_INTERMEDIARY_MAPPINGS_TASK_NAME = "extractTinyIntermediaryMappings"; + // TODO probably move to FileConstants + public static final String TARGET_MAPPINGS_DIR = ".gradle/targets"; + + private static final String QUILT_MAPPINGS_PREFIX = "quilt-mappings-"; + public static final String DECOMPILE_TARGET_VINEFLOWER_TASK_NAME = "decompileTargetVineflower"; + public static Provider provideMappingsDestFile( Provider destDir, String mappingsName, String fileExt ) { @@ -122,7 +140,7 @@ public void apply(@NotNull Project project) { } ); - final var extractServerJarTask = tasks.register( + final var extractServerJar = tasks.register( ExtractServerJarTask.TASK_NAME, ExtractServerJarTask.class, task -> { task.getServerBootstrapJar().convention( @@ -136,13 +154,15 @@ public void apply(@NotNull Project project) { } ); - tasks.register(MergeJarsTask.TASK_NAME, MergeJarsTask.class, task -> { - task.getClientJar().convention(downloadMinecraftJars.get().getClientJar()); - task.getServerJar().convention(extractServerJarTask.flatMap(ExtractServerJarTask::getServerJar)); + final var mergeJars = tasks.register(MergeJarsTask.TASK_NAME, MergeJarsTask.class, task -> { + task.getClientJar().convention(downloadMinecraftJars.flatMap(DownloadMinecraftJarsTask::getClientJar)); + task.getServerJar().convention(extractServerJar.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 File mergedFile = project.file(Constants.MINECRAFT_VERSION + "-merged.jar"); + task.getMergedFile().convention(() -> mergedFile); }); + final var downloadMinecraftLibraries = tasks.register( DownloadMinecraftLibrariesTask.TASK_NAME, DownloadMinecraftLibrariesTask.class, task -> { @@ -153,6 +173,12 @@ public void apply(@NotNull Project project) { } ); + tasks.withType(MapJarTask.class).configureEach(task -> { + task.getLibrariesDir().convention( + downloadMinecraftLibraries.flatMap(DownloadMinecraftLibrariesTask::getLibrariesDir) + ); + }); + final var downloadPerVersionMappings = tasks.register( DOWNLOAD_PER_VERSION_MAPPINGS_TASK_NAME, DownloadMappingsTask.class, task -> { @@ -164,7 +190,8 @@ public void apply(@NotNull Project project) { ); } ); - tasks.register( + + final var extractTinyPerVersionMappings = tasks.register( EXTRACT_TINY_PER_VERSION_MAPPINGS_TASK_NAME, ExtractTinyMappingsTask.class, task -> { task.getJarFile().convention(downloadPerVersionMappings.flatMap(DownloadMappingsTask::getJarFile)); @@ -173,23 +200,39 @@ public void apply(@NotNull Project project) { ); } ); + final var invertPerVersionMappings = tasks.register(InvertPerVersionMappingsTask.TASK_NAME, InvertPerVersionMappingsTask.class); + final var buildMappingsTiny = tasks.register(BuildMappingsTinyTask.TASK_NAME, BuildMappingsTinyTask.class); + + final var mapPerVersionMappingsJar = tasks.register( + MapPerVersionMappingsJarTask.TASK_NAME, MapPerVersionMappingsJarTask.class, + task -> { + task.getInputJar().convention(mergeJars.flatMap(MergeJarsTask::getMergedFile)); + + task.getMappingsFile().convention( + extractTinyPerVersionMappings.flatMap(ExtractTinyMappingsTask::getTinyFile) + ); + + task.getOutputJar().convention(() -> ext.getFileConstants().perVersionMappingsJar); + } + ); + 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( + mapPerVersionMappingsJar.flatMap(MapPerVersionMappingsJarTask::getOutputJar) + ); 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, @@ -203,6 +246,7 @@ public void apply(@NotNull Project project) { 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"); @@ -217,27 +261,42 @@ public void apply(@NotNull Project project) { 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); - tasks.register(MapPerVersionMappingsJarTask.TASK_NAME, MapPerVersionMappingsJarTask.class); - tasks.register(MapNamedJarTask.TASK_NAME, MapNamedJarTask.class); + tasks.register(MapNamedJarTask.TASK_NAME, MapNamedJarTask.class, task -> { + // TODO eliminate this + task.dependsOn("unpickHashedJar"); + + // TODO make this take the output of unpickHashedJar + task.getInputJar().convention(() -> ext.getFileConstants().unpickedJar); + task.getMappingsFile().convention( + insertAutoGeneratedMappings.flatMap(AddProposedMappingsTask::getOutputMappings) + ); + + task.getOutputJar().convention(() -> ext.getFileConstants().namedJar); + }); tasks.register(CombineUnpickDefinitionsTask.TASK_NAME, CombineUnpickDefinitionsTask.class); + tasks.register(RemapUnpickDefinitionsTask.TASK_NAME, RemapUnpickDefinitionsTask.class); - tasks.register(OpenGlConstantUnpickGeneratorTask.TASK_NAME, OpenGlConstantUnpickGeneratorTask.class, task -> { - // TODO eliminate this - task.dependsOn(MapPerVersionMappingsJarTask.TASK_NAME); - task.getVersionFile() - .convention(downloadMinecraftLibraries.flatMap(DownloadMinecraftLibrariesTask::getVersionFile)); + tasks.register(OpenGlConstantUnpickGeneratorTask.TASK_NAME, OpenGlConstantUnpickGeneratorTask.class, task -> { + task.getVersionFile().convention( + downloadMinecraftLibraries.flatMap(DownloadMinecraftLibrariesTask::getVersionFile) + ); - task.getPerVersionMappingsJar().convention(() -> ext.getFileConstants().perVersionMappingsJar); + task.getPerVersionMappingsJar().convention( + mapPerVersionMappingsJar.flatMap(MapPerVersionMappingsJarTask::getOutputJar) + ); - // TODO make sure this works even after MapPerVersionMappingsJarTask is updated - task.getArtifactsByUrl() - .convention(downloadMinecraftLibraries.flatMap(downloadTask -> downloadTask.artifactsByUrl)); + task.getArtifactsByUrl().convention( + downloadMinecraftLibraries.flatMap(DownloadMinecraftLibrariesTask::getArtifactsByUrl) + ); task.getUnpickGlStateManagerDefinitions().convention(() -> ext.getFileConstants().unpickGlStateManagerDefinitions @@ -247,8 +306,11 @@ 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().convention(mappingLint.get().getMappingDirectory()); @@ -258,6 +320,7 @@ public void apply(@NotNull Project project) { final var checkIntermediaryMappings = tasks.register(CheckIntermediaryMappingsTask.TASK_NAME, CheckIntermediaryMappingsTask.class); + final var downloadIntermediaryMappings = tasks.register( DownloadIntermediaryMappingsTask.TASK_NAME, DownloadIntermediaryMappingsTask.class, task -> { @@ -272,6 +335,7 @@ public void apply(@NotNull Project project) { task.onlyIf(unused -> checkIntermediaryMappings.get().isPresent()); } ); + final var extractTinyIntermediaryMappings = tasks.register( EXTRACT_TINY_INTERMEDIARY_MAPPINGS_TASK_NAME, ExtractTinyMappingsTask.class, task -> { @@ -281,6 +345,7 @@ public void apply(@NotNull Project project) { ); } ); + tasks.register( MergeIntermediaryTask.TASK_NAME, MergeIntermediaryTask.class, task -> { @@ -297,11 +362,150 @@ public void apply(@NotNull Project project) { ); } ); + tasks.register(RemoveIntermediaryTask.TASK_NAME, RemoveIntermediaryTask.class); - tasks.register(CheckTargetVersionExistsTask.TASK_NAME, CheckTargetVersionExistsTask.class); - tasks.register(DownloadTargetMappingJarTask.TASK_NAME, DownloadTargetMappingJarTask.class); - tasks.register(CheckUnpickVersionsMatchTask.TASK_NAME, CheckUnpickVersionsMatchTask.class); - tasks.register(RemapTargetMinecraftJarTask.TASK_NAME, RemapTargetMinecraftJarTask.class); + final var checkTargetVersionExists = tasks.register( + CheckTargetVersionExistsTask.TASK_NAME, CheckTargetVersionExistsTask.class, + task -> { + task.outputsNeverUpToDate(); + task.getMetaFile().convention(() -> new File( + ext.getFileConstants().cacheFilesMinecraft, + QUILT_MAPPINGS_PREFIX + Constants.MINECRAFT_VERSION + ".json" + )); + } + ); + + tasks.withType(TargetVersionConsumingTask.class).configureEach(task -> { + // TODO temporary, until CheckTargetVersionExistsTask is converted to a BuildService + task.dependsOn(checkTargetVersionExists); + + task.getTargetVersion().convention( + checkTargetVersionExists.flatMap(CheckTargetVersionExistsTask::getTargetVersion) + ); + + task.onlyIf(unused -> task.getTargetVersion().isPresent()); + }); + + final var downloadTargetMappingsJar = tasks.register( + DownloadTargetMappingJarTask.TASK_NAME, DownloadTargetMappingJarTask.class, + task -> { + task.getTargetUnpickConstantsFile().convention(task.provideVersionedProjectFile(version -> + Path.of(TARGET_MAPPINGS_DIR, QUILT_MAPPINGS_PREFIX + version + "-constants.jar") + )); + + task.getTargetJar().convention(task.provideVersionedProjectFile(version -> + Path.of(MappingsPlugin.TARGET_MAPPINGS_DIR, "quilt-mappings-" + version + "-v2.jar") + )); + } + ); + + final var extractTargetMappingsJar = tasks.register( + ExtractTargetMappingJarTask.TASK_NAME, ExtractTargetMappingJarTask.class, + task -> { + task.getTargetJar().convention( + downloadTargetMappingsJar.flatMap(DownloadTargetMappingJarTask::getTargetJar) + ); + task.getExtractionDest().convention(task.provideVersionedProjectDir(version -> + Path.of(MappingsPlugin.TARGET_MAPPINGS_DIR, "quilt-mappings-" + version) + )); + } + ); + + final var checkUnpickVersionsMatch = tasks.register( + CheckUnpickVersionsMatchTask.TASK_NAME, CheckUnpickVersionsMatchTask.class, + task -> { + task.getUnpickJson().convention( + extractTargetMappingsJar.flatMap(ExtractTargetMappingJarTask::getExtractionDest) + .map(dest -> dest.dir("extras").file("unpick.json")) + ); + } + ); + + tasks.withType(UnpickVersionsMatchConsumingTask.class).configureEach(task -> { + // TODO temporary, until CheckUnpickVersionsMatchTask is converted to a BuildService + task.dependsOn(checkUnpickVersionsMatch); + + task.getUnpickVersionsMatch().convention( + checkUnpickVersionsMatch.flatMap(CheckUnpickVersionsMatchTask::isMatch) + ); + + task.onlyIf(unused -> task.getUnpickVersionsMatch().getOrElse(false)); + }); + + final var remapTargetUnpickDefinitions = tasks.register( + RemapTargetUnpickDefinitionsTask.TASK_NAME, RemapTargetUnpickDefinitionsTask.class, + task -> { + task.getInput().convention( + extractTargetMappingsJar.flatMap(ExtractTargetMappingJarTask::getExtractionDest) + .map(dest -> dest.dir("extras").file("definitions.unpick")) + ); + + task.getMappings().convention( + extractTargetMappingsJar.flatMap(ExtractTargetMappingJarTask::getExtractionDest) + .map(dest -> dest.dir("mappings").file("mappings.tiny")) + ); + + task.getOutput().convention(task.provideVersionedProjectFile(version -> + Path.of(TARGET_MAPPINGS_DIR, QUILT_MAPPINGS_PREFIX + version + "remapped-unpick.unpick") + )); + } + ); + + final var unpickTargetJar = tasks.register(UnpickTargetJarTask.TASK_NAME, UnpickTargetJarTask.class, task -> { + task.getInputFile().convention( + mapPerVersionMappingsJar.flatMap(MapPerVersionMappingsJarTask::getOutputJar) + ); + + task.getUnpickDefinition().convention( + remapTargetUnpickDefinitions.flatMap(RemapTargetUnpickDefinitionsTask::getOutput) + ); + + task.getUnpickConstantsJar().convention( + downloadTargetMappingsJar.flatMap(DownloadTargetMappingJarTask::getTargetUnpickConstantsFile) + ); + + task.getOutputFile().convention(task.provideVersionedProjectFile(version -> + Path.of(TARGET_MAPPINGS_DIR, QUILT_MAPPINGS_PREFIX + version + "-unpicked.jar") + )); + }); + + final var remapTargetMinecraftJar = tasks.register( + RemapTargetMinecraftJarTask.TASK_NAME, RemapTargetMinecraftJarTask.class, + task -> { + task.getInputJar().convention(unpickTargetJar.flatMap(UnpickTargetJarTask::getOutputFile)); + + task.getMappingsFile().convention( + extractTargetMappingsJar.flatMap(ExtractTargetMappingJarTask::getExtractionDest) + .map(dest -> dest.dir("mappings").file("mappings.tiny")) + ); + + task.getOutputJar().convention(task.provideVersionedProjectFile(version -> + Path.of(TARGET_MAPPINGS_DIR, QUILT_MAPPINGS_PREFIX + version + "-named.jar") + )); + } + ); + + // TODO there was a non-fatal exception error logged by this a few times that I can't reproduce + // It mentioned jetbrains, so it might have just been intellij being iffy + // It was a FileSystemAlreadyExistsException + tasks.register(DECOMPILE_TARGET_VINEFLOWER_TASK_NAME, DecompileTargetTask.class, task -> { + task.getDecompiler().convention(Decompilers.VINEFLOWER); + + task.getNamespace().convention("named"); + + task.getInput().convention(remapTargetMinecraftJar.flatMap(RemapTargetMinecraftJarTask::getOutputJar)); + + task.getLibraries().convention( + project.files(project.getConfigurations().named("decompileClasspath")) + ); + + task.getTargetMappingsFile().convention( + extractTargetMappingsJar.flatMap(ExtractTargetMappingJarTask::getExtractionDest) + .map(dest -> dest.dir("mappings").file("mappings.tiny")) + ); + + task.getOutput().convention(() -> project.file("namedTargetSrc")); + }); } } diff --git a/buildSrc/src/main/java/quilt/internal/tasks/EnigmaProfileConsumingTask.java b/buildSrc/src/main/java/quilt/internal/tasks/EnigmaProfileConsumingTask.java index 3efee5dd8f..9b43e5db29 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/EnigmaProfileConsumingTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/EnigmaProfileConsumingTask.java @@ -13,6 +13,13 @@ import static org.quiltmc.enigma_plugin.Arguments.SIMPLE_TYPE_FIELD_NAMES_PATH; +/** + * A task that takes an {@link EnigmaProfile} as input. + *

+ * If {@link quilt.internal.MappingsPlugin MappingsPlugin} is applied, any {@code EnigmaProfileConsumingTask}s will use + * {@link quilt.internal.MappingsExtension MappingsExtension}'s + * {@link quilt.internal.MappingsExtension#enigmaProfile enigmaProfile} by default. + */ public abstract class EnigmaProfileConsumingTask extends DefaultMappingsTask { @Internal( "An EnigmaProfile cannot be fingerprinted. " + diff --git a/buildSrc/src/main/java/quilt/internal/tasks/decompile/DecompileTask.java b/buildSrc/src/main/java/quilt/internal/tasks/decompile/DecompileTask.java index 424cd97bd9..5c419eadb6 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/decompile/DecompileTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/decompile/DecompileTask.java @@ -53,7 +53,9 @@ public DecompileTask() { @TaskAction public void decompile() { - final Map options = this.getDecompilerOptions().getOrElse(new HashMap<>()); + // mapping to HashMap is required; the unmapped Map is unmodifiable and VineflowerDecompiler needs to modify it + // this issue occurred for decompileTargetVineflower + final Map options = this.getDecompilerOptions().map(HashMap::new).getOrElse(new HashMap<>()); final Collection libraries = this.getLibraries().>map(FileCollection::getFiles) .getOrElse(Collections.emptyList()); @@ -73,6 +75,7 @@ public void decompile() { decompiler.decompile(this.getInput().getAsFile().get(), this.getOutput().getAsFile().get(), options, libraries); } + // TODO see if this can use a BuildService @Internal public AbstractDecompiler getAbstractDecompiler() { return this.getDecompiler().get().getProvider().provide(this.getProject()); diff --git a/buildSrc/src/main/java/quilt/internal/tasks/diff/CheckTargetVersionExistsTask.java b/buildSrc/src/main/java/quilt/internal/tasks/diff/CheckTargetVersionExistsTask.java index 3c310c04b7..226d9cc39f 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/diff/CheckTargetVersionExistsTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/diff/CheckTargetVersionExistsTask.java @@ -4,33 +4,44 @@ import java.io.FileReader; import java.io.IOException; import java.util.Comparator; -import java.util.Optional; import java.util.stream.StreamSupport; import com.google.gson.JsonElement; import com.google.gson.JsonParser; +import org.gradle.api.GradleException; import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.provider.Property; +import org.gradle.api.provider.Provider; import org.gradle.api.tasks.Internal; import org.gradle.api.tasks.OutputFile; import org.gradle.api.tasks.TaskAction; import quilt.internal.Constants; import quilt.internal.tasks.DefaultMappingsTask; +// TODO see if this can be replaced with a ValueSource or a BuildService +/** + * @see TargetVersionConsumingTask + */ public abstract class CheckTargetVersionExistsTask extends DefaultMappingsTask { public static final String TASK_NAME = "checkTargetVersionExists"; @Internal - private Optional targetVersion = Optional.empty(); + protected abstract Property getTargetVersionImpl(); @OutputFile public abstract RegularFileProperty getMetaFile(); public CheckTargetVersionExistsTask() { super("diff"); - this.outputsNeverUpToDate(); - this.getMetaFile().convention(() -> new File( - this.fileConstants.cacheFilesMinecraft, "quilt-mappings-" + Constants.MINECRAFT_VERSION + ".json" - )); + + // provide an informative error message if getVersion is accessed incorrectly + this.getTargetVersionImpl().convention(this.getProject().provider(() -> { + throw new GradleException( + "targetVersion has not been populated. " + + "Its should only be accessed from others tasks' inputs or predicates and " + + "only after checking if it's present." + ); + })); } @TaskAction @@ -45,18 +56,30 @@ public void checkExists() { .download(); final JsonElement parsed = JsonParser.parseReader(new FileReader(metaFile)); - this.targetVersion = StreamSupport.stream(parsed.getAsJsonArray().spliterator(), false) - .max(Comparator.comparing( - element -> element.getAsJsonObject().get("build").getAsInt(), - Integer::compare - )) - .map(element -> element.getAsJsonObject().get("version").getAsString()); + this.getTargetVersionImpl().set(StreamSupport.stream(parsed.getAsJsonArray().spliterator(), false) + .max(Comparator.comparing( + element -> element.getAsJsonObject().get("build").getAsInt(), + Integer::compare + )) + .map(element -> element.getAsJsonObject().get("version").getAsString()) + .orElse(null) + ); } catch (IOException e) { - this.targetVersion = Optional.empty(); + this.getLogger().error("Failed to read target version", e); } } - public Optional getTargetVersion() { - return this.targetVersion; + /** + * This is only populated after the task has run. + *

+ * It should only be accessed from other tasks' {@linkplain TaskAction actions} or + * {@linkplain org.gradle.api.Task#onlyIf predicates} and via + * {@linkplain Property lazy} {@linkplain org.gradle.api.tasks.Input input}. + *

+ * It may be absent even after this task has run, so always check {@link Provider#isPresent() isPresent}. + */ + @Internal + public Provider getTargetVersion() { + return this.getTargetVersionImpl(); } } diff --git a/buildSrc/src/main/java/quilt/internal/tasks/diff/CheckUnpickVersionsMatchTask.java b/buildSrc/src/main/java/quilt/internal/tasks/diff/CheckUnpickVersionsMatchTask.java index 5e7b606841..72755c0186 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/diff/CheckUnpickVersionsMatchTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/diff/CheckUnpickVersionsMatchTask.java @@ -5,47 +5,62 @@ import com.google.gson.JsonElement; import com.google.gson.JsonParser; +import org.gradle.api.GradleException; import org.gradle.api.artifacts.VersionConstraint; import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.provider.Property; +import org.gradle.api.provider.Provider; import org.gradle.api.tasks.InputFile; import org.gradle.api.tasks.Internal; import org.gradle.api.tasks.TaskAction; import quilt.internal.tasks.DefaultMappingsTask; -public abstract class CheckUnpickVersionsMatchTask extends DefaultMappingsTask { +// TODO see if this can be replaced with a ValueSource or a BuildService +/** + * @see UnpickVersionsMatchConsumingTask + */ +public abstract class CheckUnpickVersionsMatchTask extends DefaultMappingsTask implements TargetVersionConsumingTask { public static final String TASK_NAME = "checkUnpickVersionsMatch"; @InputFile public abstract RegularFileProperty getUnpickJson(); @Internal - private boolean match = false; + protected abstract Property getMatch(); public CheckUnpickVersionsMatchTask() { super("diff"); - this.dependsOn(DownloadTargetMappingJarTask.TASK_NAME); - - this.onlyIf(task -> - this.getTaskNamed(CheckTargetVersionExistsTask.TASK_NAME, CheckTargetVersionExistsTask.class) - .getTargetVersion().isPresent() - ); - - this.getUnpickJson().convention( - this.getTaskNamed(DownloadTargetMappingJarTask.TASK_NAME, DownloadTargetMappingJarTask.class) - .getTargetUnpickFile() - ); + // provide an informative error message if isMatch is accessed incorrectly + this.getMatch().convention(this.getProject().provider(() -> { + throw new GradleException( + "targetVersion has not been populated. " + + "Its should only be accessed from others tasks' inputs or predicates and " + + "only after checking if it's present." + ); + })); } @TaskAction public void checkMatch() throws IOException { final JsonElement parsed = JsonParser.parseReader(new FileReader(this.getUnpickJson().getAsFile().get())); - this.match = parsed.getAsJsonObject().get("unpickVersion").getAsString().equals( - this.libs().findVersion("unpick").map(VersionConstraint::getRequiredVersion).orElse("") + this.getMatch().set( + parsed.getAsJsonObject().get("unpickVersion").getAsString().equals( + this.libs().findVersion("unpick").map(VersionConstraint::getRequiredVersion).orElse("") + ) ); } - public boolean isMatch() { - return this.match; + /** + * This is only populated after the task has run. + *

+ * It should only be accessed from other tasks' {@linkplain TaskAction actions} or + * {@linkplain org.gradle.api.Task#onlyIf predicates} and via + * {@linkplain Property lazy} {@linkplain org.gradle.api.tasks.Input input}. + *

+ * It may be absent even after this task has run, so always check {@link Provider#isPresent() isPresent}. + */ + public Provider isMatch() { + return this.getMatch(); } } diff --git a/buildSrc/src/main/java/quilt/internal/tasks/diff/DecompileTargetTask.java b/buildSrc/src/main/java/quilt/internal/tasks/diff/DecompileTargetTask.java new file mode 100644 index 0000000000..ad792e25a4 --- /dev/null +++ b/buildSrc/src/main/java/quilt/internal/tasks/diff/DecompileTargetTask.java @@ -0,0 +1,42 @@ +package quilt.internal.tasks.diff; + +import org.apache.commons.io.FileUtils; +import org.gradle.api.GradleException; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.provider.Property; +import org.gradle.api.tasks.Input; +import org.gradle.api.tasks.InputFile; +import quilt.internal.tasks.decompile.DecompileTask; +import quilt.internal.util.MappingsJavadocProvider; + +import java.io.IOException; + +public abstract class DecompileTargetTask extends DecompileTask implements UnpickVersionsMatchConsumingTask { + @Input + public abstract Property getNamespace(); + + @InputFile + public abstract RegularFileProperty getTargetMappingsFile(); + + @Override + public void decompile() { + try { + FileUtils.deleteDirectory(this.getOutput().get().getAsFile()); + } catch (IOException e) { + throw new GradleException("Failed to delete previous output", e); + } + + try { + final MappingsJavadocProvider javadocProvider = + new MappingsJavadocProvider(this.getTargetMappingsFile().get().getAsFile(), this.getNamespace().get()); + + this.classJavadocProvider(javadocProvider); + this.fieldJavadocProvider(javadocProvider); + this.methodJavadocProvider(javadocProvider); + } catch (IOException e) { + throw new GradleException("Failed to create javadoc provider", e); + } + + super.decompile(); + } +} diff --git a/buildSrc/src/main/java/quilt/internal/tasks/diff/DownloadTargetMappingJarTask.java b/buildSrc/src/main/java/quilt/internal/tasks/diff/DownloadTargetMappingJarTask.java index d851d397c9..9cc754d4b8 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/diff/DownloadTargetMappingJarTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/diff/DownloadTargetMappingJarTask.java @@ -4,83 +4,28 @@ import java.io.IOException; import org.gradle.api.file.RegularFileProperty; -import org.gradle.api.provider.Provider; -import org.gradle.api.tasks.Internal; import org.gradle.api.tasks.OutputFile; import org.gradle.api.tasks.TaskAction; -import quilt.internal.Constants; import quilt.internal.tasks.DefaultMappingsTask; -public abstract class DownloadTargetMappingJarTask extends DefaultMappingsTask { +public abstract class DownloadTargetMappingJarTask extends DefaultMappingsTask implements TargetVersionConsumingTask { public static final String TASK_NAME = "downloadTargetMappingsJar"; @OutputFile - public abstract RegularFileProperty getTargetMappingsFile(); - - @OutputFile - public abstract RegularFileProperty getTargetUnpickFile(); - - @OutputFile - public abstract RegularFileProperty getTargetUnpickDefinitionsFile(); - - @Internal - public abstract RegularFileProperty getTargetUnpickRemappedDefinitionsFile(); + public abstract RegularFileProperty getTargetJar(); @OutputFile public abstract RegularFileProperty getTargetUnpickConstantsFile(); - public static final String TARGET_MAPPINGS = ".gradle/targets"; - public DownloadTargetMappingJarTask() { super("diff"); - - final CheckTargetVersionExistsTask checkExists = - this.getTaskNamed(CheckTargetVersionExistsTask.TASK_NAME, CheckTargetVersionExistsTask.class); - this.onlyIf(task -> checkExists.getTargetVersion().isPresent()); - - this.dependsOn(CheckTargetVersionExistsTask.TASK_NAME); - - final Provider targetOrMappingsVersion = this.getProject().provider(() -> - checkExists.getTargetVersion().orElse(Constants.MAPPINGS_VERSION) - ); - - this.getTargetMappingsFile().convention(targetOrMappingsVersion.map(version -> - this.regularProjectFileOf( - TARGET_MAPPINGS + "/quilt-mappings-" + version + "/mappings/mappings.tiny" - )) - ); - this.getTargetUnpickFile().convention(targetOrMappingsVersion.map(version -> - this.regularProjectFileOf( - TARGET_MAPPINGS + "/quilt-mappings-" + version + "/extras/unpick.json" - ) - )); - this.getTargetUnpickDefinitionsFile().convention(targetOrMappingsVersion.map(version -> - this.regularProjectFileOf( - TARGET_MAPPINGS + "/quilt-mappings-" + version + "/extras/definitions.unpick" - ) - )); - this.getTargetUnpickRemappedDefinitionsFile().convention(targetOrMappingsVersion.map(version -> - this.regularProjectFileOf( - TARGET_MAPPINGS + "/quilt-mappings-" + version + "remapped-unpick.unpick" - ) - )); - this.getTargetUnpickConstantsFile().convention(targetOrMappingsVersion.map(version -> - this.regularProjectFileOf( - TARGET_MAPPINGS + "/quilt-mappings-" + version + "-constants.jar" - ) - )); } @TaskAction public void downloadTargetMappings() throws IOException { - // TODO eliminate project access in task action - final String targetVersion = - this.getTaskNamed(CheckTargetVersionExistsTask.TASK_NAME, CheckTargetVersionExistsTask.class) - .getTargetVersion().orElseThrow(); + final String targetVersion = this.getTargetVersion().get(); - // TODO eliminate project access in task action - final File targetMappingsJar = - this.getProject().file(TARGET_MAPPINGS + "/quilt-mappings-" + targetVersion + "-v2.jar"); + final File targetMappingsJar = this.getTargetJar().get().getAsFile(); this.startDownload() .src( "https://maven.quiltmc.org/repository/release/org/quiltmc/quilt-mappings/" + targetVersion + @@ -94,17 +39,7 @@ public void downloadTargetMappings() throws IOException { "https://maven.quiltmc.org/repository/release/org/quiltmc/quilt-mappings/" + targetVersion + "/quilt-mappings-" + targetVersion + "-constants.jar" ) - .dest(this.getTargetUnpickConstantsFile().getAsFile().get()) + .dest(this.getTargetUnpickConstantsFile().get().getAsFile()) .download(); - - this.getProject() - .zipTree(targetMappingsJar) - .getAsFileTree() - .visit(fileVisitDetails -> - fileVisitDetails.copyTo(this.getProject().file( - TARGET_MAPPINGS + "/quilt-mappings-" + targetVersion + "/" + - fileVisitDetails.getRelativePath() - )) - ); } } diff --git a/buildSrc/src/main/java/quilt/internal/tasks/diff/ExtractTargetMappingJarTask.java b/buildSrc/src/main/java/quilt/internal/tasks/diff/ExtractTargetMappingJarTask.java new file mode 100644 index 0000000000..53875381dc --- /dev/null +++ b/buildSrc/src/main/java/quilt/internal/tasks/diff/ExtractTargetMappingJarTask.java @@ -0,0 +1,40 @@ +package quilt.internal.tasks.diff; + +import org.gradle.api.file.DirectoryProperty; +import org.gradle.api.file.FileTree; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.tasks.InputFile; +import org.gradle.api.tasks.Optional; +import org.gradle.api.tasks.OutputDirectory; +import org.gradle.api.tasks.TaskAction; +import quilt.internal.tasks.DefaultMappingsTask; + +public abstract class ExtractTargetMappingJarTask extends DefaultMappingsTask implements TargetVersionConsumingTask { + public static final String TASK_NAME = "extractTargetMappingsJar"; + + @InputFile + @Optional + public abstract RegularFileProperty getTargetJar(); + + @OutputDirectory + public abstract DirectoryProperty getExtractionDest(); + + private final FileTree targetJarZipTree; + + public ExtractTargetMappingJarTask() { + super("diff"); + + this.targetJarZipTree = this.getProject().zipTree(this.getTargetJar()); + } + + @TaskAction + public void extractTargetMappings() { + this.targetJarZipTree + .getAsFileTree() + .visit(fileVisitDetails -> + fileVisitDetails.copyTo( + this.getExtractionDest().file(fileVisitDetails.getRelativePath().getPathString()).get().getAsFile() + ) + ); + } +} diff --git a/buildSrc/src/main/java/quilt/internal/tasks/diff/RemapTargetMinecraftJarTask.java b/buildSrc/src/main/java/quilt/internal/tasks/diff/RemapTargetMinecraftJarTask.java index 43de6abb29..7ca570a6df 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/diff/RemapTargetMinecraftJarTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/diff/RemapTargetMinecraftJarTask.java @@ -2,34 +2,30 @@ import java.util.Map; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.provider.Property; +import org.gradle.api.tasks.Input; +import org.gradle.api.tasks.Internal; +import org.gradle.api.tasks.Optional; import quilt.internal.Constants; import quilt.internal.tasks.jarmapping.MapJarTask; -public abstract class RemapTargetMinecraftJarTask extends MapJarTask { +public abstract class RemapTargetMinecraftJarTask extends MapJarTask implements UnpickVersionsMatchConsumingTask { public static final String TASK_NAME = "remapTargetMinecraftJar"; - public RemapTargetMinecraftJarTask() { - super("diff", Constants.PER_VERSION_MAPPINGS_NAME, "named"); - - final CheckTargetVersionExistsTask checkExists = - this.getTaskNamed(CheckTargetVersionExistsTask.TASK_NAME, CheckTargetVersionExistsTask.class); - final CheckUnpickVersionsMatchTask checkUnpickExists = - this.getTaskNamed(CheckUnpickVersionsMatchTask.TASK_NAME, CheckUnpickVersionsMatchTask.class); + // TODO temporarily internal, until CheckTargetVersionExistsTask is converted to a BuildService + @Internal("temporary") + @Override + // @InputFile + // @Optional + public abstract RegularFileProperty getInputJar(); - this.onlyIf(task -> checkExists.getTargetVersion().isPresent() && checkUnpickExists.isMatch()); - this.dependsOn(DownloadTargetMappingJarTask.TASK_NAME, "unpickTargetJar"); - final DownloadTargetMappingJarTask downloadTarget = - this.getTaskNamed(DownloadTargetMappingJarTask.TASK_NAME, DownloadTargetMappingJarTask.class); + @Input + @Optional + public abstract Property getUnpickVersionsMatch(); - this.getInputJar().convention(() -> this.getProject().file( - DownloadTargetMappingJarTask.TARGET_MAPPINGS + "/quilt-mappings-" + - checkExists.getTargetVersion().orElse(Constants.MAPPINGS_VERSION) + "-unpicked.jar" - )); - this.getMappingsFile().set(downloadTarget.getTargetMappingsFile()); - this.getOutputJar().convention(() -> this.getProject().file( - DownloadTargetMappingJarTask.TARGET_MAPPINGS + "/quilt-mappings-" + - checkExists.getTargetVersion().orElse(Constants.MAPPINGS_VERSION) + "-named.jar" - )); + public RemapTargetMinecraftJarTask() { + super("diff", Constants.PER_VERSION_MAPPINGS_NAME, "named"); } public Map getAdditionalMappings() { diff --git a/buildSrc/src/main/java/quilt/internal/tasks/diff/RemapTargetUnpickDefinitionsTask.java b/buildSrc/src/main/java/quilt/internal/tasks/diff/RemapTargetUnpickDefinitionsTask.java new file mode 100644 index 0000000000..30531f4bae --- /dev/null +++ b/buildSrc/src/main/java/quilt/internal/tasks/diff/RemapTargetUnpickDefinitionsTask.java @@ -0,0 +1,8 @@ +package quilt.internal.tasks.diff; + +import quilt.internal.tasks.unpick.RemapUnpickDefinitionsTask; + +public abstract class RemapTargetUnpickDefinitionsTask extends RemapUnpickDefinitionsTask implements + UnpickVersionsMatchConsumingTask { + public static final String TASK_NAME = "remapTargetUnpickDefinitions"; +} diff --git a/buildSrc/src/main/java/quilt/internal/tasks/diff/TargetVersionConsumingTask.java b/buildSrc/src/main/java/quilt/internal/tasks/diff/TargetVersionConsumingTask.java new file mode 100644 index 0000000000..97b3c0fe1e --- /dev/null +++ b/buildSrc/src/main/java/quilt/internal/tasks/diff/TargetVersionConsumingTask.java @@ -0,0 +1,57 @@ +package quilt.internal.tasks.diff; + +import org.gradle.api.Transformer; +import org.gradle.api.file.Directory; +import org.gradle.api.file.RegularFile; +import org.gradle.api.provider.Property; +import org.gradle.api.provider.Provider; +import org.gradle.api.tasks.Input; +import org.gradle.api.tasks.Optional; +import quilt.internal.tasks.MappingsTask; + +import java.io.File; +import java.nio.file.Path; + +/** + * A task that takes a target version as input. + *

+ * A target version is a published Quilt Mappings version obtained from the Quilt maven. + *

+ * If {@link quilt.internal.MappingsPlugin MappingsPlugin} is applied, any {@code TargetVersionConsumingTask}s + * will use {@value CheckTargetVersionExistsTask#TASK_NAME}'s + * {@link CheckTargetVersionExistsTask#getTargetVersion() targetVersion} by default, and they'll only run if the + * {@link #getTargetVersion() targetVersion} {@link Provider#isPresent() isPresent}. + */ +public interface TargetVersionConsumingTask extends MappingsTask { + @Input + @Optional + Property getTargetVersion(); + + /** + * @param pathFactory receives the {@linkplain #getTargetVersion() target version} + * and returns the path of the file to be provided; the path must represent a {@link RegularFile}, + * and relative paths will be resolved against the + * {@linkplain org.gradle.api.file.ProjectLayout#getProjectDirectory() project directory} + */ + default Provider provideVersionedProjectFile(Transformer pathFactory) { + return this.getProject().getLayout().file(this.providerVersionedFile(pathFactory)); + } + + /** + * @param pathFactory receives the {@linkplain #getTargetVersion() target version} + * and returns the path of the file to be provided; the path must represent a {@link Directory}, + * and relative paths will be resolved against the + * {@linkplain org.gradle.api.file.ProjectLayout#getProjectDirectory() project directory} + */ + default Provider provideVersionedProjectDir(Transformer pathFactory) { + return this.getProject().getLayout().dir(this.providerVersionedFile(pathFactory)); + } + + /** + * @param pathFactory receives the {@linkplain #getTargetVersion() target version} + * and returns the path of the file to be provided + */ + default Provider providerVersionedFile(Transformer pathFactory) { + return this.getTargetVersion().map(pathFactory).map(Path::toFile); + } +} diff --git a/buildSrc/src/main/java/quilt/internal/tasks/diff/UnpickTargetJarTask.java b/buildSrc/src/main/java/quilt/internal/tasks/diff/UnpickTargetJarTask.java new file mode 100644 index 0000000000..1e454ba641 --- /dev/null +++ b/buildSrc/src/main/java/quilt/internal/tasks/diff/UnpickTargetJarTask.java @@ -0,0 +1,7 @@ +package quilt.internal.tasks.diff; + +import quilt.internal.tasks.unpick.UnpickJarTask; + +public abstract class UnpickTargetJarTask extends UnpickJarTask implements UnpickVersionsMatchConsumingTask { + public static final String TASK_NAME = "unpickTargetJar"; +} diff --git a/buildSrc/src/main/java/quilt/internal/tasks/diff/UnpickVersionsMatchConsumingTask.java b/buildSrc/src/main/java/quilt/internal/tasks/diff/UnpickVersionsMatchConsumingTask.java new file mode 100644 index 0000000000..700064ba18 --- /dev/null +++ b/buildSrc/src/main/java/quilt/internal/tasks/diff/UnpickVersionsMatchConsumingTask.java @@ -0,0 +1,20 @@ +package quilt.internal.tasks.diff; + +import org.gradle.api.provider.Property; +import org.gradle.api.provider.Provider; +import org.gradle.api.tasks.Input; +import org.gradle.api.tasks.Optional; + +/** + * A task that takes whether two unpick versions match as input. + *

+ * If {@link quilt.internal.MappingsPlugin MappingsPlugin} is applied, any {@code UnpickVersionsMatchConsumingTask}s + * will use {@value CheckUnpickVersionsMatchTask#TASK_NAME}'s + * {@link CheckUnpickVersionsMatchTask#isMatch() match} by default, and they'll only run if + * {@link #getUnpickVersionsMatch() unpickVersionsMatch} {@link Provider#isPresent() isPresent} and {@code true}. + */ +public interface UnpickVersionsMatchConsumingTask extends TargetVersionConsumingTask { + @Input + @Optional + Property getUnpickVersionsMatch(); +} diff --git a/buildSrc/src/main/java/quilt/internal/tasks/jarmapping/MapJarTask.java b/buildSrc/src/main/java/quilt/internal/tasks/jarmapping/MapJarTask.java index 8db55b620e..3b047dd066 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/jarmapping/MapJarTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/jarmapping/MapJarTask.java @@ -2,7 +2,9 @@ import java.util.Map; +import org.gradle.api.file.DirectoryProperty; import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.tasks.InputDirectory; import org.gradle.api.tasks.InputFile; import org.gradle.api.tasks.Internal; import org.gradle.api.tasks.OutputFile; @@ -17,13 +19,16 @@ public abstract class MapJarTask extends DefaultMappingsTask { "javax/annotation/concurrent/Immutable", "org/jetbrains/annotations/Unmodifiable" ); @InputFile - protected abstract RegularFileProperty getInputJar(); + public abstract RegularFileProperty getInputJar(); @InputFile - protected abstract RegularFileProperty getMappingsFile(); + public abstract RegularFileProperty getMappingsFile(); + + @InputDirectory + public abstract DirectoryProperty getLibrariesDir(); @OutputFile - protected abstract RegularFileProperty getOutputJar(); + public abstract RegularFileProperty getOutputJar(); private final String from, to; @@ -38,10 +43,10 @@ public void remapJar() { this.getLogger().lifecycle(":mapping minecraft from " + this.from + " to " + this.to); final Map additionalMappings = this.getAdditionalMappings(); JarRemapper.mapJar( - this.getOutputJar().getAsFile().get(), - this.getInputJar().getAsFile().get(), + this.getOutputJar().get().getAsFile(), + this.getInputJar().get().getAsFile(), this.getMappingsFile().get().getAsFile(), - this.fileConstants.libraries, + this.getLibrariesDir().get().getAsFile(), this.from, this.to, builder -> builder.withMappings(out -> additionalMappings.forEach(out::acceptClass)) ); diff --git a/buildSrc/src/main/java/quilt/internal/tasks/jarmapping/MapNamedJarTask.java b/buildSrc/src/main/java/quilt/internal/tasks/jarmapping/MapNamedJarTask.java index 50ab759277..5540be0552 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/jarmapping/MapNamedJarTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/jarmapping/MapNamedJarTask.java @@ -3,28 +3,12 @@ import java.util.Map; import quilt.internal.Constants; -import quilt.internal.tasks.build.AddProposedMappingsTask; -import quilt.internal.tasks.setup.DownloadMinecraftLibrariesTask; - -import static quilt.internal.MappingsPlugin.INSERT_AUTO_GENERATED_MAPPINGS_TASK_NAME; public abstract class MapNamedJarTask extends MapJarTask { public static final String TASK_NAME = "mapNamedJar"; public MapNamedJarTask() { super(Constants.Groups.MAP_JAR_GROUP, Constants.PER_VERSION_MAPPINGS_NAME, "named"); - - this.getInputs() - .files(this.getTaskNamed(DownloadMinecraftLibrariesTask.TASK_NAME).getOutputs().getFiles().getFiles()); - - this.getInputJar().convention(() -> this.fileConstants.unpickedJar); - this.getMappingsFile().convention( - this.getTaskNamed(INSERT_AUTO_GENERATED_MAPPINGS_TASK_NAME, AddProposedMappingsTask.class) - .getOutputMappings() - ); - this.getOutputJar().convention(() -> this.fileConstants.namedJar); - - this.dependsOn(INSERT_AUTO_GENERATED_MAPPINGS_TASK_NAME, "unpickHashedJar"); } public Map getAdditionalMappings() { 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 2c217ed74a..f51376b8bb 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/jarmapping/MapPerVersionMappingsJarTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/jarmapping/MapPerVersionMappingsJarTask.java @@ -1,29 +1,11 @@ package quilt.internal.tasks.jarmapping; import quilt.internal.Constants; -import quilt.internal.MappingsPlugin; -import quilt.internal.tasks.setup.DownloadMinecraftLibrariesTask; -import quilt.internal.tasks.setup.ExtractTinyMappingsTask; -import quilt.internal.tasks.setup.MergeJarsTask; public abstract class MapPerVersionMappingsJarTask extends MapJarTask { public static final String TASK_NAME = "mapPerVersionMappingsJar"; public MapPerVersionMappingsJarTask() { super(Constants.Groups.MAP_JAR_GROUP, "official", Constants.PER_VERSION_MAPPINGS_NAME); - this.dependsOn( - DownloadMinecraftLibrariesTask.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(MappingsPlugin.EXTRACT_TINY_PER_VERSION_MAPPINGS_TASK_NAME, ExtractTinyMappingsTask.class) - .getTinyFile() - ); - this.getOutputJar().convention(() -> this.fileConstants.perVersionMappingsJar); - - this.getInputs().files(this.fileConstants.libraries); } } diff --git a/buildSrc/src/main/java/quilt/internal/tasks/setup/DownloadMinecraftJarsTask.java b/buildSrc/src/main/java/quilt/internal/tasks/setup/DownloadMinecraftJarsTask.java index 6fba659f55..0fea7df099 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/setup/DownloadMinecraftJarsTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/setup/DownloadMinecraftJarsTask.java @@ -25,6 +25,7 @@ public abstract class DownloadMinecraftJarsTask extends DefaultMappingsTask { @InputFile public abstract RegularFileProperty getVersionFile(); + // TODO put this in something Serializable or make this Transient @Internal("Fingerprinting is handled by getVersionFile") protected abstract Property getVersion(); diff --git a/buildSrc/src/main/java/quilt/internal/tasks/setup/DownloadMinecraftLibrariesTask.java b/buildSrc/src/main/java/quilt/internal/tasks/setup/DownloadMinecraftLibrariesTask.java index 28f536f21f..ba95102d65 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/setup/DownloadMinecraftLibrariesTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/setup/DownloadMinecraftLibrariesTask.java @@ -26,23 +26,16 @@ import org.quiltmc.launchermeta.version.v1.Library; import org.quiltmc.launchermeta.version.v1.Version; import quilt.internal.Constants; -import quilt.internal.FileConstants; import quilt.internal.tasks.DefaultMappingsTask; +// TODO see if this can be replaced with a ValueSource or a BuildService public abstract class DownloadMinecraftLibrariesTask extends DefaultMappingsTask { public static final String TASK_NAME = "downloadMinecraftLibraries"; - /** - * This is only populated after the task has run. - *

- * It should only be accessed from other {@linkplain TaskAction tasks' actions} and via - * {@linkplain MapProperty lazy} {@linkplain org.gradle.api.tasks.Input input}. - */ - public final Provider> artifactsByUrl; - @InputFile public abstract RegularFileProperty getVersionFile(); + // TODO put this in something Serializable or make this Transient @Internal("Fingerprinting is handled by getVersionFile") protected abstract Property getVersion(); @@ -50,7 +43,7 @@ public abstract class DownloadMinecraftLibrariesTask extends DefaultMappingsTask public abstract DirectoryProperty getLibrariesDir(); @Internal("Fingerprinting is handled by getLibrariesDir") - protected abstract MapProperty getArtifactsByUrl(); + protected abstract MapProperty getArtifactsByUrlImpl(); public DownloadMinecraftLibrariesTask() { super(Constants.Groups.SETUP_GROUP); @@ -66,14 +59,12 @@ public DownloadMinecraftLibrariesTask() { })); // provide an informative error message if this property is accessed incorrectly - this.getArtifactsByUrl().convention(this.getProject().provider(() -> { + this.getArtifactsByUrlImpl().convention(this.getProject().provider(() -> { throw new GradleException( "artifactsByUrl has not been populated. " + "It should only be accessed from other tasks' actions and via lazy input." ); })); - - this.artifactsByUrl = this.getArtifactsByUrl(); } @TaskAction @@ -133,7 +124,20 @@ public void downloadMinecraftLibrariesTask() { throw new RuntimeException("Unable to download libraries for specified minecraft version."); } - this.getArtifactsByUrl().set(artifactsByUrl); + this.getArtifactsByUrlImpl().set(artifactsByUrl); + } + + // TODO can this instead put artifacts in sub-dirs based on urls, so consumers can take getLibrariesDir as input + // and retrieve by url by finding the right sub-dir? + /** + * This is only populated after the task has run. + *

+ * It should only be accessed from other tasks' {@linkplain TaskAction actions} and via + * {@linkplain MapProperty lazy} {@linkplain org.gradle.api.tasks.Input input}. + */ + @Internal + public Provider> getArtifactsByUrl() { + return this.getArtifactsByUrlImpl(); } private File artifactOf(String url) { diff --git a/buildSrc/src/main/java/quilt/internal/tasks/setup/DownloadWantedVersionManifestTask.java b/buildSrc/src/main/java/quilt/internal/tasks/setup/DownloadWantedVersionManifestTask.java index 9205fdc7fe..3f012fca93 100644 --- a/buildSrc/src/main/java/quilt/internal/tasks/setup/DownloadWantedVersionManifestTask.java +++ b/buildSrc/src/main/java/quilt/internal/tasks/setup/DownloadWantedVersionManifestTask.java @@ -36,6 +36,7 @@ public abstract class DownloadWantedVersionManifestTask extends DefaultMappingsT @org.gradle.api.tasks.Optional protected abstract Property getReleaseTime(); + // TODO make WantedVersionConsumingTask interface for this @OutputFile public abstract RegularFileProperty getVersionFile();