From: Ben Soares Date: Mon, 6 May 2019 16:06:29 +0000 (+0100) Subject: JAL-3247 Code changes to getdown. Double click open of .jvp files in Windows and... X-Git-Tag: Release_2_11_0~12^2^2~14 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=46ba8ba2466d929d023295f38bc3572aef5467f1;p=jalview.git JAL-3247 Code changes to getdown. Double click open of .jvp files in Windows and macOS, and .jvl new appbase file working in macOS. --- diff --git a/getdown/lib/getdown-launcher.jar b/getdown/lib/getdown-launcher.jar index 8f52ad8..09ae4b5 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 212e948..182b057 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 @@ -581,6 +581,10 @@ 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"); } @@ -768,12 +772,6 @@ public class Application // add the launch specific application arguments _appargs.addAll(_envc.appArgs); - // add startupFiles - for (File f : startupFiles) { - _appargs.add("-open"); - _appargs.add(f.getAbsolutePath()); - } - // look for custom arguments fillAssignmentListFromPairs("extra.txt", _txtJvmArgs); @@ -1049,11 +1047,32 @@ public class Application args.add(_class); } + // almost finally check the startup file arguments + for (File f : startupFiles) { + _appargs.add(f.getAbsolutePath()); + break; // Only add one file to open + } + + // check if one arg with recognised extension + if ( _appargs.size() == 1 && _appargs.get(0) != null ) { + String filename = _appargs.get(0); + String ext = null; + int j = filename.lastIndexOf('.'); + if (j > -1) { + ext = filename.substring(j+1); + } + if (startupFileExtensions.contains(ext.toLowerCase())) { + _appargs.add(0, "-open"); + } else if (locatorFileExtension.equals(ext.toLowerCase())) { + // deal with this when first encountered in Getdown! + } + } + // finally add the application arguments for (String string : _appargs) { args.add(processArg(string)); } - + String[] envp = createEnvironment(); String[] sargs = args.toArray(new String[args.size()]); log.info("Running " + StringUtil.join(sargs, "\n ")); @@ -1771,6 +1790,13 @@ public class Application startupFiles.add(f); } + public void newAppbase (URL url) { + if ((url.getHost().endsWith(".jalview.org") || url.equals("jalview.org"))) { + newAppbase = url; + } + log.info("Java Version Locator url '"+url.toString()+"' does not have a jalview.org domain. Ignoring"); + } + protected final EnvConfig _envc; protected File _config; protected Digest _digest; @@ -1815,6 +1841,7 @@ public class Application protected List _jvmargs = new ArrayList<>(); protected List _appargs = new ArrayList<>(); protected List startupFiles = new ArrayList<>(); + protected URL newAppbase; protected String[] _optimumJvmArgs; @@ -1835,4 +1862,7 @@ public class Application protected static final String ENV_VAR_PREFIX = "%ENV."; protected static final Pattern ENV_VAR_PATTERN = Pattern.compile("%ENV\\.(.*?)%"); + + public static final List startupFileExtensions = Arrays.asList(new String[] { "jvp" }); + public static final String locatorFileExtension = "jvl"; } 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 ae679e2..e0f7c35 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 @@ -16,11 +16,13 @@ import java.awt.image.BufferedImage; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; +import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.net.HttpURLConnection; +import java.net.MalformedURLException; import java.net.URL; import java.util.*; @@ -1051,16 +1053,39 @@ public abstract class Getdown extends Thread if (j > -1) { ext = filename.substring(j+1); } - // jvp files - if (ext.equals("jvp")) { + // jvp files etc + boolean addedStartupFile = false; // only add one startup file + if (_app.startupFileExtensions.contains(ext.toLowerCase()) && ! addedStartupFile) { File f = new File(filename); if (f.exists()) { _app.addStartupFile(f); + addedStartupFile = true; } } // jvl files - if (ext.equals("jvl")) { - // Do stuff with the appbase here! + if (_app.locatorFileExtension.equals(ext.toLowerCase())) { + // Do something special with this here + File f = new File(filename); + if (f.exists()) { + String line = null; + try { + FileReader fr = new FileReader(f); + BufferedReader br = new BufferedReader(fr); + line = br.readLine(); + br.close(); + } catch(Exception e) { + log.warning("Something went wrong reading Jalview Version Locator file '"+filename+"'", e); + } + if (line != null) { + String urlString = line.trim(); + try { + URL newAppbase = new URL(urlString); + _app.newAppbase(newAppbase); + } catch(MalformedURLException e) { + log.warning("Java Version Locator url '"+urlString+"' found in file '"+filename+"' is malformed", e); + } + } + } } } } @@ -1099,4 +1124,5 @@ public abstract class Getdown extends Thread protected static final int MAX_LOOPS = 5; protected static final long FALLBACK_CHECK_TIME = 1000L; + } 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 f632b65..32890fa 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 @@ -93,13 +93,11 @@ public class GetdownApp try { - log.info("**** Registering i4j StartupNotification Listener"); StartupNotification.registerStartupListener( new StartupNotification.Listener() { @Override public void startupPerformed(String parameters) { - log.info("**** adding startup parameters '"+parameters+"'"); GetdownApp.setStartupFilesParameterString(parameters); } });