JAL-3111 report build type and commit in stdout from command line and in About/Splash...
[jalview.git] / src / jalview / bin / Cache.java
index 19aa800..f4b4aac 100755 (executable)
@@ -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");
+  }
 }