| 1 |
/* |
| 2 |
* Copyright 1999-2010 University of Chicago |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in |
| 5 |
* compliance with the License. You may obtain a copy of the License at |
| 6 |
* |
| 7 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
* |
| 9 |
* Unless required by applicable law or agreed to in writing, software distributed under the License is |
| 10 |
* distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 11 |
* express or implied. |
| 12 |
* |
| 13 |
* See the License for the specific language governing permissions and limitations under the License. |
| 14 |
*/ |
| 15 |
package org.globus.common; |
| 16 |
|
| 17 |
/** |
| 18 |
* This class contains version information of the JGlobus module. |
| 19 |
* The version number is composed as MAJOR.MINOR.PATCH. |
| 20 |
*/ |
| 21 |
public class Version { |
| 22 |
|
| 23 |
/** |
| 24 |
* COG version. Required to be MAJOR.MINOR.PATCH, with |
| 25 |
* format integer.integer.integer. |
| 26 |
*/ |
| 27 |
private static String COG_VERSION = "1.8.0"; |
| 28 |
|
| 29 |
/** The major release number */ |
| 30 |
public static final int MAJOR; |
| 31 |
|
| 32 |
/** The minor release number */ |
| 33 |
public static final int MINOR; |
| 34 |
|
| 35 |
/** The patchlevel of the current release */ |
| 36 |
public static final int PATCH; |
| 37 |
|
| 38 |
static { |
| 39 |
|
| 40 |
int firstDot = COG_VERSION.indexOf("."); |
| 41 |
if (firstDot == -1) { |
| 42 |
throw new IllegalArgumentException("COG version required MAJOR." |
| 43 |
+ "MINOR.PATCH. It is set as " |
| 44 |
+ COG_VERSION); |
| 45 |
} |
| 46 |
|
| 47 |
String tmp = COG_VERSION.substring(0, firstDot); |
| 48 |
if (tmp.equals("")) { |
| 49 |
throw new IllegalArgumentException("Number needed after ." + |
| 50 |
"COG version required MAJOR" |
| 51 |
+ ".MINOR.PATCH. It is set " |
| 52 |
+ "as " + COG_VERSION); |
| 53 |
} |
| 54 |
try { |
| 55 |
MAJOR = Integer.parseInt(tmp); |
| 56 |
} catch (NumberFormatException e) { |
| 57 |
throw new IllegalArgumentException("COG version numbers are" |
| 58 |
+ " required to be integers" + |
| 59 |
e.getMessage()); |
| 60 |
} |
| 61 |
|
| 62 |
int secondDot = COG_VERSION.indexOf(".", firstDot + 1); |
| 63 |
if (secondDot == -1) { |
| 64 |
PATCH = 0; |
| 65 |
tmp = COG_VERSION.substring(firstDot + 1, COG_VERSION.length()); |
| 66 |
if (tmp.equals("")) { |
| 67 |
throw new IllegalArgumentException("Number needed after . " + |
| 68 |
"COG version required " + |
| 69 |
"MAJOR.MINOR.PATCH. It " |
| 70 |
+ "is set as " + |
| 71 |
COG_VERSION); |
| 72 |
} |
| 73 |
try { |
| 74 |
MINOR = Integer.parseInt(tmp); |
| 75 |
} catch (NumberFormatException e) { |
| 76 |
throw new IllegalArgumentException("COG version numbers are" |
| 77 |
+ " required to be numbers.", e); |
| 78 |
} |
| 79 |
} else { |
| 80 |
try { |
| 81 |
MINOR = Integer.parseInt(COG_VERSION.substring(firstDot + 1, |
| 82 |
secondDot)); |
| 83 |
} catch (NumberFormatException e) { |
| 84 |
throw new IllegalArgumentException("COG version numbers are" |
| 85 |
+ " required to be numbers.", e); |
| 86 |
} |
| 87 |
|
| 88 |
try { |
| 89 |
PATCH = Integer.parseInt(COG_VERSION |
| 90 |
.substring(secondDot + 1, |
| 91 |
COG_VERSION.length())); |
| 92 |
} catch (NumberFormatException e) { |
| 93 |
throw new IllegalArgumentException("COG version numbers are" |
| 94 |
+ " required to be " |
| 95 |
+ "numbers." + |
| 96 |
e.getMessage()); |
| 97 |
} |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* Returns the current version as string in the form MAJOR.MINOR.PATCH. |
| 103 |
*/ |
| 104 |
public static String getVersion() { |
| 105 |
return getMajor() + "." + getMinor() + "." + getPatch(); |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* Returns the major release number. |
| 110 |
* |
| 111 |
* @return the major release |
| 112 |
*/ |
| 113 |
public static int getMajor() { |
| 114 |
return MAJOR; |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* Returns the minor release number. |
| 119 |
* |
| 120 |
* @return the minor release number |
| 121 |
*/ |
| 122 |
public static int getMinor() { |
| 123 |
return MINOR; |
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* Returns the patch level. |
| 128 |
* |
| 129 |
* @return the patch level |
| 130 |
*/ |
| 131 |
public static int getPatch() { |
| 132 |
return PATCH; |
| 133 |
} |
| 134 |
|
| 135 |
/** |
| 136 |
* Returns the version for the Java CoG Kit as a readble string. |
| 137 |
* |
| 138 |
* @param args |
| 139 |
*/ |
| 140 |
public static void main(String [] args) { |
| 141 |
System.out.println("Java CoG version: " + getVersion()); |
| 142 |
} |
| 143 |
|
| 144 |
} |