From: Ben Soares Date: Tue, 28 Feb 2023 18:29:20 +0000 (+0000) Subject: JAL-629 Firm up bootstrapArgs. Correct '-colour' in test. Separate --headless and... X-Git-Tag: Release_2_11_4_0~464 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=156ab6ab1046c02dc327c2ac986afa336f0bbf3b;p=jalview.git JAL-629 Firm up bootstrapArgs. Correct '-colour' in test. Separate --headless and -headless for now to avoid premature exit for -headless (fixes tests). --- diff --git a/src/jalview/bin/ArgParser.java b/src/jalview/bin/ArgParser.java index 3dc7921..be2c07f 100644 --- a/src/jalview/bin/ArgParser.java +++ b/src/jalview/bin/ArgParser.java @@ -878,14 +878,14 @@ public class ArgParser } } - private static final Collection bootstrapArgs = new ArrayList( - Arrays.asList("props", "debug")); + private static final Collection bootstrapArgs = new ArrayList( + Arrays.asList(Arg.PROPS, Arg.DEBUG)); - public static Map bootstrapArgs(String[] args) + public static Map bootstrapArgs(String[] args) { - Map argMap = new HashMap<>(); + Map bootstrapArgMap = new HashMap<>(); if (args == null) - return argMap; + return bootstrapArgMap; Enumeration argE = Collections.enumeration(Arrays.asList(args)); while (argE.hasMoreElements()) { @@ -904,10 +904,11 @@ public class ArgParser { argName = arg.substring(2); } - if (bootstrapArgs.contains(argName)) - argMap.put(argName, val); + Arg a = argMap.get(argName); + if (a != null && bootstrapArgs.contains(a)) + bootstrapArgMap.put(a, val); } } - return argMap; + return bootstrapArgMap; } } \ No newline at end of file diff --git a/src/jalview/bin/Commands.java b/src/jalview/bin/Commands.java index 429c692..af8bf65 100644 --- a/src/jalview/bin/Commands.java +++ b/src/jalview/bin/Commands.java @@ -60,7 +60,7 @@ public class Commands { argParser = ap; headless = h; - boolean argsWereParsed = false; + boolean argsWereParsed = true; if (headless) { System.setProperty("java.awt.headless", "true"); @@ -74,13 +74,15 @@ public class Commands if (id == null) { cmds.processUnlinked(id); + argsWereParsed &= cmds.wereParsed(); } else { cmds.processLinked(id); + argsWereParsed &= cmds.wereParsed(); } cmds.processImages(id); - argsWereParsed |= cmds.wereParsed(); + argsWereParsed &= cmds.wereParsed(); } } @@ -93,7 +95,7 @@ public class Commands return argsWereParsed; } - boolean argsWereParsed = false; + boolean argsWereParsed = true; // set false as soon as an arg is found private boolean wereParsed() { @@ -113,14 +115,16 @@ public class Commands protected void processUnlinked(String id) { - ArgValuesMap avm = new ArgValuesMap(argParser.linkedArgs(id)); - processLinked(id); } protected void processLinked(String id) { ArgValuesMap avm = new ArgValuesMap(argParser.linkedArgs(id)); + if (avm == null) + return; + else + argsWereParsed = false; /* // script to execute after all loading is completed one way or another diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 3cc71af..04cf2a3 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -282,7 +282,8 @@ public class Jalview } // get args needed before proper ArgParser - Map bootstrapArgs = ArgParser.bootstrapArgs(args); + Map bootstrapArgs = ArgParser + .bootstrapArgs(args); System.out .println("Java version: " + System.getProperty("java.version")); @@ -314,7 +315,7 @@ public class Jalview // get bootstrap properties (mainly for the logger level) Properties bootstrapProperties = Cache - .bootstrapProperties(bootstrapArgs.get("props")); + .bootstrapProperties(bootstrapArgs.get(Arg.PROPS)); // report Jalview version Cache.loadBuildProperties(true); @@ -322,11 +323,15 @@ public class Jalview // old ArgsParser ArgsParser aparser = new ArgsParser(args); + // old boolean headless = false; + // new + boolean headlessArg = false; try { - String logLevel = bootstrapArgs.containsKey("debug") ? "DEBUG" : null; + String logLevel = bootstrapArgs.containsKey(Arg.DEBUG) ? "DEBUG" + : null; if (logLevel == null && !(bootstrapProperties == null)) { logLevel = bootstrapProperties.getProperty(Cache.JALVIEWLOGLEVEL); @@ -363,8 +368,8 @@ public class Jalview } }); - String usrPropsFile = bootstrapArgs.containsKey("props") - ? bootstrapArgs.get("props") + String usrPropsFile = bootstrapArgs.containsKey(Arg.PROPS) + ? bootstrapArgs.get(Arg.PROPS) : aparser.getValue("props"); Cache.loadProperties(usrPropsFile); if (usrPropsFile != null) @@ -376,9 +381,6 @@ public class Jalview // new ArgParser ArgParser argparser = new ArgParser(args); - if (argparser.isSet(Arg.HEADLESS)) - headless = argparser.getBool(Arg.HEADLESS); - if (!Platform.isJS()) /** * Java only @@ -386,20 +388,24 @@ public class Jalview * @j2sIgnore */ { - if (argparser.isSet(Arg.HEADLESS)) + if (aparser.contains("help") || aparser.contains("h") + || argparser.getBool(Arg.HELP)) { - headless = argparser.getBool(Arg.HEADLESS); + showUsage(); + System.exit(0); } - if (aparser.contains("help") || aparser.contains("h")) + if (argparser.isSet(Arg.HEADLESS)) { - showUsage(); - System.exit(0); + System.setProperty("java.awt.headless", "true"); + // new + headlessArg = argparser.getBool(Arg.HEADLESS); } - if (headless || aparser.contains("nodisplay") - || aparser.contains("nogui") || aparser.contains("headless")) + if (aparser.contains("nodisplay") || aparser.contains("nogui") + || aparser.contains("headless")) { System.setProperty("java.awt.headless", "true"); + // old headless = true; } // anything else! @@ -466,7 +472,8 @@ public class Jalview } desktop = null; - setLookAndFeel(); + if (!(headless || headlessArg)) + setLookAndFeel(); /* * configure 'full' SO model if preferences say to, else use the default (full SO) @@ -478,7 +485,7 @@ public class Jalview SequenceOntologyFactory.setInstance(new SequenceOntology()); } - if (!headless) + if (!(headless || headlessArg)) { Desktop.nosplash = aparser.contains("nosplash"); desktop = new Desktop(); @@ -605,13 +612,13 @@ public class Jalview if (commandsSuccess) { Console.info("Successfully completed commands"); - if (headless) + if (headlessArg) System.exit(0); } else { Console.warn("Error when running commands"); - if (headless) + if (headlessArg) System.exit(1); } @@ -727,7 +734,7 @@ public class Jalview if (cs != null) { System.out.println( - "CMD [-color " + data + "] executed successfully!"); + "CMD [-colour " + data + "] executed successfully!"); } af.changeColour(cs); } diff --git a/test/jalview/bin/CommandLineOperations.java b/test/jalview/bin/CommandLineOperations.java index a9b7640..7509ec9 100644 --- a/test/jalview/bin/CommandLineOperations.java +++ b/test/jalview/bin/CommandLineOperations.java @@ -53,10 +53,8 @@ public class CommandLineOperations JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); } - private static final int TEST_TIMEOUT = 13000; // Note longer timeout needed - // on - // full test run than on - // individual tests + // Note longer timeout needed on full test run than on individual tests + private static final int TEST_TIMEOUT = 13000; private static final int SETUP_TIMEOUT = 9500; @@ -342,7 +340,7 @@ public class CommandLineOperations { return new Object[][] { // headless mode input operations - { "CMD [-color zappo] executed successfully!", + { "CMD [-colour zappo] executed successfully!", "Failed command : -color zappo" }, { "CMD [-props test/jalview/bin/testProps.jvprops] executed successfully!", "Failed command : --props=File" },