Skip to content
Merged
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,22 +6,26 @@

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());
Expand All @@ -31,35 +35,41 @@ static TaskProvider<SlimeLauncherMetadata> register(Project project, MinecraftDe
});
}

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

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 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);
Comment thread
PaintNinja marked this conversation as resolved.
});

// 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);
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/net/minecraftforge/gradle/internal/Tools.java
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");
static final Tool MAVENIZER = Tool.ofForge("mavenizer", "net.minecraftforge:minecraft-mavenizer:0.5.21", 25, "net.minecraftforge.mcmaven.cli.Main");
}