KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > util > VersionHelper


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
19 import java.io.InputStream JavaDoc;
20 import java.io.IOException JavaDoc;
21
22 public class VersionHelper {
23     public static String JavaDoc getVersion(Properties JavaDoc versionProps) {
24         return versionProps.getProperty("artifact.version");
25     }
26
27     public static String JavaDoc formatVersionString(Properties JavaDoc versionProps) {
28         // stored version info
29
String JavaDoc version = versionProps.getProperty("artifact.version");
30         String JavaDoc hostName = versionProps.getProperty("build.hostname");
31         String JavaDoc date = versionProps.getProperty("build.datetime");
32
33         // runtime
34
String JavaDoc os = System.getProperty("os.name");
35         String JavaDoc osArch = System.getProperty("os.arch");
36         String JavaDoc osVersion = System.getProperty("os.version");
37         String JavaDoc 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 JavaDoc getVersionProperties(ClassLoader JavaDoc classLoader, String JavaDoc versionPropsLocation) throws IOException JavaDoc {
43         Properties JavaDoc versionProps = new Properties JavaDoc();
44         InputStream JavaDoc versionPropIs = null;
45         try {
46             versionPropIs = classLoader.getResourceAsStream(versionPropsLocation);
47             if (versionPropIs == null)
48                 throw new IOException JavaDoc("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 JavaDoc getVersionString(ClassLoader JavaDoc classLoader, String JavaDoc versionPropsLocation) throws IOException JavaDoc {
58         Properties JavaDoc properties = getVersionProperties(classLoader, versionPropsLocation);
59         return formatVersionString(properties);
60     }
61 }
62
Popular Tags