01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.aspectwerkz.util;
05:
06: /**
07: * Detects Java JVM vendor and Java version
08: * Usage: -jvm | -java
09: * System.exit code is:
10: * 2:BEA, 1:IBM, 0:SUN
11: * MajorMinor (f.e. 15) for Java Major.Minor version or 0
12: *
13: * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur</a>
14: */
15: public class EnvironmentDetect {
16:
17: public static void main(String a[]) {
18: if (a.length < 1) {
19: usage();
20: show();
21: System.exit(-1);
22: }
23: if (a[0].equals("-jvm")) {
24: String vendor = detectJVM();
25: if (vendor.indexOf("BEA") >= 0) {
26: System.exit(2);
27: } else if (vendor.indexOf("IBM") >= 0) {
28: System.exit(1);
29: } else {
30: System.exit(0);
31: }
32: }
33: if (a[0].equals("-java")) {
34: String java = detectJava();
35: if (java.indexOf("1.5") >= 0) {
36: System.exit(15);
37: } else if (java.indexOf("1.4") >= 0) {
38: System.exit(14);
39: } else if (java.indexOf("1.3") >= 0) {
40: System.exit(13);
41: } else {
42: System.exit(0);
43: }
44: }
45: if (a.length > 1) {
46: show();
47: }
48: }
49:
50: public static String detectJVM() {
51: return System.getProperty("java.vendor").toUpperCase();
52: }
53:
54: public static String detectJava() {
55: return System.getProperty("java.version").toUpperCase();
56: }
57:
58: public static void show() {
59: System.out.println(detectJVM());
60: System.out.println(detectJava());
61: }
62:
63: public static void usage() {
64: System.out.println("Usage: -jvm | -java");
65: }
66: }
|