From 7f0a4109670acd7b68b4f1d38c99da4f1dde608e Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Sat, 20 May 2023 10:59:53 +0100 Subject: [PATCH] JAL-4160 JAL-3830 Improve jalview.bin.Launcher for launcher script launch with new ArgParser --- src/jalview/bin/Launcher.java | 82 +++++++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 28 deletions(-) diff --git a/src/jalview/bin/Launcher.java b/src/jalview/bin/Launcher.java index c5268fa..2155f8d 100644 --- a/src/jalview/bin/Launcher.java +++ b/src/jalview/bin/Launcher.java @@ -26,6 +26,7 @@ import java.lang.management.ManagementFactory; import java.util.ArrayList; import java.util.List; import java.util.Locale; +import java.util.concurrent.TimeUnit; import jalview.util.ChannelProperties; import jalview.util.LaunchUtils; @@ -91,10 +92,12 @@ public class Launcher String jvmmempc = null; String jvmmemmax = null; boolean debug = false; - boolean help = false; + boolean wait = true; boolean quiet = false; + // must set --debug before --launcher... boolean launcherstop = false; boolean launcherprint = false; + boolean launcherwait = false; ArrayList arguments = new ArrayList<>(); for (String arg : args) { @@ -106,18 +109,30 @@ public class Launcher { quiet = true; } - if (arg.equals("--help") || arg.startsWith("--help-")) - { - help = true; - } - if (arg.equals("--launcherprint")) + if (debug && arg.equals("--launcherprint")) { launcherprint = true; } - if (arg.equals("--launcherstop")) + if (debug && arg.equals("--launcherstop")) { launcherstop = true; } + if (debug && arg.equals("--launcherwait")) + { + launcherwait = true; + } + // these quite immediately + if (arg.equals("--version") || arg.equals("--help") + || arg.startsWith("--help-") + || (debug && arg.equals("--launchernowait"))) + { + wait = false; + } + // Don't add the --launcher... args to Jalview launch + if (arg.startsWith("--launcher")) + { + continue; + } // jvmmempc and jvmmemmax args used to set memory and are not passed on to // startClass if (arg.startsWith( @@ -233,11 +248,8 @@ public class Launcher String scalePropertyArg = HiDPISetting.getScalePropertyArg(); if (scalePropertyArg != null) { - if (debug && !quiet) - { - System.out.println("Running " + startClass + " with scale setting " - + scalePropertyArg); - } + sysout(debug, quiet, "Running " + startClass + " with scale setting " + + scalePropertyArg); command.add(scalePropertyArg); } @@ -246,35 +258,41 @@ public class Launcher final ProcessBuilder builder = new ProcessBuilder(command); - if (!quiet && (Boolean - .parseBoolean(System.getProperty("launcherprint", "false")) - || (debug && launcherprint))) + if ((Boolean.parseBoolean(System.getProperty("launcherprint", "false")) + || launcherprint)) { - System.out.println( + sysout(debug, quiet, "LAUNCHER COMMAND: " + String.join(" ", builder.command())); } - if (debug && !quiet) - { - System.out.println("Running " + startClass + " with " - + (memSetting == null ? "no memory setting" - : ("memory setting " + memSetting))); - } + sysout(debug, quiet, + "Running " + startClass + " with " + + (memSetting == null ? "no memory setting" + : ("memory setting " + memSetting))); if (Boolean.parseBoolean(System.getProperty("launcherstop", "false")) || (debug && launcherstop)) { - if (!quiet) - { - System.out.println( - "System property 'launcherstop' is set and not 'false'. Exiting."); - } + sysout(debug, quiet, + "System property 'launcherstop' is set and not 'false'. Exiting."); System.exit(0); } try { builder.inheritIO(); Process process = builder.start(); - process.waitFor(); + if (wait || launcherwait) + { + sysout(debug, quiet, "Launching application process"); + process.waitFor(); + } + else + { + int waitInt = 0; + sysout(debug, quiet, + "Wait time for application process is " + waitInt + "ms"); + process.waitFor(waitInt, TimeUnit.MILLISECONDS); + } + sysout(debug, quiet, "Launcher process ending"); } catch (IOException e) { if (e.getMessage().toLowerCase(Locale.ROOT).contains("memory")) @@ -314,4 +332,12 @@ public class Launcher } } + private static void sysout(boolean debug, boolean quiet, String message) + { + if (debug && !quiet) + { + System.out.println("LAUNCHERDEBUG - " + message); + } + } + } -- 1.7.10.2