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