|
1 /* |
|
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 */ |
|
25 |
|
26 package com.sun.xml.internal.ws.util; |
|
27 |
|
28 import java.io.InputStream; |
|
29 import java.io.IOException; |
|
30 import java.util.Properties; |
|
31 |
|
32 /** |
|
33 * Represents the version information. |
|
34 * |
|
35 * @author Kohsuke Kawaguchi |
|
36 */ |
|
37 public final class Version { |
|
38 /** |
|
39 * Represents the build id, which is a string like "b13" or "hudson-250". |
|
40 */ |
|
41 public final String BUILD_ID; |
|
42 /** |
|
43 * Represents the complete version string, such as "JAX-WS RI 2.0-b19" |
|
44 */ |
|
45 public final String BUILD_VERSION; |
|
46 /** |
|
47 * Represents the major JAX-WS version, such as "2.0". |
|
48 */ |
|
49 public final String MAJOR_VERSION; |
|
50 |
|
51 /** |
|
52 * Represents the latest Subversion Reversion number. |
|
53 */ |
|
54 public final String SVN_REVISION; |
|
55 |
|
56 /** |
|
57 * The Runtime Version. |
|
58 */ |
|
59 public static final Version RUNTIME_VERSION = Version.create(Version.class.getResourceAsStream("version.properties")); |
|
60 |
|
61 private Version(String buildId, String buildVersion, String majorVersion, String svnRev) { |
|
62 this.BUILD_ID = fixNull(buildId); |
|
63 this.BUILD_VERSION = fixNull(buildVersion); |
|
64 this.MAJOR_VERSION = fixNull(majorVersion); |
|
65 this.SVN_REVISION = fixNull(svnRev); |
|
66 } |
|
67 |
|
68 public static Version create(InputStream is) { |
|
69 Properties props = new Properties(); |
|
70 try { |
|
71 props.load(is); |
|
72 } catch (IOException e) { |
|
73 // ignore even if the property was not found. we'll treat everything as unknown |
|
74 } catch (Exception e) { |
|
75 //ignore even if property not found |
|
76 } |
|
77 |
|
78 return new Version( |
|
79 props.getProperty("build-id"), |
|
80 props.getProperty("build-version"), |
|
81 props.getProperty("major-version"), |
|
82 props.getProperty("svn-revision")); |
|
83 } |
|
84 |
|
85 private String fixNull(String v) { |
|
86 if(v==null) return "unknown"; |
|
87 return v; |
|
88 } |
|
89 |
|
90 public String toString() { |
|
91 return BUILD_VERSION + " svn-revision#" + SVN_REVISION; |
|
92 } |
|
93 } |