Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add downloadMojangMappings task #668

Open
wants to merge 4 commits into
base: 25w02a
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ public interface Extensions {
String UNPICK = Constants.UNPICK_NAME;
String GZ = "gz";
String JSON = "json";
String TXT = "txt";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
));
}
);

Expand All @@ -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)
));
}
);

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <a href=https://minecraft.wiki/w/Obfuscation_map>Obfuscation map</a>
* @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")
);
}
}