X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fbin%2FCache.java;h=d4c7e5de2f7064675905e547dd099c0ec4b1f5ce;hb=1ee8b306b296ea2724e128f66486675bdaac7a3d;hp=57ae4ce07ff21ba95bad188930c8f95c2db1e0d0;hpb=efc31b4a8d5cee63555586804a2b79c06bdb5a14;p=jalview.git diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 57ae4ce..d4c7e5d 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,59 +51,68 @@ 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"; - } - + applicationProperties = new Properties(); - // get last build time. - long date = 0; + 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); + 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(); - } - - applicationProperties = new Properties(); + java.net.URL localJarFileURL = new java.net.URL(buildDetails); - try - { - FileInputStream in = new FileInputStream(propertiesFile); - applicationProperties = new Properties(); + InputStream in = localJarFileURL.openStream(); applicationProperties.load(in); in.close(); + } + catch (Exception ex) + { + System.out.println("Error reading build details: "+ex); } - catch (Exception ex) + + String jnlpVersion = System.getProperty("jalview.version"); + String codeVersion = getProperty("VERSION"); + + // 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("\"")); + setProperty("jalview.version", line); + } + }catch(Exception ex) + {setProperty("jalview.version", codeVersion);} } }