JAL-4477 Re-work install4j and getdown to use the installer.appdir first or installer...
authorBen Soares <b.soares@dundee.ac.uk>
Wed, 20 Nov 2024 16:06:51 +0000 (16:06 +0000)
committerBen Soares <b.soares@dundee.ac.uk>
Wed, 20 Nov 2024 16:06:51 +0000 (16:06 +0000)
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/jalview/util/FileUtils.java
j11lib/getdown-core.jar
j8lib/getdown-core.jar
src/jalview/util/FileUtils.java
utils/install4j/install4j11_template.install4j

index e52042f..925eb6f 100644 (file)
Binary files a/getdown/lib/getdown-core.jar and b/getdown/lib/getdown-core.jar differ
index 4ae1f62..cab2213 100644 (file)
Binary files a/getdown/lib/getdown-launcher-local.jar and b/getdown/lib/getdown-launcher-local.jar differ
index 331e5d0..8bd0e78 100644 (file)
Binary files a/getdown/lib/getdown-launcher.jar and b/getdown/lib/getdown-launcher.jar differ
index d1ae75f..83278c0 100644 (file)
@@ -459,8 +459,19 @@ public final class EnvConfig {
     }
     
     public static void setVarsFromProperties() {
-      applicationFolder = System.getProperty("installer.application_folder");
+      // this method gets run very early on, before any other system properties have been read
+      // Use the original installer appdir if the current installer appdir doesn't exist (most likely a wide character in the path problem)
       installerAppdir = System.getProperty(APPLICATION_APPDIR_PROPERTY);
+      if (!new File(installerAppdir).exists()
+              && System.getProperty(BACKUP_APPLICATION_APPDIR_PROPERTY) != null
+              && new File(System.getProperty(BACKUP_APPLICATION_APPDIR_PROPERTY)).exists()) {
+        // if this one exists, reset the installer.appdir property for other accesses to it
+        installerAppdir = System.getProperty(BACKUP_APPLICATION_APPDIR_PROPERTY);
+        System.setProperty(APPLICATION_APPDIR_PROPERTY, installerAppdir);
+      }
+      
+      applicationFolder = System.getProperty("installer.application_folder");
       appName = System.getProperty("channel.app_name");
     }
     
