diff --git a/Launcher/build.gradle b/Launcher/build.gradle index 0990074d..0103a307 100644 --- a/Launcher/build.gradle +++ b/Launcher/build.gradle @@ -1,4 +1,4 @@ -String mainClassName = "ru.gravit.launcher.LauncherEngine" +String mainClassName = "ru.gravit.launcher.ClientLauncherWrapper" String mainAgentName = "ru.gravit.launcher.LauncherAgent" diff --git a/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java new file mode 100644 index 00000000..dbea8921 --- /dev/null +++ b/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java @@ -0,0 +1,48 @@ +package ru.gravit.launcher; + +import ru.gravit.launcher.client.ClientLauncher; +import ru.gravit.utils.helper.EnvHelper; +import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.JVMHelper; +import ru.gravit.utils.helper.LogHelper; + +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +public class ClientLauncherWrapper { + @LauncherAPI + public static void main(String[] arguments) throws IOException, InterruptedException { + LogHelper.printVersion("Launcher"); + JVMHelper.checkStackTrace(ClientLauncherWrapper.class); + JVMHelper.verifySystemProperties(Launcher.class, true); + EnvHelper.checkDangerousParametrs(); + LogHelper.debug("Restart Launcher"); + ProcessBuilder processBuilder = new ProcessBuilder(); + processBuilder.inheritIO(); + Path javaBin = IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home"))); + List args = new LinkedList<>(); + args.add(javaBin.toString()); + String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString(); + Collections.addAll(args, "-javaagent:".concat(pathLauncher)); + Collections.addAll(args, LauncherEngine.class.getName()); + EnvHelper.addEnv(processBuilder); + processBuilder.command(args); + Process process = processBuilder.start(); + if(!LogHelper.isDebugEnabled()) { + Thread.sleep(3000); + if (!process.isAlive()) { + LogHelper.error("Process error code: %d", process.exitValue()); + } else { + LogHelper.debug("Process started success"); + } + } + else + { + process.waitFor(); + } + } +} diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index e541007b..7d1ad60f 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -4,10 +4,10 @@ import java.io.IOException; import java.net.URL; import java.nio.file.Path; +import java.nio.file.Paths; import java.time.Duration; import java.time.Instant; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import javax.script.Bindings; diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java index 3e88ab7d..a23f8c67 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java @@ -140,7 +140,7 @@ public static void checkStackTrace(Class mainClass) StackTraceElement[] list = e.getStackTrace(); if(!list[list.length - 1].getClassName().equals(mainClass.getName())) { - throw new SecurityException(String.format("Invalid StackTraceElement: %s",list[0].getClassName())); + throw new SecurityException(String.format("Invalid StackTraceElement: %s",list[list.length - 1].getClassName())); } }