Skip to content
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 @@ -137,7 +137,7 @@ static TaskProvider<SlimeLauncherEclipseConfiguration> register(Project project,

task.getCacheDir().set(task.getObjects().directoryProperty().value(task.globalCaches().dir("slime-launcher/cache/%s".formatted(mcdep.getPath())).map(task.problems.ensureFileLocation())));
task.getLocalCacheDir().set(task.getObjects().directoryProperty().value(task.localCaches().dir("slime-launcher/cache/%s".formatted(task.getName())).map(task.problems.ensureFileLocation())));
task.getMetadata().setFrom(metadata.map(SlimeLauncherMetadata::getMetadata));
task.getMetadata().setFrom(metadata.map(SlimeLauncherMetadata::getOutputDirectory));
task.getRunsJson().set(metadata.flatMap(SlimeLauncherMetadata::getRunsJson));

task.getOptions().set(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static TaskProvider<SlimeLauncherExec> register(Project project, SourceSet sourc

task.getCacheDir().set(task.getObjectFactory().directoryProperty().value(task.globalCaches().dir("slime-launcher/cache/%s".formatted(mcdep.getPath())).map(task.problems.ensureFileLocation())));
task.getLocalCacheDir().set(task.getObjectFactory().directoryProperty().value(task.localCaches().dir("slime-launcher/cache/%s".formatted(task.getName())).map(task.problems.ensureFileLocation())));
task.getMetadata().setFrom(metadata.map(SlimeLauncherMetadata::getMetadata));
task.getMetadata().setFrom(metadata.map(SlimeLauncherMetadata::getOutputDirectory));
task.getRunsJson().set(metadata.flatMap(SlimeLauncherMetadata::getRunsJson));

task.getOptions().set(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,70 @@

import org.gradle.api.DefaultTask;
import org.gradle.api.Project;
import org.gradle.api.file.ArchiveOperations;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.FileSystemOperations;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.OutputDirectory;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.PathSensitive;
import org.gradle.api.tasks.PathSensitivity;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.TaskProvider;

import javax.inject.Inject;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

@CacheableTask
abstract class SlimeLauncherMetadata extends DefaultTask implements ForgeGradleTask {
static TaskProvider<SlimeLauncherMetadata> register(Project project, MinecraftDependencyInternal mcdep) {
var taskName = "slimeLauncherMetadataFor" + Util.dependencyToCamelCase(mcdep.getModule());
return project.getTasks().register(taskName, SlimeLauncherMetadata.class, task -> {
task.setDescription("Extracts the Slime Launcher metadata for '%s'.".formatted(mcdep.toString()));
task.getMetadata().setFrom(mcdep.getMetadataDependency());
task.getMetadataZip().setFrom(mcdep.getMetadataDependency());
});
}

protected abstract @InputFiles ConfigurableFileCollection getMetadata();
@PathSensitive(PathSensitivity.NONE)
protected abstract @InputFiles ConfigurableFileCollection getMetadataZip();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking DSL change, i'd keep the property named getMetadata so that we don't have to worry about that.


protected abstract @OutputDirectory DirectoryProperty getOutputDirectory();

protected abstract @OutputFile RegularFileProperty getRunsJson();

protected abstract @Inject ArchiveOperations getArchiveOperations();

protected abstract @Inject FileSystemOperations getFileSystemOperations();

@Inject
public SlimeLauncherMetadata() {
this.getRunsJson().convention(this.getDefaultOutputDirectory().map(d -> d.file("runs.json")));
this.getOutputDirectory().convention(this.getDefaultOutputDirectory());
this.getRunsJson().convention(
this.getOutputDirectory().map(d -> d.dir("launcher").file("runs.json"))
);
}

@TaskAction
protected void exec() throws IOException {
var archive = this.getMetadata().getSingleFile();
var json = this.getRunsJson().getAsFile().get().toPath();
var archive = this.getMetadataZip().getSingleFile();
var outputDir = this.getOutputDirectory().get();

boolean foundRuns = false;
try (var zin = new ZipInputStream(new FileInputStream(archive))) {
for (ZipEntry entry; ((entry = zin.getNextEntry()) != null); ) {
if (!entry.getName().startsWith("launcher/"))
continue;
if (entry.getName().equals("launcher/runs.json")) {
Files.copy(zin, json, StandardCopyOption.REPLACE_EXISTING);
foundRuns = true;
}
}
}
this.getFileSystemOperations().sync(spec -> {
spec.from(this.getArchiveOperations().zipTree(archive));
spec.into(outputDir);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for note, this technically causes the entire zip archive to be extracted to disc twice due to how zipTree is implemented in gradle. Once in their zipTree cache and then to the output directory.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there another way that would be preferred over this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old code extracts just the files needed, do file locking. Its a trade off of which part you care about. It would probably be worth doing a matching('launcher/') to emulate the filter we had before. But the metadata zip doesn't contain much in it.

});

// If we don't find a metadata file, write an empty runs
// This happens when using a 'vanilla' minecraft dependency
if (!foundRuns)
// Write an empty runs.json if it doesn't exist
// This happens when using a 'vanilla' Minecraft dependency
var json = this.getRunsJson().getAsFile().get().toPath();
if (!Files.exists(json)) {
Files.createDirectories(json.getParent());
Files.writeString(json, "{}", StandardCharsets.UTF_8);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
final class Tools {
private Tools() { }

static final Tool SLIMELAUNCHER = Tool.ofForge("slimelauncher", "net.minecraftforge:slime-launcher:0.2.2", 8, "net.minecraftforge.launcher.Main");
static final Tool SLIMELAUNCHER = Tool.ofForge("slimelauncher", "net.minecraftforge:slime-launcher:0.2.3", 8, "net.minecraftforge.launcher.Main");

static final Tool MAVENIZER = Tool.ofForge("mavenizer", "net.minecraftforge:minecraft-mavenizer:0.5.19", 25, "net.minecraftforge.mcmaven.cli.Main");
}