mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-01-12 14:14:52 +08:00
* fix #1999: Add overrideJavaArguments to LaunchOptions * fix checkstyle
This commit is contained in:
parent
0ec00ede70
commit
0130676b42
@ -327,7 +327,7 @@ public class HMCLGameRepository extends DefaultGameRepository {
|
||||
.setVersionName(version)
|
||||
.setProfileName(Metadata.TITLE)
|
||||
.setGameArguments(StringUtils.tokenize(vs.getMinecraftArgs()))
|
||||
.setJavaArguments(StringUtils.tokenize(vs.getJavaArgs()))
|
||||
.setOverrideJavaArguments(StringUtils.tokenize(vs.getJavaArgs()))
|
||||
.setMaxMemory(vs.isNoJVMArgs() && vs.isAutoMemory() ? null : (int)(getAllocatedMemory(
|
||||
vs.getMaxMemory() * 1024L * 1024L,
|
||||
OperatingSystem.getPhysicalMemoryStatus().orElse(OperatingSystem.PhysicalMemoryStatus.INVALID).getAvailable(),
|
||||
|
@ -38,9 +38,10 @@ public class LaunchOptions implements Serializable {
|
||||
private String versionName;
|
||||
private String versionType;
|
||||
private String profileName;
|
||||
private List<String> gameArguments = new ArrayList<>();
|
||||
private List<String> javaArguments = new ArrayList<>();
|
||||
private List<String> javaAgents = new ArrayList<>(0);
|
||||
private final List<String> gameArguments = new ArrayList<>();
|
||||
private final List<String> overrideJavaArguments = new ArrayList<>();
|
||||
private final List<String> javaArguments = new ArrayList<>();
|
||||
private final List<String> javaAgents = new ArrayList<>(0);
|
||||
private Integer minMemory;
|
||||
private Integer maxMemory;
|
||||
private Integer metaspace;
|
||||
@ -108,6 +109,14 @@ public class LaunchOptions implements Serializable {
|
||||
return Collections.unmodifiableList(gameArguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* The highest priority JVM arguments (overrides the version setting)
|
||||
*/
|
||||
@NotNull
|
||||
public List<String> getOverrideJavaArguments() {
|
||||
return Collections.unmodifiableList(overrideJavaArguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* User custom additional java virtual machine command line arguments.
|
||||
*/
|
||||
@ -314,6 +323,13 @@ public class LaunchOptions implements Serializable {
|
||||
return options.gameArguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* The highest priority JVM arguments (overrides the version setting)
|
||||
*/
|
||||
public List<String> getOverrideJavaArguments() {
|
||||
return options.overrideJavaArguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* User custom additional java virtual machine command line arguments.
|
||||
*/
|
||||
@ -473,6 +489,12 @@ public class LaunchOptions implements Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setOverrideJavaArguments(List<String> overrideJavaArguments) {
|
||||
options.overrideJavaArguments.clear();
|
||||
options.overrideJavaArguments.addAll(overrideJavaArguments);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setJavaArguments(List<String> javaArguments) {
|
||||
options.javaArguments.clear();
|
||||
options.javaArguments.addAll(javaArguments);
|
||||
|
@ -105,15 +105,7 @@ public class DefaultLauncher extends Launcher {
|
||||
|
||||
res.add(options.getJava().getBinary().toString());
|
||||
|
||||
// Fix RCE vulnerability of log4j2
|
||||
res.addDefault("-Djava.rmi.server.useCodebaseOnly=", "true");
|
||||
res.addDefault("-Dcom.sun.jndi.rmi.object.trustURLCodebase=", "false");
|
||||
res.addDefault("-Dcom.sun.jndi.cosnaming.object.trustURLCodebase=", "false");
|
||||
|
||||
String formatMsgNoLookups = res.addDefault("-Dlog4j2.formatMsgNoLookups=", "true");
|
||||
if (!"-Dlog4j2.formatMsgNoLookups=false".equals(formatMsgNoLookups) && isUsingLog4j()) {
|
||||
res.addDefault("-Dlog4j.configurationFile=", getLog4jConfigurationFile().getAbsolutePath());
|
||||
}
|
||||
res.addAllWithoutParsing(options.getOverrideJavaArguments());
|
||||
|
||||
Proxy proxy = options.getProxy();
|
||||
if (proxy != null && StringUtils.isBlank(options.getProxyUser()) && StringUtils.isBlank(options.getProxyPass())) {
|
||||
@ -160,6 +152,16 @@ public class DefaultLauncher extends Launcher {
|
||||
res.addDefault("-Dsun.stdout.encoding=", encoding.name());
|
||||
res.addDefault("-Dsun.stderr.encoding=", encoding.name());
|
||||
|
||||
// Fix RCE vulnerability of log4j2
|
||||
res.addDefault("-Djava.rmi.server.useCodebaseOnly=", "true");
|
||||
res.addDefault("-Dcom.sun.jndi.rmi.object.trustURLCodebase=", "false");
|
||||
res.addDefault("-Dcom.sun.jndi.cosnaming.object.trustURLCodebase=", "false");
|
||||
|
||||
String formatMsgNoLookups = res.addDefault("-Dlog4j2.formatMsgNoLookups=", "true");
|
||||
if (!"-Dlog4j2.formatMsgNoLookups=false".equals(formatMsgNoLookups) && isUsingLog4j()) {
|
||||
res.addDefault("-Dlog4j.configurationFile=", getLog4jConfigurationFile().getAbsolutePath());
|
||||
}
|
||||
|
||||
// Default JVM Args
|
||||
if (!options.isNoGeneratedJVMArgs()) {
|
||||
appendJvmArgs(res);
|
||||
|
Loading…
Reference in New Issue
Block a user