1 /* 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package com.oracle.java.testlibrary; 25 26 public class Platform { 27 private static final String osName = System.getProperty("os.name"); 28 private static final String dataModel = System.getProperty("sun.arch.data.model"); 29 private static final String vmVersion = System.getProperty("java.vm.version"); 30 private static final String osArch = System.getProperty("os.arch"); 31 private static final String vmName = System.getProperty("java.vm.name"); 32 33 public static boolean isClient() { 34 return vmName.endsWith(" Client VM"); 35 } 36 37 public static boolean isServer() { 38 return vmName.endsWith(" Server VM"); 39 } 40 41 public static boolean is32bit() { 42 return dataModel.equals("32"); 43 } 44 45 public static boolean is64bit() { 46 return dataModel.equals("64"); 47 } 48 49 public static boolean isSolaris() { 50 return isOs("sunos"); 51 } 52 53 public static boolean isWindows() { 54 return isOs("win"); 55 } 56 57 public static boolean isOSX() { 58 return isOs("mac"); 59 } 60 61 public static boolean isLinux() { 62 return isOs("linux"); 63 } 64 65 private static boolean isOs(String osname) { 66 return osName.toLowerCase().startsWith(osname.toLowerCase()); 67 } 68 69 public static String getOsName() { 70 return osName; 71 } 72 73 public static boolean isDebugBuild() { 74 return vmVersion.toLowerCase().contains("debug"); 75 } 76 77 public static String getVMVersion() { 78 return vmVersion; 79 } 80 81 // Returns true for sparc and sparcv9. 82 public static boolean isSparc() { 83 return isArch("sparc"); 84 } 85 86 public static boolean isARM() { 87 return isArch("arm"); 88 } 89 90 public static boolean isPPC() { 91 return isArch("ppc"); 92 } 93 94 public static boolean isX86() { 95 // On Linux it's 'i386', Windows 'x86' 96 return (isArch("i386") || isArch("x86")); 97 } 98 99 public static boolean isX64() { 100 // On OSX it's 'x86_64' and on other (Linux, Windows and Solaris) platforms it's 'amd64' 101 return (isArch("amd64") || isArch("x86_64")); 102 } 103 104 private static boolean isArch(String archname) { 105 return osArch.toLowerCase().startsWith(archname.toLowerCase()); 106 } 107 108 public static String getOsArch() { 109 return osArch; 110 } 111 112 }