From 1a751b8ddf0c8e7730dffced17cad4a1105da907 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Fri, 14 Jun 2019 16:48:19 +0100 Subject: [PATCH] JAL-3111 report build type and commit in stdout from command line and in About/Splash screen --- src/jalview/bin/Cache.java | 133 +++++++++++++++++++++++++++++------------- src/jalview/bin/Jalview.java | 2 + src/jalview/gui/Desktop.java | 29 ++------- 3 files changed, 99 insertions(+), 65 deletions(-) diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 19aa800..f4b4aac 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -405,41 +405,7 @@ public class Cache applicationProperties.remove("YEAR"); } - // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar - // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE - // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW - try - { - String buildDetails = "jar:".concat(Cache.class.getProtectionDomain() - .getCodeSource().getLocation().toString() - .concat("!/.build_properties")); - - java.net.URL localJarFileURL = new java.net.URL(buildDetails); - - InputStream in = localJarFileURL.openStream(); - applicationProperties.load(in); - in.close(); - } catch (Exception ex) - { - System.out.println("Error reading build details: " + ex); - applicationProperties.remove("VERSION"); - } - - String jnlpVersion = System.getProperty("jalview.version"); - String codeVersion = getProperty("VERSION"); - String codeInstallation = getProperty("INSTALLATION"); - if (codeVersion == null) - { - // THIS SHOULD ONLY BE THE CASE WHEN TESTING!! - codeVersion = "Test"; - jnlpVersion = "Test"; - codeInstallation = ""; - } - else - { - codeInstallation = " (" + codeInstallation + ")"; - } - new BuildDetails(codeVersion, null, codeInstallation); + loadBuildProperties(false); SiftsSettings .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false)); @@ -459,9 +425,6 @@ public class Cache "http://www.jalview.org/services/identifiers")); IdOrgSettings.setDownloadLocation(ID_ORG_FILE); - System.out - .println("Jalview Version: " + codeVersion + codeInstallation); - StructureImportSettings.setDefaultStructureFileFormat(jalview.bin.Cache .getDefault("PDB_DOWNLOAD_FORMAT", PDB_DOWNLOAD_FORMAT)); StructureImportSettings @@ -469,8 +432,13 @@ public class Cache // StructureImportSettings // .setDefaultPDBFileParser(jalview.bin.Cache.getDefault( // "DEFAULT_PDB_FILE_PARSER", DEFAULT_PDB_FILE_PARSER)); - // jnlpVersion will be null if we're using InstallAnywhere + + String jnlpVersion = System.getProperty("jalview.version"); + + // jnlpVersion will be null if a latest version check for the channel needs to + // be done // Dont do this check if running in headless mode + if (jnlpVersion == null && getDefault("VERSION_CHECK", true) && (System.getProperty("java.awt.headless") == null || System .getProperty("java.awt.headless").equals("false"))) @@ -541,8 +509,6 @@ public class Cache } } - setProperty("VERSION", codeVersion); - // LOAD USERDEFINED COLOURS jalview.bin.Cache .initUserColourSchemes(getProperty("USER_DEFINED_COLOURS")); @@ -550,6 +516,50 @@ public class Cache false); } + public static void loadBuildProperties(boolean reportVersion) + { + String codeInstallation = getProperty("INSTALLATION"); + boolean printV = codeInstallation == null; + + // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar + try + { + String buildDetails = "jar:".concat(Cache.class.getProtectionDomain() + .getCodeSource().getLocation().toString() + .concat("!/.build_properties")); + + java.net.URL localJarFileURL = new java.net.URL(buildDetails); + + InputStream in = localJarFileURL.openStream(); + applicationProperties.load(in); + in.close(); + } catch (Exception ex) + { + System.out.println("Error reading build details: " + ex); + applicationProperties.remove("VERSION"); + } + String codeVersion = getProperty("VERSION"); + codeInstallation = getProperty("INSTALLATION"); + + if (codeVersion == null) + { + // THIS SHOULD ONLY BE THE CASE WHEN TESTING!! + codeVersion = "Test"; + codeInstallation = ""; + } + else + { + codeInstallation = " (" + codeInstallation + ")"; + } + setProperty("VERSION", codeVersion); + new BuildDetails(codeVersion, null, codeInstallation); + if (printV && reportVersion) + { + System.out + .println("Jalview Version: " + codeVersion + codeInstallation); + } + } + private static void deleteBuildProperties() { applicationProperties.remove("LATEST_VERSION"); @@ -640,7 +650,7 @@ public class Cache try { oldValue = applicationProperties.setProperty(key, obj); - if (!propsAreReadOnly) + if (propertiesFile != null && !propsAreReadOnly) { FileOutputStream out = new FileOutputStream(propertiesFile); applicationProperties.store(out, "---JalviewX Properties File---"); @@ -1063,4 +1073,43 @@ public class Cache } } } + + /** + * + * @return Jalview version, build details and JVM platform version for console + */ + public static String getVersionDetailsForConsole() + { + return "Jalview Version: " + + jalview.bin.Cache.getDefault("VERSION", "TEST") + + "\n" + "Jalview Installation: " + + jalview.bin.Cache.getDefault("INSTALLATION", + "unknown") + + "\n" + "Build Date: " + + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown") + + "\n" + "Java version: " + + System.getProperty("java.version") + "\n" + + System.getProperty("os.arch") + " " + + System.getProperty("os.name") + " " + + System.getProperty("os.version") + + (jalview.bin.Cache.getDefault("VERSION", "TEST") + .equals("DEVELOPMENT") + ? "\nJava path:" + + System.getProperty( + "java.home") + + File.separator + "bin" + + File.separator + "java" + : ""); + } + + /** + * + * @return build details as reported in splashscreen + */ + public static String getBuildDetailsForSplash() + { + // consider returning more human friendly info + // eg 'built from Source' or update channel + return jalview.bin.Cache.getDefault("INSTALLATION", "unknown"); + } } diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 449c1fb..74889d7 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -202,6 +202,8 @@ public class Jalview System.out.println(System.getProperty("os.arch") + " " + System.getProperty("os.name") + " " + System.getProperty("os.version")); + // report Jalview version + Cache.loadBuildProperties(true); String appdirString = System.getProperty("getdownappdir"); if (appdirString != null && appdirString.length() > 0) diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 0523d41..cf91b9c 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -424,26 +424,7 @@ public class Desktop extends jalview.jbgui.GDesktop } jconsole = new Console(this, showjconsole); // add essential build information - jconsole.setHeader( - "Jalview Version: " + jalview.bin.Cache.getProperty("VERSION") - + "\n" + "Jalview Installation: " - + jalview.bin.Cache.getDefault("INSTALLATION", - "unknown") - + "\n" + "Build Date: " - + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown") - + "\n" + "Java version: " - + System.getProperty("java.version") + "\n" - + System.getProperty("os.arch") + " " - + System.getProperty("os.name") + " " - + System.getProperty("os.version") - + (jalview.bin.Cache.getProperty("VERSION").equals("DEVELOPMENT") - ? "\nJava path:" - + System.getProperty( - "java.home") - + File.separator + "bin" - + File.separator + "java" - : "") - ); + jconsole.setHeader(jalview.bin.Cache.getVersionDetailsForConsole()); showConsole(showjconsole); @@ -1376,9 +1357,10 @@ public class Desktop extends jalview.jbgui.GDesktop message.append("

Version: " + jalview.bin.Cache.getProperty("VERSION") + "

"); - message.append("Last Updated: " + message.append("Built: " + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown") - + ""); + + " from " + jalview.bin.Cache.getBuildDetailsForSplash() + + ""); } else @@ -1393,7 +1375,8 @@ public class Desktop extends jalview.jbgui.GDesktop if (jalview.bin.Cache.getDefault("LATEST_VERSION", "Checking") .equals("Checking")) { - message.append("
...Checking latest version...
"); + // JBP removed this message for 2.11: May be reinstated in future version + // message.append("
...Checking latest version...
"); } else if (!jalview.bin.Cache.getDefault("LATEST_VERSION", "Checking") .equals(jalview.bin.Cache.getProperty("VERSION"))) -- 1.7.10.2