source: CMDIValidator/trunk/cmdi-validator-core/src/main/java/eu/clarin/cmdi/validator/Version.java @ 5335

Last change on this file since 5335 was 5335, checked in by Oliver Schonefeld, 10 years ago
  • add Version class
  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1package eu.clarin.cmdi.validator;
2
3import java.io.IOException;
4import java.net.URL;
5import java.util.Properties;
6
7
8public final class Version {
9    private static final String VERSION_PROPERTIES_URL = "/version.properties";
10    private static final String PROP_VERSION           = "version";
11    private static final String PROP_TIMESTAMP         = "timestamp";
12    private static final Version INSTANCE;
13    private final String version;
14    private final String timestamp;
15
16
17    private Version() {
18        String version = null;
19        String timestamp = null;
20
21        final URL url = Version.class.getResource(VERSION_PROPERTIES_URL);
22        if (url != null) {
23            try {
24                Properties props = new Properties();
25                props.load(url.openStream());
26                version   = props.getProperty(PROP_VERSION);
27                timestamp = props.getProperty(PROP_TIMESTAMP);
28            } catch (IOException e) {
29                /* IGNORE */
30            }
31        }
32        if ((version == null) || version.isEmpty() || version.contains("$")) {
33            version = "[UNKNOWN]";
34        }
35        if ((timestamp == null) || timestamp.isEmpty() ||
36                timestamp.contains("$")) {
37            timestamp = "[UNKNOWN]";
38        }
39
40        this.version   = version;
41        this.timestamp = timestamp;
42    }
43
44
45    public static String getVersion() {
46        return INSTANCE.version;
47    }
48
49
50    public static String getTimestamp() {
51        return INSTANCE.timestamp;
52    }
53
54
55    static {
56        INSTANCE = new Version();
57    }
58
59} // class Version
Note: See TracBrowser for help on using the repository browser.