From: Ben Soares Date: Fri, 21 Jun 2024 12:48:41 +0000 (+0100) Subject: JAL-4409 Add two empty args to getdown call from install4j for backward compatibility... X-Git-Tag: Release_2_11_4_0~24^2~27 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=c2893a5ec37de7d2b72ec954ab0eb10a6fc52d73;p=jalview.git JAL-4409 Add two empty args to getdown call from install4j for backward compatibility, and further arguments such as JVL file. Improve handling of a JVL file with an appbase in it. --- diff --git a/getdown/lib/getdown-core.jar b/getdown/lib/getdown-core.jar index 4d92cc8..44bdf88 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 0cae0b8..a8b3fb5 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 722e965..a458557 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 59e1bcb..9429efc 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 @@ -283,7 +283,7 @@ public class Application /** The proxy that should be used to do HTTP downloads. This must be configured prior to using * the application instance. Yes this is a public mutable field, no I'm not going to create a * getter and setter just to pretend like that's not the case. */ - public Proxy proxy = Proxy.NO_PROXY; + public static Proxy proxy = Proxy.NO_PROXY; /** * Creates an application instance which records the location of the getdown.txt @@ -647,10 +647,12 @@ public class Application // merge the locator file config into config (or replace config with) if (locatorConfig != null) { - if (config == null || locatorConfig.getBoolean(LOCATOR_FILE_EXTENSION+"_replace")) { + if (config == null || locatorConfig.getBoolean(LOCATOR_FILE_EXTENSION+"_replace") || locatorConfig.hasValue("appbase")) { config = locatorConfig; + log.warning("Replacing config with locator file", LOCATOR_FILE_EXTENSION+" file", locatorConfig); } else { config.mergeConfig(locatorConfig, locatorConfig.getBoolean(LOCATOR_FILE_EXTENSION+"_merge")); + log.warning("Merging config with locator file", LOCATOR_FILE_EXTENSION+" file", locatorConfig); } } @@ -2020,7 +2022,7 @@ public class Application _jalviewUri = uri; } - private Config createLocatorConfig(Config.ParseOpts opts) { + protected static Config createLocatorConfig(Config.ParseOpts opts) { if (_locatorFile == null) { return null; } 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 3780e6c..735ce8d 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 @@ -16,6 +16,7 @@ import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; import java.util.*; +import com.threerings.getdown.util.Config; import com.threerings.getdown.util.LaunchUtil; import com.threerings.getdown.util.StringUtil; @@ -160,6 +161,7 @@ public final class EnvConfig { appIdProv + "'")); } } + int skipArgs = 2; boolean userAppDir = false; // platform user appdir addition @@ -219,14 +221,18 @@ public final class EnvConfig { } } - 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(Locale.ROOT).endsWith("."+Application.LOCATOR_FILE_EXTENSION)) { + && argvLocatorFilename.toLowerCase(Locale.ROOT).endsWith("." + Application.LOCATOR_FILE_EXTENSION)) { argvLocatorFilename = HttpUtils.equivalentJalviewUrl(argvLocatorFilename); - notes.add(Note.info("locatorFilename in args: '"+argv[2]+"'")); + notes.add(Note.info("locatorFilename in args: '" + argv[2] + "'")); Application.setLocatorFile(argvLocatorFilename); + String lfAppBase = getLocatorFileAppBase(argvLocatorFilename); + if (!StringUtil.isBlank(lfAppBase)) { + appBase = lfAppBase; + appBaseProv = "from " + Application.LOCATOR_FILE_EXTENSION + " file"; + } skipArgs++; } @@ -365,6 +371,16 @@ public final class EnvConfig { public static boolean getRelaunched() { return relaunched; } + + private static String getLocatorFileAppBase(String locatorFile) { + String lfAppBase = null; + Config.ParseOpts opts = Config.createOpts(false); + Config checkConfig = Application.createLocatorConfig(opts); + if (!StringUtil.isBlank(checkConfig.getString("appbase"))) { + lfAppBase = checkConfig.getString("appbase"); + } + return lfAppBase; + } private static boolean relaunched = false; diff --git a/getdown/src/getdown/core/src/main/java/jalview/util/LaunchUtils.java b/getdown/src/getdown/core/src/main/java/jalview/util/LaunchUtils.java index 66c983c..0b18c6c 100644 --- a/getdown/src/getdown/core/src/main/java/jalview/util/LaunchUtils.java +++ b/getdown/src/getdown/core/src/main/java/jalview/util/LaunchUtils.java @@ -371,7 +371,6 @@ public class LaunchUtils boolean launcherwait, boolean launcherstop, boolean debug, boolean quiet) { - int exitValue = -1; if (javaBinary == null) { javaBinary = findJavaBin(false, true, true); @@ -500,7 +499,16 @@ public class LaunchUtils // application args command.addAll(applicationArguments); + return runProcess(command, launcherprint, launcherwait, launcherstop, + debug, quiet); + } + + private static int runProcess(List command, boolean launcherprint, + boolean launcherwait, boolean launcherstop, boolean debug, + boolean quiet) + { final ProcessBuilder builder = new ProcessBuilder(command); + int exitValue = -1; if (Boolean.parseBoolean(System.getProperty("launcherprint", "false")) || launcherprint) @@ -582,6 +590,88 @@ public class LaunchUtils return exitValue; } + /* + public void invokeDirect() throws IOException + { + ClassPath classPath = PathBuilder.buildClassPath(this); + URL[] jarUrls = classPath.asUrls(); + + // create custom class loader + URLClassLoader loader = new URLClassLoader(jarUrls, + ClassLoader.getSystemClassLoader()) + { + @Override + protected PermissionCollection getPermissions(CodeSource code) + { + Permissions perms = new Permissions(); + perms.add(new AllPermission()); + return perms; + } + }; + Thread.currentThread().setContextClassLoader(loader); + + log.info("Configured URL class loader:"); + for (URL url : jarUrls) + log.info(" " + url); + + // configure any system properties that we can + for (String jvmarg : _jvmargs) + { + if (jvmarg.startsWith("-D")) + { + jvmarg = processArg(jvmarg.substring(2)); + int eqidx = jvmarg.indexOf("="); + if (eqidx == -1) + { + log.warning("Bogus system property: '" + jvmarg + "'?"); + } + else + { + System.setProperty(jvmarg.substring(0, eqidx), + jvmarg.substring(eqidx + 1)); + } + } + } + + // pass along any pass-through arguments + Map passProps = new HashMap<>(); + for (Map.Entry entry : System.getProperties() + .entrySet()) + { + String key = (String) entry.getKey(); + if (key.startsWith(PROP_PASSTHROUGH_PREFIX)) + { + key = key.substring(PROP_PASSTHROUGH_PREFIX.length()); + passProps.put(key, (String) entry.getValue()); + } + } + // we can't set these in the above loop lest we get a + // ConcurrentModificationException + for (Map.Entry entry : passProps.entrySet()) + { + System.setProperty(entry.getKey(), entry.getValue()); + } + + // prepare our app arguments + String[] args = new String[_appargs.size()]; + for (int ii = 0; ii < args.length; ii++) + args[ii] = processArg(_appargs.get(ii)); + + try + { + log.info("Loading " + _class); + Class appclass = loader.loadClass(_class); + Method main = appclass.getMethod("main", + EMPTY_STRING_ARRAY.getClass()); + log.info("Invoking main({" + StringUtil.join(args, ", ") + "})"); + main.invoke(null, new Object[] { args }); + } catch (Exception e) + { + log.warning("Failure invoking app main", e); + } + } + */ + public static void syserr(boolean debug, boolean quiet, String message) { if (debug && !quiet) diff --git a/j11lib/getdown-core.jar b/j11lib/getdown-core.jar index 4d92cc8..44bdf88 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 4d92cc8..44bdf88 100644 Binary files a/j8lib/getdown-core.jar and b/j8lib/getdown-core.jar differ diff --git a/src/jalview/util/LaunchUtils.java b/src/jalview/util/LaunchUtils.java index 66c983c..0b18c6c 100644 --- a/src/jalview/util/LaunchUtils.java +++ b/src/jalview/util/LaunchUtils.java @@ -371,7 +371,6 @@ public class LaunchUtils boolean launcherwait, boolean launcherstop, boolean debug, boolean quiet) { - int exitValue = -1; if (javaBinary == null) { javaBinary = findJavaBin(false, true, true); @@ -500,7 +499,16 @@ public class LaunchUtils // application args command.addAll(applicationArguments); + return runProcess(command, launcherprint, launcherwait, launcherstop, + debug, quiet); + } + + private static int runProcess(List command, boolean launcherprint, + boolean launcherwait, boolean launcherstop, boolean debug, + boolean quiet) + { final ProcessBuilder builder = new ProcessBuilder(command); + int exitValue = -1; if (Boolean.parseBoolean(System.getProperty("launcherprint", "false")) || launcherprint) @@ -582,6 +590,88 @@ public class LaunchUtils return exitValue; } + /* + public void invokeDirect() throws IOException + { + ClassPath classPath = PathBuilder.buildClassPath(this); + URL[] jarUrls = classPath.asUrls(); + + // create custom class loader + URLClassLoader loader = new URLClassLoader(jarUrls, + ClassLoader.getSystemClassLoader()) + { + @Override + protected PermissionCollection getPermissions(CodeSource code) + { + Permissions perms = new Permissions(); + perms.add(new AllPermission()); + return perms; + } + }; + Thread.currentThread().setContextClassLoader(loader); + + log.info("Configured URL class loader:"); + for (URL url : jarUrls) + log.info(" " + url); + + // configure any system properties that we can + for (String jvmarg : _jvmargs) + { + if (jvmarg.startsWith("-D")) + { + jvmarg = processArg(jvmarg.substring(2)); + int eqidx = jvmarg.indexOf("="); + if (eqidx == -1) + { + log.warning("Bogus system property: '" + jvmarg + "'?"); + } + else + { + System.setProperty(jvmarg.substring(0, eqidx), + jvmarg.substring(eqidx + 1)); + } + } + } + + // pass along any pass-through arguments + Map passProps = new HashMap<>(); + for (Map.Entry entry : System.getProperties() + .entrySet()) + { + String key = (String) entry.getKey(); + if (key.startsWith(PROP_PASSTHROUGH_PREFIX)) + { + key = key.substring(PROP_PASSTHROUGH_PREFIX.length()); + passProps.put(key, (String) entry.getValue()); + } + } + // we can't set these in the above loop lest we get a + // ConcurrentModificationException + for (Map.Entry entry : passProps.entrySet()) + { + System.setProperty(entry.getKey(), entry.getValue()); + } + + // prepare our app arguments + String[] args = new String[_appargs.size()]; + for (int ii = 0; ii < args.length; ii++) + args[ii] = processArg(_appargs.get(ii)); + + try + { + log.info("Loading " + _class); + Class appclass = loader.loadClass(_class); + Method main = appclass.getMethod("main", + EMPTY_STRING_ARRAY.getClass()); + log.info("Invoking main({" + StringUtil.join(args, ", ") + "})"); + main.invoke(null, new Object[] { args }); + } catch (Exception e) + { + log.warning("Failure invoking app main", e); + } + } + */ + public static void syserr(boolean debug, boolean quiet, String message) { if (debug && !quiet) diff --git a/utils/install4j/install4j10_template.install4j b/utils/install4j/install4j10_template.install4j index e019562..f24478c 100644 --- a/utils/install4j/install4j10_template.install4j +++ b/utils/install4j/install4j10_template.install4j @@ -1,5 +1,5 @@ - + @@ -147,7 +147,7 @@ - +