KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > aspectwerkz > util > EnvironmentDetect


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.aspectwerkz.util;
5
6 /**
7  * Detects Java JVM vendor and Java version
8  * Usage: -jvm | -java
9  * 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 JavaDoc a[]) {
18     if (a.length < 1) {
19       usage();
20       show();
21       System.exit(-1);
22     }
23     if (a[0].equals("-jvm")) {
24       String JavaDoc 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 JavaDoc 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 JavaDoc detectJVM() {
51     return System.getProperty("java.vendor").toUpperCase();
52   }
53
54   public static String JavaDoc 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 }
67
Popular Tags