JAL-629 Firm up bootstrapArgs. Correct '-colour' in test. Separate --headless and...
[jalview.git] / src / jalview / bin / Jalview.java
index 3cc71af..04cf2a3 100755 (executable)
@@ -282,7 +282,8 @@ public class Jalview
     }
 
     // get args needed before proper ArgParser
-    Map<String, String> bootstrapArgs = ArgParser.bootstrapArgs(args);
+    Map<ArgParser.Arg, String> 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);
         }