mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
Экспериментальный класс ClientLauncherWrapper
This commit is contained in:
parent
761ddc3087
commit
300e8cfcec
4 changed files with 52 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
|||
String mainClassName = "ru.gravit.launcher.LauncherEngine"
|
||||
String mainClassName = "ru.gravit.launcher.ClientLauncherWrapper"
|
||||
String mainAgentName = "ru.gravit.launcher.LauncherAgent"
|
||||
|
||||
|
||||
|
|
|
@ -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<String> 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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue