Release and build date methods changed
[jalview.git] / src / jalview / bin / Cache.java
index 57ae4ce..d4c7e5d 100755 (executable)
@@ -22,6 +22,8 @@ import java.io.*;
 \r
 import java.util.*;\r
 \r
+import java.net.*;\r
+\r
 \r
 /**\r
  * Stores and retrieves Jalview Application Properties\r
@@ -39,11 +41,6 @@ import java.util.*;
  */\r
 public class Cache\r
 {\r
-    /** Current release tag */\r
-    public static String VERSION = "AW Test";\r
-\r
-    /** Date Jalview was last packaged, else compilation date of Cache.class */\r
-    public static String BUILD_DATE = "";\r
 \r
     /** Jalview Properties */\r
     public static Properties applicationProperties;\r
@@ -54,59 +51,68 @@ public class Cache
     /** Called when Jalview is started */\r
     public static void loadProperties(String propsFile)\r
     {\r
-      propertiesFile = propsFile;\r
-      if (propsFile == null)\r
-      {\r
-        propertiesFile = System.getProperty("user.home") + "/.jalview_properties";\r
-      }\r
-\r
+        applicationProperties = new Properties();\r
 \r
-        // get last build time.\r
-        long date = 0;\r
+        propertiesFile = propsFile;\r
+        if (propsFile == null)\r
+        {\r
+          propertiesFile = System.getProperty("user.home") + "/.jalview_properties";\r
+        }\r
 \r
         try\r
         {\r
-            String localFile = Cache.class.getProtectionDomain().getCodeSource()\r
-                                          .getLocation().toString();\r
-            localFile = localFile.concat("!/");\r
-\r
-            String tmpString = "jar:";\r
-            String localJarFileString = tmpString.concat(localFile);\r
-            java.net.URL localJarFileURL = new java.net.URL(localJarFileString);\r
-            java.net.JarURLConnection localJarFile = (java.net.JarURLConnection) localJarFileURL.openConnection();\r
-            date = localJarFile.getLastModified();\r
+            FileInputStream fis = new FileInputStream(propertiesFile);\r
+            applicationProperties.load(fis);\r
+            fis.close();\r
         }\r
         catch (Exception ex)\r
         {\r
-            ex.printStackTrace();\r
+          System.out.println("Error reading properties file: "+ex);\r
         }\r
 \r
-        if (date == 0)\r
-        {\r
-            // this is called for unpackaged class files, ie not in a Jar file\r
-            // InstallAnywhere version will find build date this way\r
-            // not entirely accurate as it only tells you when Cache.class was last compiled\r
-            java.io.File f = new java.io.File(System.getProperty("user.dir") +\r
-                    "/jalview/bin/Cache.class");\r
-            date = f.lastModified();\r
-        }\r
+        // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar\r
+        // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE\r
+        // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW\r
+         try\r
+         {\r
+             String buildDetails = "jar:"\r
+                 .concat(\r
+                 Cache.class.getProtectionDomain().getCodeSource().getLocation().toString()\r
+                 .concat("!/.build_properties")\r
+                 );\r
 \r
-        if (date != 0)\r
-        {\r
-            BUILD_DATE = new Date(date).toString();\r
-        }\r
-\r
-        applicationProperties = new Properties();\r
+             java.net.URL localJarFileURL = new java.net.URL(buildDetails);\r
 \r
-        try\r
-        {\r
-            FileInputStream in = new FileInputStream(propertiesFile);\r
-            applicationProperties = new Properties();\r
+            InputStream in = localJarFileURL.openStream();\r
             applicationProperties.load(in);\r
             in.close();\r
+         }\r
+         catch (Exception ex)\r
+         {\r
+           System.out.println("Error reading build details: "+ex);\r
         }\r
-        catch (Exception ex)\r
+\r
+        String jnlpVersion = System.getProperty("jalview.version");\r
+        String codeVersion = getProperty("VERSION");\r
+\r
+        // jnlpVersion will be null if we're using InstallAnywhere\r
+        if(jnlpVersion==null)\r
         {\r
+          try{\r
+            java.net.URL url = new java.net.URL("http://www.jalview.org/webstart/jalview.jnlp");\r
+            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));\r
+            String line = null;\r
+            while( (line = in.readLine()) !=null)\r
+            {\r
+              if(line.indexOf("jalview.version")==-1)\r
+                continue;\r
+\r
+              line = line.substring(line.indexOf("value=")+7);\r
+              line = line.substring(0, line.lastIndexOf("\""));\r
+              setProperty("jalview.version", line);\r
+            }\r
+          }catch(Exception ex)\r
+          {setProperty("jalview.version", codeVersion);}\r
         }\r
     }\r
 \r