Merge branch 'task/JAL-3236_install4j_linux_unix_userland_installers' into develop
[jalview.git] / getdown / src / getdown / core / src / main / java / com / threerings / getdown / data / Application.java
index 212e948..7376cdb 100644 (file)
@@ -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 (locatorFileExtension.equals(ext.toLowerCase())) {
+            // this file extension should have been dealt with in Getdown class
+          } else {
+            _appargs.add(0, "-open");
+          }
+        }
+
         // 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,23 @@ public class Application
       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;
+      }
+      log.info("Java Version Locator url '"+url.toString()+"' does not have satisfy domain rules ("
+      +(allowLocatorFileProtocol?"file:///|":"")
+      +"https://"
+      +(allowLocatorSubdomains?"[*.]":locatorDomain)
+      +"). Ignoring");
+    }
+
     protected final EnvConfig _envc;
     protected File _config;
     protected Digest _digest;
@@ -1815,6 +1851,7 @@ public class Application
     protected List<String> _jvmargs = new ArrayList<>();
     protected List<String> _appargs = new ArrayList<>();
     protected List<File> startupFiles = new ArrayList<>();
+    protected URL newAppbase;
 
     protected String[] _optimumJvmArgs;
 
@@ -1835,4 +1872,9 @@ 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";
 }