@@ -488,6 +499,8 @@ public final class EnvConfig {
     
     protected static final String APPLICATION_APPDIR_PROPERTY = "installer.appdir";
     
+    protected static final String BACKUP_APPLICATION_APPDIR_PROPERTY = "installer.original_appdir";
+    
     protected static final String POPULATE_DEFAULT_APPDIR_PROPERTY = "populatedefaultappdir";
     
     protected static final String SET_USER_APPDIR_PATH = "setuserappdirpath";
index ce74673..cfc4858 100644 (file)
@@ -36,7 +36,9 @@ import java.nio.file.attribute.BasicFileAttributes;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.EnumSet;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 import java.util.stream.Collectors;
 
 public class FileUtils
@@ -93,6 +95,14 @@ public class FileUtils
         {
           String glob = "glob:" + parentDir.toString() + File.separator
                   + rest;
+          // don't use Platform.isWin() as this class is used in getdown
+          if (System.getProperty("os.name").indexOf("Win") >= 0)
+          {
+            // escape "\\" on Windows
+            // This ultimately replaces "\\" == '\' with "\\\\" = '\\' to escape
+            // backslashes
+            glob = glob.replaceAll("\\\\", "\\\\\\\\");
+          }
           PathMatcher pm = FileSystems.getDefault().getPathMatcher(glob);
           int maxDepth = rest.contains("**") ? 1028
                   : (int) (rest.chars()
@@ -399,4 +409,134 @@ public class FileUtils
     }
     return false;
   }
+
+  /**
+   * Look for files that use a template, with two "%s" formatting entries, to
+   * look for files with the template substituted with combinations of root and
+   * version. If versionWhitelist is not null then these paths will be added. If
+   * versionBlacklist is not null then globbed versions will be looked for and
+   * these versions excluded. If both are given then both will be included. If
+   * separator is not null then it will be added before the version number, and
+   * additionally a path without the separator and version will be looked for or
+   * added if the whitelist or blacklist are supplied respectively.
+   * 
+   * @param templates
+   * @param roots
+   * @param versionWhitelist
+   * @param versionBlacklist
+   * @param separator
+   * @return
+   */
+  public static List<File> getMatchingVersionedFiles(String[] templates,
+          String[] roots, String[] versionWhitelist,
+          String[] versionBlacklist, String versionSeparator,
+          boolean exists)
+  {
+    Set<File> matchingFiles = new HashSet<>();
+    if (templates == null)
+    {
+      ErrorLog.errPrintln(
+              "getMatchingVersionedFiles called with a null template array");
+      List<File> files = new ArrayList<File>();
+      files.addAll(matchingFiles);
+      return files;
+    }
+
+    for (String template : templates)
+    {
+      ErrorLog.errPrintln("Using template '" + template + "'");
+      for (String root : roots)
+      {
+        ErrorLog.errPrintln("Using root '" + root + "'");
+
+        // Blacklist. Use a file glob for version and see what's there
+        if (versionBlacklist != null)
+        {
+          String globMatch = String.format(template, root, "*");
+          ErrorLog.errPrintln("Using glob '" + globMatch + "'");
+          List<File> foundFiles = FileUtils.getFilesFromGlob(globMatch,
+                  false);
+          for (File found : foundFiles)
+          {
+            ErrorLog.errPrintln("Checking " + found.getPath() + " is okay");
+            boolean add = true;
+            for (String notVersion : versionBlacklist)
+            {
+              StringBuilder vSB = new StringBuilder();
+              if (versionSeparator != null)
+              {
+                vSB.append(versionSeparator);
+              }
+              vSB.append(notVersion);
+              String versionString = vSB.toString();
+              if (String.format(template, root, versionString)
+                      .equals(found.getPath()))
+              {
+                add = false;
+                ErrorLog.errPrintln(
+                        "Not adding " + found.getPath() + ": version '"
+                                + notVersion + "' is in the blacklist");
+                break;
+              }
+            }
+            if (add)
+            {
+              ErrorLog.errPrintln("Adding " + found.getPath() + " to list");
+              matchingFiles.add(found);
+            }
+          }
+
+          if (versionSeparator != null)
+          {
+            // try without a version number too
+            String nonVersioned = String.format(template, root, "");
+            matchingFiles.addAll(
+                    FileUtils.getFilesFromGlob(nonVersioned, false));
+          }
+        }
+
+        // Whitelist. Just add a path for every whitelisted version (or check it
+        // exists).
+        if (versionWhitelist != null)
+        {
+          ErrorLog.errPrintln("Adding " + versionWhitelist.length
+                  + " whitelist versions");
+          for (String addVersion : versionWhitelist)
+          {
+            StringBuilder vSB = new StringBuilder();
+            if (versionSeparator != null)
+            {
+              vSB.append(versionSeparator);
+            }
+            vSB.append(addVersion);
+            String versionString = vSB.toString();
+            String versionPath = String.format(template, root,
+                    versionString);
+            ErrorLog.errPrintln(
+                    "Adding whitelist path '" + versionPath + "'");
+            File file = new File(versionPath);
+            if (file.exists() || !exists)
+            {
+              matchingFiles.add(file);
+            }
+          }
+
+          if (versionSeparator != null)
+          {
+            // try without a version number too
+            String nonVersioned = String.format(template, root, "");
+            File file = new File(nonVersioned);
+            if (file.exists() || !exists)
+            {
+              matchingFiles.add(file);
+            }
+          }
+        }
+      }
+    }
+
+    List<File> files = new ArrayList<File>();
+    files.addAll(matchingFiles);
+    return files;
+  }
 }
index e52042f..925eb6f 100644 (file)
Binary files a/j11lib/getdown-core.jar and b/j11lib/getdown-core.jar differ
index e52042f..925eb6f 100644 (file)
Binary files a/j8lib/getdown-core.jar and b/j8lib/getdown-core.jar differ
index d31ff54..cfc4858 100644 (file)
@@ -41,8 +41,6 @@ import java.util.List;
 import java.util.Set;
 import java.util.stream.Collectors;
 
