01: /**************************************************************************************
02: * Copyright (c) Jonas Bon?r, Alexandre Vasseur. All rights reserved. *
03: * http://aspectwerkz.codehaus.org *
04: * ---------------------------------------------------------------------------------- *
05: * The software in this package is published under the terms of the LGPL license *
06: * a copy of which has been included with this distribution in the license.txt file. *
07: **************************************************************************************/package org.codehaus.aspectwerkz.util;
08:
09: /**
10: * Detects Java JVM vendor and Java version
11: * Usage: -jvm | -java
12: * System.exit code is:
13: * 2:BEA, 1:IBM, 0:SUN
14: * MajorMinor (f.e. 15) for Java Major.Minor version or 0
15: *
16: * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur</a>
17: */
18: public class EnvironmentDetect {
19:
20: public static void main(String a[]) {
21: if (a.length < 1) {
22: usage();
23: show();
24: System.exit(-1);
25: }
26: if (a[0].equals("-jvm")) {
27: String vendor = detectJVM();
28: if (vendor.indexOf("BEA") >= 0) {
29: System.exit(2);
30: } else if (vendor.indexOf("IBM") >= 0) {
31: System.exit(1);
32: } else {
33: System.exit(0);
34: }
35: }
36: if (a[0].equals("-java")) {
37: String java = detectJava();
38: if (java.indexOf("1.5") >= 0) {
39: System.exit(15);
40: } else if (java.indexOf("1.4") >= 0) {
41: System.exit(14);
42: } else if (java.indexOf("1.3") >= 0) {
43: System.exit(13);
44: } else {
45: System.exit(0);
46: }
47: }
48: if (a.length > 1) {
49: show();
50: }
51: }
52:
53: public static String detectJVM() {
54: return System.getProperty("java.vendor").toUpperCase();
55: }
56:
57: public static String detectJava() {
58: return System.getProperty("java.version").toUpperCase();
59: }
60:
61: public static void show() {
62: System.out.println(detectJVM());
63: System.out.println(detectJava());
64: }
65:
66: public static void usage() {
67: System.out.println("Usage: -jvm | -java");
68: }
69: }
|