KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > Version


1 /*
2  * Version.java
3  *
4  * Copyright (C) 1998-2002 Peter Graves
5  * $Id: Version.java,v 1.1.1.1 2002/09/24 16:08:45 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.j;
23
24 import java.io.BufferedReader JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.InputStream JavaDoc;
27 import java.io.InputStreamReader JavaDoc;
28
29 public final class Version
30 {
31     private static String JavaDoc version;
32     private static String JavaDoc build;
33     private static String JavaDoc hostName;
34     private static String JavaDoc snapshot;
35
36     private static boolean initialized;
37
38     // "0.16.0+"
39
public static String JavaDoc getVersion()
40     {
41         initialize();
42         return version;
43     }
44
45     // "J 0.16.0+"
46
public static String JavaDoc getShortVersionString()
47     {
48         initialize();
49         FastStringBuffer sb = new FastStringBuffer("J");
50         if (version != null && version.length() > 0) {
51             sb.append(' ');
52             sb.append(version);
53         }
54         return sb.toString();
55     }
56
57     // "J 0.16.0+ (built Fri Jul 26 2002 07:03:12 PDT on merlin)"
58
public static String JavaDoc getLongVersionString()
59     {
60         FastStringBuffer sb = new FastStringBuffer(getShortVersionString());
61         if (build != null && build.length() > 0) {
62             sb.append(" (built ");
63             sb.append(build);
64             if (hostName != null && hostName.length() > 0) {
65                 sb.append(" on ");
66                 sb.append(hostName);
67             }
68             sb.append(")");
69         }
70         return sb.toString();
71     }
72
73     /**
74      * Returns a string describing the source snapshot from which the running
75      * instance of j was built, if applicable.
76      *
77      * @return a string describing the source snapshot, or <code>null</code>
78      * if not applicable.
79      * @since 0.16.1
80      */

81     public static String JavaDoc getSnapshotInformation()
82     {
83         if (version != null && version.endsWith("+") && snapshot != null) {
84             if (!snapshot.equals(build)) {
85                 FastStringBuffer sb =
86                     new FastStringBuffer("(built from development snapshot created ");
87                 sb.append(snapshot);
88                 sb.append(')');
89                 return sb.toString();
90             }
91         }
92         return null;
93     }
94
95     private static void initialize()
96     {
97         if (!initialized) {
98             InputStream JavaDoc inputStream =
99                 Editor.class.getResourceAsStream("version");
100             if (inputStream != null) {
101                 try {
102                     BufferedReader JavaDoc reader =
103                         new BufferedReader JavaDoc(new InputStreamReader JavaDoc(inputStream));
104                     version = reader.readLine();
105                     reader.close();
106                 }
107                 catch (IOException JavaDoc e) {
108                     Log.error(e);
109                 }
110             }
111             inputStream = Editor.class.getResourceAsStream("build");
112             if (inputStream != null) {
113                 try {
114                     BufferedReader JavaDoc reader =
115                         new BufferedReader JavaDoc(new InputStreamReader JavaDoc(inputStream));
116                     build = reader.readLine();
117                     hostName = reader.readLine();
118                     reader.close();
119                 }
120                 catch (IOException JavaDoc e) {
121                     Log.error(e);
122                 }
123             }
124             inputStream = Editor.class.getResourceAsStream("snapshot");
125             if (inputStream != null) {
126                 try {
127                     BufferedReader JavaDoc reader =
128                         new BufferedReader JavaDoc(new InputStreamReader JavaDoc(inputStream));
129                     snapshot = reader.readLine();
130                     reader.close();
131                 }
132                 catch (IOException JavaDoc e) {
133                     Log.error(e);
134                 }
135             }
136             initialized = true;
137         }
138     }
139 }
140
Popular Tags