001: /*
002: * Copyright 2005 Joe Walker
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.directwebremoting.util;
017:
018: import java.io.IOException;
019: import java.io.InputStream;
020: import java.util.Properties;
021:
022: /**
023: * Interface to the system version info file.
024: * DWR version numbers are of the form "Version 1.2.3.3128[.beta]", where:
025: * <ul>
026: * <li>1 is the major release number. Changes in major version number indicate
027: * significant enhancements in functionality</li>
028: * <li>2 is the minor release number. Changes in minor version number indicate
029: * less significant changes in functionality</li>
030: * <li>3 is the revision release number. Changes here typically indicate bug
031: * fixes only</li>
032: * <li>3128 is the build number. This number increments for each build</li>
033: * <li>.beta is a release title that is generally only used for non production
034: * releases to indicate the purpose/quality of the release</li>
035: * <li>The label is these strings concatenated</li>
036: * </ul>
037: * @author Joe Walker [joe at getahead dot ltd dot uk]
038: */
039: public class VersionUtil {
040: /**
041: * Fish the version number out of the dwr.properties file.
042: * @return The current version number.
043: */
044: public static String getSourceControlInfo() {
045: loadProperties();
046: return sccInfo;
047: }
048:
049: /**
050: * Fish the version number out of the dwr.properties file.
051: * @return The current version number.
052: * @deprecated Use {@link #getLabel()}
053: */
054: @Deprecated
055: public static String getVersion() {
056: return getLabel();
057: }
058:
059: /**
060: * @return The major version number of this release
061: */
062: public static int getMajor() {
063: return major;
064: }
065:
066: /**
067: * @return The minor version number of this release
068: */
069: public static int getMinor() {
070: return minor;
071: }
072:
073: /**
074: * @return The revision version number of this release
075: */
076: public static int getRevision() {
077: return revision;
078: }
079:
080: /**
081: * @return The build number of this release
082: */
083: public static int getBuild() {
084: return build;
085: }
086:
087: /**
088: * @return The optional title of this release
089: */
090: public static String getTitle() {
091: loadProperties();
092: return title;
093: }
094:
095: /**
096: * @return The full version string
097: */
098: public static String getLabel() {
099: loadProperties();
100: return label;
101: }
102:
103: /**
104: * Load the properties from the internal properties file.
105: */
106: private static synchronized void loadProperties() {
107: if (loaded) {
108: return;
109: }
110:
111: try {
112: InputStream in = VersionUtil.class
113: .getResourceAsStream(FILENAME_VERSION);
114: Properties props = new Properties();
115: props.load(in);
116:
117: sccInfo = props.getProperty(KEY_SCC_INFO);
118: major = Integer.parseInt(props.getProperty(KEY_MAJOR));
119: minor = Integer.parseInt(props.getProperty(KEY_MINOR));
120: revision = Integer
121: .parseInt(props.getProperty(KEY_REVISION));
122: build = Integer.parseInt(props.getProperty(KEY_BUILD));
123: title = props.getProperty(KEY_TITLE);
124:
125: if (title.length() == 0) {
126: label = major + "." + minor + "." + revision;
127: } else {
128: label = major + "." + minor + "." + revision + "."
129: + build + "." + title;
130: }
131:
132: loaded = true;
133: } catch (IOException ex) {
134: throw new RuntimeException(ex);
135: }
136: }
137:
138: private static boolean loaded = false;
139:
140: private static final String FILENAME_VERSION = "/dwr-version.properties";
141:
142: private static final String KEY_MAJOR = "major";
143: private static int major;
144:
145: private static final String KEY_MINOR = "minor";
146: private static int minor;
147:
148: private static final String KEY_REVISION = "revision";
149: private static int revision;
150:
151: private static final String KEY_BUILD = "build";
152: private static int build;
153:
154: private static final String KEY_TITLE = "title";
155: private static String title;
156:
157: private static String label;
158:
159: private static final String KEY_SCC_INFO = "scc-info";
160: private static String sccInfo;
161: }
|