diff --git a/buildSrc/src/main/java/quilt/internal/constants/Extensions.java b/buildSrc/src/main/java/quilt/internal/constants/Extensions.java index 0c5d4b8712..1d96afd3ea 100644 --- a/buildSrc/src/main/java/quilt/internal/constants/Extensions.java +++ b/buildSrc/src/main/java/quilt/internal/constants/Extensions.java @@ -8,4 +8,5 @@ public interface Extensions { String UNPICK = Constants.UNPICK_NAME; String GZ = "gz"; String JSON = "json"; + String TXT = "txt"; } diff --git a/buildSrc/src/main/java/quilt/internal/plugin/MinecraftJarsPlugin.java b/buildSrc/src/main/java/quilt/internal/plugin/MinecraftJarsPlugin.java index e372b72cd7..19dd3f3acd 100644 --- a/buildSrc/src/main/java/quilt/internal/plugin/MinecraftJarsPlugin.java +++ b/buildSrc/src/main/java/quilt/internal/plugin/MinecraftJarsPlugin.java @@ -12,6 +12,7 @@ import quilt.internal.task.VersionParserConsumingTask; import quilt.internal.task.setup.DownloadMinecraftJarsTask; import quilt.internal.task.setup.DownloadMinecraftLibrariesTask; +import quilt.internal.task.setup.DownloadMojangMappingsTask; import quilt.internal.task.setup.DownloadWantedVersionManifestTask; import quilt.internal.task.setup.ExtractServerJarTask; import quilt.internal.task.setup.MergeJarsTask; @@ -98,9 +99,9 @@ protected MinecraftJarsExtension applyImpl(@NotNull Project project) { downloadMinecraftJars.flatMap(DownloadMinecraftJarsTask::getServerBootstrapJar) ); - task.getExtractionDest().convention( - this.provideMinecraftBuildFile(quiltExt.provideSuffixedMinecraftVersion("-server." + Extensions.JAR)) - ); + task.getExtractionDest().convention(this.provideMinecraftBuildFile( + quiltExt.provideSuffixedMinecraftVersion("-server." + Extensions.JAR) + )); } ); @@ -112,9 +113,9 @@ protected MinecraftJarsExtension applyImpl(@NotNull Project project) { task.getServerJar().convention(extractServerJar.flatMap(ExtractServerJarTask::getExtractionDest)); - task.getMergedFile().convention( - this.provideMinecraftBuildFile(quiltExt.provideSuffixedMinecraftVersion("-merged." + Extensions.JAR)) - ); + task.getMergedFile().convention(this.provideMinecraftBuildFile( + quiltExt.provideSuffixedMinecraftVersion("-merged." + Extensions.JAR) + )); } ); @@ -126,6 +127,20 @@ protected MinecraftJarsExtension applyImpl(@NotNull Project project) { } ); + tasks.register( + DownloadMojangMappingsTask.DOWNLOAD_MOJANG_MAPPINGS_TASK_NAME, + DownloadMojangMappingsTask.class, + task -> { + task.getClientMappings().convention( + this.getMinecraftBuildDir().map(dir -> dir.file("client." + Extensions.TXT)) + ); + + task.getServerMappings().convention( + this.getMinecraftBuildDir().map(dir -> dir.file("server." + Extensions.TXT)) + ); + } + ); + return project.getExtensions().create( MinecraftJarsExtension.NAME, MinecraftJarsExtension.class, new Tasks(mergeJars, downloadMinecraftLibraries) diff --git a/buildSrc/src/main/java/quilt/internal/task/setup/DownloadMojangMappingsTask.java b/buildSrc/src/main/java/quilt/internal/task/setup/DownloadMojangMappingsTask.java new file mode 100644 index 0000000000..d16e6a89fd --- /dev/null +++ b/buildSrc/src/main/java/quilt/internal/task/setup/DownloadMojangMappingsTask.java @@ -0,0 +1,58 @@ +package quilt.internal.task.setup; + +import org.gradle.api.DefaultTask; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.tasks.OutputFile; +import org.gradle.api.tasks.TaskAction; +import org.quiltmc.launchermeta.version.v1.Downloads; +import quilt.internal.constants.Groups; +import quilt.internal.plugin.MinecraftJarsPlugin; +import quilt.internal.task.VersionParserConsumingTask; +import quilt.internal.util.DownloadUtil; + +/** + * Downloads Mojang's client and server mappings for the passed {@linkplain #getVersionParser version}. + * + * @see Obfuscation map + * @see MinecraftJarsPlugin MinecraftJarsPlugin's configureEach + */ +public abstract class DownloadMojangMappingsTask extends DefaultTask implements VersionParserConsumingTask { + /** + * {@linkplain org.gradle.api.tasks.TaskContainer#register Registered} by + * {@link MinecraftJarsPlugin MinecraftJarsPlugin}. + */ + public static final String DOWNLOAD_MOJANG_MAPPINGS_TASK_NAME = "downloadMojangMappings"; + + @OutputFile + public abstract RegularFileProperty getClientMappings(); + + @OutputFile + public abstract RegularFileProperty getServerMappings(); + + public DownloadMojangMappingsTask() { + this.setGroup(Groups.SETUP); + } + + @TaskAction + public void download() { + final Downloads downloads = this.getVersionParser().get().get().getDownloads(); + + downloads.getClientMappings().ifPresentOrElse( + clientMappings -> DownloadUtil.download( + clientMappings.getUrl(), + this.getClientMappings().get().getAsFile(), + false, this.getLogger() + ), + () -> this.getLogger().warn("No client mappings available") + ); + + downloads.getServerMappings().ifPresentOrElse( + serverMappings -> DownloadUtil.download( + serverMappings.getUrl(), + this.getServerMappings().get().getAsFile(), + false, this.getLogger() + ), + () -> this.getLogger().warn("No server mappings available") + ); + } +}