JAL-4409 Add two empty args to getdown call from install4j for backward compatibility...
authorBen Soares <b.soares@dundee.ac.uk>
Fri, 21 Jun 2024 12:48:41 +0000 (13:48 +0100)
committerBen Soares <b.soares@dundee.ac.uk>
Fri, 21 Jun 2024 12:48:41 +0000 (13:48 +0100)
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/Application.java
getdown/src/getdown/core/src/main/java/com/threerings/getdown/data/EnvConfig.java
getdown/src/getdown/core/src/main/java/jalview/util/LaunchUtils.java
j11lib/getdown-core.jar
j8lib/getdown-core.jar
src/jalview/util/LaunchUtils.java
utils/install4j/install4j10_template.install4j

index 4d92cc8..44bdf88 100644 (file)
Binary files a/getdown/lib/getdown-core.jar and b/getdown/lib/getdown-core.jar differ
index 0cae0b8..a8b3fb5 100644 (file)
Binary files a/getdown/lib/getdown-launcher-local.jar and b/getdown/lib/getdown-launcher-local.jar differ
index 722e965..a458557 100644 (file)
Binary files a/getdown/lib/getdown-launcher.jar and b/getdown/lib/getdown-launcher.jar differ
index 59e1bcb..9429efc 100644 (file)
@@ -283,7 +283,7 @@ public class Application
     /** The proxy that should be used to do HTTP downloads. This must be configured prior to using
       * the application instance. Yes this is a public mutable field, no I'm not going to create a
       * getter and setter just to pretend like that's not the case. */
