1 22 package org.jboss; 23 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 27 import java.util.Collections ; 28 import java.util.Map ; 29 import java.util.Properties ; 30 31 38 public final class Version 39 { 40 public final static String VERSION_MAJOR = "version.major"; 41 public final static String VERSION_MINOR = "version.minor"; 42 public final static String VERSION_REVISION = "version.revision"; 43 public final static String VERSION_TAG = "version.tag"; 44 public final static String VERSION_NAME = "version.name"; 45 public final static String VERSION_CVSTAG = "version.cvstag"; 46 47 public final static String BUILD_NUMBER = "build.number"; 48 public final static String BUILD_ID = "build.id"; 49 public final static String BUILD_DATE = "build.day"; 50 public final static String BUILD_JVM_VERSION = "java.vm.version"; 51 public final static String BUILD_JVM_VENDOR = "java.vendor"; 52 public final static String BUILD_OS = "os.name"; 53 public final static String BUILD_OS_ARCH = "os.arch"; 54 public final static String BUILD_OS_VERSION = "os.version"; 55 56 59 private static Version instance = null; 60 61 64 private Properties props; 65 66 69 private Version() 70 { 71 props = loadProperties(); 72 } 73 74 79 public static Version getInstance() 80 { 81 if (instance == null) 82 { 83 instance = new Version(); 84 } 85 return instance; 86 } 87 88 93 public Map getProperties() 94 { 95 return Collections.unmodifiableMap(props); 96 } 97 98 104 public String getProperty(final String name) 105 { 106 return props.getProperty(name); 107 } 108 109 114 public int getMajor() 115 { 116 return getIntProperty(VERSION_MAJOR); 117 } 118 119 124 public int getMinor() 125 { 126 return getIntProperty(VERSION_MINOR); 127 } 128 129 134 public int getRevision() 135 { 136 return getIntProperty(VERSION_REVISION); 137 } 138 139 144 public String getTag() 145 { 146 return props.getProperty(VERSION_TAG); 147 } 148 153 public String getCvsTag() 154 { 155 return props.getProperty(VERSION_CVSTAG); 156 } 157 158 163 public String getName() 164 { 165 return props.getProperty(VERSION_NAME); 166 } 167 168 173 public String getBuildID() 174 { 175 return props.getProperty(BUILD_ID); 176 } 177 178 183 public String getBuildNumber() 184 { 185 return props.getProperty(BUILD_NUMBER); 186 } 187 188 193 public String getBuildDate() 194 { 195 return props.getProperty(BUILD_DATE); 196 } 197 198 202 public String getBuildJVM() 203 { 204 String vm = props.getProperty(BUILD_JVM_VERSION); 205 String vendor = props.getProperty(BUILD_JVM_VENDOR); 206 return vm + '(' + vendor + ')'; 207 } 208 209 215 public String getBuildOS() 216 { 217 String os = props.getProperty(BUILD_OS); 218 String arch = props.getProperty(BUILD_OS_ARCH); 219 String version = props.getProperty(BUILD_OS_VERSION); 220 return os + '(' + arch +',' + version + ')'; 221 } 222 223 228 public String toString() 229 { 230 StringBuffer buff = new StringBuffer (); 231 232 buff.append(getMajor()).append("."); 233 buff.append(getMinor()).append("."); 234 buff.append(getRevision()).append(getTag()); 235 buff.append("(build: CVSTag="); 236 buff.append(getCvsTag()); 237 buff.append(" date="); 238 buff.append(getBuildID()); 239 buff.append(")"); 240 return buff.toString(); 241 } 242 243 250 private int getIntProperty(final String name) 251 { 252 try 253 { 254 return Integer.valueOf(props.getProperty(name)).intValue(); 255 } 256 catch (Exception e) 257 { 258 return -1; 259 } 260 } 261 262 265 private Properties loadProperties() 266 { 267 props = new Properties (); 268 269 try 270 { 271 InputStream in = 272 Version.class.getResourceAsStream("/org/jboss/version.properties"); 273 if( in != null ) 274 { 275 props.load(in); 276 in.close(); 277 } 278 } 279 catch (IOException e) 280 { 281 throw new Error ("Missing version.properties"); 282 } 283 284 return props; 285 } 286 } 287 | Popular Tags |