001: /*
002: JSPWiki - a JSP-based WikiWiki clone.
003:
004: Copyright (C) 2001-2007 Janne Jalkanen (Janne.Jalkanen@iki.fi)
005:
006: This program is free software; you can redistribute it and/or modify
007: it under the terms of the GNU Lesser General Public License as published by
008: the Free Software Foundation; either version 2.1 of the License, or
009: (at your option) any later version.
010:
011: This program is distributed in the hope that it will be useful,
012: but WITHOUT ANY WARRANTY; without even the implied warranty of
013: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: GNU Lesser General Public License for more details.
015:
016: You should have received a copy of the GNU Lesser General Public License
017: along with this program; if not, write to the Free Software
018: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020:
021: package com.ecyrd.jspwiki;
022:
023: import org.apache.commons.lang.StringUtils;
024:
025: /**
026: * Contains release and version information. You may also invoke this
027: * class directly, in which case it prints out the version string. This
028: * is a handy way of checking which JSPWiki version you have - just type
029: * from a command line:
030: * <pre>
031: * % java -cp JSPWiki.jar com.ecyrd.jspwiki.Release
032: * 2.5.38
033: * </pre>
034: * <p>
035: * As a historical curiosity, this is the oldest JSPWiki file. According
036: * to the CVS history, it dates from 6.7.2001, and it really hasn't changed
037: * much since.
038: * </p>
039: * @author Janne Jalkanen
040: * @since 1.0
041: */
042: public final class Release {
043: private static final String VERSION_SEPARATORS = ".-";
044:
045: /**
046: * This is the default application name.
047: */
048: public static final String APPNAME = "JSPWiki";
049:
050: /**
051: * This should be empty when doing a release - otherwise
052: * keep it as "cvs" so that whenever someone checks out the code,
053: * they know it is a bleeding-edge version. Other possible
054: * values are "alpha" and "beta" for alpha and beta versions,
055: * respectively.
056: * <p>
057: * If the POSTFIX is empty, it is not added to the version string.
058: */
059: private static final String POSTFIX = "";
060:
061: /** The JSPWiki major version. */
062: public static final int VERSION = 2;
063:
064: /** The JSPWiki revision. */
065: public static final int REVISION = 6;
066:
067: /** The minor revision. */
068: public static final int MINORREVISION = 1;
069:
070: /** The build number/identifier. This is a String as opposed to an integer, just
071: * so that people can add other identifiers to it. The build number is incremented
072: * every time a committer checks in code, and reset when the a release is made.
073: * <p>
074: * If you are a person who likes to build his own releases, we recommend that you
075: * add your initials to this identifier (e.g. "13-jj", or 49-aj").
076: * <p>
077: * If the build identifier is empty, it is not added.
078: */
079: public static final String BUILD = "";
080:
081: /**
082: * This is the generic version string you should use
083: * when printing out the version. It is of the form "VERSION.REVISION.MINORREVISION[-POSTFIX][-BUILD]".
084: */
085: public static final String VERSTR = VERSION + "." + REVISION + "."
086: + MINORREVISION
087: + ((POSTFIX.length() != 0) ? "-" + POSTFIX : "")
088: + ((BUILD.length() != 0 ? "-" + BUILD : ""));
089:
090: /**
091: * Private constructor prevents instantiation.
092: */
093: private Release() {
094: }
095:
096: /**
097: * This method is useful for templates, because hopefully it will
098: * not be inlined, and thus any change to version number does not
099: * need recompiling the pages.
100: *
101: * @since 2.1.26.
102: * @return The version string (e.g. 2.5.23).
103: */
104: public static String getVersionString() {
105: return VERSTR;
106: }
107:
108: /**
109: * Returns true, if this version of JSPWiki is newer or equal than what is requested.
110: * @param version A version parameter string (a.b.c-something). B and C are optional.
111: * @return A boolean value describing whether the given version is newer than the current JSPWiki.
112: * @since 2.4.57
113: * @throws IllegalArgumentException If the version string could not be parsed.
114: */
115: public static boolean isNewerOrEqual(String version)
116: throws IllegalArgumentException {
117: if (version == null)
118: return true;
119: String[] versionComponents = StringUtils.split(version,
120: VERSION_SEPARATORS);
121: int reqVersion = versionComponents.length > 0 ? Integer
122: .parseInt(versionComponents[0]) : Release.VERSION;
123: int reqRevision = versionComponents.length > 1 ? Integer
124: .parseInt(versionComponents[1]) : Release.REVISION;
125: int reqMinorRevision = versionComponents.length > 2 ? Integer
126: .parseInt(versionComponents[2]) : Release.MINORREVISION;
127:
128: if (VERSION == reqVersion) {
129: if (REVISION == reqRevision) {
130: if (MINORREVISION == reqMinorRevision) {
131: return true;
132: }
133:
134: return MINORREVISION > reqMinorRevision;
135: }
136:
137: return REVISION > reqRevision;
138: }
139:
140: return VERSION > reqVersion;
141: }
142:
143: /**
144: * Returns true, if this version of JSPWiki is older or equal than what is requested.
145: * @param version A version parameter string (a.b.c-something)
146: * @return A boolean value describing whether the given version is older than the current JSPWiki version
147: * @since 2.4.57
148: * @throws IllegalArgumentException If the version string could not be parsed.
149: */
150: public static boolean isOlderOrEqual(String version)
151: throws IllegalArgumentException {
152: if (version == null)
153: return true;
154:
155: String[] versionComponents = StringUtils.split(version,
156: VERSION_SEPARATORS);
157: int reqVersion = versionComponents.length > 0 ? Integer
158: .parseInt(versionComponents[0]) : Release.VERSION;
159: int reqRevision = versionComponents.length > 1 ? Integer
160: .parseInt(versionComponents[1]) : Release.REVISION;
161: int reqMinorRevision = versionComponents.length > 2 ? Integer
162: .parseInt(versionComponents[2]) : Release.MINORREVISION;
163:
164: if (VERSION == reqVersion) {
165: if (REVISION == reqRevision) {
166: if (MINORREVISION == reqMinorRevision) {
167: return true;
168: }
169:
170: return MINORREVISION < reqMinorRevision;
171: }
172:
173: return REVISION < reqRevision;
174: }
175:
176: return VERSION < reqVersion;
177: }
178:
179: /**
180: * Executing this class directly from command line prints out
181: * the current version. It is very useful for things like
182: * different command line tools.
183: * <P>Example:
184: * <PRE>
185: * % java com.ecyrd.jspwiki.Release
186: * 1.9.26-cvs
187: * </PRE>
188: *
189: * @param argv The argument string. This class takes in no arguments.
190: */
191: public static void main(String[] argv) {
192: System.out.println(VERSTR);
193: }
194: }
|