mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[FEATURE] RuntimeInClient Java 9+
This commit is contained in:
parent
c37fb47795
commit
f317912de7
2 changed files with 56 additions and 0 deletions
|
@ -249,14 +249,23 @@ public static int getJavaVersion(String version) {
|
||||||
public static class JavaVersion {
|
public static class JavaVersion {
|
||||||
public final Path jvmDir;
|
public final Path jvmDir;
|
||||||
public final int version;
|
public final int version;
|
||||||
|
public final int build;
|
||||||
public boolean enabledJavaFX;
|
public boolean enabledJavaFX;
|
||||||
|
|
||||||
public JavaVersion(Path jvmDir, int version) {
|
public JavaVersion(Path jvmDir, int version) {
|
||||||
this.jvmDir = jvmDir;
|
this.jvmDir = jvmDir;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
|
this.build = 0;
|
||||||
this.enabledJavaFX = true;
|
this.enabledJavaFX = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JavaVersion(Path jvmDir, int version, int build, boolean enabledJavaFX) {
|
||||||
|
this.jvmDir = jvmDir;
|
||||||
|
this.version = version;
|
||||||
|
this.build = build;
|
||||||
|
this.enabledJavaFX = enabledJavaFX;
|
||||||
|
}
|
||||||
|
|
||||||
public static JavaVersion getCurrentJavaVersion() {
|
public static JavaVersion getCurrentJavaVersion() {
|
||||||
return new JavaVersion(Paths.get(System.getProperty("java.home")), JVMHelper.getVersion());
|
return new JavaVersion(Paths.get(System.getProperty("java.home")), JVMHelper.getVersion());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package pro.gravit.launcher.client;
|
package pro.gravit.launcher.client;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.ClientLauncherWrapper;
|
||||||
import pro.gravit.launcher.Launcher;
|
import pro.gravit.launcher.Launcher;
|
||||||
import pro.gravit.launcher.LauncherEngine;
|
import pro.gravit.launcher.LauncherEngine;
|
||||||
import pro.gravit.launcher.LauncherNetworkAPI;
|
import pro.gravit.launcher.LauncherNetworkAPI;
|
||||||
|
@ -30,6 +31,8 @@
|
||||||
public class ClientLauncherProcess {
|
public class ClientLauncherProcess {
|
||||||
public final ClientParams params = new ClientParams();
|
public final ClientParams params = new ClientParams();
|
||||||
public final List<String> jvmArgs = new LinkedList<>();
|
public final List<String> jvmArgs = new LinkedList<>();
|
||||||
|
public final List<String> jvmModules = new LinkedList<>();
|
||||||
|
public final List<Path> jvmModulesPaths = new LinkedList<>();
|
||||||
public final List<String> systemClientArgs = new LinkedList<>();
|
public final List<String> systemClientArgs = new LinkedList<>();
|
||||||
public final List<String> systemClassPath = new LinkedList<>();
|
public final List<String> systemClassPath = new LinkedList<>();
|
||||||
public final Map<String, String> systemEnv = new HashMap<>();
|
public final Map<String, String> systemEnv = new HashMap<>();
|
||||||
|
@ -41,6 +44,7 @@ public class ClientLauncherProcess {
|
||||||
public int bits;
|
public int bits;
|
||||||
public boolean useLegacyJavaClassPathProperty;
|
public boolean useLegacyJavaClassPathProperty;
|
||||||
public boolean isStarted;
|
public boolean isStarted;
|
||||||
|
public ClientLauncherWrapper.JavaVersion javaVersion;
|
||||||
private transient Process process;
|
private transient Process process;
|
||||||
|
|
||||||
public ClientLauncherProcess(Path executeFile, Path workDir, Path javaDir, String mainClass) {
|
public ClientLauncherProcess(Path executeFile, Path workDir, Path javaDir, String mainClass) {
|
||||||
|
@ -81,6 +85,12 @@ public ClientLauncherProcess(Path clientDir, Path assetDir, Path javaDir, Path r
|
||||||
if (view != null) {
|
if (view != null) {
|
||||||
this.params.actions = view.getEnabledActions();
|
this.params.actions = view.getEnabledActions();
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
javaVersion = ClientLauncherWrapper.JavaVersion.getByPath(javaDir);
|
||||||
|
} catch (IOException e) {
|
||||||
|
LogHelper.error(e);
|
||||||
|
javaVersion = ClientLauncherWrapper.JavaVersion.getCurrentJavaVersion();
|
||||||
|
}
|
||||||
this.bits = JVMHelper.JVM_BITS;
|
this.bits = JVMHelper.JVM_BITS;
|
||||||
applyClientProfile();
|
applyClientProfile();
|
||||||
}
|
}
|
||||||
|
@ -106,6 +116,14 @@ private void applyClientProfile() {
|
||||||
this.jvmArgs.add("-Xmx" + params.ram + 'M');
|
this.jvmArgs.add("-Xmx" + params.ram + 'M');
|
||||||
}
|
}
|
||||||
this.params.session = Request.getSession();
|
this.params.session = Request.getSession();
|
||||||
|
|
||||||
|
if(this.params.profile.getRuntimeInClientConfig() != ClientProfile.RuntimeInClientConfig.NONE) {
|
||||||
|
jvmModules.add("javafx.base");
|
||||||
|
jvmModules.add("javafx.graphics");
|
||||||
|
jvmModules.add("javafx.fxml");
|
||||||
|
jvmModules.add("javafx.controls");
|
||||||
|
jvmModules.add("javafx.swing");
|
||||||
|
}
|
||||||
LauncherEngine.modulesManager.invokeEvent(new ClientProcessBuilderCreateEvent(this));
|
LauncherEngine.modulesManager.invokeEvent(new ClientProcessBuilderCreateEvent(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,6 +134,9 @@ public void start(boolean pipeOutput) throws IOException, InterruptedException {
|
||||||
List<String> processArgs = new LinkedList<>();
|
List<String> processArgs = new LinkedList<>();
|
||||||
processArgs.add(executeFile.toString());
|
processArgs.add(executeFile.toString());
|
||||||
processArgs.addAll(jvmArgs);
|
processArgs.addAll(jvmArgs);
|
||||||
|
if(javaVersion.version >= 9) {
|
||||||
|
applyJava9Params(processArgs);
|
||||||
|
}
|
||||||
//ADD CLASSPATH
|
//ADD CLASSPATH
|
||||||
if (params.profile.getClassLoaderConfig() == ClientProfile.ClassLoaderConfig.AGENT) {
|
if (params.profile.getClassLoaderConfig() == ClientProfile.ClassLoaderConfig.AGENT) {
|
||||||
processArgs.add("-javaagent:".concat(IOHelper.getCodeSource(ClientLauncherEntryPoint.class).toAbsolutePath().toString()));
|
processArgs.add("-javaagent:".concat(IOHelper.getCodeSource(ClientLauncherEntryPoint.class).toAbsolutePath().toString()));
|
||||||
|
@ -150,6 +171,32 @@ public void start(boolean pipeOutput) throws IOException, InterruptedException {
|
||||||
isStarted = true;
|
isStarted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void applyJava9Params(List<String> processArgs) {
|
||||||
|
jvmModulesPaths.add(javaVersion.jvmDir);
|
||||||
|
jvmModulesPaths.add(javaVersion.jvmDir.resolve("jre"));
|
||||||
|
Path openjfxPath = ClientLauncherWrapper.tryGetOpenJFXPath(javaVersion.jvmDir);
|
||||||
|
if(openjfxPath != null) {
|
||||||
|
jvmModulesPaths.add(openjfxPath);
|
||||||
|
}
|
||||||
|
StringBuilder modulesPath = new StringBuilder();
|
||||||
|
StringBuilder modulesAdd = new StringBuilder();
|
||||||
|
for(String moduleName : jvmModules) {
|
||||||
|
boolean success = ClientLauncherWrapper.tryAddModule(jvmModulesPaths, moduleName, modulesPath);
|
||||||
|
if(success) {
|
||||||
|
if(modulesAdd.length() > 0) modulesAdd.append(",");
|
||||||
|
modulesAdd.append(moduleName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(modulesAdd.length() > 0) {
|
||||||
|
processArgs.add("--add-modules");
|
||||||
|
processArgs.add(modulesAdd.toString());
|
||||||
|
}
|
||||||
|
if(modulesPath.length() > 0) {
|
||||||
|
processArgs.add("--module-path");
|
||||||
|
processArgs.add(modulesPath.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void runWriteParams(SocketAddress address) throws IOException {
|
public void runWriteParams(SocketAddress address) throws IOException {
|
||||||
try (ServerSocket serverSocket = new ServerSocket()) {
|
try (ServerSocket serverSocket = new ServerSocket()) {
|
||||||
serverSocket.bind(address);
|
serverSocket.bind(address);
|
||||||
|
|
Loading…
Reference in a new issue