JAL-629 move getdown update to earlier stage
[jalview.git] / src / jalview / bin / Jalview.java
index a54259e..5f1f228 100755 (executable)
@@ -286,6 +286,25 @@ public class Jalview
       System.setSecurityManager(null);
     }
 
+    // Move any new getdown-launcher-new.jar into place over old
+    // getdown-launcher.jar
+    String appdirString = System.getProperty("getdownappdir");
+    if (appdirString != null && appdirString.length() > 0)
+    {
+      final File appdir = new File(appdirString);
+      new Thread()
+      {
+        @Override
+        public void run()
+        {
+          LaunchUtil.upgradeGetdown(
+                  new File(appdir, "getdown-launcher-old.jar"),
+                  new File(appdir, "getdown-launcher.jar"),
+                  new File(appdir, "getdown-launcher-new.jar"));
+        }
+      }.start();
+    }
+
     // get args needed before proper ArgParser
     BootstrapArgs bootstrapArgs = BootstrapArgs.getBootstrapArgs(args);
 
@@ -365,9 +384,9 @@ public class Jalview
     } catch (NoClassDefFoundError error)
     {
       error.printStackTrace();
-      System.out.println("\nEssential logging libraries not found."
-              + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
-      System.exit(0);
+      String message = "\nEssential logging libraries not found."
+              + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview";
+      Jalview.exit(message, 0);
     }
 
     // register SIGTERM listener
@@ -427,7 +446,7 @@ public class Jalview
               || argparser.getBool(Arg.HELP))
       {
         showUsage();
-        System.exit(0);
+        Jalview.exit(null, 0);
       }
 
       if (bootstrapArgs.contains(Arg.HEADLESS))
@@ -501,9 +520,9 @@ public class Jalview
     NoClassDefFoundError error)
     {
       error.printStackTrace();
-      System.out.println("\nEssential logging libraries not found."
-              + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
-      System.exit(0);
+      String message = "\nEssential logging libraries not found."
+              + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview";
+      Jalview.exit(message, 0);
     }
     desktop = null;
 
@@ -647,18 +666,19 @@ public class Jalview
     boolean commandsSuccess = cmds.argsWereParsed();
     if (commandsSuccess)
     {
-      Console.info("Successfully completed commands");
       if (headlessArg)
       {
-        System.out.println("#### EXITING");
-        System.exit(0);
+        Jalview.exit("Successfully completed commands in headless mode", 0);
       }
+      Console.info("Successfully completed commands");
     }
     else
     {
-      Console.warn("Error when running commands");
       if (headlessArg)
-        System.exit(1);
+      {
+        Jalview.exit("Error when running Commands in headless mode", 1);
+      }
+      Console.warn("Error when running commands");
     }
 
     // Check if JVM and compile version might cause problems and log if it
@@ -671,25 +691,6 @@ public class Jalview
               + LaunchUtils.getJavaCompileVersion() + ".");
     }
 
-    // Move any new getdown-launcher-new.jar into place over old
-    // getdown-launcher.jar
-    String appdirString = System.getProperty("getdownappdir");
-    if (appdirString != null && appdirString.length() > 0)
-    {
-      final File appdir = new File(appdirString);
-      new Thread()
-      {
-        @Override
-        public void run()
-        {
-          LaunchUtil.upgradeGetdown(
-                  new File(appdir, "getdown-launcher-old.jar"),
-                  new File(appdir, "getdown-launcher.jar"),
-                  new File(appdir, "getdown-launcher-new.jar"));
-        }
-      }.start();
-    }
-
     String file = null, data = null;
 
     FileFormatI format = null;
@@ -706,8 +707,7 @@ public class Jalview
 
     if (file == null && desktop == null)
     {
-      System.out.println("No files to open!");
-      System.exit(1);
+      Jalview.exit("No files to open!", 1);
     }
 
     long progress = -1;
@@ -734,11 +734,12 @@ public class Jalview
         {
           if (!(new File(file)).exists())
           {
-            System.out.println("Can't find " + file);
             if (headless)
             {
-              System.exit(1);
+              Jalview.exit(
+                      "Can't find file '" + file + "' in headless mode", 1);
             }
+            Console.warn("Can't find file'" + file + "'");
           }
         }
       }
@@ -1354,12 +1355,7 @@ public class Jalview
   private static boolean setLinuxLookAndFeel()
   {
     boolean set = false;
-    /*
-     *  THIS IS A TEST FOR THE BUILD SERVER!
-     *
-    set = setMetalLookAndFeel();
-    //set = setFlatLookAndFeel();
-     */
+    set = setFlatLookAndFeel();
     if (!set)
       set = setMetalLookAndFeel();
     // avoid GtkLookAndFeel -- not good results especially on HiDPI
@@ -1583,8 +1579,7 @@ public class Jalview
   public void quit()
   {
     // System.exit will run the shutdownHook first
-    System.out.println("Quitting now. Bye!");
-    System.exit(0);
+    Jalview.exit("Quitting now. Bye!", 0);
   }
 
   public static AlignFrame getCurrentAlignFrame()
@@ -1601,4 +1596,17 @@ public class Jalview
   {
     return cmds;
   }
+
+  public static void exit(String message, int exitcode)
+  {
+    System.err.println("####### EXITING HERE!");
+    Console.debug("Using Jalview.exit");
+    if (message != null)
+      if (exitcode == 0)
+        Console.info(message);
+      else
+        Console.error(message);
+    if (exitcode > -1)
+      System.exit(exitcode);
+  }
 }