-import jalview.bin.Console;
-
 public class FileUtils
 {
   /*
@@ -97,7 +95,8 @@ public class FileUtils
         {
           String glob = "glob:" + parentDir.toString() + File.separator
                   + rest;
-          if (Platform.isWin())
+          // don't use Platform.isWin() as this class is used in getdown
+          if (System.getProperty("os.name").indexOf("Win") >= 0)
           {
             // escape "\\" on Windows
             // This ultimately replaces "\\" == '\' with "\\\\" = '\\' to escape
@@ -410,6 +409,7 @@ public class FileUtils
     }
     return false;
   }
+
   /**
    * Look for files that use a template, with two "%s" formatting entries, to
    * look for files with the template substituted with combinations of root and
@@ -435,7 +435,7 @@ public class FileUtils
     Set<File> matchingFiles = new HashSet<>();
     if (templates == null)
     {
-      Console.debug(
+      ErrorLog.errPrintln(
               "getMatchingVersionedFiles called with a null template array");
       List<File> files = new ArrayList<File>();
       files.addAll(matchingFiles);
@@ -444,21 +444,21 @@ public class FileUtils
 
     for (String template : templates)
     {
-      Console.debug("Using template '" + template + "'");
+      ErrorLog.errPrintln("Using template '" + template + "'");
       for (String root : roots)
       {
-        Console.debug("Using root '" + root + "'");
+        ErrorLog.errPrintln("Using root '" + root + "'");
 
         // Blacklist. Use a file glob for version and see what's there
         if (versionBlacklist != null)
         {
           String globMatch = String.format(template, root, "*");
-          Console.debug("Using glob '" + globMatch + "'");
+          ErrorLog.errPrintln("Using glob '" + globMatch + "'");
           List<File> foundFiles = FileUtils.getFilesFromGlob(globMatch,
                   false);
           for (File found : foundFiles)
           {
-            Console.debug("Checking " + found.getPath() + " is okay");
+            ErrorLog.errPrintln("Checking " + found.getPath() + " is okay");
             boolean add = true;
             for (String notVersion : versionBlacklist)
             {
@@ -473,7 +473,7 @@ public class FileUtils
                       .equals(found.getPath()))
               {
                 add = false;
-                Console.debug(
+                ErrorLog.errPrintln(
                         "Not adding " + found.getPath() + ": version '"
                                 + notVersion + "' is in the blacklist");
                 break;
@@ -481,7 +481,7 @@ public class FileUtils
             }
             if (add)
             {
-              Console.debug("Adding " + found.getPath() + " to list");
+              ErrorLog.errPrintln("Adding " + found.getPath() + " to list");
               matchingFiles.add(found);
             }
           }
@@ -499,7 +499,7 @@ public class FileUtils
         // exists).
         if (versionWhitelist != null)
         {
-          Console.debug("Adding " + versionWhitelist.length
+          ErrorLog.errPrintln("Adding " + versionWhitelist.length
                   + " whitelist versions");
           for (String addVersion : versionWhitelist)
           {
@@ -512,7 +512,8 @@ public class FileUtils
             String versionString = vSB.toString();
             String versionPath = String.format(template, root,
                     versionString);
-            Console.debug("Adding whitelist path '" + versionPath + "'");
+            ErrorLog.errPrintln(
+                    "Adding whitelist path '" + versionPath + "'");
             File file = new File(versionPath);
             if (file.exists() || !exists)
             {
index 705e0ea..a6ec4f3 100644 (file)
           <versionLine x="85" y="109" text="version ${compiler:sys.version}" />
         </text>
       </splashScreen>
-      <java mainClass="com.threerings.getdown.launcher.GetdownApp" vmParameters="-Dsun.jnu.encoding=UTF-8 -Dfile.encoding=UTF-8 -Duserdefaultappdir=true -Dpopulatedefaultappdir=true -Dappid=jalview -Dinstaller.template_version=${compiler:INSTALLER_TEMPLATE_VERSION} -Dinstaller.appdir=&quot;${installer:sys.contentDir}&quot; -Dinstaller.application_folder=&quot;${compiler:APPLICATION_FOLDER}&quot; -Dchannel.app_name=&quot;${compiler:JALVIEW_APPLICATION_NAME}&quot; -Dinstaller.icon=&quot;${compiler:PNG_ICON_FILE}&quot; -Dinstaller.mac_icons=&quot;${compiler:MAC_ICONS_FILE}&quot; -Dinstaller.logfile=&quot;~/.${compiler:LOG_FILE}&quot; -Dinstaller.logfile_append=true" arguments="&quot;&quot; &quot;&quot;">
+      <java mainClass="com.threerings.getdown.launcher.GetdownApp" vmParameters="-Dsun.jnu.encoding=UTF-8 -Dfile.encoding=UTF-8 -Duserdefaultappdir=true -Dpopulatedefaultappdir=true -Dappid=jalview -Dinstaller.template_version=${compiler:INSTALLER_TEMPLATE_VERSION} -Dinstaller.appdir=&quot;${launcher:sys.launcherDirectory}&quot; -Dinstaller.original_appdir=&quot;${installer:sys.contentDir}&quot; -Dinstaller.application_folder=&quot;${compiler:APPLICATION_FOLDER}&quot; -Dchannel.app_name=&quot;${compiler:JALVIEW_APPLICATION_NAME}&quot; -Dinstaller.icon=&quot;${compiler:PNG_ICON_FILE}&quot; -Dinstaller.mac_icons=&quot;${compiler:MAC_ICONS_FILE}&quot; -Dinstaller.logfile=&quot;~/.${compiler:LOG_FILE}&quot; -Dinstaller.logfile_append=true" arguments="&quot;&quot; &quot;&quot;">
         <classPath>
           <archive location="getdown-launcher.jar" failOnError="false" />
           <archive location="${compiler:GETDOWN_INSTALL_DIR}/getdown-launcher.jar" failOnError="false" />