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