001: package abbot;
002:
003: import java.util.StringTokenizer;
004:
005: /** Simple utility to figure out what platform we're on, what java version
006: * we're running.
007: */
008:
009: public class Platform {
010:
011: public static final int JAVA_1_0 = 0x1000;
012: public static final int JAVA_1_1 = 0x1100;
013: public static final int JAVA_1_2 = 0x1200;
014: public static final int JAVA_1_3 = 0x1300;
015: public static final int JAVA_1_4 = 0x1400;
016: public static final int JAVA_1_5 = 0x1500;
017: public static final int JAVA_1_6 = 0x1600;
018:
019: public static final String OS_NAME;
020: public static final String JAVA_VERSION_STRING;
021: public static final int JAVA_VERSION;
022:
023: static {
024: OS_NAME = System.getProperty("os.name");
025: JAVA_VERSION_STRING = System.getProperty("java.version");
026: JAVA_VERSION = parse(JAVA_VERSION_STRING);
027: }
028:
029: private static boolean isWindows = OS_NAME.startsWith("Windows");
030: private static boolean isWindows9X = isWindows
031: && (OS_NAME.indexOf("95") != -1
032: || OS_NAME.indexOf("98") != -1 || OS_NAME
033: .indexOf("ME") != -1);
034: private static boolean isWindowsXP = isWindows
035: && OS_NAME.indexOf("XP") != -1;
036: private static boolean isMac = System.getProperty("mrj.version") != null;
037: private static boolean isOSX = isMac
038: && OS_NAME.indexOf("OS X") != -1;
039: private static boolean isSunOS = (OS_NAME.startsWith("SunOS") || OS_NAME
040: .startsWith("Solaris"));
041: private static boolean isHPUX = OS_NAME.equals("HP-UX");
042: private static boolean isLinux = OS_NAME.equals("Linux");
043:
044: /** No instantiations. */
045: private Platform() {
046: }
047:
048: private static String strip(String number) {
049: while (number.startsWith("0") && number.length() > 1)
050: number = number.substring(1);
051: return number;
052: }
053:
054: static int parse(String vs) {
055: int version = 0;
056: try {
057: StringTokenizer st = new StringTokenizer(vs, "._");
058: version = Integer.parseInt(strip(st.nextToken())) * 0x1000;
059: version += Integer.parseInt(strip(st.nextToken())) * 0x100;
060: version += Integer.parseInt(strip(st.nextToken())) * 0x10;
061: version += Integer.parseInt(strip(st.nextToken()));
062: } catch (NumberFormatException nfe) {
063: } catch (java.util.NoSuchElementException nse) {
064: }
065: return version;
066: }
067:
068: // FIXME this isn't entirely correct, maybe should look for a motif class
069: // instead.
070: public static boolean isX11() {
071: return !isOSX && !isWindows;
072: }
073:
074: public static boolean isWindows() {
075: return isWindows;
076: }
077:
078: public static boolean isWindows9X() {
079: return isWindows9X;
080: }
081:
082: public static boolean isWindowsXP() {
083: return isWindowsXP;
084: }
085:
086: public static boolean isMacintosh() {
087: return isMac;
088: }
089:
090: public static boolean isOSX() {
091: return isOSX;
092: }
093:
094: public static boolean isSolaris() {
095: return isSunOS;
096: }
097:
098: public static boolean isHPUX() {
099: return isHPUX;
100: }
101:
102: public static boolean isLinux() {
103: return isLinux;
104: }
105:
106: public static void main(String[] args) {
107: System.out.println("Java version is " + JAVA_VERSION_STRING);
108: System.out.println("Version number is "
109: + Integer.toHexString(JAVA_VERSION));
110: System.out.println("os.name=" + OS_NAME);
111: }
112: }
|