01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
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: // stored version info
29: String version = versionProps.getProperty("artifact.version");
30: String hostName = versionProps.getProperty("build.hostname");
31: String date = versionProps.getProperty("build.datetime");
32:
33: // runtime
34: 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
40: + "; run: " + os + "/" + osArch + "/" + osVersion
41: + " java/" + vmVersion + ")";
42: }
43:
44: public static Properties getVersionProperties(
45: ClassLoader classLoader, String versionPropsLocation)
46: throws IOException {
47: Properties versionProps = new Properties();
48: InputStream versionPropIs = null;
49: try {
50: versionPropIs = classLoader
51: .getResourceAsStream(versionPropsLocation);
52: if (versionPropIs == null)
53: throw new IOException(
54: "Version properties files could not be found: "
55: + versionPropsLocation);
56: versionProps.load(versionPropIs);
57: } finally {
58: if (versionPropIs != null)
59: versionPropIs.close();
60: }
61: return versionProps;
62: }
63:
64: public static String getVersionString(ClassLoader classLoader,
65: String versionPropsLocation) throws IOException {
66: Properties properties = getVersionProperties(classLoader,
67: versionPropsLocation);
68: return formatVersionString(properties);
69: }
70: }
|