From: Ben Soares Date: Sat, 29 Jun 2024 21:53:27 +0000 (+0100) Subject: JAL-3631 JVL file with appbase now relaunches getdown X-Git-Tag: Release_2_11_4_0~24^2~2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=2987943975f888af6c6d7a14d0614aa407a04663;p=jalview.git JAL-3631 JVL file with appbase now relaunches getdown --- diff --git a/getdown/lib/getdown-core.jar b/getdown/lib/getdown-core.jar index d5fc86a..323bf3b 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 c59986e..b4b2130 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 ea3700a..b451a80 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 8db0983..a9734a8 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,7 @@ import java.util.zip.GZIPInputStream; import jalview.bin.HiDPISetting; import jalview.bin.MemorySetting; +import jalview.util.ChannelProperties; import jalview.util.HttpUtils; import jalview.util.LaunchUtils; @@ -293,7 +294,8 @@ public class Application public Application (EnvConfig envc) { _envc = envc; _config = getLocalPath(envc.appDir, CONFIG_FILE); - _backupConfig = getLocalPath(envc.appDir, BACKUP_CONFIG_DIR+File.separator+CONFIG_FILE); + _backupConfig = getLocalPath(envc.appDir, BACKUP_CONFIG_DIR + File.separator + CONFIG_FILE); + log.warning("##### SET _config to", "_config", _config.getAbsolutePath()); } /** @@ -302,6 +304,10 @@ public class Application public File getAppDir () { return _envc.appDir; } + + public EnvConfig getEnvConfig() { + return _envc; + } /** * Returns whether the application should cache code resources prior to launching the @@ -589,13 +595,19 @@ public class Application * @exception IOException thrown if there is an error reading the file or an error encountered * during its parsing. */ - public Config init (boolean checkPlatform) + public Config init (boolean checkPlatform) throws IOException { + /*##### + return init(checkPlatform, false); + } + + public Config init (boolean checkPlatform, boolean secondCall) throws IOException { - if (_initialised && _initialisedConfig != null) - { - return _initialisedConfig; - } + */ + if (_initialised && _initialisedConfig != null) + { + return _initialisedConfig; + } try { Application.i4jVersion = com.install4j.api.launcher.Variables.getCompilerVariable("sys.install4jVersion"); @@ -647,9 +659,10 @@ 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") || locatorConfig.hasValue("appbase")) { + //##### if (config == null || locatorConfig.getBoolean(LOCATOR_FILE_EXTENSION+"_replace") || (locatorConfig.hasValue("appbase") && !secondCall)) { + if (config == null || locatorConfig.getBoolean(LOCATOR_FILE_EXTENSION+"_replace")) { config = locatorConfig; - log.warning("Replacing config with locator file", LOCATOR_FILE_EXTENSION+" file", 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); @@ -670,10 +683,23 @@ public class Application // process, our caller can use the appbase to download a new configuration file _appbase = config.getString("appbase"); + /* ##### // see if locatorConfig override - if (locatorConfig != null && !StringUtil.isBlank(locatorConfig.getString("appbase"))) { - _appbase = locatorConfig.getString("appbase"); + if (!secondCall && locatorConfig != null && !StringUtil.isBlank(locatorConfig.getString("appbase"))) { + String lAppbase = locatorConfig.getString("appbase"); + if (lAppbase != null && !lAppbase.endsWith("/")) { + lAppbase = lAppbase + "/"; + } + if (lAppbase != null && !lAppbase.equals(_appbase)) { + _appbase = lAppbase; + // get new getdown.txt + log.warning("Attempting to download new getdown.txt from " + _appbase + " and use that"); + updateMetadata(); + setLocatorFile(null); + return init(checkPlatform, true); + } } + */ if (_appbase == null) { throw new RuntimeException("m.missing_appbase"); @@ -2000,6 +2026,10 @@ public class Application return sb.toString(); } + public static String getLocatorFile() { + return _locatorFile; + } + public static void setLocatorFile(String filename) { _locatorFile = filename; } @@ -2207,6 +2237,58 @@ public class Application args.add(sb.toString()); } + public boolean updateMetadataAndRelaunch(String newAppbase, Class startClass, String locatorFileArg, String[] argv, List notes) { + _appbase = newAppbase; + try { + updateMetadata(); + } catch(IOException e) { + notes.add(Note.warn("IOException when trying to update metadata files with new appbase '" + newAppbase + "': " + e.getMessage())); + return false; + } + + String appDir = this.getAppDir().getAbsolutePath(); + String appName = StringUtil.isBlank(_envc.getAppname()) ? ChannelProperties.FALLBACK_APPNAME : _envc.getAppname(); + + String javaBin = LaunchUtils.findJavaBin(false); + + List removeJvmArgs = new ArrayList<>(); + removeJvmArgs.add("-Dappbase="); + List addJvmArgs = new ArrayList<>(); + addJvmArgs.add("-Dappbase=" + newAppbase); + + String macIcons = System.getProperty("installer.mac_icons"); + // we love our Mac users, so we do nice things to preserve our application identity + if (LaunchUtil.isMacOS()) { + removeJvmArgs = new ArrayList<>(); + addJvmArgs = new ArrayList<>(); + if (macIcons != null) { + removeJvmArgs.add("-Xdock:icon="); + addJvmArgs.add("-Xdock:icon=" + appDir + File.separator + "resource" + File.separator + macIcons ); + } + removeJvmArgs.add("-Xdock:name="); + addJvmArgs.add("-Xdock:name=" + ( appName != null ? appName : ChannelProperties.FALLBACK_APPNAME )); + } + + List removeArgs = new ArrayList<>(); + if (locatorFileArg != null) { + removeArgs.add("locatorFileArg"); + } + + String startClassName = startClass == null ? null : startClass.getName(); + + int exitValue = LaunchUtils.startNewJvm(javaBin, removeJvmArgs, addJvmArgs, null, null, null, startClassName, removeArgs, null, Arrays.asList(argv), true, true, false, true, false); + + if (exitValue == 0) { + notes.add(Note.info("Relaunching getdown succeeded. Original getdown exiting now.")); + _envc.setRelaunched(true); + return true; + } else { + notes.add(Note.warn("Relaunching getdown did not seem to succeed with exit value " + exitValue + ". Continuing with this getdown process.")); + } + + return false; + } + protected final EnvConfig _envc; protected File _config; protected File _backupConfig; 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 0342f70..e5051de 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 @@ -385,7 +385,7 @@ public final class EnvConfig { return relaunched; } - private static String getLocatorFileAppBase(String locatorFile) { + public static String getLocatorFileAppBase(String locatorFile) { String lfAppBase = null; Config.ParseOpts opts = Config.createOpts(false); Config checkConfig = Application.createLocatorConfig(opts); @@ -394,7 +394,11 @@ public final class EnvConfig { } return lfAppBase; } - + + public static String getAppname() { + return appName; + } + private static boolean relaunched = false; private static final String USER_HOME_KEY = "${user.home}"; 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 fcd6dce..653bf7a 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 @@ -1173,6 +1173,10 @@ public abstract class Getdown extends Thread _latestInstance = app; } + public Application getApplication() { + return _app; + } + 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 6800f5a..17f5949 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 @@ -77,6 +77,7 @@ public class GetdownApp } else { System.err.println("Usage: java -jar getdown.jar [app_dir] [app_id] [app args]"); } + // if EnvConfig has relaunched, it sets its own _relaunched flag and returns null System.exit(EnvConfig.getRelaunched() ? 0 : -1); } @@ -311,6 +312,32 @@ public class GetdownApp if (getStartupFilesParameters().size() > 0) { Application.setStartupFilesFromParameters(getStartupFilesParameters()); } + + String locatorFile = Application.getLocatorFile(); + if (locatorFile != null) { + String lfAppbase = app.getApplication().getEnvConfig().getLocatorFileAppBase(locatorFile); + if (lfAppbase != null && !lfAppbase.equals(app.getApplication().getAppbase())) { + + /** ###### + * DO METADATA DOWNLOAD AND RESLAUNCH GETDOWN WITH DON'T RESTART PROPERTY (MAKE IT UP) HERE! + */ + notes = new ArrayList<>(); + + boolean relaunched = app.getApplication().updateMetadataAndRelaunch(lfAppbase, GetdownApp.class, locatorFile, argv, notes); + + if (!notes.isEmpty()) { + for (EnvConfig.Note n : notes) { + System.err.println(n.message); + } + } + + if (relaunched) { + System.exit(0); + } + + } + + } Getdown.setInstance(app); app.start(); diff --git a/j11lib/getdown-core.jar b/j11lib/getdown-core.jar index d5fc86a..323bf3b 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 d5fc86a..323bf3b 100644 Binary files a/j8lib/getdown-core.jar and b/j8lib/getdown-core.jar differ