Skip to content

Commit 1b5adfc

Browse files
committed
Add --decompile-memory argument, partially addresses #21
1 parent 38d327f commit 1b5adfc

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ static OptionParser run(String[] args, boolean getParser) throws Exception {
9898
var parchmentO = parser.accepts("parchment",
9999
"Version of parchment mappings to use, snapshots are not supported")
100100
.availableIf(mappingsO).withRequiredArg();
101+
102+
// ignore caches, currently only invalidates HashStore entries
103+
var ignoreCacheO = parser.accepts("ignore-cache",
104+
"Forces all cache checks to fail, which results in all tasks re-running");
105+
106+
// Add extra memory to the java decompile and recompile tasks
107+
var decompileMemoryO = parser.accepts("decompile-memory",
108+
"Overrides the -Xmx argument passed into the decompile sub-processes")
109+
.withRequiredArg();
101110
//@formatter:on
102111

103112
if (getParser)
@@ -110,6 +119,11 @@ static OptionParser run(String[] args, boolean getParser) throws Exception {
110119
return parser;
111120
}
112121

122+
if (options.has(ignoreCacheO))
123+
Mavenizer.setIgnoreCache();
124+
if (options.has(decompileMemoryO))
125+
Mavenizer.setDecompileMemory(options.valueOf(decompileMemoryO));
126+
113127
var output = options.valueOf(outputO);
114128
var outputFiles = options.valueOf(outputFilesO);
115129
var cacheRoot = options.valueOf(cacheO);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ static OptionParser run(String[] args, boolean getParser) throws Exception {
7878
.availableUnless(cacheOnlyO);
7979
cacheOnlyO.availableUnless(ignoreCacheO);
8080

81+
// Add extra memory to the java decompile and recompile tasks
82+
var decompileMemoryO = parser.accepts("decompile-memory",
83+
"Overrides the -Xmx argument passed into the decompile sub-processes")
84+
.withRequiredArg();
85+
8186
var mappingsO = parser.accepts("mappings",
8287
"Mappings to use for this artifact. Formatted as channel:version")
8388
.withRequiredArg().ofType(String.class).defaultsTo("official");
@@ -154,6 +159,8 @@ static OptionParser run(String[] args, boolean getParser) throws Exception {
154159
Mavenizer.setCacheOnly();
155160
if (options.has(ignoreCacheO))
156161
Mavenizer.setIgnoreCache();
162+
if (options.has(decompileMemoryO))
163+
Mavenizer.setDecompileMemory(options.valueOf(decompileMemoryO));
157164

158165
var output = options.valueOf(outputO);
159166
var cache = options.valueOf(cacheO);

src/main/java/net/minecraftforge/mcmaven/impl/Mavenizer.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
package net.minecraftforge.mcmaven.impl;
66

77
import java.io.File;
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
11+
import org.jetbrains.annotations.Nullable;
812

913
import net.minecraftforge.util.hash.HashStore;
1014
import net.minecraftforge.util.logging.Logger;
@@ -65,4 +69,24 @@ public static boolean checkCache(File output, HashStore cache) {
6569
Mavenizer.assertNotCacheOnly();
6670
return false;
6771
}
72+
73+
private static @Nullable String decompileMemory = null;
74+
public static void setDecompileMemory(String value) {
75+
decompileMemory = value;
76+
}
77+
public static List<String> fillDecompileJvmArgs(List<String> args) {
78+
return fillJvmArgs(decompileMemory, args);
79+
}
80+
private static List<String> fillJvmArgs(@Nullable String mx, List<String> args) {
81+
if (mx == null)
82+
return args;
83+
var ret = new ArrayList<String>();
84+
ret.add("-Xmx" + mx);
85+
for (var arg : args) {
86+
if (arg.startsWith("-Xmx"))
87+
continue;
88+
ret.add(arg);
89+
}
90+
return ret;
91+
}
6892
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,9 @@ private File execute(String name, List<TaskOrArg> jvmArgs, List<TaskOrArg> runAr
899899
throw new IllegalStateException("Failed to find JDK for version " + java_version, e);
900900
}
901901

902+
if (isDecompile)
903+
jvm = Mavenizer.fillDecompileJvmArgs(jvm);
904+
902905
var ret = ProcessUtils.runJar(jdk, log.getParentFile(), log, tool, jvm, run, isDecompile ? MCPTaskFactory::parseDecompileLog : null);
903906
if (ret.exitCode != 0)
904907
throw new IllegalStateException("Failed to run MCP Step (exit code " + ret.exitCode + "), See log: " + log.getAbsolutePath());

src/main/java/net/minecraftforge/mcmaven/impl/util/ProcessUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@ private static Result runJavac(File javaHome, File workDir, File logFile, List<S
413413
};
414414

415415
int ret = runCommand(workDir, lines, command.toArray(String[]::new));
416-
System.currentTimeMillis();
417416

418417
log.flush();
419418
return new Result(consoleLog, ret);

0 commit comments

Comments
 (0)