001: /*
002: * FindBugs - Find bugs in Java programs
003: * Copyright (C) 2003-2005 University of Maryland
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package edu.umd.cs.findbugs;
021:
022: import java.io.IOException;
023: import java.io.InputStream;
024: import java.text.SimpleDateFormat;
025: import java.util.Date;
026: import java.util.Properties;
027:
028: /**
029: * Version number and release date information.
030: */
031: public class Version {
032: /**
033: * Major version number.
034: */
035: public static final int MAJOR = 1;
036:
037: /**
038: * Minor version number.
039: */
040: public static final int MINOR = 3;
041:
042: /**
043: * Patch level.
044: */
045: public static final int PATCHLEVEL = 2;
046:
047: /**
048: * Development version or release candidate?
049: */
050: public static final boolean IS_DEVELOPMENT = false;
051:
052: /**
053: * Release candidate number.
054: * "0" indicates that the version is not a release candidate.
055: */
056: public static final int RELEASE_CANDIDATE = 0;
057:
058: /**
059: * Release date.
060: */
061: public static final String COMPUTED_DATE;
062: public static final String DATE;
063: public static final String COMPUTED_ECLIPSE_DATE;
064: public static final String ECLIPSE_DATE;
065:
066: static {
067: SimpleDateFormat dateFormat = new SimpleDateFormat(
068: "HH:mm:ss z, dd MMMM, yyyy");
069: SimpleDateFormat eclipseDateFormat = new SimpleDateFormat(
070: "yyyyMMdd");
071:
072: COMPUTED_DATE = dateFormat.format(new Date());
073: COMPUTED_ECLIPSE_DATE = eclipseDateFormat.format(new Date());
074: }
075:
076: /**
077: * Preview release number.
078: * "0" indicates that the version is not a preview release.
079: */
080: public static final int PREVIEW = 0;
081:
082: private static final String RELEASE_SUFFIX_WORD = (RELEASE_CANDIDATE > 0 ? "rc"
083: + RELEASE_CANDIDATE
084: : (PREVIEW > 0 ? "preview" + PREVIEW : "dev-"
085: + COMPUTED_ECLIPSE_DATE));
086:
087: public static final String RELEASE_BASE = MAJOR + "." + MINOR + "."
088: + PATCHLEVEL;
089: /**
090: * Release version string.
091: */
092: public static final String COMPUTED_RELEASE = RELEASE_BASE
093: + (IS_DEVELOPMENT ? "-" + RELEASE_SUFFIX_WORD : "");
094:
095: /**
096: * Release version string.
097: */
098: public static final String RELEASE;
099:
100: /**
101: * Version of Eclipse plugin.
102: */
103: public static final String COMPUTED_ECLIPSE_UI_VERSION = MAJOR
104: + "." + MINOR + "." + PATCHLEVEL + "."
105: + COMPUTED_ECLIPSE_DATE;
106: public static final String ECLIPSE_UI_VERSION;
107:
108: static {
109: InputStream in = null;
110: String release, eclipse_ui_version, date, eclipseDate;
111: try {
112: Properties versionProperties = new Properties();
113: in = Version.class
114: .getResourceAsStream("/version.properties");
115: versionProperties.load(in);
116: release = (String) versionProperties.get("release.number");
117: eclipse_ui_version = (String) versionProperties
118: .get("eclipse.ui.version");
119: date = (String) versionProperties.get("release.date");
120: eclipseDate = (String) versionProperties
121: .get("eclipse.date");
122: } catch (RuntimeException e) {
123: release = COMPUTED_RELEASE;
124: eclipse_ui_version = COMPUTED_ECLIPSE_UI_VERSION;
125: date = COMPUTED_DATE;
126: eclipseDate = COMPUTED_ECLIPSE_DATE;
127: } catch (IOException e) {
128: release = COMPUTED_RELEASE;
129: eclipse_ui_version = COMPUTED_ECLIPSE_UI_VERSION;
130: date = COMPUTED_DATE;
131: eclipseDate = COMPUTED_ECLIPSE_DATE;
132: } finally {
133: try {
134: if (in != null)
135: in.close();
136: } catch (IOException e) {
137: assert true; // nothing to do here
138: }
139: }
140: RELEASE = release;
141: ECLIPSE_UI_VERSION = eclipse_ui_version;
142: DATE = date;
143: ECLIPSE_DATE = eclipseDate;
144: }
145:
146: /**
147: * FindBugs website.
148: */
149: public static final String WEBSITE = "http://findbugs.sourceforge.net";
150:
151: /**
152: * Downloads website.
153: */
154: public static final String DOWNLOADS_WEBSITE = "http://prdownloads.sourceforge.net/findbugs";
155:
156: /**
157: * Support email.
158: */
159: public static final String SUPPORT_EMAIL = "http://findbugs.sourceforge.net/reportingBugs.html";
160:
161: public static void main(String[] argv) {
162: if (argv.length != 1)
163: usage();
164:
165: String arg = argv[0];
166: if (!IS_DEVELOPMENT && RELEASE_CANDIDATE != 0) {
167: throw new IllegalStateException(
168: "Non developmental version, but is release candidate "
169: + RELEASE_CANDIDATE);
170: }
171: if (arg.equals("-release"))
172: System.out.println(RELEASE);
173: else if (arg.equals("-date"))
174: System.out.println(DATE);
175: else if (arg.equals("-props")) {
176: System.out.println("release.number=" + COMPUTED_RELEASE);
177: System.out.println("release.date=" + COMPUTED_DATE);
178: System.out.println("eclipse.date=" + COMPUTED_ECLIPSE_DATE);
179: System.out.println("eclipse.ui.version="
180: + COMPUTED_ECLIPSE_UI_VERSION);
181: System.out.println("findbugs.website=" + WEBSITE);
182: System.out.println("findbugs.downloads.website="
183: + DOWNLOADS_WEBSITE);
184: } else {
185: usage();
186: System.exit(1);
187: }
188: }
189:
190: private static void usage() {
191: System.err.println("Usage: " + Version.class.getName()
192: + " (-release|-date|-props)");
193: }
194: }
195:
196: // vim:ts=4
|