01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.version;
19:
20: import java.io.*;
21: import java.util.*;
22:
23: public final class Version {
24:
25: private static String version;
26:
27: private static final String VERSION_BASE = "/org/apache/cxf/version/";
28:
29: private Version() {
30: // utility class - never constructed
31: }
32:
33: private static InputStream getResourceAsStream(String resource) {
34: ClassLoader cl = Version.class.getClassLoader();
35: InputStream ins = cl.getResourceAsStream(resource);
36: if (ins == null && resource.startsWith("/")) {
37: ins = cl.getResourceAsStream(resource.substring(1));
38: }
39: return ins;
40: }
41:
42: private static synchronized void loadProperties() {
43: if (version == null) {
44: Properties p = new Properties();
45:
46: try {
47: InputStream ins = getResourceAsStream(VERSION_BASE
48: + "version.properties");
49:
50: p.load(ins);
51: ins.close();
52: } catch (IOException ex) {
53: // ignore, will end up with defaults
54: }
55:
56: version = p.getProperty("product.version");
57: }
58: }
59:
60: public static String getCurrentVersion() {
61: loadProperties();
62: return version;
63: }
64:
65: /**
66: * Returns version string as normally used in print, such as 3.2.4
67: *
68: */
69: public static String getCompleteVersionString() {
70: return getCurrentVersion();
71: }
72: }
|