2019-06-02 05:03:08 +03:00
|
|
|
package pro.gravit.launcher;
|
2018-10-22 14:38:01 +03:00
|
|
|
|
2019-09-17 23:25:59 +03:00
|
|
|
import pro.gravit.launcher.client.ClientModuleManager;
|
2019-06-03 10:58:10 +03:00
|
|
|
import pro.gravit.launcher.client.DirBridge;
|
2019-12-18 19:24:07 +03:00
|
|
|
import pro.gravit.launcher.utils.DirWatcher;
|
2019-06-03 10:58:10 +03:00
|
|
|
import pro.gravit.utils.helper.EnvHelper;
|
|
|
|
import pro.gravit.utils.helper.IOHelper;
|
|
|
|
import pro.gravit.utils.helper.JVMHelper;
|
|
|
|
import pro.gravit.utils.helper.LogHelper;
|
|
|
|
|
2019-10-19 19:46:04 +03:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2021-04-15 18:02:30 +03:00
|
|
|
import java.nio.file.Files;
|
2019-10-19 19:46:04 +03:00
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.nio.file.Paths;
|
2021-04-15 18:02:30 +03:00
|
|
|
import java.util.*;
|
2019-10-19 19:46:04 +03:00
|
|
|
|
2018-10-22 14:38:01 +03:00
|
|
|
public class ClientLauncherWrapper {
|
2019-04-03 16:27:40 +03:00
|
|
|
public static final String MAGIC_ARG = "-Djdk.attach.allowAttachSelf";
|
2019-04-24 11:49:01 +03:00
|
|
|
public static final String WAIT_PROCESS_PROPERTY = "launcher.waitProcess";
|
2020-06-17 11:32:30 +03:00
|
|
|
public static final String NO_JAVA_CHECK_PROPERTY = "launcher.noJavaCheck";
|
|
|
|
public static boolean noJavaCheck = Boolean.getBoolean(NO_JAVA_CHECK_PROPERTY);
|
2020-04-05 10:27:04 +03:00
|
|
|
public static boolean waitProcess = Boolean.getBoolean(WAIT_PROCESS_PROPERTY);
|
2021-01-28 20:13:21 +03:00
|
|
|
@LauncherInject("launcher.memory")
|
|
|
|
public static int launcherMemoryLimit;
|
2020-09-25 18:48:33 +03:00
|
|
|
|
2018-10-22 14:38:01 +03:00
|
|
|
public static void main(String[] arguments) throws IOException, InterruptedException {
|
|
|
|
LogHelper.printVersion("Launcher");
|
2018-11-27 14:34:39 +03:00
|
|
|
LogHelper.printLicense("Launcher");
|
2018-10-22 14:38:01 +03:00
|
|
|
JVMHelper.checkStackTrace(ClientLauncherWrapper.class);
|
|
|
|
JVMHelper.verifySystemProperties(Launcher.class, true);
|
2018-10-26 17:42:20 +03:00
|
|
|
EnvHelper.checkDangerousParams();
|
2019-04-24 11:49:01 +03:00
|
|
|
LauncherConfig config = Launcher.getConfig();
|
2019-09-17 23:25:59 +03:00
|
|
|
LauncherEngine.modulesManager = new ClientModuleManager();
|
2020-01-31 21:21:24 +03:00
|
|
|
LauncherConfig.initModules(LauncherEngine.modulesManager);
|
2019-09-17 23:25:59 +03:00
|
|
|
|
2019-10-19 19:52:57 +03:00
|
|
|
LogHelper.info("Launcher for project %s", config.projectName);
|
2019-05-15 14:11:22 +03:00
|
|
|
if (config.environment.equals(LauncherConfig.LauncherEnvironment.PROD)) {
|
|
|
|
if (System.getProperty(LogHelper.DEBUG_PROPERTY) != null) {
|
2019-04-24 11:49:01 +03:00
|
|
|
LogHelper.warning("Found -Dlauncher.debug=true");
|
|
|
|
}
|
2019-05-15 14:11:22 +03:00
|
|
|
if (System.getProperty(LogHelper.STACKTRACE_PROPERTY) != null) {
|
2019-04-24 11:49:01 +03:00
|
|
|
LogHelper.warning("Found -Dlauncher.stacktrace=true");
|
|
|
|
}
|
|
|
|
LogHelper.info("Debug mode disabled (found env PRODUCTION)");
|
2019-05-15 14:11:22 +03:00
|
|
|
} else {
|
2019-04-24 11:49:01 +03:00
|
|
|
LogHelper.info("If need debug output use -Dlauncher.debug=true");
|
|
|
|
LogHelper.info("If need stacktrace output use -Dlauncher.stacktrace=true");
|
2019-05-15 14:11:22 +03:00
|
|
|
if (LogHelper.isDebugEnabled()) waitProcess = true;
|
2019-04-24 11:49:01 +03:00
|
|
|
}
|
|
|
|
LogHelper.info("Restart Launcher with JavaAgent...");
|
2021-04-15 18:02:30 +03:00
|
|
|
ClientLauncherWrapperContext context = new ClientLauncherWrapperContext();
|
|
|
|
context.processBuilder = new ProcessBuilder();
|
|
|
|
if (waitProcess) context.processBuilder.inheritIO();
|
2020-06-17 11:32:30 +03:00
|
|
|
|
2021-05-31 01:51:40 +03:00
|
|
|
context.javaVersion = null;
|
2020-06-08 11:45:49 +03:00
|
|
|
try {
|
2021-05-28 23:14:03 +03:00
|
|
|
if (!noJavaCheck) {
|
|
|
|
List<JavaVersion> javaVersions = findJava();
|
|
|
|
for (JavaVersion version : javaVersions) {
|
2021-05-31 04:25:33 +03:00
|
|
|
LogHelper.debug("Found Java %d b%d in %s javafx %s", version.version, version.build, version.jvmDir.toString(), version.enabledJavaFX ? "supported" : "not supported");
|
2021-05-28 23:14:03 +03:00
|
|
|
if (context.javaVersion == null) {
|
|
|
|
context.javaVersion = version;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (version.enabledJavaFX && !context.javaVersion.enabledJavaFX) {
|
|
|
|
context.javaVersion = version;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (version.enabledJavaFX) {
|
|
|
|
if (context.javaVersion.version < version.version) {
|
|
|
|
context.javaVersion = version;
|
|
|
|
} else if (context.javaVersion.version == version.version && context.javaVersion.build < version.build) {
|
|
|
|
context.javaVersion = version;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-17 11:32:30 +03:00
|
|
|
} catch (Throwable e) {
|
2020-06-08 11:45:49 +03:00
|
|
|
LogHelper.error(e);
|
|
|
|
}
|
2021-05-31 04:25:33 +03:00
|
|
|
if (context.javaVersion == null) {
|
|
|
|
context.javaVersion = JavaVersion.getCurrentJavaVersion();
|
|
|
|
}
|
2020-06-17 11:32:30 +03:00
|
|
|
|
2021-04-15 18:02:30 +03:00
|
|
|
context.executePath = IOHelper.resolveJavaBin(context.javaVersion.jvmDir);
|
|
|
|
//List<String> args = new LinkedList<>();
|
|
|
|
//args.add(javaBin.toString());
|
2020-03-22 04:40:14 +03:00
|
|
|
String pathLauncher = IOHelper.getCodeSource(LauncherEngine.class).toString();
|
2021-04-15 18:02:30 +03:00
|
|
|
context.mainClass = LauncherEngine.class.getName();
|
|
|
|
context.memoryLimit = launcherMemoryLimit;
|
|
|
|
context.classpath.add(pathLauncher);
|
|
|
|
context.jvmProperties.put(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled()));
|
|
|
|
context.jvmProperties.put(LogHelper.STACKTRACE_PROPERTY, Boolean.toString(LogHelper.isStacktraceEnabled()));
|
|
|
|
context.jvmProperties.put(LogHelper.DEV_PROPERTY, Boolean.toString(LogHelper.isDevEnabled()));
|
|
|
|
context.addSystemProperty(DirBridge.CUSTOMDIR_PROPERTY);
|
|
|
|
context.addSystemProperty(DirBridge.USE_CUSTOMDIR_PROPERTY);
|
|
|
|
context.addSystemProperty(DirBridge.USE_OPTDIR_PROPERTY);
|
|
|
|
context.addSystemProperty(DirWatcher.IGN_OVERFLOW);
|
|
|
|
context.jvmModules.add("javafx.base");
|
|
|
|
context.jvmModules.add("javafx.graphics");
|
|
|
|
context.jvmModules.add("javafx.fxml");
|
|
|
|
context.jvmModules.add("javafx.controls");
|
|
|
|
context.jvmModules.add("javafx.swing");
|
2021-05-29 00:42:09 +03:00
|
|
|
context.jvmModules.add("javafx.media");
|
|
|
|
context.jvmModules.add("javafx.web");
|
2021-04-15 18:02:30 +03:00
|
|
|
context.args.add(MAGIC_ARG);
|
|
|
|
context.args.add("-XX:+DisableAttachMechanism");
|
|
|
|
EnvHelper.addEnv(context.processBuilder);
|
|
|
|
LauncherEngine.modulesManager.callWrapper(context);
|
|
|
|
// ---------
|
|
|
|
List<String> args = new ArrayList<>(16);
|
|
|
|
args.add(context.executePath.toAbsolutePath().toString());
|
|
|
|
args.addAll(context.args);
|
2021-05-25 12:17:29 +03:00
|
|
|
context.jvmProperties.forEach((key, value) -> args.add(String.format("-D%s=%s", key, value)));
|
|
|
|
if (context.javaVersion.version >= 9) {
|
2021-04-15 18:02:30 +03:00
|
|
|
context.javaFXPaths.add(context.javaVersion.jvmDir);
|
|
|
|
context.javaFXPaths.add(context.javaVersion.jvmDir.resolve("jre"));
|
|
|
|
Path openjfxPath = tryGetOpenJFXPath(context.javaVersion.jvmDir);
|
2021-05-25 12:17:29 +03:00
|
|
|
if (openjfxPath != null) {
|
2021-04-15 18:02:30 +03:00
|
|
|
context.javaFXPaths.add(openjfxPath);
|
|
|
|
}
|
|
|
|
StringBuilder modulesPath = new StringBuilder();
|
|
|
|
StringBuilder modulesAdd = new StringBuilder();
|
2021-05-25 12:17:29 +03:00
|
|
|
for (String moduleName : context.jvmModules) {
|
2021-04-15 18:02:30 +03:00
|
|
|
boolean success = tryAddModule(context.javaFXPaths, moduleName, modulesPath);
|
2021-05-25 12:17:29 +03:00
|
|
|
if (success) {
|
|
|
|
if (modulesAdd.length() > 0) modulesAdd.append(",");
|
2021-04-15 18:02:30 +03:00
|
|
|
modulesAdd.append(moduleName);
|
|
|
|
}
|
|
|
|
}
|
2021-05-25 12:17:29 +03:00
|
|
|
if (modulesAdd.length() > 0) {
|
2020-01-04 17:54:17 +03:00
|
|
|
args.add("--add-modules");
|
2021-04-15 18:02:30 +03:00
|
|
|
args.add(modulesAdd.toString());
|
|
|
|
}
|
2021-05-25 12:17:29 +03:00
|
|
|
if (modulesPath.length() > 0) {
|
2019-11-28 20:12:40 +03:00
|
|
|
args.add("--module-path");
|
2021-04-15 18:02:30 +03:00
|
|
|
args.add(modulesPath.toString());
|
2019-09-18 00:11:13 +03:00
|
|
|
}
|
2019-09-17 23:32:57 +03:00
|
|
|
}
|
2021-04-15 18:02:30 +03:00
|
|
|
if (context.memoryLimit != 0) {
|
|
|
|
args.add(String.format("-Xmx%dM", context.memoryLimit));
|
2021-03-20 11:50:32 +03:00
|
|
|
}
|
2019-11-28 20:12:40 +03:00
|
|
|
args.add("-cp");
|
2021-04-15 18:02:30 +03:00
|
|
|
args.add(String.join(IOHelper.PLATFORM_SEPARATOR, context.classpath));
|
|
|
|
args.add(context.mainClass);
|
|
|
|
args.addAll(context.clientArgs);
|
2018-10-24 16:40:51 +03:00
|
|
|
LogHelper.debug("Commandline: " + args);
|
2021-04-15 18:02:30 +03:00
|
|
|
context.processBuilder.command(args);
|
|
|
|
Process process = context.processBuilder.start();
|
2019-04-24 11:49:01 +03:00
|
|
|
if (!waitProcess) {
|
2018-10-22 14:38:01 +03:00
|
|
|
Thread.sleep(3000);
|
|
|
|
if (!process.isAlive()) {
|
2018-11-27 14:34:39 +03:00
|
|
|
int errorcode = process.exitValue();
|
2018-12-20 18:45:01 +03:00
|
|
|
if (errorcode != 0)
|
2019-03-10 15:01:14 +03:00
|
|
|
LogHelper.error("Process exit with error code: %d", errorcode);
|
2018-11-27 14:34:39 +03:00
|
|
|
else
|
2019-03-10 15:01:14 +03:00
|
|
|
LogHelper.info("Process exit with code 0");
|
2018-10-22 14:38:01 +03:00
|
|
|
} else {
|
|
|
|
LogHelper.debug("Process started success");
|
|
|
|
}
|
2018-11-08 15:30:16 +03:00
|
|
|
} else {
|
2018-10-22 14:38:01 +03:00
|
|
|
process.waitFor();
|
|
|
|
}
|
|
|
|
}
|
2019-10-19 19:46:04 +03:00
|
|
|
|
2021-04-15 18:02:30 +03:00
|
|
|
public static Path tryGetOpenJFXPath(Path jvmDir) {
|
|
|
|
String dirName = jvmDir.getFileName().toString();
|
|
|
|
Path parent = jvmDir.getParent();
|
2021-05-25 12:17:29 +03:00
|
|
|
if (parent == null) return null;
|
2021-04-15 18:02:30 +03:00
|
|
|
Path archJFXPath = parent.resolve(dirName.replace("openjdk", "openjfx"));
|
2021-05-25 12:17:29 +03:00
|
|
|
if (Files.isDirectory(archJFXPath)) {
|
2021-04-15 18:02:30 +03:00
|
|
|
return archJFXPath;
|
|
|
|
}
|
|
|
|
Path arch2JFXPath = parent.resolve(dirName.replace("jdk", "openjfx"));
|
2021-05-25 12:17:29 +03:00
|
|
|
if (Files.isDirectory(arch2JFXPath)) {
|
2021-04-15 18:02:30 +03:00
|
|
|
return arch2JFXPath;
|
|
|
|
}
|
2021-05-25 12:17:29 +03:00
|
|
|
if (JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) {
|
2021-04-15 18:02:30 +03:00
|
|
|
Path debianJfxPath = Paths.get("/usr/share/openjfx");
|
2021-05-25 12:17:29 +03:00
|
|
|
if (Files.isDirectory(debianJfxPath)) {
|
2021-04-15 18:02:30 +03:00
|
|
|
return debianJfxPath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-10-19 19:46:04 +03:00
|
|
|
public static Path tryFindModule(Path path, String moduleName) {
|
2019-09-18 00:11:13 +03:00
|
|
|
Path result = path.resolve(moduleName.concat(".jar"));
|
2019-10-19 19:46:04 +03:00
|
|
|
if (!IOHelper.isFile(result))
|
2019-09-18 00:11:13 +03:00
|
|
|
result = path.resolve("lib").resolve(moduleName.concat(".jar"));
|
|
|
|
else return result;
|
2019-10-19 19:46:04 +03:00
|
|
|
if (!IOHelper.isFile(result))
|
2019-09-18 00:11:13 +03:00
|
|
|
return null;
|
|
|
|
else return result;
|
|
|
|
}
|
2019-10-19 19:46:04 +03:00
|
|
|
|
2021-04-15 18:02:30 +03:00
|
|
|
public static boolean tryAddModule(List<Path> paths, String moduleName, StringBuilder args) {
|
2019-10-19 19:46:04 +03:00
|
|
|
for (Path path : paths) {
|
|
|
|
if (path == null) continue;
|
2019-09-18 00:11:13 +03:00
|
|
|
Path result = tryFindModule(path, moduleName);
|
2019-10-19 19:46:04 +03:00
|
|
|
if (result != null) {
|
|
|
|
if (args.length() != 0) args.append(File.pathSeparatorChar);
|
2019-09-18 00:11:13 +03:00
|
|
|
args.append(result.toAbsolutePath().toString());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2020-06-08 11:45:49 +03:00
|
|
|
|
2021-05-28 23:14:03 +03:00
|
|
|
public static List<JavaVersion> findJava() {
|
|
|
|
List<String> javaPaths = new ArrayList<>(4);
|
|
|
|
List<JavaVersion> result = new ArrayList<>(4);
|
|
|
|
try {
|
|
|
|
tryAddJava(javaPaths, result, ClientLauncherWrapper.JavaVersion.getCurrentJavaVersion());
|
|
|
|
} catch (IOException e) {
|
|
|
|
LogHelper.error(e);
|
|
|
|
}
|
|
|
|
String[] path = System.getenv("PATH").split(JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE ? ";" : ":");
|
|
|
|
for (String p : path) {
|
2020-06-17 11:32:30 +03:00
|
|
|
try {
|
2021-05-28 23:14:03 +03:00
|
|
|
Path p1 = Paths.get(p);
|
|
|
|
Path javaExecPath = JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE ? p1.resolve("java.exe") : p1.resolve("java");
|
|
|
|
if (Files.exists(javaExecPath)) {
|
|
|
|
if (Files.isSymbolicLink(javaExecPath)) {
|
|
|
|
javaExecPath = javaExecPath.toRealPath();
|
|
|
|
}
|
|
|
|
p1 = javaExecPath.getParent().getParent();
|
|
|
|
tryAddJava(javaPaths, result, ClientLauncherWrapper.JavaVersion.getByPath(p1));
|
|
|
|
trySearchJava(javaPaths, result, p1.getParent());
|
2020-06-17 11:32:30 +03:00
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
LogHelper.error(e);
|
|
|
|
}
|
|
|
|
}
|
2021-05-28 23:14:03 +03:00
|
|
|
if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) {
|
|
|
|
Path rootDrive = Paths.get(System.getProperty("java.home"));
|
|
|
|
try {
|
|
|
|
trySearchJava(javaPaths, result, rootDrive.resolve("Program Files").resolve("Java"));
|
|
|
|
trySearchJava(javaPaths, result, rootDrive.resolve("Program Files").resolve("AdoptOpenJDK"));
|
|
|
|
} catch (IOException e) {
|
|
|
|
LogHelper.error(e);
|
|
|
|
}
|
|
|
|
} else if (JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) {
|
|
|
|
try {
|
|
|
|
trySearchJava(javaPaths, result, Paths.get("/usr/lib/jvm"));
|
|
|
|
} catch (IOException e) {
|
|
|
|
LogHelper.error(e);
|
|
|
|
}
|
2020-06-17 11:54:23 +03:00
|
|
|
}
|
2021-05-28 23:14:03 +03:00
|
|
|
return result;
|
2020-06-17 11:32:30 +03:00
|
|
|
}
|
|
|
|
|
2021-05-28 23:14:03 +03:00
|
|
|
public static boolean tryAddJava(List<String> javaPaths, List<JavaVersion> result, ClientLauncherWrapper.JavaVersion version) throws IOException {
|
|
|
|
if (version == null) return false;
|
|
|
|
String path = version.jvmDir.toAbsolutePath().toString();
|
|
|
|
if (javaPaths.contains(path)) return false;
|
|
|
|
javaPaths.add(path);
|
|
|
|
result.add(version);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void trySearchJava(List<String> javaPaths, List<JavaVersion> result, Path path) throws IOException {
|
|
|
|
if (!Files.isDirectory(path)) return;
|
|
|
|
Files.list(path).filter(p -> Files.exists(p.resolve("bin").resolve(JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE ? "java.exe" : "java"))).forEach(e -> {
|
|
|
|
try {
|
|
|
|
tryAddJava(javaPaths, result, JavaVersion.getByPath(e));
|
|
|
|
if (Files.exists(e.resolve("jre"))) {
|
|
|
|
tryAddJava(javaPaths, result, JavaVersion.getByPath(e.resolve("jre")));
|
2020-06-08 11:45:49 +03:00
|
|
|
}
|
2021-05-28 23:14:03 +03:00
|
|
|
} catch (IOException ioException) {
|
|
|
|
LogHelper.error(ioException);
|
2020-06-08 11:45:49 +03:00
|
|
|
}
|
2021-05-28 23:14:03 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static class JavaVersionAndBuild {
|
|
|
|
public int version;
|
|
|
|
public int build;
|
|
|
|
|
|
|
|
public JavaVersionAndBuild(int version, int build) {
|
|
|
|
this.version = version;
|
|
|
|
this.build = build;
|
|
|
|
}
|
|
|
|
|
|
|
|
public JavaVersionAndBuild() {
|
2020-06-08 11:45:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-28 23:14:03 +03:00
|
|
|
public static JavaVersionAndBuild getJavaVersion(String version) {
|
|
|
|
JavaVersionAndBuild result = new JavaVersionAndBuild();
|
2020-06-08 11:45:49 +03:00
|
|
|
if (version.startsWith("1.")) {
|
2021-05-28 23:14:03 +03:00
|
|
|
result.version = Integer.parseInt(version.substring(2, 3));
|
|
|
|
result.build = Integer.parseInt(version.substring(version.indexOf('_') + 1));
|
2020-06-08 11:45:49 +03:00
|
|
|
} else {
|
|
|
|
int dot = version.indexOf(".");
|
|
|
|
if (dot != -1) {
|
2021-05-28 23:14:03 +03:00
|
|
|
result.version = Integer.parseInt(version.substring(0, dot));
|
|
|
|
dot = version.lastIndexOf(".");
|
|
|
|
result.build = Integer.parseInt(version.substring(dot + 1));
|
2020-06-08 11:45:49 +03:00
|
|
|
}
|
|
|
|
}
|
2021-05-28 23:14:03 +03:00
|
|
|
return result;
|
2020-06-08 11:45:49 +03:00
|
|
|
}
|
2021-03-20 11:53:22 +03:00
|
|
|
|
|
|
|
public static class JavaVersion {
|
|
|
|
public final Path jvmDir;
|
|
|
|
public final int version;
|
2021-05-22 19:51:46 +03:00
|
|
|
public final int build;
|
2021-03-20 11:53:22 +03:00
|
|
|
public boolean enabledJavaFX;
|
|
|
|
|
|
|
|
public JavaVersion(Path jvmDir, int version) {
|
|
|
|
this.jvmDir = jvmDir;
|
|
|
|
this.version = version;
|
2021-05-22 19:51:46 +03:00
|
|
|
this.build = 0;
|
2021-03-20 11:53:22 +03:00
|
|
|
this.enabledJavaFX = true;
|
|
|
|
}
|
|
|
|
|
2021-05-22 19:51:46 +03:00
|
|
|
public JavaVersion(Path jvmDir, int version, int build, boolean enabledJavaFX) {
|
|
|
|
this.jvmDir = jvmDir;
|
|
|
|
this.version = version;
|
|
|
|
this.build = build;
|
|
|
|
this.enabledJavaFX = enabledJavaFX;
|
|
|
|
}
|
|
|
|
|
2021-03-20 11:53:22 +03:00
|
|
|
public static JavaVersion getCurrentJavaVersion() {
|
2021-05-31 04:25:33 +03:00
|
|
|
return new JavaVersion(Paths.get(System.getProperty("java.home")), JVMHelper.getVersion(), 0, isCurrentJavaSupportJavaFX());
|
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean isCurrentJavaSupportJavaFX() {
|
|
|
|
try {
|
|
|
|
Class.forName("javafx.application.Application");
|
|
|
|
return true;
|
|
|
|
} catch (ClassNotFoundException e) {
|
2021-05-31 04:49:09 +03:00
|
|
|
if (JVMHelper.getVersion() > 8) {
|
|
|
|
Path jvmDir = Paths.get(System.getProperty("java.home"));
|
|
|
|
return tryFindModule(jvmDir, "javafx.base") != null;
|
|
|
|
}
|
2021-05-31 04:25:33 +03:00
|
|
|
return false;
|
|
|
|
}
|
2021-03-20 11:53:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public static JavaVersion getByPath(Path jvmDir) throws IOException {
|
|
|
|
Path releaseFile = jvmDir.resolve("release");
|
2021-05-28 23:14:03 +03:00
|
|
|
JavaVersionAndBuild versionAndBuild;
|
|
|
|
if (IOHelper.isFile(releaseFile)) {
|
|
|
|
Properties properties = new Properties();
|
|
|
|
properties.load(IOHelper.newReader(releaseFile));
|
|
|
|
versionAndBuild = getJavaVersion(properties.getProperty("JAVA_VERSION").replaceAll("\"", ""));
|
|
|
|
} else {
|
|
|
|
versionAndBuild = new JavaVersionAndBuild(isExistExtJavaLibrary(jvmDir, "jfxrt") ? 8 : 9, 0);
|
|
|
|
}
|
|
|
|
JavaVersion resultJavaVersion = new JavaVersion(jvmDir, versionAndBuild.version, versionAndBuild.build, false);
|
|
|
|
if (versionAndBuild.version <= 8) {
|
2021-03-20 11:53:22 +03:00
|
|
|
resultJavaVersion.enabledJavaFX = isExistExtJavaLibrary(jvmDir, "jfxrt");
|
|
|
|
} else {
|
|
|
|
resultJavaVersion.enabledJavaFX = tryFindModule(jvmDir, "javafx.base") != null;
|
|
|
|
if (!resultJavaVersion.enabledJavaFX)
|
|
|
|
resultJavaVersion.enabledJavaFX = tryFindModule(jvmDir.resolve("jre"), "javafx.base") != null;
|
|
|
|
}
|
|
|
|
return resultJavaVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isExistExtJavaLibrary(Path jvmDir, String name) {
|
|
|
|
Path jrePath = jvmDir.resolve("lib").resolve("ext").resolve(name.concat(".jar"));
|
|
|
|
Path jdkPath = jvmDir.resolve("jre").resolve("lib").resolve("ext").resolve(name.concat(".jar"));
|
|
|
|
return IOHelper.isFile(jrePath) || IOHelper.isFile(jdkPath);
|
|
|
|
}
|
|
|
|
}
|
2021-05-25 12:17:29 +03:00
|
|
|
|
2021-04-15 18:02:30 +03:00
|
|
|
public static class ClientLauncherWrapperContext {
|
|
|
|
public JavaVersion javaVersion;
|
|
|
|
public Path executePath;
|
|
|
|
public String mainClass;
|
|
|
|
public int memoryLimit;
|
|
|
|
public ProcessBuilder processBuilder;
|
|
|
|
public List<String> args = new ArrayList<>(8);
|
|
|
|
public Map<String, String> jvmProperties = new HashMap<>();
|
|
|
|
public List<String> classpath = new ArrayList<>();
|
|
|
|
public List<String> jvmModules = new ArrayList<>();
|
|
|
|
public List<String> clientArgs = new ArrayList<>();
|
|
|
|
public List<Path> javaFXPaths = new ArrayList<>();
|
2021-05-25 12:17:29 +03:00
|
|
|
|
2021-04-15 18:02:30 +03:00
|
|
|
public void addSystemProperty(String name) {
|
|
|
|
String property = System.getProperty(name);
|
|
|
|
if (property != null)
|
|
|
|
jvmProperties.put(name, property);
|
|
|
|
}
|
|
|
|
}
|
2018-10-22 14:38:01 +03:00
|
|
|
}
|