}
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");
}
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";
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
{
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()
}
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;
+ }
}
import java.util.Set;
import java.util.stream.Collectors;
-import jalview.bin.Console;
-
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
}
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
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);
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)
{
.equals(found.getPath()))
{
add = false;
- Console.debug(
+ ErrorLog.errPrintln(
"Not adding " + found.getPath() + ": version '"
+ notVersion + "' is in the blacklist");
break;
}
if (add)
{
- Console.debug("Adding " + found.getPath() + " to list");
+ ErrorLog.errPrintln("Adding " + found.getPath() + " to list");
matchingFiles.add(found);
}
}
// exists).
if (versionWhitelist != null)
{
- Console.debug("Adding " + versionWhitelist.length
+ ErrorLog.errPrintln("Adding " + versionWhitelist.length
+ " whitelist versions");
for (String addVersion : versionWhitelist)
{
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)
{