001: /*
002:
003: Derby - Class org.apache.derbyTesting.functionTests.harness.JavaVersionHolder
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derbyTesting.functionTests.harness;
023:
024: import java.util.StringTokenizer;
025:
026: /**
027: To break down the java version into major and minor
028: Used by the test harness for special cases
029: */
030: public class JavaVersionHolder {
031:
032: private String majorVersion;
033: private String minorVersion;
034: private int major;
035: private int minor;
036:
037: public JavaVersionHolder(String javaVersion)
038: throws java.lang.NumberFormatException {
039: // check for jdk12 or higher
040: int i = javaVersion.indexOf('.');
041: int j = javaVersion.indexOf('.', i + 1);
042: majorVersion = javaVersion.substring(0, i);
043: try {
044: Integer imajor = new Integer(majorVersion);
045: major = imajor.intValue();
046: if (j != -1) {
047: minorVersion = javaVersion.substring(i + 1, j);
048: Integer iminor = new Integer(minorVersion);
049: minor = iminor.intValue();
050: } else {
051: minorVersion = javaVersion.substring(i + 1);
052: Integer iminor = new Integer(minorVersion);
053: minor = iminor.intValue();
054: }
055: } catch (NumberFormatException nfe) {
056: // Cannot parse the version as an Integer
057: // such as on HP: hack for this special case
058: if (javaVersion.startsWith("HP")) {
059: // attempt to get the version
060: StringTokenizer st = new StringTokenizer(javaVersion,
061: ".");
062: String tmp = st.nextToken();
063: majorVersion = st.nextToken();
064: if (majorVersion.equals("01"))
065: majorVersion = "1";
066: else if (majorVersion.equals("02"))
067: majorVersion = "2";
068: minorVersion = st.nextToken();
069: if (minorVersion.startsWith("1"))
070: minorVersion = "1";
071: else if (minorVersion.startsWith("2"))
072: minorVersion = "2";
073: //System.out.println("majorVersion: " + majorVersion);
074: //System.out.println("minorVersion: " + minorVersion);
075: try {
076: Integer imajor = new Integer(majorVersion);
077: major = imajor.intValue();
078: Integer iminor = new Integer(minorVersion);
079: minor = iminor.intValue();
080: } catch (NumberFormatException nfe2) {
081: System.out.println("Could not parse version: "
082: + nfe2);
083: // Still couldn't parse the vesion
084: // have to give up
085: }
086: } else {
087: System.out
088: .println("NumberFormatException thrown trying to parse the version. "
089: + javaVersion);
090: System.out
091: .println("The test harness only handles the HP special case.");
092: }
093:
094: }
095: }
096:
097: public String getMajorVersion() {
098: return majorVersion;
099: }
100:
101: public String getMinorVersion() {
102: return minorVersion;
103: }
104:
105: public int getMajorNumber() {
106: return major;
107: }
108:
109: public int getMinorNumber() {
110: return minor;
111: }
112:
113: /**
114: * <p>
115: * Return true if we are at least at the passed in version.
116: * </p>
117: */
118: public boolean atLeast(int baseMajor, int baseMinor) {
119: if (major < baseMajor) {
120: return false;
121: }
122: if (major > baseMajor) {
123: return true;
124: }
125:
126: // same major number
127:
128: return (minor >= baseMinor);
129: }
130:
131: }
|