01: package org.objectweb.celtix.version;
02:
03: import java.io.*;
04: import java.util.*;
05:
06: public final class Version {
07:
08: private static String version;
09:
10: private static final String VERSION_BASE = "/org/objectweb/celtix/version/";
11:
12: private Version() {
13: // utility class - never constructed
14: }
15:
16: private static InputStream getResourceAsStream(String resource) {
17: ClassLoader cl = Version.class.getClassLoader();
18: InputStream ins = cl.getResourceAsStream(resource);
19: if (ins == null && resource.startsWith("/")) {
20: ins = cl.getResourceAsStream(resource.substring(1));
21: }
22: return ins;
23: }
24:
25: private static synchronized void loadProperties() {
26: if (version == null) {
27: Properties p = new Properties();
28:
29: try {
30: InputStream ins = getResourceAsStream(VERSION_BASE
31: + "version.properties");
32:
33: p.load(ins);
34: ins.close();
35: } catch (IOException ex) {
36: // ignore, will end up with defaults
37: }
38:
39: version = p.getProperty("product.version");
40: }
41: }
42:
43: public static String getCurrentVersion() {
44: loadProperties();
45: return version;
46: }
47:
48: /**
49: * Returns version string as normally used in print, such as 3.2.4
50: *
51: */
52: public static String getCompleteVersionString() {
53: return getCurrentVersion();
54: }
55: }
|