From: Ben Soares Date: Fri, 10 May 2019 16:39:24 +0000 (+0100) Subject: JAL-3246 JAL-3247 Reworked JVL files as getdown.txt config with limitations X-Git-Tag: Release_2_11_0~12^2^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=dbfa10a0954d79fe8f0cde05dd23aa86efc3885b;hp=-c;p=jalview.git JAL-3246 JAL-3247 Reworked JVL files as getdown.txt config with limitations --- dbfa10a0954d79fe8f0cde05dd23aa86efc3885b diff --git a/getdown/lib/getdown-core-1.8.3-SNAPSHOT.jar b/getdown/lib/getdown-core-1.8.3-SNAPSHOT.jar index 9f62e34..67434e8 100644 Binary files a/getdown/lib/getdown-core-1.8.3-SNAPSHOT.jar and b/getdown/lib/getdown-core-1.8.3-SNAPSHOT.jar differ diff --git a/getdown/lib/getdown-launcher.jar b/getdown/lib/getdown-launcher.jar index b25920e..43a9fb6 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/Application.java b/getdown/src/getdown/core/src/main/java/com/threerings/getdown/data/Application.java index 7376cdb..17e98f8 100644 --- a/getdown/src/getdown/core/src/main/java/com/threerings/getdown/data/Application.java +++ b/getdown/src/getdown/core/src/main/java/com/threerings/getdown/data/Application.java @@ -31,6 +31,9 @@ import com.threerings.getdown.util.*; // avoid ambiguity with java.util.Base64 which we can't use as it's 1.8+ import com.threerings.getdown.util.Base64; +import com.threerings.getdown.data.EnvConfig; +import com.threerings.getdown.data.EnvConfig.Note; + import static com.threerings.getdown.Log.log; import static java.nio.charset.StandardCharsets.UTF_8; @@ -565,7 +568,19 @@ public class Application log.info("Found no getdown.txt file", "appdir", getAppDir()); } } catch (Exception e) { - log.warning("Failure reading config file", "file", config, e); + log.warning("Failure reading config file", "file", _config, e); + } + + // see if there's an override config from locator file + Config locatorConfig = createLocatorConfig(opts); + + // merge the locator file config into config (or replace config with) + if (locatorConfig != null) { + if (config == null || locatorConfig.getBoolean(LOCATOR_FILE_EXTENSION+"_replace")) { + config = locatorConfig; + } else { + config.mergeConfig(locatorConfig, locatorConfig.getBoolean(LOCATOR_FILE_EXTENSION+"_merge")); + } } // if we failed to read our config file, check for an appbase specified via a system @@ -581,10 +596,7 @@ public class Application // first determine our application base, this way if anything goes wrong later in the // process, our caller can use the appbase to download a new configuration file _appbase = config.getString("appbase"); - // override if a Version Locator file has been used - if (newAppbase != null) { - _appbase = newAppbase.toString(); - } + if (_appbase == null) { throw new RuntimeException("m.missing_appbase"); } @@ -1048,7 +1060,7 @@ public class Application } // almost finally check the startup file arguments - for (File f : startupFiles) { + for (File f : _startupFiles) { _appargs.add(f.getAbsolutePath()); break; // Only add one file to open } @@ -1061,7 +1073,7 @@ public class Application if (j > -1) { ext = filename.substring(j+1); } - if (locatorFileExtension.equals(ext.toLowerCase())) { + if (LOCATOR_FILE_EXTENSION.equals(ext.toLowerCase())) { // this file extension should have been dealt with in Getdown class } else { _appargs.add(0, "-open"); @@ -1785,28 +1797,86 @@ public class Application { return new File(appdir, path); } - - public void addStartupFile (File f) { - startupFiles.add(f); - } - - public void newAppbase (URL url) { - if ( - url.getHost().equals(locatorDomain) - || (allowLocatorSubdomains && url.getHost().endsWith("."+locatorDomain)) - || (allowLocatorFileProtocol && url.getProtocol().equals("file") && url.getHost().equals("")) - ) { - newAppbase = url; - log.info("Appbase set to Java Version Locator url '"+url.toString()+"'"); - return; + + public static void setStartupFilesFromParameterString(String p) { + // multiple files *might* be passed in as space separated quoted filenames + String q = "\""; + if (!StringUtil.isBlank(p)) { + String[] filenames; + // split quoted params or treat as single string array + if (p.startsWith(q) && p.endsWith(q)) { + // this fails if, e.g. + // p=q("stupidfilename\" " "otherfilename") + // let's hope no-one ever ends a filename with '" ' + filenames = p.substring(q.length(),p.length()-q.length()).split(q+" "+q); + } else { + // single unquoted filename + filenames = new String[]{p}; + } + + // check for locator file. Only allow one locator file to be double clicked (if multiple files opened, ignore locator files) + String locatorFilename = filenames.length >= 1 ? filenames[0] : null; + if ( + !StringUtil.isBlank(locatorFilename) + && locatorFilename.toLowerCase().endsWith("."+Application.LOCATOR_FILE_EXTENSION) + ) { + setLocatorFile(locatorFilename); + // remove the locator filename from the filenames array + String[] otherFilenames = new String[filenames.length - 1]; + System.arraycopy(filenames, 1, otherFilenames, 0, otherFilenames.length); + filenames = otherFilenames; + } + + for (int i = 0; i < filenames.length; i++) { + String filename = filenames[i]; + // skip any other locator files in a multiple file list + if (! filename.toLowerCase().endsWith("."+Application.LOCATOR_FILE_EXTENSION)) { + addStartupFile(filename); + } + } } - log.info("Java Version Locator url '"+url.toString()+"' does not have satisfy domain rules (" - +(allowLocatorFileProtocol?"file:///|":"") - +"https://" - +(allowLocatorSubdomains?"[*.]":locatorDomain) - +"). Ignoring"); + } + + public static void setLocatorFile(String filename) { + _locatorFile = new File(filename); + } + + public static void addStartupFile(String filename) { + _startupFiles.add(new File(filename)); } + + private Config createLocatorConfig(Config.ParseOpts opts) { + if (_locatorFile == null) { + return null; + } + + Config locatorConfig = null; + + try { + Config tmpConfig = null; + if (_locatorFile.exists()) { + tmpConfig = Config.parseConfig(_locatorFile, opts); + } else { + log.warning("Given locator file does not exist", "file", _locatorFile); + } + + // appbase is sanitised in HostWhitelist and here! + Map tmpdata = new HashMap<>(); + tmpdata.put("appbase", tmpConfig.getString("appbase")); + tmpdata.put("appargs", tmpConfig.getString("appargs")); + tmpdata.put("jvmargs", tmpConfig.getString("jvmargs")); + tmpdata.put(LOCATOR_FILE_EXTENSION+"replace", tmpConfig.getString(LOCATOR_FILE_EXTENSION+"replace")); + tmpdata.put(LOCATOR_FILE_EXTENSION+"merge", tmpConfig.getString(LOCATOR_FILE_EXTENSION+"merge")); + locatorConfig = new Config(tmpdata); + + } catch (Exception e) { + log.warning("Failure reading locator file", "file", _locatorFile, e); + } + + return locatorConfig; + } + protected final EnvConfig _envc; protected File _config; protected Digest _digest; @@ -1850,8 +1920,6 @@ public class Application protected List _jvmargs = new ArrayList<>(); protected List _appargs = new ArrayList<>(); - protected List startupFiles = new ArrayList<>(); - protected URL newAppbase; protected String[] _optimumJvmArgs; @@ -1872,9 +1940,8 @@ public class Application protected static final String ENV_VAR_PREFIX = "%ENV."; protected static final Pattern ENV_VAR_PATTERN = Pattern.compile("%ENV\\.(.*?)%"); - protected static final String locatorDomain = "jalview.org"; - protected boolean allowLocatorSubdomains = true; - protected boolean allowLocatorFileProtocol = true; - - public static final String locatorFileExtension = "jvl"; + + protected static File _locatorFile; + protected static List _startupFiles = new ArrayList<>(); + public static final String LOCATOR_FILE_EXTENSION = "jvl"; } 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 6de4e2e..57b8d84 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 @@ -7,12 +7,15 @@ package com.threerings.getdown.data; import java.io.File; import java.io.FileInputStream; +import java.net.MalformedURLException; +import java.net.URL; import java.security.cert.Certificate; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; import java.util.*; import com.threerings.getdown.util.StringUtil; +import com.threerings.getdown.data.Application; /** Configuration that comes from our "environment" (command line args, sys props, etc.). */ public final class EnvConfig { @@ -138,8 +141,21 @@ public final class EnvConfig { appIdProv + "'")); } } + + 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().endsWith("."+Application.LOCATOR_FILE_EXTENSION) + ) { + notes.add(Note.info("locatorFilename in args: '"+argv[2]+"'")); + Application.setLocatorFile(argvLocatorFilename); + + skipArgs++; + } - // ensure that we were able to fine an app dir + // ensure that we were able to find an app dir if (appDir == null) { return null; // caller will report problem to user } @@ -171,9 +187,9 @@ public final class EnvConfig { return null; } - // pass along anything after the first two args as extra app args - List appArgs = argv.length > 2 ? - Arrays.asList(argv).subList(2, argv.length) : + // pass along anything after the first two (or three) args as extra app args + List appArgs = argv.length > skipArgs ? + Arrays.asList(argv).subList(skipArgs, argv.length) : Collections.emptyList(); // load X.509 certificate if it exists diff --git a/getdown/src/getdown/core/src/main/java/com/threerings/getdown/util/Config.java b/getdown/src/getdown/core/src/main/java/com/threerings/getdown/util/Config.java index 4fc5e16..6f99fa6 100644 --- a/getdown/src/getdown/core/src/main/java/com/threerings/getdown/util/Config.java +++ b/getdown/src/getdown/core/src/main/java/com/threerings/getdown/util/Config.java @@ -373,6 +373,72 @@ public class Config String os = bits[0], arch = (bits.length > 1) ? bits[1] : ""; return (osname.indexOf(os) != -1) && (osarch.indexOf(arch) != -1); } + + public void mergeConfig(Config newValues, boolean merge) { + + for (Map.Entry entry : newValues.getData().entrySet()) { + + String key = entry.getKey(); + Object nvalue = entry.getValue(); + + if (!merge || key.equals("appbase")) { + _data.put(key, nvalue); + } else { + + // merge + + Object value = _data.get(key); + + if (value == null) { + _data.put(key, nvalue); + } else if (value instanceof String) { + if (nvalue instanceof String) { + + // value is String, nvalue is String + _data.put(key, new String[] { (String)value, (String)nvalue }); + + } else if (nvalue instanceof String[]) { + + // value is String, nvalue is String[] + String[] nvalues = (String[])nvalue; + String[] newvalues = new String[nvalues.length+1]; + newvalues[0] = (String)value; + System.arraycopy(nvalues, 0, newvalues, 1, nvalues.length); + _data.put(key, newvalues); + + } + } else if (value instanceof String[]) { + if (nvalue instanceof String) { + + // value is String[], nvalue is String + String[] values = (String[])value; + String[] newvalues = new String[values.length+1]; + System.arraycopy(values, 0, newvalues, 0, values.length); + newvalues[values.length] = (String)nvalue; + _data.put(key, newvalues); + + } else if (nvalue instanceof String[]) { + + // value is String[], nvalue is String[] + String[] values = (String[])value; + String[] nvalues = (String[])nvalue; + String[] newvalues = new String[values.length + nvalues.length]; + System.arraycopy(values, 0, newvalues, 0, values.length); + System.arraycopy(nvalues, 0, newvalues, values.length, newvalues.length); + _data.put(key, newvalues); + + } + } + + } + + } + + } + + public Map getData() { + return _data; + } private final Map _data; } diff --git a/getdown/src/getdown/core/src/main/java/com/threerings/getdown/util/HostWhitelist.java b/getdown/src/getdown/core/src/main/java/com/threerings/getdown/util/HostWhitelist.java index c05992a..f2f7ef3 100644 --- a/getdown/src/getdown/core/src/main/java/com/threerings/getdown/util/HostWhitelist.java +++ b/getdown/src/getdown/core/src/main/java/com/threerings/getdown/util/HostWhitelist.java @@ -25,6 +25,8 @@ public final class HostWhitelist */ public static URL verify (URL url) throws MalformedURLException { + + return verify(Build.hostWhitelist(), url); } @@ -41,6 +43,12 @@ public final class HostWhitelist } String urlHost = url.getHost(); + String protocol = url.getProtocol(); + + if (ALLOW_LOCATOR_FILE_PROTOCOL && protocol.equals("file") && urlHost.equals("")) { + return url; + } + for (String host : hosts) { String regex = host.replace(".", "\\.").replace("*", ".*"); if (urlHost.matches(regex)) { @@ -51,4 +59,5 @@ public final class HostWhitelist throw new MalformedURLException( "The host for the specified URL (" + url + ") is not in the host whitelist: " + hosts); } + private static boolean ALLOW_LOCATOR_FILE_PROTOCOL = true; } diff --git a/getdown/src/getdown/launcher/src/main/java/com/threerings/getdown/launcher/Getdown.java b/getdown/src/getdown/launcher/src/main/java/com/threerings/getdown/launcher/Getdown.java index 33f97e8..66629f2 100644 --- a/getdown/src/getdown/launcher/src/main/java/com/threerings/getdown/launcher/Getdown.java +++ b/getdown/src/getdown/launcher/src/main/java/com/threerings/getdown/launcher/Getdown.java @@ -1038,61 +1038,6 @@ public abstract class Getdown extends Thread } }; - public void setStartupFilesFromParameterString(String p) { - String q = "\""; - if (p != null && p.length() > 0) { - String[] filenames; - if (p.startsWith(q) && p.endsWith(q)) { - filenames = p.substring(q.length(),p.length()-q.length()).split(q+" "+q); - } else { - filenames = new String[]{p}; - } - for (int i = 0; i < filenames.length; i++) { - String filename = filenames[i]; - String ext = null; - int j = filename.lastIndexOf('.'); - if (j > -1) { - ext = filename.substring(j+1); - } - // jvl files - if (_app.locatorFileExtension.equals(ext.toLowerCase())) { - File f = new File(filename); - if (f.exists()) { - String appbase = null; - try { - java.util.Properties jvlprops = new java.util.Properties(); - FileInputStream in = new FileInputStream(f); - jvlprops.load(in); - in.close(); - appbase = jvlprops.getProperty("appbase"); - } catch(Exception e) { - log.warning("Something went wrong reading Jalview Version Locator file '"+filename+"'", e); - } - if (appbase != null) { - try { - URL newAppbase = new URL(appbase); - _app.newAppbase(newAppbase); - log.warning("Java Version Locator url '"+appbase+"' found in file '"+filename+"' being used"); - } catch(MalformedURLException e) { - log.warning("Java Version Locator url '"+appbase+"' found in file '"+filename+"' is malformed", e); - } - } - } - } else { - // jvp files etc - boolean addedStartupFile = false; // only add one startup file - if (! addedStartupFile) { - File f = new File(filename); - if (f.exists()) { - _app.addStartupFile(f); - addedStartupFile = true; - } - } - } - } - } - } - protected Application _app; protected Application.UpdateInterface _ifc = new Application.UpdateInterface(Config.EMPTY); diff --git a/getdown/src/getdown/launcher/src/main/java/com/threerings/getdown/launcher/GetdownApp.java b/getdown/src/getdown/launcher/src/main/java/com/threerings/getdown/launcher/GetdownApp.java index a907cef..5e168ff 100644 --- a/getdown/src/getdown/launcher/src/main/java/com/threerings/getdown/launcher/GetdownApp.java +++ b/getdown/src/getdown/launcher/src/main/java/com/threerings/getdown/launcher/GetdownApp.java @@ -99,7 +99,7 @@ public class GetdownApp @Override public void startupPerformed(String parameters) { - log.warning("startupPerformed: '"+parameters+"'"); + log.warning("StartupNotification.Listener.startupPerformed: '"+parameters+"'"); setStartupFilesParameterString(parameters); } }); @@ -108,8 +108,6 @@ public class GetdownApp e.printStackTrace(); } - //Thread.sleep(200); - // record a few things for posterity log.info("------------------ VM Info ------------------"); log.info("-- OS Name: " + System.getProperty("os.name")); @@ -269,34 +267,12 @@ public class GetdownApp protected JFrame _frame; }; - /* - log.warning("Startup file?", - "paramstring", '"'+getStartupFilesParameterString()+'"', - "isWindows", LaunchUtil.isWindows(), - "argv.length", argv.length, - "argv[0]", argv.length>0?argv[0]:"NULL", - "argv[1]", argv.length>1?argv[1]:"NULL", - "argv[2]", argv.length>2?argv[2]:"NULL", - "argv[3]", argv.length>3?argv[3]:"NULL" - ); - */ - if (getStartupFilesParameterString() != null && getStartupFilesParameterString().length() > 0) { - app.setStartupFilesFromParameterString(getStartupFilesParameterString()); - } else if ( - getStartupFilesParameterString().length() == 0 - && LaunchUtil.isWindows() - && argv.length >= 3 - && argv[0].equals(".") - && argv[1].equals("noappid") - && argv[2].endsWith("."+Application.locatorFileExtension) - ) { - log.info("Jalview Version Locator in args: "+argv[2]); - app.setStartupFilesFromParameterString(argv[2]); - String[] newArgv = new String[argv.length - 1]; - System.arraycopy(argv, 0, newArgv, 0, 2); - System.arraycopy(argv, 3, newArgv, 2, argv.length - 3); - argv = newArgv; + + String startupFile = getStartupFilesParameterString(); + if (!StringUtil.isBlank(startupFile)) { + Application.setStartupFilesFromParameterString(startupFile); } + app.start(); return app; } diff --git a/getdown/src/getdown/mvn_cmd b/getdown/src/getdown/mvn_cmd new file mode 100644 index 0000000..db10789 --- /dev/null +++ b/getdown/src/getdown/mvn_cmd @@ -0,0 +1 @@ +mv clean package -Dgetdown.host.whitelist=jalview.org,*.jalview.org && cp launcher/target/getdown-launcher-1.8.3-SNAPSHOT.jar ../../../getdown/lib/getdown-launcher.jar && cp core/target/getdown-core-1.8.3-SNAPSHOT.jar ../../../getdown/lib/getdown-core-1.8.3-SNAPSHOT.jar && cp core/target/getdown-core-1.8.3-SNAPSHOT.jar ../../../j8lib/getdown-core.jar && cp core/target/getdown-core-1.8.3-SNAPSHOT.jar ../../../j11lib/getdown-core.jar diff --git a/j11lib/getdown-core.jar b/j11lib/getdown-core.jar index 9f62e34..67434e8 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 9f62e34..67434e8 100644 Binary files a/j8lib/getdown-core.jar and b/j8lib/getdown-core.jar differ diff --git a/utils/dev_macos_install.sh b/utils/dev_macos_install.sh index 61155c2..c4cd94c 100755 --- a/utils/dev_macos_install.sh +++ b/utils/dev_macos_install.sh @@ -6,9 +6,13 @@ APP=Jalview.app APPLICATIONS=/Applications CHANNEL=NOCHANNEL -DMG=build/install4j/11/Jalview-OFFLINE_macos-app_DEVELOPMENT-j11.dmg +DMG=build/install4j/1.8/Jalview-OFFLINE_macos-app_DEVELOPMENT-j8.dmg -gradle installers -Pgetdown_channel_name=NOCHANNEL -Pinstall4jMediaTypes=macosArchive -Pgetdown_local=true +if [ $1 != "nogradle" ]; then + gradle installers -Pgetdown_channel_name=NOCHANNEL -Pinstall4jMediaTypes=macosArchive -Pgetdown_local=true -Pdev=true +else + echo "Not running gradle installers" +fi if [ $? = 0 ]; then umount "/Volumes/$INSTALLERVOL" diff --git a/utils/install4j/install4j_template.install4j b/utils/install4j/install4j_template.install4j index 3825190..4b05d18 100644 --- a/utils/install4j/install4j_template.install4j +++ b/utils/install4j/install4j_template.install4j @@ -1784,29 +1784,6 @@ return console.askYesNo(message, true); - - - - - - - - - - - - - - - - - - - - - - - @@ -1874,17 +1851,38 @@ return console.askYesNo(message, true); + + + + + + + + + + + + + + + + + + + + + + - - +