001: /*
002: * Version.java
003: *
004: * Copyright (C) 1998-2002 Peter Graves
005: * $Id: Version.java,v 1.1.1.1 2002/09/24 16:08:45 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.j;
023:
024: import java.io.BufferedReader;
025: import java.io.IOException;
026: import java.io.InputStream;
027: import java.io.InputStreamReader;
028:
029: public final class Version {
030: private static String version;
031: private static String build;
032: private static String hostName;
033: private static String snapshot;
034:
035: private static boolean initialized;
036:
037: // "0.16.0+"
038: public static String getVersion() {
039: initialize();
040: return version;
041: }
042:
043: // "J 0.16.0+"
044: public static String getShortVersionString() {
045: initialize();
046: FastStringBuffer sb = new FastStringBuffer("J");
047: if (version != null && version.length() > 0) {
048: sb.append(' ');
049: sb.append(version);
050: }
051: return sb.toString();
052: }
053:
054: // "J 0.16.0+ (built Fri Jul 26 2002 07:03:12 PDT on merlin)"
055: public static String getLongVersionString() {
056: FastStringBuffer sb = new FastStringBuffer(
057: getShortVersionString());
058: if (build != null && build.length() > 0) {
059: sb.append(" (built ");
060: sb.append(build);
061: if (hostName != null && hostName.length() > 0) {
062: sb.append(" on ");
063: sb.append(hostName);
064: }
065: sb.append(")");
066: }
067: return sb.toString();
068: }
069:
070: /**
071: * Returns a string describing the source snapshot from which the running
072: * instance of j was built, if applicable.
073: *
074: * @return a string describing the source snapshot, or <code>null</code>
075: * if not applicable.
076: * @since 0.16.1
077: */
078: public static String getSnapshotInformation() {
079: if (version != null && version.endsWith("+")
080: && snapshot != null) {
081: if (!snapshot.equals(build)) {
082: FastStringBuffer sb = new FastStringBuffer(
083: "(built from development snapshot created ");
084: sb.append(snapshot);
085: sb.append(')');
086: return sb.toString();
087: }
088: }
089: return null;
090: }
091:
092: private static void initialize() {
093: if (!initialized) {
094: InputStream inputStream = Editor.class
095: .getResourceAsStream("version");
096: if (inputStream != null) {
097: try {
098: BufferedReader reader = new BufferedReader(
099: new InputStreamReader(inputStream));
100: version = reader.readLine();
101: reader.close();
102: } catch (IOException e) {
103: Log.error(e);
104: }
105: }
106: inputStream = Editor.class.getResourceAsStream("build");
107: if (inputStream != null) {
108: try {
109: BufferedReader reader = new BufferedReader(
110: new InputStreamReader(inputStream));
111: build = reader.readLine();
112: hostName = reader.readLine();
113: reader.close();
114: } catch (IOException e) {
115: Log.error(e);
116: }
117: }
118: inputStream = Editor.class.getResourceAsStream("snapshot");
119: if (inputStream != null) {
120: try {
121: BufferedReader reader = new BufferedReader(
122: new InputStreamReader(inputStream));
123: snapshot = reader.readLine();
124: reader.close();
125: } catch (IOException e) {
126: Log.error(e);
127: }
128: }
129: initialized = true;
130: }
131: }
132: }
|