1 16 package org.outerj.daisy.util; 17 18 import java.util.Properties ; 19 import java.io.InputStream ; 20 import java.io.IOException ; 21 22 public class VersionHelper { 23 public static String getVersion(Properties versionProps) { 24 return versionProps.getProperty("artifact.version"); 25 } 26 27 public static String formatVersionString(Properties versionProps) { 28 String version = versionProps.getProperty("artifact.version"); 30 String hostName = versionProps.getProperty("build.hostname"); 31 String date = versionProps.getProperty("build.datetime"); 32 33 String os = System.getProperty("os.name"); 35 String osArch = System.getProperty("os.arch"); 36 String osVersion = System.getProperty("os.version"); 37 String vmVersion = System.getProperty("java.vm.version"); 38 39 return version + " (build: " + hostName + "/" + date + "; run: " + os + "/" + osArch + "/" + osVersion + " java/" + vmVersion + ")"; 40 } 41 42 public static Properties getVersionProperties(ClassLoader classLoader, String versionPropsLocation) throws IOException { 43 Properties versionProps = new Properties (); 44 InputStream versionPropIs = null; 45 try { 46 versionPropIs = classLoader.getResourceAsStream(versionPropsLocation); 47 if (versionPropIs == null) 48 throw new IOException ("Version properties files could not be found: " + versionPropsLocation); 49 versionProps.load(versionPropIs); 50 } finally { 51 if (versionPropIs != null) 52 versionPropIs.close(); 53 } 54 return versionProps; 55 } 56 57 public static String getVersionString(ClassLoader classLoader, String versionPropsLocation) throws IOException { 58 Properties properties = getVersionProperties(classLoader, versionPropsLocation); 59 return formatVersionString(properties); 60 } 61 } 62 | Popular Tags |