X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fbin%2FCache.java;h=e2477d9eab317abb2452fff15073bfd7a4f3770f;hb=b8d09897dacc7b0ad203982b4578e2c1d8929142;hp=57ae4ce07ff21ba95bad188930c8f95c2db1e0d0;hpb=efc31b4a8d5cee63555586804a2b79c06bdb5a14;p=jalview.git diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 57ae4ce..e2477d9 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -22,6 +22,8 @@ import java.io.*; import java.util.*; +import java.net.*; + /** * Stores and retrieves Jalview Application Properties @@ -39,11 +41,6 @@ import java.util.*; */ public class Cache { - /** Current release tag */ - public static String VERSION = "AW Test"; - - /** Date Jalview was last packaged, else compilation date of Cache.class */ - public static String BUILD_DATE = ""; /** Jalview Properties */ public static Properties applicationProperties; @@ -54,60 +51,86 @@ public class Cache /** Called when Jalview is started */ public static void loadProperties(String propsFile) { - propertiesFile = propsFile; - if (propsFile == null) - { - propertiesFile = System.getProperty("user.home") + "/.jalview_properties"; - } - - - // get last build time. - long date = 0; + applicationProperties = new Properties(); + propertiesFile = propsFile; + if (propsFile == null) + { + propertiesFile = System.getProperty("user.home") + "/.jalview_properties"; + } try { - String localFile = Cache.class.getProtectionDomain().getCodeSource() - .getLocation().toString(); - localFile = localFile.concat("!/"); - - String tmpString = "jar:"; - String localJarFileString = tmpString.concat(localFile); - java.net.URL localJarFileURL = new java.net.URL(localJarFileString); - java.net.JarURLConnection localJarFile = (java.net.JarURLConnection) localJarFileURL.openConnection(); - date = localJarFile.getLastModified(); + FileInputStream fis = new FileInputStream(propertiesFile); + applicationProperties.load(fis); + applicationProperties.remove("LATEST_VERSION"); + applicationProperties.remove("VERSION"); + fis.close(); } catch (Exception ex) { - ex.printStackTrace(); + System.out.println("Error reading properties file: "+ex); } - if (date == 0) - { - // this is called for unpackaged class files, ie not in a Jar file - // InstallAnywhere version will find build date this way - // not entirely accurate as it only tells you when Cache.class was last compiled - java.io.File f = new java.io.File(System.getProperty("user.dir") + - "/jalview/bin/Cache.class"); - date = f.lastModified(); - } + // 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") + ); - if (date != 0) - { - BUILD_DATE = new Date(date).toString(); + 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"); } - applicationProperties = new Properties(); + String jnlpVersion = System.getProperty("jalview.version"); + String codeVersion = getProperty("VERSION"); - try + + if(codeVersion==null) { - FileInputStream in = new FileInputStream(propertiesFile); - applicationProperties = new Properties(); - applicationProperties.load(in); - in.close(); + // THIS SHOULD ONLY BE THE CASE WHEN TESTING!! + codeVersion = "Test"; + jnlpVersion = "Test"; } - catch (Exception ex) + + // jnlpVersion will be null if we're using InstallAnywhere + if(jnlpVersion==null) { + try{ + java.net.URL url = new java.net.URL("http://www.jalview.org/webstart/jalview.jnlp"); + BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); + String line = null; + while( (line = in.readLine()) !=null) + { + if(line.indexOf("jalview.version")==-1) + continue; + + line = line.substring(line.indexOf("value=")+7); + line = line.substring(0, line.lastIndexOf("\"")); + jnlpVersion = line; + break; + } + }catch(Exception ex) + { jnlpVersion = codeVersion; } } + + System.out.println("Version: "+codeVersion); + System.out.println("Latest : "+jnlpVersion); + + setProperty("LATEST_VERSION", jnlpVersion); + setProperty("VERSION", codeVersion); } /**