mirror of
https://github.com/SKCraft/Launcher.git
synced 2024-11-27 12:46:22 +01:00
Add a check for Java runtime version before setting permgen flag
Some newer GraalVM versions appear to be throwing a hard error when the PermGen flag is specified; this commit changes the behaviour so the flag is only passed when the Java version is unknown or older than 1.8
This commit is contained in:
parent
8612b951e1
commit
cd88effb59
@ -27,7 +27,7 @@ public class JavaProcessBuilder {
|
||||
|
||||
private static final Pattern argsPattern = Pattern.compile("(?:([^\"]\\S*)|\"(.+?)\")\\s*");
|
||||
|
||||
@Getter @Setter private File jvmPath = JavaRuntimeFinder.findBestJavaPath();
|
||||
@Getter @Setter private JavaRuntime runtime;
|
||||
@Getter @Setter private int minMemory;
|
||||
@Getter @Setter private int maxMemory;
|
||||
@Getter @Setter private int permGen;
|
||||
@ -37,7 +37,9 @@ public class JavaProcessBuilder {
|
||||
@Getter private final List<String> args = new ArrayList<String>();
|
||||
@Getter @Setter private String mainClass;
|
||||
|
||||
public void tryJvmPath(File path) throws IOException {
|
||||
private File getJavaBinPath() throws IOException {
|
||||
File path = runtime.getDir().getAbsoluteFile();
|
||||
|
||||
// Try the parent directory
|
||||
if (!path.exists()) {
|
||||
throw new IOException(
|
||||
@ -51,7 +53,7 @@ public class JavaProcessBuilder {
|
||||
path = binDir;
|
||||
}
|
||||
|
||||
setJvmPath(path);
|
||||
return path;
|
||||
}
|
||||
|
||||
public JavaProcessBuilder classPath(File file) {
|
||||
@ -81,36 +83,35 @@ public class JavaProcessBuilder {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public List<String> buildCommand() {
|
||||
public List<String> buildCommand() throws IOException {
|
||||
List<String> command = new ArrayList<String>();
|
||||
|
||||
if (getJvmPath() != null) {
|
||||
command.add(getJvmPath() + File.separator + "java");
|
||||
if (getRuntime() != null) {
|
||||
File javaBinary = new File(getJavaBinPath(), "java");
|
||||
command.add(javaBinary.getAbsolutePath());
|
||||
} else {
|
||||
command.add("java");
|
||||
}
|
||||
|
||||
for (String flag : flags) {
|
||||
command.add(flag);
|
||||
}
|
||||
command.addAll(flags);
|
||||
|
||||
if (minMemory > 0) {
|
||||
command.add("-Xms" + String.valueOf(minMemory) + "M");
|
||||
command.add("-Xms" + minMemory + "M");
|
||||
}
|
||||
|
||||
if (maxMemory > 0) {
|
||||
command.add("-Xmx" + String.valueOf(maxMemory) + "M");
|
||||
command.add("-Xmx" + maxMemory + "M");
|
||||
}
|
||||
|
||||
if (permGen > 0) {
|
||||
command.add("-XX:MaxPermSize=" + String.valueOf(permGen) + "M");
|
||||
// If we know the Java version, only add permsize for 7 or older
|
||||
if (getRuntime() == null || getRuntime().getMajorVersion() < 8) {
|
||||
command.add("-XX:MaxPermSize=" + permGen + "M");
|
||||
}
|
||||
}
|
||||
|
||||
command.add(mainClass);
|
||||
|
||||
for (String arg : args) {
|
||||
command.add(arg);
|
||||
}
|
||||
command.addAll(args);
|
||||
|
||||
return command;
|
||||
}
|
||||
|
@ -255,13 +255,8 @@ public class Runner implements Callable<Process>, ProgressObservable {
|
||||
.orElse(config.getJavaRuntime())
|
||||
);
|
||||
|
||||
// Builder defaults to a found runtime or just the PATH `java` otherwise
|
||||
if (selectedRuntime != null) {
|
||||
String rawJvmPath = selectedRuntime.getDir().getAbsolutePath();
|
||||
if (!Strings.isNullOrEmpty(rawJvmPath)) {
|
||||
builder.tryJvmPath(new File(rawJvmPath));
|
||||
}
|
||||
}
|
||||
// Builder defaults to the PATH `java` if the runtime is null
|
||||
builder.setRuntime(selectedRuntime);
|
||||
|
||||
List<String> flags = builder.getFlags();
|
||||
String[] rawJvmArgsList = new String[] {
|
||||
|
Loading…
Reference in New Issue
Block a user