< prev index next >

test/lib/jdk/test/lib/Platform.java

Print this page
rev 51542 : 8210039: move OSInfo to top level testlibrary
Reviewed-by: duke


  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 jdk.test.lib;
  25 
  26 import java.io.File;
  27 import java.io.IOException;
  28 import java.io.RandomAccessFile;
  29 import java.util.Arrays;
  30 import java.util.List;
  31 import java.util.Objects;
  32 import java.util.regex.Pattern;
  33 import java.util.stream.Collectors;
  34 
  35 public class Platform {
  36     public  static final String vmName      = System.getProperty("java.vm.name");
  37     public  static final String vmInfo      = System.getProperty("java.vm.info");
  38     private static final String osVersion   = System.getProperty("os.version");
  39     private static       String[] osVersionTokens;
  40     private static       int osVersionMajor = -1;
  41     private static       int osVersionMinor = -1;
  42     private static final String osName      = System.getProperty("os.name");
  43     private static final String dataModel   = System.getProperty("sun.arch.data.model");
  44     private static final String vmVersion   = System.getProperty("java.vm.version");
  45     private static final String jdkDebug    = System.getProperty("jdk.debug");
  46     private static final String osArch      = System.getProperty("os.arch");
  47     private static final String userName    = System.getProperty("user.name");
  48     private static final String compiler    = System.getProperty("sun.management.compiler");
  49 
  50     public static boolean isClient() {
  51         return vmName.endsWith(" Client VM");
  52     }
  53 
  54     public static boolean isServer() {
  55         return vmName.endsWith(" Server VM");
  56     }
  57 
  58     public static boolean isGraal() {
  59         return vmName.endsWith(" Graal VM");


 112     }
 113 
 114     public static boolean isSolaris() {
 115         return isOs("sunos");
 116     }
 117 
 118     public static boolean isWindows() {
 119         return isOs("win");
 120     }
 121 
 122     private static boolean isOs(String osname) {
 123         return osName.toLowerCase().startsWith(osname.toLowerCase());
 124     }
 125 
 126     public static String getOsName() {
 127         return osName;
 128     }
 129 
 130     // Os version support.
 131     private static void init_version() {
 132         osVersionTokens = osVersion.split("\\.");
 133         try {
 134             if (osVersionTokens.length > 0) {
 135                 osVersionMajor = Integer.parseInt(osVersionTokens[0]);
 136                 if (osVersionTokens.length > 1) {
 137                     osVersionMinor = Integer.parseInt(osVersionTokens[1]);
 138                 }
 139             }
 140         } catch (NumberFormatException e) {
 141             osVersionMajor = osVersionMinor = 0;
 142         }
 143     }
 144 
 145     public static String getOsVersion() {
 146         return osVersion;
 147     }
 148 
 149     // Returns major version number from os.version system property.
 150     // E.g. 5 on Solaris 10 and 3 on SLES 11.3 (for the linux kernel version).
 151     public static int getOsVersionMajor() {
 152         if (osVersionMajor == -1) init_version();
 153         return osVersionMajor;
 154     }
 155 
 156     // Returns minor version number from os.version system property.
 157     // E.g. 10 on Solaris 10 and 0 on SLES 11.3 (for the linux kernel version).
 158     public static int getOsVersionMinor() {
 159         if (osVersionMinor == -1) init_version();
 160         return osVersionMinor;
 161     }
 162 
 163     /**
 164      * Compares the platform version with the supplied version. The
 165      * version must be of the form a[.b[.c[.d...]]] where a, b, c, d, ...
 166      * are decimal integers.
 167      *
 168      * @throws NullPointerException if the parameter is null
 169      * @throws NumberFormatException if there is an error parsing either
 170      *         version as split into component strings
 171      * @return -1, 0, or 1 according to whether the platform version is
 172      *         less than, equal to, or greater than the supplied version
 173      */
 174     public static int compareOsVersion(String version) {
 175         if (osVersionTokens == null) init_version();
 176 
 177         Objects.requireNonNull(version);
 178 
 179         List<Integer> s1 = Arrays
 180             .stream(osVersionTokens)
 181             .map(Integer::valueOf)
 182             .collect(Collectors.toList());
 183         List<Integer> s2 = Arrays
 184             .stream(version.split("\\."))
 185             .map(Integer::valueOf)
 186             .collect(Collectors.toList());
 187 
 188         int count = Math.max(s1.size(), s2.size());
 189         for (int i = 0; i < count; i++) {
 190             int i1 = i < s1.size() ? s1.get(i) : 0;
 191             int i2 = i < s2.size() ? s2.get(i) : 0;
 192             if (i1 > i2) {
 193                 return 1;
 194             } else if (i2 > i1) {
 195                 return -1;
 196             }
 197         }
 198 
 199         return 0;
 200     }
 201 
 202     public static boolean isDebugBuild() {
 203         return (jdkDebug.toLowerCase().contains("debug"));
 204     }
 205 
 206     public static boolean isSlowDebugBuild() {
 207         return (jdkDebug.toLowerCase().equals("slowdebug"));
 208     }
 209 
 210     public static boolean isFastDebugBuild() {
 211         return (jdkDebug.toLowerCase().equals("fastdebug"));
 212     }
 213 
 214     public static String getVMVersion() {
 215         return vmVersion;
 216     }
 217 
 218     public static boolean isAArch64() {
 219         return isArch("aarch64");
 220     }
 221 




  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 jdk.test.lib;
  25 
  26 import java.io.File;
  27 import java.io.IOException;
  28 import java.io.RandomAccessFile;
  29 import java.util.Arrays;
  30 import java.util.List;
  31 import java.util.Objects;
  32 import java.util.regex.Pattern;
  33 import java.util.stream.Collectors;
  34 
  35 public class Platform {
  36     public  static final String vmName      = System.getProperty("java.vm.name");
  37     public  static final String vmInfo      = System.getProperty("java.vm.info");
  38     private static final String osVersion   = System.getProperty("os.version");

  39     private static       int osVersionMajor = -1;
  40     private static       int osVersionMinor = -1;
  41     private static final String osName      = System.getProperty("os.name");
  42     private static final String dataModel   = System.getProperty("sun.arch.data.model");
  43     private static final String vmVersion   = System.getProperty("java.vm.version");
  44     private static final String jdkDebug    = System.getProperty("jdk.debug");
  45     private static final String osArch      = System.getProperty("os.arch");
  46     private static final String userName    = System.getProperty("user.name");
  47     private static final String compiler    = System.getProperty("sun.management.compiler");
  48 
  49     public static boolean isClient() {
  50         return vmName.endsWith(" Client VM");
  51     }
  52 
  53     public static boolean isServer() {
  54         return vmName.endsWith(" Server VM");
  55     }
  56 
  57     public static boolean isGraal() {
  58         return vmName.endsWith(" Graal VM");


 111     }
 112 
 113     public static boolean isSolaris() {
 114         return isOs("sunos");
 115     }
 116 
 117     public static boolean isWindows() {
 118         return isOs("win");
 119     }
 120 
 121     private static boolean isOs(String osname) {
 122         return osName.toLowerCase().startsWith(osname.toLowerCase());
 123     }
 124 
 125     public static String getOsName() {
 126         return osName;
 127     }
 128 
 129     // Os version support.
 130     private static void init_version() {
 131         String[] osVersionTokens = osVersion.split("\\.");
 132         try {
 133             if (osVersionTokens.length > 0) {
 134                 osVersionMajor = Integer.parseInt(osVersionTokens[0]);
 135                 if (osVersionTokens.length > 1) {
 136                     osVersionMinor = Integer.parseInt(osVersionTokens[1]);
 137                 }
 138             }
 139         } catch (NumberFormatException e) {
 140             osVersionMajor = osVersionMinor = 0;
 141         }
 142     }
 143 
 144     public static String getOsVersion() {
 145         return osVersion;
 146     }
 147 
 148     // Returns major version number from os.version system property.
 149     // E.g. 5 on Solaris 10 and 3 on SLES 11.3 (for the linux kernel version).
 150     public static int getOsVersionMajor() {
 151         if (osVersionMajor == -1) init_version();
 152         return osVersionMajor;
 153     }
 154 
 155     // Returns minor version number from os.version system property.
 156     // E.g. 10 on Solaris 10 and 0 on SLES 11.3 (for the linux kernel version).
 157     public static int getOsVersionMinor() {
 158         if (osVersionMinor == -1) init_version();
 159         return osVersionMinor;
 160     }
 161 







































 162     public static boolean isDebugBuild() {
 163         return (jdkDebug.toLowerCase().contains("debug"));
 164     }
 165 
 166     public static boolean isSlowDebugBuild() {
 167         return (jdkDebug.toLowerCase().equals("slowdebug"));
 168     }
 169 
 170     public static boolean isFastDebugBuild() {
 171         return (jdkDebug.toLowerCase().equals("fastdebug"));
 172     }
 173 
 174     public static String getVMVersion() {
 175         return vmVersion;
 176     }
 177 
 178     public static boolean isAArch64() {
 179         return isArch("aarch64");
 180     }
 181 


< prev index next >