001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.jellytools;
042:
043: import java.util.MissingResourceException;
044: import java.util.jar.Manifest;
045:
046: /**
047: * Class to obtain version of jellytools and to check whether user run tests
048: * on correct Jemmy version.
049: * <BR>
050: * Information about versions is stored in org/netbeans/jellytools/version_info
051: * file. To check jemmy version in runtime we use JemmyProperties.getVersion().
052: *
053: * @author Jiri.Skrivanek@sun.com
054: */
055: public class JellyVersion {
056:
057: /** Flag to check Jemmy version only once. */
058: private static boolean jemmyVersionChecked = false;
059:
060: /** Writes version of jellytools to standard output.
061: * @param argv not used
062: */
063: public static void main(String[] argv) {
064: System.out.println("Jellytools version : " + getVersion()
065: + // NOI18N
066: " (Build " + getBuild() + " on " + getIDEVersion()
067: + " and Jemmy " + getJemmyVersion() + ")"); // NOI18N
068: }
069:
070: /** Checks if version of Jemmy which is used to test execution is the same
071: * or greater than version of Jemmy which jellytools were build on. If not,
072: * it prints a message to Jemmy error output.
073: */
074: public static synchronized void checkJemmyVersion() {
075: if (!jemmyVersionChecked) {
076: jemmyVersionChecked = true;
077: String jemmyVersion = null;
078: try {
079: jemmyVersion = org.netbeans.jemmy.JemmyProperties
080: .getVersion();
081: } catch (Exception e) {
082: // jemmy version is not available
083: return;
084: }
085: String builtOnJemmyVersion = getJemmyVersion();
086: if (jemmyVersion.compareTo(builtOnJemmyVersion) < 0) {
087: String line = "\n##############################################\n"; // NOI18N
088: String message = "Need to upgrade Jemmy to version: "
089: + // NOI18N
090: builtOnJemmyVersion
091: + "\nCurrent Jemmy version: " + jemmyVersion; // NOI18N
092: org.netbeans.jemmy.JemmyProperties.getCurrentOutput()
093: .printError(line + message + line);
094: }
095: }
096: }
097:
098: /** Creates instance of Manifest for file org/netbeans/jellytools/version_info
099: * where information about version is stored in manifest-like format.
100: */
101: private static Manifest getManifest() {
102: String info = "org/netbeans/jellytools/version_info"; // NOI18N
103: try {
104: return new Manifest(new JellyVersion().getClass()
105: .getClassLoader().getResourceAsStream(info));
106: } catch (Exception e) {
107: throw new MissingResourceException(
108: "Version info not available.", null, null);// NOI18N
109: }
110: }
111:
112: /** Returns Jellytools major version number.
113: * @return Jellytools major version number
114: */
115: public static String getMajorVersion() {
116: return getManifest().getMainAttributes().getValue(
117: "Jellytools-MajorVersion"); // NOI18N
118: }
119:
120: /** Returns Jellytools minor version number.
121: * @return Jellytools minor version number
122: */
123: public static String getMinorVersion() {
124: return getManifest().getMainAttributes().getValue(
125: "Jellytools-MinorVersion"); // NOI18N
126: }
127:
128: /** Returns Jellytools version.
129: * @return Jellytools version
130: */
131: public static String getVersion() {
132: return (getMajorVersion() + "." + getMinorVersion()); // NOI18N
133: }
134:
135: /** Returns Jellytools build number.
136: * @return Jellytools build number
137: */
138: public static String getBuild() {
139: return getManifest().getMainAttributes().getValue(
140: "Jellytools-Build"); // NOI18N
141: }
142:
143: /** Returns IDE version which Jellytools were build on.
144: * @return IDE version which Jellytools were build on
145: */
146: public static String getIDEVersion() {
147: return getManifest().getMainAttributes().getValue(
148: "Jellytools-IDEVersion"); // NOI18N
149: }
150:
151: /** Returns Jemmy major version which Jellytools were build on.
152: * @return Jemmy major version which Jellytools were build on
153: */
154: public static String getJemmyMajorVersion() {
155: return getManifest().getMainAttributes().getValue(
156: "Jemmy-MajorVersion"); // NOI18N
157: }
158:
159: /** Returns Jemmy minor version which Jellytools were build on.
160: * @return Jemmy minor version which Jellytools were build on
161: */
162: public static String getJemmyMinorVersion() {
163: return getManifest().getMainAttributes().getValue(
164: "Jemmy-MinorVersion"); // NOI18N
165: }
166:
167: /** Returns Jemmy version which Jellytools were build on.
168: * @return Jemmy version which Jellytools were build on
169: */
170: public static String getJemmyVersion() {
171: return (getJemmyMajorVersion() + "." + getJemmyMinorVersion()); // NOI18N
172: }
173: }
|