JAL-3631 Changes to Getdown to call getdown-launcher.jar update without launching...
authorBen Soares <b.soares@dundee.ac.uk>
Wed, 31 Jul 2024 15:36:01 +0000 (16:36 +0100)
committerBen Soares <b.soares@dundee.ac.uk>
Wed, 31 Jul 2024 15:36:01 +0000 (16:36 +0100)
14 files changed:
getdown/lib/getdown-core.jar
getdown/lib/getdown-launcher-local.jar
getdown/lib/getdown-launcher.jar
getdown/src/getdown/core/src/main/java/com/threerings/getdown/data/EnvConfig.java
getdown/src/getdown/core/src/main/java/com/threerings/getdown/util/LaunchUtil.java
getdown/src/getdown/core/src/main/java/jalview/bin/GetdownLauncherUpdate.java [new file with mode: 0644]
getdown/src/getdown/core/src/main/java/jalview/util/ErrorLog.java
gradle.properties
j11lib/getdown-core.jar
j8lib/getdown-core.jar
src/jalview/bin/GetdownLauncherUpdate.java [new file with mode: 0644]
src/jalview/bin/Jalview.java
src/jalview/bin/Launcher.java
src/jalview/util/ErrorLog.java

index d125cc7..c433ea4 100644 (file)
Binary files a/getdown/lib/getdown-core.jar and b/getdown/lib/getdown-core.jar differ
index f982611..1fe31b9 100644 (file)
Binary files a/getdown/lib/getdown-launcher-local.jar and b/getdown/lib/getdown-launcher-local.jar differ
index ccfcaf0..8513bf6 100644 (file)
Binary files a/getdown/lib/getdown-launcher.jar and b/getdown/lib/getdown-launcher.jar differ
index 81a3777..596dae6 100644 (file)
@@ -79,7 +79,6 @@ public final class EnvConfig {
         String appBaseProv = null;
         applicationFolder = System.getProperty("installer.application_folder");
         installerAppdir = System.getProperty(APPLICATION_APPDIR_PROPERTY);
-        
         appName = System.getProperty("channel.app_name");
         
         // start with bootstrap.properties config, if avaialble
@@ -363,7 +362,7 @@ public final class EnvConfig {
       return hash.substring(0,8);
     }
     
-    protected static final String getUserAppdir() {
+    public static final String getUserAppdir() {
       final String noUseDefaultAppDirProperty = "no" + USER_DEFAULT_APPDIR_PROPERTY;
       if (Boolean.valueOf(System.getProperty(noUseDefaultAppDirProperty))) {
         System.err.println("Not using default user appdir because property '" + noUseDefaultAppDirProperty + "' is '" + System.getProperty(noUseDefaultAppDirProperty) + "'");
@@ -375,6 +374,13 @@ public final class EnvConfig {
       }
       String appdirname = applicationFolder == null || applicationFolder.length() == 0 ? ChannelProperties.FALLBACK_APPNAME : applicationFolder;
       String home = System.getProperty("user.home");
+      // for times when using this method without running GetdownApp
+      if (appName == null) {
+        appName = System.getProperty("channel.app_name");
+      }
+      if (installerAppdir == null) {
+        installerAppdir = System.getProperty(APPLICATION_APPDIR_PROPERTY);
+      }
       String appname = StringUtil.isBlank(appName) ? ChannelProperties.FALLBACK_APPNAME : appName;
       final String FS = File.separator;
       String appDirHash;
@@ -454,7 +460,7 @@ public final class EnvConfig {
     
     private static String appName = null;
     
-    protected static final String USER_DEFAULT_APPDIR_PROPERTY = "userdefaultappdir";
+    public static final String USER_DEFAULT_APPDIR_PROPERTY = "userdefaultappdir";
     
     protected static final String APPLICATION_APPDIR_PROPERTY = "installer.appdir";
     
index d6ad03d..3fbff0a 100644 (file)
@@ -13,8 +13,6 @@ import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.Locale;
 
-import javax.xml.bind.DatatypeConverter;
-
 import java.security.MessageDigest;
 
 import jalview.util.ChannelProperties;
@@ -149,7 +147,7 @@ public class LaunchUtil
                MessageDigest md = MessageDigest.getInstance(algo);
                md.update(Files.readAllBytes(Paths.get(file.getAbsolutePath())));
                byte[] digest = md.digest();
-               checksum = DatatypeConverter.printHexBinary(digest).toUpperCase(Locale.ROOT);
+               checksum = printHexBinary(digest).toUpperCase(Locale.ROOT);
        } catch (Exception e) {
                System.out.println("Couldn't create "+algo+" digest of "+file.getPath());
        }
@@ -322,4 +320,23 @@ public class LaunchUtil
             // can't grab system properties; we'll just pretend we're not on any of these OSes
         }
     }
+    
+    private static String printHexBinary(byte[] bytes) {
+      if (bytes == null) {
+        return null;
+      }
+      StringBuilder sb = new StringBuilder();
+      for (int i = 0; i < bytes.length; i++) {
+        sb.append(byteToHex(bytes[i]));
+      }
+      return sb.toString();
+    }
+    
+    private static String byteToHex(byte num) {
+        char[] hexDigits = new char[2];
+        hexDigits[0] = Character.forDigit((num >> 4) & 0xF, 16);
+        hexDigits[1] = Character.forDigit((num & 0xF), 16);
+        return new String(hexDigits);
+    }
+
 }
diff --git a/getdown/src/getdown/core/src/main/java/jalview/bin/GetdownLauncherUpdate.java b/getdown/src/getdown/core/src/main/java/jalview/bin/GetdownLauncherUpdate.java
new file mode 100644 (file)
index 0000000..be7862d
--- /dev/null
@@ -0,0 +1,53 @@
+package jalview.bin;
+
+import java.io.File;
+
+import com.threerings.getdown.data.EnvConfig;
+import com.threerings.getdown.util.LaunchUtil;
+
+public class GetdownLauncherUpdate
+{
+  public static void main(String[] args)
+  {
+    String appdir = args.length > 0 ? args[0] : null;
+    if (appdir == null || appdir.length() == 0)
+    {
+      appdir = System.getProperty("launcher.appdir", null);
+    }
+    if (appdir == null)
+    {
+      appdir = EnvConfig.getUserAppdir();
+    }
+    if (appdir == null)
+    {
+      System.err.println("Not running upgradeGetdown");
+      return;
+    }
+    boolean debug = false;
+    for (int i = 0; i < args.length; i++)
+    {
+      if ("--debug".equals(args[i]))
+      {
+        debug = true;
+        break;
+      }
+    }
+    if (debug)
+    {
+      System.err.println("Running upgradeGetdown");
+    }
+    File appdirFile = new File(appdir);
+    if (!appdirFile.exists())
+    {
+      System.err.println("Directory '" + appdirFile.getAbsolutePath()
+              + "' doesn't exist, cannot update getdown-launcher.jar.");
+      if (Boolean.valueOf(System.getProperty("launcher.update")))
+      {
+        System.exit(1);
+      }
+    }
+    LaunchUtil.upgradeGetdown(new File(appdir, "getdown-launcher-old.jar"),
+            new File(appdir, "getdown-launcher.jar"),
+            new File(appdir, "getdown-launcher-new.jar"));
+  }
+}
index c204783..4c9c5ea 100644 (file)
@@ -17,11 +17,18 @@ public class ErrorLog
 
   private static String prefix = null;
 
+  private static boolean quiet = false;
+
   public static void setHasConsole(boolean b)
   {
     hasConsole = b;
   }
 
+  public static void setQuiet(boolean b)
+  {
+    quiet = b;
+  }
+
   public static void setPrefix(String s)
   {
     prefix = s;
@@ -45,6 +52,10 @@ public class ErrorLog
   public static void println(String message0, boolean err,
           boolean thisHasConsole)
   {
+    if (!err && quiet)
+    {
+      return;
+    }
     String message = prefix == null ? message0 : prefix + message0;
     if (thisHasConsole && hasConsole)
     {
index fb6be1a..0b722ef 100644 (file)
@@ -83,7 +83,6 @@ getdown_lib_dir = getdown/lib
 getdown_launcher = getdown-launcher.jar
 getdown_launcher_local = getdown-launcher-local.jar
 getdown_launcher_new = getdown-launcher-new.jar
-getdown_core = getdown/lib/getdown-core.jar
 getdown_build_properties = build_properties
 getdown_launch_jvl_name = channel_launch
 getdown_images_dir = utils/getdown
@@ -98,6 +97,7 @@ getdown_txt_max_concurrent_downloads = 10
 # now got better (dynamic) defaults when jvmmem* not set
 #getdown_txt_jalview.jvmmempc = 90
 #getdown_txt_jalview.jvmmemmax = 32G
+getdown_txt_resource = getdown/lib/getdown-core.jar
 getdown_txt_strict_comments = true
 getdown_txt_ui.progress_sync_before_shown = true
 getdown_txt_ui.progress_sync_after_shown = false
index d125cc7..c433ea4 100644 (file)
Binary files a/j11lib/getdown-core.jar and b/j11lib/getdown-core.jar differ
index d125cc7..c433ea4 100644 (file)
Binary files a/j8lib/getdown-core.jar and b/j8lib/getdown-core.jar differ
diff --git a/src/jalview/bin/GetdownLauncherUpdate.java b/src/jalview/bin/GetdownLauncherUpdate.java
new file mode 100644 (file)
index 0000000..be7862d
--- /dev/null
@@ -0,0 +1,53 @@
+package jalview.bin;
+
+import java.io.File;
+
+import com.threerings.getdown.data.EnvConfig;
+import com.threerings.getdown.util.LaunchUtil;
+
+public class GetdownLauncherUpdate
+{
+  public static void main(String[] args)
+  {
+    String appdir = args.length > 0 ? args[0] : null;
+    if (appdir == null || appdir.length() == 0)
+    {
+      appdir = System.getProperty("launcher.appdir", null);
+    }
+    if (appdir == null)
+    {
+      appdir = EnvConfig.getUserAppdir();
+    }
+    if (appdir == null)
+    {
+      System.err.println("Not running upgradeGetdown");
+      return;
+    }
+    boolean debug = false;
+    for (int i = 0; i < args.length; i++)
+    {
+      if ("--debug".equals(args[i]))
+      {
+        debug = true;
+        break;
+      }
+    }
+    if (debug)
+    {
+      System.err.println("Running upgradeGetdown");
+    }
+    File appdirFile = new File(appdir);
+    if (!appdirFile.exists())
+    {
+      System.err.println("Directory '" + appdirFile.getAbsolutePath()
+              + "' doesn't exist, cannot update getdown-launcher.jar.");
+      if (Boolean.valueOf(System.getProperty("launcher.update")))
+      {
+        System.exit(1);
+      }
+    }
+    LaunchUtil.upgradeGetdown(new File(appdir, "getdown-launcher-old.jar"),
+            new File(appdir, "getdown-launcher.jar"),
+            new File(appdir, "getdown-launcher-new.jar"));
+  }
+}
index 0e3b30a..8bddae3 100755 (executable)
@@ -64,7 +64,6 @@ import javax.swing.UnsupportedLookAndFeelException;
 import com.formdev.flatlaf.FlatLightLaf;
 import com.formdev.flatlaf.themes.FlatMacLightLaf;
 import com.formdev.flatlaf.util.SystemInfo;
-import com.threerings.getdown.util.LaunchUtil;
 
 //import edu.stanford.ejalbert.launching.IBrowserLaunching;
 import groovy.lang.Binding;
@@ -383,17 +382,13 @@ public class Jalview implements JalviewObjectI
     String appdirString = System.getProperty("launcher.appdir");
     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"));
+          GetdownLauncherUpdate.main(new String[] { appdirString });
         }
       }.start();
     }
index ec53219..579b682 100644 (file)
@@ -210,6 +210,8 @@ public class Launcher
       headless = assumeheadless;
     }
 
