1 23 24 29 30 package com.sun.enterprise.util; 31 32 import java.io.*; 33 34 39 public class OS 40 { 41 private OS() 42 { 43 } 44 45 47 public static boolean isWindows() 48 { 49 return File.separatorChar == '\\'; 50 } 51 52 54 public static boolean isUNIX() 55 { 56 return File.separatorChar == '/'; 57 } 58 59 61 public static boolean isUnix() 62 { 63 return isUNIX(); 65 } 66 67 69 public static boolean isSun() 70 { 71 return isName("sun"); 72 } 73 74 76 public static boolean isSolaris10() 77 { 78 return isSun() && isVersion("5.10"); 79 } 80 81 83 public static boolean isSunSparc() 84 { 85 return isName("sun") && isArch("sparc"); 86 } 87 89 public static boolean isSunX86() 90 { 91 return isName("sun") && isArch("x86"); 92 } 93 94 96 public static boolean isLinux() 97 { 98 return isName("linux"); 99 } 100 101 103 public static boolean isDarwin() 104 { 105 return isName("Mac OS X"); 106 } 107 108 110 public static boolean isWindowsForSure() 111 { 112 return isName("windows") && isWindows(); 113 } 114 115 117 private static boolean isArch(String name) 118 { 119 String archname = System.getProperty("os.arch"); 120 121 if(archname == null || archname.length() <= 0) 122 return false; 123 124 archname= archname.toLowerCase(); 126 name= name.toLowerCase(); 127 128 if(archname.indexOf(name) >= 0) 129 return true; 130 131 return false; 132 } 133 134 136 private static boolean isName(String name) 137 { 138 String osname = System.getProperty("os.name"); 139 140 if(osname == null || osname.length() <= 0) 141 return false; 142 143 osname = osname.toLowerCase(); 145 name = name.toLowerCase(); 146 147 if(osname.indexOf(name) >= 0) 148 return true; 149 150 return false; 151 } 152 153 155 private static boolean isVersion(String version) 156 { 157 String osversion = System.getProperty("os.version"); 158 159 if(osversion == null || osversion.length() <= 0 || version == null || version.length() <= 0 ) 160 return false; 161 162 if(osversion.equals(version)) 163 return true; 164 165 return false; 166 } 167 168 170 public static final String WINDOWS_BATCH_FILE_EXTENSION = ".bat"; 171 172 175 public static void main(String args[]) 176 { 177 System.out.println("os.version = " + System.getProperty("os.version")); 178 System.out.println("os.name = " + System.getProperty("os.name")); 179 System.out.println("os.arch = " + System.getProperty("os.arch")); 180 System.out.println("isUNIX() returned: " + isUNIX()); 181 System.out.println("isWindows() returned: " + isWindows()); 182 System.out.println("isWindowsForSure() returned: " + isWindowsForSure()); 183 System.out.println("isSun() returned: " + isSun()); 184 System.out.println("isLinux() returned: " + isLinux()); 185 System.out.println("isSunX86() returned: " + isSunX86()); 186 System.out.println("isSunSparc() returned: " + isSunSparc()); 187 System.out.println("isDarwin() returned: " + isDarwin()); 188 System.out.println("isSolaris10() returned: " + isSolaris10()); 189 } 190 } 191 | Popular Tags |