Skip to content

Commit 6ce3379

Browse files
committed
Added --raw flag to MCPTask to output the raw jar
Combine with `--searge` for the SRG jar. This may or may not be removed at a later date depending on how ForgeDev turns out.
1 parent c12ef55 commit 6ce3379

File tree

1 file changed

+47
-5
lines changed

1 file changed

+47
-5
lines changed

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

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,24 @@ public static void run(String[] args) throws Exception {
6464
"MCPConfig pipeline to run, typically [client|server|joined]")
6565
.withRequiredArg().defaultsTo("joined");
6666

67+
var rawO = parser.accepts("raw",
68+
"Use to output a raw jar file without any MCPConfig transformations.");
69+
70+
var seargeO = parser.accepts("searge",
71+
"Use with --raw to output the raw jar file renamed with SRG names")
72+
.availableIf(rawO);
73+
6774
var atO = parser.accepts("at",
6875
"Access Transformer config file to apply")
69-
.withOptionalArg().ofType(File.class);
76+
.availableUnless(rawO).withOptionalArg().ofType(File.class);
7077

7178
var sasO = parser.accepts("sas",
7279
"Side Annotation Stripper confg file to apply")
73-
.withOptionalArg().ofType(File.class);
80+
.availableUnless(rawO).withOptionalArg().ofType(File.class);
7481

7582
var mappingsO = parser.accepts("mappings",
76-
"Use to enable using official mappings");
83+
"Use to enable using official mappings")
84+
.availableUnless(rawO);
7785

7886
var parchmentO = parser.accepts("parchment",
7987
"Version of parchment mappings to use, snapshots are not supported")
@@ -114,12 +122,46 @@ public static void run(String[] args) throws Exception {
114122
Log.info(" JDK Cache: " + jdkCacheRoot.getAbsolutePath());
115123
Log.info(" Artifact: " + artifact);
116124
Log.info(" Pipeline: " + pipeline);
117-
Log.info(" Access: " + (ats == null ? null : ats.getAbsolutePath()));
118-
Log.info(" SAS: " + (sas == null ? null : sas.getAbsolutePath()));
125+
if (options.has(rawO)) {
126+
Log.info(" Raw Names: " + (options.has(seargeO) ? "Searge" : "Notch"));
127+
} else {
128+
Log.info(" Access: " + (ats == null ? null : ats.getAbsolutePath()));
129+
Log.info(" SAS: " + (sas == null ? null : sas.getAbsolutePath()));
130+
}
119131
Log.info();
120132

121133
var mcp = repo.get(artifact);
122134
var side = mcp.getSide(pipeline);
135+
136+
if (options.has(rawO)) {
137+
var searge = options.has(seargeO);
138+
var cache = HashStore.fromFile(output)
139+
.addKnown("obfuscation", searge ? "srg" : "notch");
140+
141+
Task rawTask = searge ? side.getTasks().getSrgJar() : side.getTasks().getRawJar();
142+
File raw;
143+
144+
Log.info("Creating Raw Jar");
145+
var indent = Log.push();
146+
try {
147+
raw = rawTask.execute();
148+
cache.add("raw", raw);
149+
} finally {
150+
Log.pop(indent);
151+
}
152+
153+
if (!output.exists() || !cache.isSame()) {
154+
try {
155+
org.apache.commons.io.FileUtils.copyFile(raw, output);
156+
cache.save();
157+
} catch (Throwable t) {
158+
throw new RuntimeException("Failed to generate artifact: %s".formatted(artifact), t);
159+
}
160+
}
161+
162+
return;
163+
}
164+
123165
var sourcesTask = side.getSources();
124166

125167
if (ats != null || sas != null) {

0 commit comments

Comments
 (0)