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: package org.apache.openjpa.conf;
020:
021: import java.io.File;
022: import java.io.InputStream;
023: import java.security.AccessController;
024: import java.util.Properties;
025: import java.util.StringTokenizer;
026:
027: import org.apache.openjpa.lib.util.J2DoPrivHelper;
028:
029: /**
030: * This class contains version information for OpenJPA. It uses
031: * Ant's filter tokens to convert the template into a java
032: * file with current information.
033: *
034: * @author Marc Prud'hommeaux, Patrick Linskey
035: */
036: public class OpenJPAVersion {
037:
038: public static final String VERSION_NUMBER;
039: public static final String VERSION_ID;
040: public static final String VENDOR_NAME = "OpenJPA";
041: public static final int MAJOR_RELEASE;
042: public static final int MINOR_RELEASE;
043: public static final int PATCH_RELEASE;
044: public static final String RELEASE_STATUS;
045: public static final String REVISION_NUMBER;
046:
047: static {
048: Properties revisionProps = new Properties();
049: try {
050: InputStream in = OpenJPAVersion.class
051: .getResourceAsStream("/META-INF/org.apache.openjpa.revision.properties");
052: if (in != null) {
053: try {
054: revisionProps.load(in);
055: } finally {
056: in.close();
057: }
058: }
059: } catch (Exception e) {
060: }
061:
062: String vers = revisionProps.getProperty("openjpa.version");
063: if (vers == null || "".equals(vers.trim()))
064: vers = "0.0.0";
065: VERSION_NUMBER = vers;
066:
067: StringTokenizer tok = new StringTokenizer(VERSION_NUMBER, ".-");
068: int major, minor, patch;
069: try {
070: major = tok.hasMoreTokens() ? Integer.parseInt(tok
071: .nextToken()) : 0;
072: } catch (Exception e) {
073: major = 0;
074: }
075:
076: try {
077: minor = tok.hasMoreTokens() ? Integer.parseInt(tok
078: .nextToken()) : 0;
079: } catch (Exception e) {
080: minor = 0;
081: }
082:
083: try {
084: patch = tok.hasMoreTokens() ? Integer.parseInt(tok
085: .nextToken()) : 0;
086: } catch (Exception e) {
087: patch = 0;
088: }
089:
090: String revision = revisionProps.getProperty("revision.number");
091:
092: MAJOR_RELEASE = major;
093: MINOR_RELEASE = minor;
094: PATCH_RELEASE = patch;
095: RELEASE_STATUS = tok.hasMoreTokens() ? tok.nextToken("!") : "";
096: REVISION_NUMBER = revision;
097: VERSION_ID = "openjpa-" + VERSION_NUMBER + "-r"
098: + REVISION_NUMBER;
099: }
100:
101: public static void main(String[] args) {
102: System.out.println(new OpenJPAVersion().toString());
103: }
104:
105: public String toString() {
106: StringBuffer buf = new StringBuffer(80 * 30);
107: appendOpenJPABanner(buf);
108: buf.append("\n");
109:
110: appendProperty("os.name", buf).append("\n");
111: appendProperty("os.version", buf).append("\n");
112: appendProperty("os.arch", buf).append("\n\n");
113:
114: appendProperty("java.version", buf).append("\n");
115: appendProperty("java.vendor", buf).append("\n\n");
116:
117: buf.append("java.class.path:\n");
118: StringTokenizer tok = new StringTokenizer(
119: (String) AccessController.doPrivileged(J2DoPrivHelper
120: .getPropertyAction("java.class.path")),
121: File.pathSeparator);
122: while (tok.hasMoreTokens()) {
123: buf.append("\t").append(tok.nextToken());
124: buf.append("\n");
125: }
126: buf.append("\n");
127:
128: appendProperty("user.dir", buf);
129: return buf.toString();
130: }
131:
132: public void appendOpenJPABanner(StringBuffer buf) {
133: buf.append(VENDOR_NAME).append(" ");
134: buf.append(VERSION_NUMBER);
135: buf.append("\n");
136: buf.append("version id: ").append(VERSION_ID);
137: buf.append("\n");
138: buf.append("Apache svn revision: ").append(REVISION_NUMBER);
139: buf.append("\n");
140: }
141:
142: private StringBuffer appendProperty(String prop, StringBuffer buf) {
143: return buf.append(prop).append(": ").append(
144: (String) AccessController.doPrivileged(J2DoPrivHelper
145: .getPropertyAction(prop)));
146: }
147: }
|