+    ErrorLog.setQuiet(quiet);
+
     final String appName = ChannelProperties.getProperty("app_name");
 
     // if we're using jalview.bin.Launcher we always assume a console is in use
@@ -327,8 +329,8 @@ public class Launcher
     String scalePropertyArg = HiDPISetting.getScalePropertyArg();
     if (scalePropertyArg != null)
     {
-      LaunchUtils.syserr(debug, quiet, "Running " + startClass
-              + " with scale setting " + scalePropertyArg);
+      ErrorLog.errPrintln("Running " + startClass + " with scale setting "
+              + scalePropertyArg);
       addJvmArgs.add(scalePropertyArg);
     }
 
@@ -336,7 +338,7 @@ public class Launcher
             addJvmArgs, null, null, null, startClass, null, null, arguments,
             launcherprint, launcherwait, launcherstop, debug, quiet);
 
-    LaunchUtils.syserr(debug, quiet, "JVM exited with value " + exitValue);
+    ErrorLog.errPrintln("JVM exited with value " + exitValue);
   }
 
 }
index c204783..4c9c5ea 100644 (file)
@@ -17,11 +17,18 @@ public class ErrorLog
 
   private static String prefix = null;
 
+  private static boolean quiet = false;
+
   public static void setHasConsole(boolean b)
   {
     hasConsole = b;
   }
 
+  public static void setQuiet(boolean b)
+  {
+    quiet = b;
+  }
+
   public static void setPrefix(String s)
   {
     prefix = s;
@@ -45,6 +52,10 @@ public class ErrorLog
   public static void println(String message0, boolean err,
           boolean thisHasConsole)
   {
+    if (!err && quiet)
+    {
+      return;
+    }
     String message = prefix == null ? message0 : prefix + message0;
     if (thisHasConsole && hasConsole)
     {