JAL-629 bootstrap args and properties. Remember index of args for 'previous structure...
[jalview.git] / src / jalview / bin / Jalview.java
index 402235b..71c6cf0 100755 (executable)
@@ -40,6 +40,7 @@ import java.security.Policy;
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Vector;
 import java.util.logging.ConsoleHandler;
 import java.util.logging.Level;
@@ -278,30 +279,11 @@ public class Jalview
     if (!Platform.isJS())
     {
       System.setSecurityManager(null);
-
-      Runtime.getRuntime().addShutdownHook(new Thread()
-      {
-        public void run()
-        {
-          Console.debug("Running shutdown hook");
-          if (QuitHandler.gotQuitResponse() == QResponse.CANCEL_QUIT)
-          {
-            // Got to here by a SIGTERM signal.
-            // Note we will not actually cancel the quit from here -- it's too
-            // late -- but we can wait for saving files.
-            Console.debug("Checking for saving files");
-            QuitHandler.getQuitResponse(false);
-          }
-          else
-          {
-            Console.debug("Nothing more to do");
-          }
-          Console.debug("Exiting, bye!");
-          // shutdownHook cannot be cancelled, JVM will now halt
-        }
-      });
     }
 
+    // get args needed before proper ArgParser
+    Map<String, String> bootstrapArgs = ArgParser.bootstrapArgs(args);
+
     System.out
             .println("Java version: " + System.getProperty("java.version"));
     System.out.println("Java Home: " + System.getProperty("java.home"));
@@ -330,6 +312,10 @@ public class Jalview
       System.setProperty("flatlaf.uiScale", "1");
     }
 
+    // get bootstrap properties (mainly for the logger level)
+    Properties bootstrapProperties = Cache
+            .bootstrapProperties(bootstrapArgs.get("props"));
+
     // report Jalview version
     Cache.loadBuildProperties(true);
 
@@ -340,7 +326,12 @@ public class Jalview
 
     try
     {
-      Console.initLogger();
+      String logLevel = bootstrapArgs.containsKey("debug") ? "DEBUG" : null;
+      if (logLevel == null && !(bootstrapProperties == null))
+      {
+        logLevel = bootstrapProperties.getProperty(Cache.JALVIEWLOGLEVEL);
+      }
+      Console.initLogger(logLevel);
     } catch (NoClassDefFoundError error)
     {
       error.printStackTrace();
@@ -349,23 +340,41 @@ public class Jalview
       System.exit(0);
     }
 
-    String usrPropsFile = aparser.getValue("props");
-    Cache.loadProperties(usrPropsFile); // must do this
-                                        // before
+    // register SIGTERM listener
+    Runtime.getRuntime().addShutdownHook(new Thread()
+    {
+      public void run()
+      {
+        Console.debug("Running shutdown hook");
+        if (QuitHandler.gotQuitResponse() == QResponse.CANCEL_QUIT)
+        {
+          // Got to here by a SIGTERM signal.
+          // Note we will not actually cancel the quit from here -- it's too
+          // late -- but we can wait for saving files.
+          Console.debug("Checking for saving files");
+          QuitHandler.getQuitResponse(false);
+        }
+        else
+        {
+          Console.debug("Nothing more to do");
+        }
+        Console.debug("Exiting, bye!");
+        // shutdownHook cannot be cancelled, JVM will now halt
+      }
+    });
+
+    String usrPropsFile = bootstrapArgs.containsKey("props")
+            ? bootstrapArgs.get("props")
+            : aparser.getValue("props");
+    Cache.loadProperties(usrPropsFile);
     if (usrPropsFile != null)
     {
       System.out.println(
               "CMD [-props " + usrPropsFile + "] executed successfully!");
     }
 
-    // set log level from cache properties
-    Console.setLogLevel(Cache.getDefault(Cache.JALVIEWLOGLEVEL, "INFO"));
-
     // new ArgParser
-    ArgParser argparser = new ArgParser(args); // do this after
-                                               // Console.initLogger, but TODO
-                                               // want --props before then
-                                               // CATCH22
+    ArgParser argparser = new ArgParser(args);
 
     if (argparser.isSet(Arg.HEADLESS))
       headless = argparser.getBool(Arg.HEADLESS);