1 17 package org.apache.geronimo.kernel.config; 18 19 import java.util.Locale ; 20 21 26 public class Os { 27 private static final String OS_NAME = System.getProperty("os.name").toLowerCase(Locale.US); 28 private static final String OS_ARCH = System.getProperty("os.arch").toLowerCase(Locale.US); 29 private static final String OS_VERSION = System.getProperty("os.version").toLowerCase(Locale.US); 30 private static final String PATH_SEP = System.getProperty("path.separator"); 31 32 35 public static final String FAMILY_WINDOWS = "windows"; 36 39 public static final String FAMILY_9X = "win9x"; 40 43 public static final String FAMILY_NT = "winnt"; 44 47 public static final String FAMILY_OS2 = "os/2"; 48 51 public static final String FAMILY_NETWARE = "netware"; 52 55 public static final String FAMILY_DOS = "dos"; 56 59 public static final String FAMILY_MAC = "mac"; 60 63 public static final String FAMILY_TANDEM = "tandem"; 64 67 public static final String FAMILY_UNIX = "unix"; 68 71 public static final String FAMILY_VMS = "openvms"; 72 75 public static final String FAMILY_ZOS = "z/os"; 76 79 public static final String FAMILY_OS400 = "os/400"; 80 81 private Os() { 82 } 84 85 92 public static boolean isFamily(String family) { 93 return isOs(family, null, null, null); 94 } 95 96 117 public static boolean isName(String name) { 118 return isOs(null, name, null, null); 119 } 120 121 129 public static boolean isArch(String arch) { 130 return isOs(null, null, arch, null); 131 } 132 133 141 public static boolean isVersion(String version) { 142 return isOs(null, null, null, version); 143 } 144 145 156 public static boolean isOs(String family, String name, String arch, 157 String version) { 158 boolean retValue = false; 159 160 if (family != null || name != null || arch != null 161 || version != null) { 162 163 boolean isFamily = true; 164 boolean isName = true; 165 boolean isArch = true; 166 boolean isVersion = true; 167 168 if (family != null) { 169 170 boolean isWindows = OS_NAME.indexOf(FAMILY_WINDOWS) > -1; 173 boolean is9x = false; 174 boolean isNT = false; 175 if(isWindows) { 176 is9x = (OS_NAME.indexOf("95") >= 0 178 || OS_NAME.indexOf("98") >= 0 179 || OS_NAME.indexOf("me") >= 0 180 || OS_NAME.indexOf("ce") >= 0); 183 isNT = !is9x; 184 } 185 if (family.equals(FAMILY_WINDOWS)) { 186 isFamily = isWindows; 187 } else if (family.equals(FAMILY_9X)) { 188 isFamily = isWindows && is9x; 189 } else if (family.equals(FAMILY_NT)) { 190 isFamily = isWindows && isNT; 191 } else if (family.equals(FAMILY_OS2)) { 192 isFamily = OS_NAME.indexOf(FAMILY_OS2) > -1; 193 } else if (family.equals(FAMILY_NETWARE)) { 194 isFamily = OS_NAME.indexOf(FAMILY_NETWARE) > -1; 195 } else if (family.equals(FAMILY_DOS)) { 196 isFamily = PATH_SEP.equals(";") && !isFamily(FAMILY_NETWARE); 197 } else if (family.equals(FAMILY_MAC)) { 198 isFamily = OS_NAME.indexOf(FAMILY_MAC) > -1; 199 } else if (family.equals(FAMILY_TANDEM)) { 200 isFamily = OS_NAME.indexOf("nonstop_kernel") > -1; 201 } else if (family.equals(FAMILY_UNIX)) { 202 isFamily = PATH_SEP.equals(":") 203 && !isFamily(FAMILY_VMS) 204 && (!isFamily(FAMILY_MAC) || OS_NAME.endsWith("x")); 205 } else if (family.equals(FAMILY_ZOS)) { 206 isFamily = OS_NAME.indexOf(FAMILY_ZOS) > -1 207 || OS_NAME.indexOf("os/390") > -1; 208 } else if (family.equals(FAMILY_OS400)) { 209 isFamily = OS_NAME.indexOf(FAMILY_OS400) > -1; 210 } else if (family.equals(FAMILY_VMS)) { 211 isFamily = OS_NAME.indexOf(FAMILY_VMS) > -1; 212 } else { 213 throw new IllegalArgumentException ( 214 "Don\'t know how to detect os family \"" 215 + family + "\""); 216 } 217 } 218 if (name != null) { 219 isName = name.equals(OS_NAME); 220 } 221 if (arch != null) { 222 isArch = arch.equals(OS_ARCH); 223 } 224 if (version != null) { 225 isVersion = version.equals(OS_VERSION); 226 } 227 retValue = isFamily && isName && isArch && isVersion; 228 } 229 return retValue; 230 } 231 } | Popular Tags |