From 88be2a623be8fae37daca07766fa969241fd8686 Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 12 Mar 2019 15:24:48 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=92=D0=BA=D0=BB=D1=8E=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D1=84=D0=B8=D1=82=D1=87=D0=B0=20customDir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/gravit/launcher/ClientLauncherWrapper.java | 7 ++++++- .../main/java/ru/gravit/launcher/LauncherEngine.java | 1 - .../ru/gravit/launcher/client/ClientLauncher.java | 3 +++ .../java/ru/gravit/launcher/client/DirBridge.java | 11 ++++++++--- .../main/java/ru/gravit/utils/helper/JVMHelper.java | 9 +++++++++ 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java index 3c2d9df1..eb0f6aa9 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java +++ b/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java @@ -1,6 +1,7 @@ package ru.gravit.launcher; import ru.gravit.launcher.client.ClientLauncher; +import ru.gravit.launcher.client.DirBridge; import ru.gravit.utils.helper.EnvHelper; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.JVMHelper; @@ -19,18 +20,22 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep LogHelper.printLicense("Launcher"); LogHelper.info("Restart Launcher with JavaAgent..."); LogHelper.info("If need debug output use -Dlauncher.debug=true"); + LogHelper.info("If need stacktrace output use -Dlauncher.stacktrace=true"); JVMHelper.checkStackTrace(ClientLauncherWrapper.class); JVMHelper.verifySystemProperties(Launcher.class, true); EnvHelper.checkDangerousParams(); LogHelper.debug("Restart Launcher"); ProcessBuilder processBuilder = new ProcessBuilder(); - processBuilder.inheritIO(); + if (LogHelper.isDebugEnabled()) 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(); args.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled()))); args.add(JVMHelper.jvmProperty(LogHelper.STACKTRACE_PROPERTY, Boolean.toString(LogHelper.isStacktraceEnabled()))); + JVMHelper.addSystemPropertyToArgs(args, DirBridge.CUSTOMDIR_PROPERTY); + JVMHelper.addSystemPropertyToArgs(args, DirBridge.USE_CUSTOMDIR_PROPERTY); + JVMHelper.addSystemPropertyToArgs(args, DirBridge.USE_OPTDIR_PROPERTY); Collections.addAll(args, "-javaagent:".concat(pathLauncher)); Collections.addAll(args, "-cp"); Collections.addAll(args, pathLauncher); diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index 37a794fa..9b04ca09 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -58,7 +58,6 @@ private LauncherEngine() { @LauncherAPI public void start(String... args) throws Throwable { - LogHelper.debug("%d", LauncherSettings.settingsMagic); Launcher.modulesManager = new ClientModuleManager(this); LauncherConfig.getAutogenConfig().initModules(); Launcher.modulesManager.preInitModules(); diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java index 840f51ff..6b9944c1 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java @@ -347,6 +347,9 @@ public static Process launch( context.args.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled()))); context.args.add(JVMHelper.jvmProperty(LogHelper.STACKTRACE_PROPERTY, Boolean.toString(LogHelper.isStacktraceEnabled()))); context.args.add(JVMHelper.jvmProperty(LogHelper.DEV_PROPERTY, Boolean.toString(LogHelper.isDevEnabled()))); + JVMHelper.addSystemPropertyToArgs(context.args, DirBridge.CUSTOMDIR_PROPERTY); + JVMHelper.addSystemPropertyToArgs(context.args, DirBridge.USE_CUSTOMDIR_PROPERTY); + JVMHelper.addSystemPropertyToArgs(context.args, DirBridge.USE_OPTDIR_PROPERTY); if (LauncherConfig.ADDRESS_OVERRIDE != null) context.args.add(JVMHelper.jvmProperty(LauncherConfig.ADDRESS_OVERRIDE_PROPERTY, LauncherConfig.ADDRESS_OVERRIDE)); if (JVMHelper.OS_TYPE == OS.MUSTDIE) { diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java b/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java index c24b966a..830249a0 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java @@ -10,6 +10,11 @@ import java.nio.file.Paths; public class DirBridge { + + public static final String USE_CUSTOMDIR_PROPERTY = "launcher.usecustomdir"; + public static final String CUSTOMDIR_PROPERTY = "launcher.customdir"; + public static final String USE_OPTDIR_PROPERTY = "launcher.useoptdir"; + @LauncherAPI public static Path dir; @LauncherAPI @@ -27,12 +32,12 @@ public static void move(Path newDir) throws IOException { @LauncherAPI public static Path getAppDataDir() throws IOException { - Boolean isCustomDir = Boolean.getBoolean(System.getProperty("launcher.usecustomdir", "false")); + boolean isCustomDir = Boolean.getBoolean(System.getProperty(USE_CUSTOMDIR_PROPERTY, "false")); if (isCustomDir) { - return Paths.get(System.getProperty("launcher.customdir")); + return Paths.get(System.getProperty(CUSTOMDIR_PROPERTY)); } if (JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) { - Boolean isOpt = Boolean.getBoolean(System.getProperty("launcher.useoptdir", "false")); + boolean isOpt = Boolean.getBoolean(System.getProperty(USE_OPTDIR_PROPERTY, "false")); if (isOpt) { Path opt = Paths.get("/").resolve("opt"); if (!IOHelper.isDir(opt)) Files.createDirectories(opt); 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 32b66599..a4e3710c 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java @@ -10,6 +10,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; +import java.util.Collection; import java.util.Locale; import java.util.Map; @@ -155,6 +156,14 @@ public static String systemToJvmProperty(String name) { return String.format("-D%s=%s", name, System.getProperties().getProperty(name)); } + @LauncherAPI + public static void addSystemPropertyToArgs(Collection args, String name) + { + String property = System.getProperty(name); + if(property != null) + args.add(String.format("-D%s=%s", name, property)); + } + public static void verifySystemProperties(Class mainClass, boolean requireSystem) { Locale.setDefault(Locale.US);