From: Ben Soares Date: Wed, 20 Nov 2024 16:06:51 +0000 (+0000) Subject: JAL-4477 Re-work install4j and getdown to use the installer.appdir first or installer... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=160fe15b38e09fd37d11b2f6fd42f6e5d600c420;p=jalview.git JAL-4477 Re-work install4j and getdown to use the installer.appdir first or installer.original_appdir if installer.appdir doesn't exist. Fix FileUtils to workj with getdown. --- diff --git a/getdown/lib/getdown-core.jar b/getdown/lib/getdown-core.jar index e52042f..925eb6f 100644 Binary files a/getdown/lib/getdown-core.jar and b/getdown/lib/getdown-core.jar differ diff --git a/getdown/lib/getdown-launcher-local.jar b/getdown/lib/getdown-launcher-local.jar index 4ae1f62..cab2213 100644 Binary files a/getdown/lib/getdown-launcher-local.jar and b/getdown/lib/getdown-launcher-local.jar differ diff --git a/getdown/lib/getdown-launcher.jar b/getdown/lib/getdown-launcher.jar index 331e5d0..8bd0e78 100644 Binary files a/getdown/lib/getdown-launcher.jar and b/getdown/lib/getdown-launcher.jar differ diff --git a/getdown/src/getdown/core/src/main/java/com/threerings/getdown/data/EnvConfig.java b/getdown/src/getdown/core/src/main/java/com/threerings/getdown/data/EnvConfig.java index d1ae75f..83278c0 100644 --- a/getdown/src/getdown/core/src/main/java/com/threerings/getdown/data/EnvConfig.java +++ b/getdown/src/getdown/core/src/main/java/com/threerings/getdown/data/EnvConfig.java @@ -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"; diff --git a/getdown/src/getdown/core/src/main/java/jalview/util/FileUtils.java b/getdown/src/getdown/core/src/main/java/jalview/util/FileUtils.java index ce74673..cfc4858 100644 --- a/getdown/src/getdown/core/src/main/java/jalview/util/FileUtils.java +++ b/getdown/src/getdown/core/src/main/java/jalview/util/FileUtils.java @@ -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 getMatchingVersionedFiles(String[] templates, + String[] roots, String[] versionWhitelist, + String[] versionBlacklist, String versionSeparator, + boolean exists) + { + Set matchingFiles = new HashSet<>(); + if (templates == null) + { + ErrorLog.errPrintln( + "getMatchingVersionedFiles called with a null template array"); + List files = new ArrayList(); + 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 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 files = new ArrayList(); + files.addAll(matchingFiles); + return files; + } } diff --git a/j11lib/getdown-core.jar b/j11lib/getdown-core.jar index e52042f..925eb6f 100644 Binary files a/j11lib/getdown-core.jar and b/j11lib/getdown-core.jar differ diff --git a/j8lib/getdown-core.jar b/j8lib/getdown-core.jar index e52042f..925eb6f 100644 Binary files a/j8lib/getdown-core.jar and b/j8lib/getdown-core.jar differ diff --git a/src/jalview/util/FileUtils.java b/src/jalview/util/FileUtils.java index d31ff54..cfc4858 100644 --- a/src/jalview/util/FileUtils.java +++ b/src/jalview/util/FileUtils.java @@ -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 matchingFiles = new HashSet<>(); if (templates == null) { - Console.debug( + ErrorLog.errPrintln( "getMatchingVersionedFiles called with a null template array"); List files = new ArrayList(); 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 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) { diff --git a/utils/install4j/install4j11_template.install4j b/utils/install4j/install4j11_template.install4j index 705e0ea..a6ec4f3 100644 --- a/utils/install4j/install4j11_template.install4j +++ b/utils/install4j/install4j11_template.install4j @@ -152,7 +152,7 @@ - +