001: /*
002:
003: This software is OSI Certified Open Source Software.
004: OSI Certified is a certification mark of the Open Source Initiative.
005:
006: The license (Mozilla version 1.0) can be read at the MMBase site.
007: See http://www.MMBase.org/license
008:
009: */
010: package org.mmbase;
011:
012: import java.io.*;
013:
014: /**
015: * MMBase version reporter. The only goal of this class is providing the current version of
016: * MMBase. The function 'get' will return it as one String.
017: *
018: * @author Daniel Ockeloen
019: * @author Michiel Meeuwissen
020: * @version $Id: Version.java,v 1.42 2008/02/16 22:13:53 nklasens Exp $
021: */
022: public class Version {
023:
024: /**
025: * Get Version Control tag
026: * @return version Control tag
027: * @since MMBase-1.9
028: */
029: public static String getTag() {
030: String cvsTag = "$Name: $";
031: return cvsTag.substring(6, cvsTag.length() - 1).trim();
032: }
033:
034: /**
035: * Returns the 'name' part of the MMBase version. This will normally be 'MMBase'.
036: * @return Name part of version
037: * @since MMBase-1.6
038: */
039: public static String getName() {
040: return "MMBase";
041: }
042:
043: /**
044: * Returns the major version number of this MMBase.
045: * @return major version number
046: * @since MMBase-1.6
047: */
048: public static int getMajor() {
049: return 1;
050: }
051:
052: /**
053: * Returns the minor version number of this MMBase.
054: * @return minor version number
055: * @since MMBase-1.6
056: */
057: public static int getMinor() {
058: return 9;
059: }
060:
061: /**
062: * Returns the patch level number of this MMBase.
063: * @return patch level number
064: * @since MMBase-1.6
065: */
066: public static int getPatchLevel() {
067: return 0;
068: }
069:
070: /**
071: * Returns the build date of this MMBase. During the build, the
072: * value of this is stored in builddate.properties.
073: * @return build date of this MMBase
074: *
075: * @since MMBase-1.6
076: */
077: public static String getBuildDate() {
078: String resource = "";
079: InputStream builddate = Version.class
080: .getResourceAsStream("builddate.properties");
081: if (builddate != null) {
082: try {
083: BufferedReader buffer = new BufferedReader(
084: new InputStreamReader(builddate));
085: resource = buffer.readLine();
086: buffer.close();
087: } catch (IOException e) {
088: // error
089: resource = "" + e;
090: }
091: }
092: return resource;
093: }
094:
095: /**
096: * Returns the version number of this MMBase.
097: * @return version number
098: * @since MMBase-1.6
099: */
100: public static String getNumber() {
101: return getMajor() + "." + getMinor() + "." + getPatchLevel()
102: + (isRelease() ? "-" + getReleaseStatus() + " " : ".")
103: + getBuildDate();
104: }
105:
106: /**
107: * Returns if this is a release version of MMBase. If this is false this MMBase is only a CVS snapshot.
108: * @return is a release version
109: * @since MMBase-1.6
110: */
111: public static boolean isRelease() {
112: return false;
113: };
114:
115: /**
116: * A String describing the status of this release. Like 'final' or 'rc3'.
117: * @return status of this release
118: * @since MMBase-1.7
119: */
120: public static String getReleaseStatus() {
121: return "";
122: };
123:
124: /**
125: * Returns the version of this MMBase.
126: * @return version of this MMBase
127: * @since MMBase-1.6
128: */
129: public static String get() {
130: String tag = getTag();
131: if (tag.startsWith("MMBase")) {
132: return tag + " " + getBuildDate();
133: } else {
134: return getName() + " " + getNumber();
135: }
136: }
137:
138: /**
139: * Prints the version of this mmbase on stdout.
140: * can be usefull on command line:
141: * <code>java -jar mmbase.jar<code>
142: *
143: * @param args command line args
144: */
145: public static void main(String args[]) {
146: System.out.println(get());
147: }
148:
149: }
|