Skip to content

Commit 59fb3ce

Browse files
committed
Add experimental "output-files" flag to MCPTask
`--output-files` expects a file for where the JSON file with paths to extra files will be placed. Extra files, for now, includes raw jars, version manifest/json, mappings, libraries.txt. These are all things that Mavenizer does so that ForgeDev doesn't have to do them. **This is EXPERIMENTAL and the flag will likely be removed soon!** This is only up for testing purposes right now, as I try and figure out a way to make ForgeDev 7 do less work.
1 parent 5f38053 commit 59fb3ce

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

src/main/java/net/minecraftforge/mcmaven/cli/MCPTask.java

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,27 @@
55
package net.minecraftforge.mcmaven.cli;
66

77
import java.io.File;
8-
import java.util.Set;
8+
import java.io.IOException;
9+
import java.nio.file.Files;
910

1011
import joptsimple.OptionParser;
1112
import net.minecraftforge.mcmaven.impl.MinecraftMaven;
1213
import net.minecraftforge.mcmaven.impl.cache.Cache;
14+
import net.minecraftforge.mcmaven.impl.data.MCPSetupFiles;
1315
import net.minecraftforge.mcmaven.impl.mappings.Mappings;
1416
import net.minecraftforge.mcmaven.impl.mappings.ParchmentMappings;
1517
import net.minecraftforge.mcmaven.impl.repo.forge.Patcher;
1618
import net.minecraftforge.mcmaven.impl.repo.mcpconfig.MCPConfigRepo;
19+
import net.minecraftforge.mcmaven.impl.repo.mcpconfig.MCPTaskFactory;
1720
import net.minecraftforge.mcmaven.impl.tasks.RenameTask;
1821
import net.minecraftforge.mcmaven.impl.util.Artifact;
1922
import net.minecraftforge.mcmaven.impl.util.Task;
2023
import net.minecraftforge.mcmaven.impl.util.Util;
24+
import net.minecraftforge.util.data.json.JsonData;
2125
import net.minecraftforge.util.hash.HashFunction;
2226
import net.minecraftforge.util.hash.HashStore;
2327
import net.minecraftforge.util.logging.Log;
28+
import org.jetbrains.annotations.Nullable;
2429

2530
// TODO [Mavenizer][MCPTask] Cleanup. Works well but is a mess.
2631
public class MCPTask {
@@ -49,9 +54,14 @@ public static void run(String[] args) throws Exception {
4954

5055
// mcp artifact output
5156
var outputO = parser.accepts("output",
52-
"Root directory to generate the maven repository")
57+
"File to output the final jar")
5358
.withRequiredArg().ofType(File.class).defaultsTo(new File("output.jar"));
5459

60+
// mcp artifact output
61+
var outputFilesO = parser.accepts("output-files",
62+
"File to output a JSON containing paths to extra files")
63+
.withRequiredArg().ofType(File.class).defaultsTo(new File("files.json"));
64+
5565
var artifactO = parser.accepts("artifact",
5666
"MCPConfig artifact coordinates")
5767
.withRequiredArg();
@@ -96,6 +106,7 @@ public static void run(String[] args) throws Exception {
96106
}
97107

98108
var output = options.valueOf(outputO);
109+
var outputFiles = options.valueOf(outputFilesO);
99110
var cacheRoot = options.valueOf(cacheO);
100111
var jdkCacheRoot = !options.has(cacheO) || options.has(jdkCacheO)
101112
? options.valueOf(jdkCacheO)
@@ -153,6 +164,8 @@ public static void run(String[] args) throws Exception {
153164
if (!output.exists() || !cache.isSame()) {
154165
try {
155166
org.apache.commons.io.FileUtils.copyFile(raw, output);
167+
if (outputFiles != null)
168+
writeFiles(side.getTasks(), outputFiles);
156169
cache.save();
157170
} catch (Throwable t) {
158171
throw new RuntimeException("Failed to generate artifact: %s".formatted(artifact), t);
@@ -217,10 +230,31 @@ public static void run(String[] args) throws Exception {
217230
if (!output.exists() || !cache.isSame()) {
218231
try {
219232
org.apache.commons.io.FileUtils.copyFile(sources, output);
233+
if (outputFiles != null)
234+
writeFiles(side.getTasks(), outputFiles);
220235
cache.save();
221236
} catch (Throwable t) {
222237
throw new RuntimeException("Failed to generate artifact: %s".formatted(artifact), t);
223238
}
224239
}
225240
}
241+
242+
// TODO [Mavenizer][Extra MCPTask Files] do this better
243+
private static void writeFiles(MCPTaskFactory mcpTaskFactory, File output) {
244+
var files = new MCPSetupFiles();
245+
files.versionManifest = mcpTaskFactory.findStep("downloadManifest").execute();
246+
files.versionJson = mcpTaskFactory.findStep("downloadJson").execute();
247+
files.clientRaw = mcpTaskFactory.findStep("downloadClient").execute();
248+
files.serverRaw = mcpTaskFactory.findStep("downloadServer").execute();
249+
files.serverExtracted = mcpTaskFactory.findStep("extractServer").execute();
250+
files.clientMappings = mcpTaskFactory.findStep("downloadClientMappings").execute();
251+
files.serverMappings = mcpTaskFactory.findStep("downloadServerMappings").execute();
252+
files.librariesList = mcpTaskFactory.findStep("listLibraries").execute();
253+
254+
try {
255+
JsonData.toJson(files, output);
256+
} catch (IOException e) {
257+
throw new RuntimeException("Failed to write extra files data: " + output.getPath(), e);
258+
}
259+
}
226260
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) Forge Development LLC and contributors
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
5+
package net.minecraftforge.mcmaven.impl.data;
6+
7+
import java.io.File;
8+
9+
public class MCPSetupFiles {
10+
public File versionManifest;
11+
public File versionJson;
12+
public File clientRaw;
13+
public File clientMappings;
14+
public File serverRaw;
15+
public File serverExtracted;
16+
public File serverMappings;
17+
public File librariesList;
18+
public File joinedSrgMappings;
19+
}

src/main/java/net/minecraftforge/mcmaven/impl/repo/mcpconfig/MCPTaskFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ private File getData() {
239239
return this.side.getMCP().getData();
240240
}
241241

242-
private Task findStep(String name) {
242+
public Task findStep(String name) {
243243
if (name.startsWith("{") && name.endsWith("Output}"))
244244
name = name.substring(1, name.length() - 7);
245245

0 commit comments

Comments
 (0)