[FEATURE][EXPERIMENTAL] Support debug args

This commit is contained in:
Gravita 2023-09-13 16:35:01 +07:00
parent d9082f21a3
commit faa5189795
2 changed files with 28 additions and 5 deletions

View file

@ -32,6 +32,7 @@
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.KeyPair;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
@ -102,12 +103,24 @@ public static void exitLauncher(int code) {
forceExit(code);
}
public static boolean contains(String[] array, String value) {
for(String s : array) {
if(s.equals(value)) {
return true;
}
}
return false;
}
public static void main(String... args) throws Throwable {
JVMHelper.checkStackTrace(LauncherEngineWrapper.class);
JVMHelper.verifySystemProperties(Launcher.class, true);
EnvHelper.checkDangerousParams();
//if(!LauncherAgent.isStarted()) throw new SecurityException("JavaAgent not set");
verifyNoAgent();
if(contains(args, "--log-output") && Launcher.getConfig().environment != LauncherConfig.LauncherEnvironment.PROD) {
LogHelper.addOutput(Paths.get("Launcher.log"));
}
LogHelper.printVersion("Launcher");
LogHelper.printLicense("Launcher");
LauncherEngine.checkClass(LauncherEngineWrapper.class);

View file

@ -7,10 +7,7 @@
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
public class ClientLauncherWrapper {
public static final String MAGIC_ARG = "-Djdk.attach.allowAttachSelf";
@ -24,6 +21,15 @@ public class ClientLauncherWrapper {
public static List<String> customJvmOptions;
public static RuntimeModuleManager modulesManager;
public static boolean contains(String[] array, String value) {
for(String s : array) {
if(s.equals(value)) {
return true;
}
}
return false;
}
public static void main(String[] arguments) throws IOException, InterruptedException {
LogHelper.printVersion("Launcher");
LogHelper.printLicense("Launcher");
@ -33,7 +39,6 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep
LauncherConfig config = Launcher.getConfig();
modulesManager = new RuntimeModuleManager();
LauncherConfig.initModules(modulesManager);
LogHelper.info("Launcher for project %s", config.projectName);
if (config.environment.equals(LauncherConfig.LauncherEnvironment.PROD)) {
if (System.getProperty(LogHelper.DEBUG_PROPERTY) != null) {
@ -46,6 +51,10 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep
} else {
LogHelper.info("If need debug output use -Dlauncher.debug=true");
LogHelper.info("If need stacktrace output use -Dlauncher.stacktrace=true");
if(contains(arguments, "--debug")) {
LogHelper.setDebugEnabled(true);
LogHelper.setStacktraceEnabled(true);
}
if (LogHelper.isDebugEnabled()) waitProcess = true;
}
LogHelper.info("Restart Launcher with JavaAgent...");
@ -104,6 +113,7 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep
context.jvmModules.add("javafx.web");
context.args.add(MAGIC_ARG);
context.args.add("-XX:+DisableAttachMechanism");
context.clientArgs.addAll(Arrays.asList(arguments));
EnvHelper.addEnv(context.processBuilder);
modulesManager.callWrapper(context);
// ---------