1 /** 2 * The utillib library. 3 * More information is available at http://www.jinchess.com/. 4 * Copyright (C) 2004 Alexander Maryanovsky. 5 * All rights reserved. 6 * 7 * The utillib library is free software; you can redistribute 8 * it and/or modify it under the terms of the GNU Lesser General Public License 9 * as published by the Free Software Foundation; either version 2 of the 10 * License, or (at your option) any later version. 11 * 12 * The utillib library is distributed in the hope that it will 13 * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 15 * General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public License 18 * along with utillib library; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 */ 21 22 package free.util; 23 24 25 /** 26 * A class which contains various platform specific utilities. 27 */ 28 29 public class PlatformUtils{ 30 31 32 33 /** 34 * Returns whether the version of Java we're running in is higher than or 35 * equal to the specified version. 36 */ 37 isJavaBetterThan(String ver)38 public static boolean isJavaBetterThan(String ver){ 39 return System.getProperty("java.version").compareTo(ver) >= 0; 40 } 41 42 43 44 /** 45 * Returns whether we're running under the old (just in case there's ever a 46 * new one) Microsoft VM. 47 */ 48 isOldMicrosoftVM()49 public static boolean isOldMicrosoftVM(){ 50 String vendor = System.getProperty("java.vendor"); 51 52 return (vendor != null) && vendor.toLowerCase().startsWith("microsoft") && 53 !isJavaBetterThan("1.2"); 54 } 55 56 57 58 /** 59 * Returns whether we're running under Windows. 60 */ 61 isWindows()62 public static boolean isWindows(){ 63 String os = System.getProperty("os.name"); 64 65 return (os != null) && os.toLowerCase().startsWith("windows"); 66 } 67 68 69 70 /** 71 * Returns whether we're running under Windows 95/98/ME. 72 */ 73 isOldWindows()74 public static boolean isOldWindows(){ 75 String os = System.getProperty("os.name"); 76 77 return isWindows() && (System.getProperty("os.version").compareTo("5.0") < 0) && 78 !os.toLowerCase().startsWith("windows nt"); 79 } 80 81 82 83 /** 84 * Returns whether we're running under Linux. 85 */ 86 isLinux()87 public static boolean isLinux(){ 88 String os = System.getProperty("os.name"); 89 90 return (os != null) && os.toLowerCase().startsWith("linux"); 91 } 92 93 94 95 /** 96 * Returns whether we're running under Mac OS. 97 */ 98 isMacOS()99 public static boolean isMacOS(){ 100 String os = System.getProperty("os.name"); 101 102 return (os != null) && os.toLowerCase().startsWith("mac"); 103 } 104 105 106 107 /** 108 * Returns whether we're running under Mac OS X. 109 */ 110 isMacOSX()111 public static boolean isMacOSX(){ 112 String os = System.getProperty("os.name"); 113 114 return (os != null) && os.toLowerCase().startsWith("mac os x"); 115 } 116 117 118 119 /** 120 * Returns whether we're running under Solaris. 121 */ 122 isSolaris()123 public static boolean isSolaris(){ 124 String os = System.getProperty("os.name"); 125 126 return (os != null) && (os.toLowerCase().startsWith("solaris") || 127 os.toLowerCase().startsWith("sunos")); 128 } 129 130 131 132 /** 133 * Returns the name of the OS we're running on, out of the specified list: 134 * <ul> 135 * <li>windows 136 * <li>linux 137 * <li>macosx 138 * <li>solaris 139 * </ul> 140 * 141 * Returns <code>null</code> if we're running on an OS which is not in the 142 * above list. 143 */ 144 getOSName()145 public static String getOSName(){ 146 if (isWindows() || isOldWindows()) 147 return "windows"; 148 else if (isLinux()) 149 return "linux"; 150 else if (isMacOSX()) 151 return "macosx"; 152 else if (isSolaris()) 153 return "solaris"; 154 else 155 return null; 156 } 157 158 159 160 }