Экспериментальный класс ClientLauncherWrapper

This commit is contained in:
Gravit 2018-10-22 18:38:01 +07:00
parent 761ddc3087
commit 300e8cfcec
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
4 changed files with 52 additions and 4 deletions

View file

@ -1,4 +1,4 @@
String mainClassName = "ru.gravit.launcher.LauncherEngine"
String mainClassName = "ru.gravit.launcher.ClientLauncherWrapper"
String mainAgentName = "ru.gravit.launcher.LauncherAgent"

View file

@ -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();
}
}
}

View file

@ -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;

View file

@ -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()));
}
}