-    public Proxy proxy = Proxy.NO_PROXY;
+    public static Proxy proxy = Proxy.NO_PROXY;
 
     /**
      * Creates an application instance which records the location of the <code>getdown.txt</code>
@@ -647,10 +647,12 @@ public class Application
         
         // merge the locator file config into config (or replace config with)
         if (locatorConfig != null) {
-          if (config == null || locatorConfig.getBoolean(LOCATOR_FILE_EXTENSION+"_replace")) {
+          if (config == null || locatorConfig.getBoolean(LOCATOR_FILE_EXTENSION+"_replace") || locatorConfig.hasValue("appbase")) {
             config = locatorConfig;
+                       log.warning("Replacing config with locator file", LOCATOR_FILE_EXTENSION+" file", locatorConfig);
           } else {
             config.mergeConfig(locatorConfig, locatorConfig.getBoolean(LOCATOR_FILE_EXTENSION+"_merge"));
+                       log.warning("Merging config with locator file", LOCATOR_FILE_EXTENSION+" file", locatorConfig);
           }
         }
 
@@ -2020,7 +2022,7 @@ public class Application
       _jalviewUri = uri;
     }
     
-    private Config createLocatorConfig(Config.ParseOpts opts) {
+    protected static Config createLocatorConfig(Config.ParseOpts opts) {
       if (_locatorFile == null) {
         return null;
       }
index 3780e6c..735ce8d 100644 (file)
@@ -16,6 +16,7 @@ import java.security.cert.CertificateFactory;
 import java.security.cert.X509Certificate;
 import java.util.*;
 
+import com.threerings.getdown.util.Config;
 import com.threerings.getdown.util.LaunchUtil;
 import com.threerings.getdown.util.StringUtil;
 
@@ -160,6 +161,7 @@ public final class EnvConfig {
                                     appIdProv + "'"));
             }
         }
+        int skipArgs = 2;
         
         boolean userAppDir = false;
         // platform user appdir addition
@@ -219,14 +221,18 @@ public final class EnvConfig {
           }
         }
         
-        int skipArgs = 2;
         // Look for locator file, pass to Application and remove from appArgs
         String argvLocatorFilename = argv.length > 2 ? argv[2] : null;
         if (!StringUtil.isBlank(argvLocatorFilename)
-              && argvLocatorFilename.toLowerCase(Locale.ROOT).endsWith("."+Application.LOCATOR_FILE_EXTENSION)) {
+              && argvLocatorFilename.toLowerCase(Locale.ROOT).endsWith("." + Application.LOCATOR_FILE_EXTENSION)) {
           argvLocatorFilename = HttpUtils.equivalentJalviewUrl(argvLocatorFilename);
-          notes.add(Note.info("locatorFilename in args: '"+argv[2]+"'"));
+          notes.add(Note.info("locatorFilename in args: '" + argv[2] + "'"));
           Application.setLocatorFile(argvLocatorFilename);
+          String lfAppBase = getLocatorFileAppBase(argvLocatorFilename);
+          if (!StringUtil.isBlank(lfAppBase)) {
+            appBase = lfAppBase;
+            appBaseProv = "from " + Application.LOCATOR_FILE_EXTENSION + " file";
+          }
           
           skipArgs++;
         }
@@ -365,6 +371,16 @@ public final class EnvConfig {
     public static boolean getRelaunched() {
       return relaunched;
     }
+    
+    private static String getLocatorFileAppBase(String locatorFile) {
+      String lfAppBase = null;
+      Config.ParseOpts opts = Config.createOpts(false);
+      Config checkConfig = Application.createLocatorConfig(opts);
+      if (!StringUtil.isBlank(checkConfig.getString("appbase"))) {
+        lfAppBase = checkConfig.getString("appbase");
+      }
+      return lfAppBase;
+    }
 
     private static boolean relaunched = false;
     
index 66c983c..0b18c6c 100644 (file)
@@ -371,7 +371,6 @@ public class LaunchUtils
           boolean launcherwait, boolean launcherstop, boolean debug,
           boolean quiet)
   {
-    int exitValue = -1;
     if (javaBinary == null)
     {
       javaBinary = findJavaBin(false, true, true);
@@ -500,7 +499,16 @@ public class LaunchUtils
     // application args
     command.addAll(applicationArguments);
 
+    return runProcess(command, launcherprint, launcherwait, launcherstop,
+            debug, quiet);
+  }
+
+  private static int runProcess(List<String> command, boolean launcherprint,
+          boolean launcherwait, boolean launcherstop, boolean debug,
+          boolean quiet)
+  {
     final ProcessBuilder builder = new ProcessBuilder(command);
+    int exitValue = -1;
 
     if (Boolean.parseBoolean(System.getProperty("launcherprint", "false"))
             || launcherprint)
@@ -582,6 +590,88 @@ public class LaunchUtils
     return exitValue;
   }
 
+  /*
+  public void invokeDirect() throws IOException
+  {
+    ClassPath classPath = PathBuilder.buildClassPath(this);
+    URL[] jarUrls = classPath.asUrls();
+  
+    // create custom class loader
+    URLClassLoader loader = new URLClassLoader(jarUrls,
+            ClassLoader.getSystemClassLoader())
+    {
+      @Override
+      protected PermissionCollection getPermissions(CodeSource code)
+      {
+        Permissions perms = new Permissions();
+        perms.add(new AllPermission());
+        return perms;
+      }
+    };
+    Thread.currentThread().setContextClassLoader(loader);
+  
+    log.info("Configured URL class loader:");
+    for (URL url : jarUrls)
+      log.info("  " + url);
+  
+    // configure any system properties that we can
+    for (String jvmarg : _jvmargs)
+    {
+      if (jvmarg.startsWith("-D"))
+      {
+        jvmarg = processArg(jvmarg.substring(2));
+        int eqidx = jvmarg.indexOf("=");
+        if (eqidx == -1)
+        {
+          log.warning("Bogus system property: '" + jvmarg + "'?");
+        }
+        else
+        {
+          System.setProperty(jvmarg.substring(0, eqidx),
+                  jvmarg.substring(eqidx + 1));
+        }
+      }
+    }
+  
+    // pass along any pass-through arguments
+    Map<String, String> passProps = new HashMap<>();
+    for (Map.Entry<Object, Object> entry : System.getProperties()
+            .entrySet())
+    {
+      String key = (String) entry.getKey();
+      if (key.startsWith(PROP_PASSTHROUGH_PREFIX))
+      {
+        key = key.substring(PROP_PASSTHROUGH_PREFIX.length());
+        passProps.put(key, (String) entry.getValue());
+      }
+    }
+    // we can't set these in the above loop lest we get a
+    // ConcurrentModificationException
+    for (Map.Entry<String, String> entry : passProps.entrySet())
+    {
+      System.setProperty(entry.getKey(), entry.getValue());
+    }
+  
+    // prepare our app arguments
+    String[] args = new String[_appargs.size()];
+    for (int ii = 0; ii < args.length; ii++)
+      args[ii] = processArg(_appargs.get(ii));
+  
+    try
+    {
+      log.info("Loading " + _class);
+      Class<?> appclass = loader.loadClass(_class);
+      Method main = appclass.getMethod("main",
+              EMPTY_STRING_ARRAY.getClass());
+      log.info("Invoking main({" + StringUtil.join(args, ", ") + "})");
+      main.invoke(null, new Object[] { args });
+    } catch (Exception e)
+    {
+      log.warning("Failure invoking app main", e);
+    }
+  }
+  */
+
   public static void syserr(boolean debug, boolean quiet, String message)
   {
     if (debug && !quiet)
index 4d92cc8..44bdf88 100644 (file)
Binary files a/j11lib/getdown-core.jar and b/j11lib/getdown-core.jar differ
index 4d92cc8..44bdf88 100644 (file)
Binary files a/j8lib/getdown-core.jar and b/j8lib/getdown-core.jar differ
index 66c983c..0b18c6c 100644 (file)
@@ -371,7 +371,6 @@ public class LaunchUtils
           boolean launcherwait, boolean launcherstop, boolean debug,
           boolean quiet)
   {
-    int exitValue = -1;
     if (javaBinary == null)
     {
       javaBinary = findJavaBin(false, true, true);
@@ -500,7 +499,16 @@ public class LaunchUtils
     // application args
     command.addAll(applicationArguments);
 
+    return runProcess(command, launcherprint, launcherwait, launcherstop,
+            debug, quiet);
+  }
+
+  private static int runProcess(List<String> command, boolean launcherprint,
+          boolean launcherwait, boolean launcherstop, boolean debug,
+          boolean quiet)
+  {
     final ProcessBuilder builder = new ProcessBuilder(command);
+    int exitValue = -1;
 
     if (Boolean.parseBoolean(System.getProperty("launcherprint", "false"))
             || launcherprint)
@@ -582,6 +590,88 @@ public class LaunchUtils
     return exitValue;
   }
 
+  /*
+  public void invokeDirect() throws IOException
+  {
+    ClassPath classPath = PathBuilder.buildClassPath(this);
+    URL[] jarUrls = classPath.asUrls();
+  
+    // create custom class loader
+    URLClassLoader loader = new URLClassLoader(jarUrls,
+            ClassLoader.getSystemClassLoader())
+    {
+      @Override
+      protected PermissionCollection getPermissions(CodeSource code)
+      {
+        Permissions perms = new Permissions();
+        perms.add(new AllPermission());
+        return perms;
+      }
+    };
+    Thread.currentThread().setContextClassLoader(loader);
+  
+    log.info("Configured URL class loader:");
+    for (URL url : jarUrls)
+      log.info("  " + url);
+  
+    // configure any system properties that we can
+    for (String jvmarg : _jvmargs)
+    {
+      if (jvmarg.startsWith("-D"))
+      {
+        jvmarg = processArg(jvmarg.substring(2));
+        int eqidx = jvmarg.indexOf("=");
+        if (eqidx == -1)
+        {
+          log.warning("Bogus system property: '" + jvmarg + "'?");
+        }
+        else
+        {
+          System.setProperty(jvmarg.substring(0, eqidx),
+                  jvmarg.substring(eqidx + 1));
+        }
+      }
+    }
+  
+    // pass along any pass-through arguments
+    Map<String, String> passProps = new HashMap<>();
+    for (Map.Entry<Object, Object> entry : System.getProperties()
+            .entrySet())
+    {
+      String key = (String) entry.getKey();
+      if (key.startsWith(PROP_PASSTHROUGH_PREFIX))
+      {
+        key = key.substring(PROP_PASSTHROUGH_PREFIX.length());
+        passProps.put(key, (String) entry.getValue());
+      }
+    }
+    // we can't set these in the above loop lest we get a
+    // ConcurrentModificationException
+    for (Map.Entry<String, String> entry : passProps.entrySet())
+    {
+      System.setProperty(entry.getKey(), entry.getValue());
+    }
+  
+    // prepare our app arguments
+    String[] args = new String[_appargs.size()];
+    for (int ii = 0; ii < args.length; ii++)
+      args[ii] = processArg(_appargs.get(ii));
+  
+    try
+    {
+      log.info("Loading " + _class);
+      Class<?> appclass = loader.loadClass(_class);
+      Method main = appclass.getMethod("main",
+              EMPTY_STRING_ARRAY.getClass());
+      log.info("Invoking main({" + StringUtil.join(args, ", ") + "})");
+      main.invoke(null, new Object[] { args });
+    } catch (Exception e)
+    {
+      log.warning("Failure invoking app main", e);
+    }
+  }
+  */
+
   public static void syserr(boolean debug, boolean quiet, String message)
   {
     if (debug && !quiet)
index e019562..f24478c 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<install4j version="10.0.7" transformSequenceNumber="10">
+<install4j version="10.0.8" transformSequenceNumber="10">
   <directoryPresets config="bin/Jalview" />
   <application name="${compiler:JALVIEW_APPLICATION_NAME}" applicationId="${compiler:WINDOWS_APPLICATION_ID}" mediaDir="${compiler:BUILD_DIR}" lzmaCompression="true" shortName="${compiler:INTERNAL_ID}" publisher="University of Dundee" publisherWeb="https://www.jalview.org/" version="${compiler:JALVIEW_VERSION}" allPathsRelative="true" macVolumeId="5aac4968c304f65" javaMinVersion="${compiler:JAVA_MIN_VERSION}" javaMaxVersion="${compiler:JAVA_MAX_VERSION}" allowBetaVM="true" jdkMode="jdk" jdkName="JDK 11.0">
     <searchSequence>
           <versionLine x="85" y="109" text="version ${compiler:sys.version}" />
         </text>
       </splashScreen>
-      <java mainClass="com.threerings.getdown.launcher.GetdownApp" vmParameters="-Duserdefaultappdir=true -Dpopulatedefaultappdir=true -Dappid=jalview -Dinstaller.template_version=${compiler:INSTALLER_TEMPLATE_VERSION} -Dinstaller.appdir=&quot;${launcher:sys.launcherDirectory}&quot; -Dinstaller.application_folder=&quot;${compiler:APPLICATION_FOLDER}&quot; -Dchannel.app_name=&quot;${compiler:JALVIEW_APPLICATION_NAME}&quot;">
+      <java mainClass="com.threerings.getdown.launcher.GetdownApp" vmParameters="-Duserdefaultappdir=true -Dpopulatedefaultappdir=true -Dappid=jalview -Dinstaller.template_version=${compiler:INSTALLER_TEMPLATE_VERSION} -Dinstaller.appdir=&quot;${launcher:sys.launcherDirectory}&quot; -Dinstaller.application_folder=&quot;${compiler:APPLICATION_FOLDER}&quot; -Dchannel.app_name=&quot;${compiler:JALVIEW_APPLICATION_NAME}&quot;" arguments="&quot;&quot; &quot;&quot;">
         <classPath>
           <archive location="getdown-launcher.jar" failOnError="false" />
           <archive location="${compiler:GETDOWN_INSTALL_DIR}/getdown-launcher.jar" failOnError="false" />