Coverage Report - org.apache.commons.lang3.SystemUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
SystemUtils
97%
119/122
90%
18/20
2,067
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.commons.lang3;
 18  
 
 19  
 import java.io.File;
 20  
 
 21  
 /**
 22  
  * <p>
 23  
  * Helpers for {@code java.lang.System}.
 24  
  * </p>
 25  
  * <p>
 26  
  * If a system property cannot be read due to security restrictions, the corresponding field in this class will be set
 27  
  * to {@code null} and a message will be written to {@code System.err}.
 28  
  * </p>
 29  
  * <p>
 30  
  * #ThreadSafe#
 31  
  * </p>
 32  
  *
 33  
  * @since 1.0
 34  
  */
 35  
 public class SystemUtils {
 36  
 
 37  
     /**
 38  
      * The prefix String for all Windows OS.
 39  
      */
 40  
     private static final String OS_NAME_WINDOWS_PREFIX = "Windows";
 41  
 
 42  
     // System property constants
 43  
     // -----------------------------------------------------------------------
 44  
     // These MUST be declared first. Other constants depend on this.
 45  
 
 46  
     /**
 47  
      * The System property key for the user home directory.
 48  
      */
 49  
     private static final String USER_HOME_KEY = "user.home";
 50  
 
 51  
     /**
 52  
      * The System property key for the user directory.
 53  
      */
 54  
     private static final String USER_DIR_KEY = "user.dir";
 55  
 
 56  
     /**
 57  
      * The System property key for the Java IO temporary directory.
 58  
      */
 59  
     private static final String JAVA_IO_TMPDIR_KEY = "java.io.tmpdir";
 60  
 
 61  
     /**
 62  
      * The System property key for the Java home directory.
 63  
      */
 64  
     private static final String JAVA_HOME_KEY = "java.home";
 65  
 
 66  
     /**
 67  
      * <p>
 68  
      * The {@code awt.toolkit} System Property.
 69  
      * </p>
 70  
      * <p>
 71  
      * Holds a class name, on Windows XP this is {@code sun.awt.windows.WToolkit}.
 72  
      * </p>
 73  
      * <p>
 74  
      * <b>On platforms without a GUI, this value is {@code null}.</b>
 75  
      * </p>
 76  
      * <p>
 77  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 78  
      * not exist.
 79  
      * </p>
 80  
      * <p>
 81  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 82  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 83  
      * sync with that System property.
 84  
      * </p>
 85  
      *
 86  
      * @since 2.1
 87  
      */
 88  1
     public static final String AWT_TOOLKIT = getSystemProperty("awt.toolkit");
 89  
 
 90  
     /**
 91  
      * <p>
 92  
      * The {@code file.encoding} System Property.
 93  
      * </p>
 94  
      * <p>
 95  
      * File encoding, such as {@code Cp1252}.
 96  
      * </p>
 97  
      * <p>
 98  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 99  
      * not exist.
 100  
      * </p>
 101  
      * <p>
 102  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 103  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 104  
      * sync with that System property.
 105  
      * </p>
 106  
      *
 107  
      * @since 2.0
 108  
      * @since Java 1.2
 109  
      */
 110  1
     public static final String FILE_ENCODING = getSystemProperty("file.encoding");
 111  
 
 112  
     /**
 113  
      * <p>
 114  
      * The {@code file.separator} System Property.
 115  
      * The file separator is:
 116  
      * </p>
 117  
      * <ul>
 118  
      * <li>{@code "/"} on UNIX</li>
 119  
      * <li>{@code "\"} on Windows.</li>
 120  
      * </ul>
 121  
      *
 122  
      * <p>
 123  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 124  
      * not exist.
 125  
      * </p>
 126  
      * <p>
 127  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 128  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 129  
      * sync with that System property.
 130  
      * </p>
 131  
      *
 132  
      * @since Java 1.1
 133  
      */
 134  1
     public static final String FILE_SEPARATOR = getSystemProperty("file.separator");
 135  
 
 136  
     /**
 137  
      * <p>
 138  
      * The {@code java.awt.fonts} System Property.
 139  
      * </p>
 140  
      * <p>
 141  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 142  
      * not exist.
 143  
      * </p>
 144  
      * <p>
 145  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 146  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 147  
      * sync with that System property.
 148  
      * </p>
 149  
      *
 150  
      * @since 2.1
 151  
      */
 152  1
     public static final String JAVA_AWT_FONTS = getSystemProperty("java.awt.fonts");
 153  
 
 154  
     /**
 155  
      * <p>
 156  
      * The {@code java.awt.graphicsenv} System Property.
 157  
      * </p>
 158  
      * <p>
 159  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 160  
      * not exist.
 161  
      * </p>
 162  
      * <p>
 163  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 164  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 165  
      * sync with that System property.
 166  
      * </p>
 167  
      *
 168  
      * @since 2.1
 169  
      */
 170  1
     public static final String JAVA_AWT_GRAPHICSENV = getSystemProperty("java.awt.graphicsenv");
 171  
 
 172  
     /**
 173  
      * <p>
 174  
      * The {@code java.awt.headless} System Property. The value of this property is the String {@code "true"} or
 175  
      * {@code "false"}.
 176  
      * </p>
 177  
      * <p>
 178  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 179  
      * not exist.
 180  
      * </p>
 181  
      * <p>
 182  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 183  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 184  
      * sync with that System property.
 185  
      * </p>
 186  
      *
 187  
      * @see #isJavaAwtHeadless()
 188  
      * @since 2.1
 189  
      * @since Java 1.4
 190  
      */
 191  1
     public static final String JAVA_AWT_HEADLESS = getSystemProperty("java.awt.headless");
 192  
 
 193  
     /**
 194  
      * <p>
 195  
      * The {@code java.awt.printerjob} System Property.
 196  
      * </p>
 197  
      * <p>
 198  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 199  
      * not exist.
 200  
      * </p>
 201  
      * <p>
 202  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 203  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 204  
      * sync with that System property.
 205  
      * </p>
 206  
      *
 207  
      * @since 2.1
 208  
      */
 209  1
     public static final String JAVA_AWT_PRINTERJOB = getSystemProperty("java.awt.printerjob");
 210  
 
 211  
     /**
 212  
      * <p>
 213  
      * The {@code java.class.path} System Property. Java class path.
 214  
      * </p>
 215  
      * <p>
 216  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 217  
      * not exist.
 218  
      * </p>
 219  
      * <p>
 220  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 221  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 222  
      * sync with that System property.
 223  
      * </p>
 224  
      *
 225  
      * @since Java 1.1
 226  
      */
 227  1
     public static final String JAVA_CLASS_PATH = getSystemProperty("java.class.path");
 228  
 
 229  
     /**
 230  
      * <p>
 231  
      * The {@code java.class.version} System Property. Java class format version number.
 232  
      * </p>
 233  
      * <p>
 234  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 235  
      * not exist.
 236  
      * </p>
 237  
      * <p>
 238  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 239  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 240  
      * sync with that System property.
 241  
      * </p>
 242  
      *
 243  
      * @since Java 1.1
 244  
      */
 245  1
     public static final String JAVA_CLASS_VERSION = getSystemProperty("java.class.version");
 246  
 
 247  
     /**
 248  
      * <p>
 249  
      * The {@code java.compiler} System Property. Name of JIT compiler to use. First in JDK version 1.2. Not used in Sun
 250  
      * JDKs after 1.2.
 251  
      * </p>
 252  
      * <p>
 253  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 254  
      * not exist.
 255  
      * </p>
 256  
      * <p>
 257  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 258  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 259  
      * sync with that System property.
 260  
      * </p>
 261  
      *
 262  
      * @since Java 1.2. Not used in Sun versions after 1.2.
 263  
      */
 264  1
     public static final String JAVA_COMPILER = getSystemProperty("java.compiler");
 265  
 
 266  
     /**
 267  
      * <p>
 268  
      * The {@code java.endorsed.dirs} System Property. Path of endorsed directory or directories.
 269  
      * </p>
 270  
      * <p>
 271  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 272  
      * not exist.
 273  
      * </p>
 274  
      * <p>
 275  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 276  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 277  
      * sync with that System property.
 278  
      * </p>
 279  
      *
 280  
      * @since Java 1.4
 281  
      */
 282  1
     public static final String JAVA_ENDORSED_DIRS = getSystemProperty("java.endorsed.dirs");
 283  
 
 284  
     /**
 285  
      * <p>
 286  
      * The {@code java.ext.dirs} System Property. Path of extension directory or directories.
 287  
      * </p>
 288  
      * <p>
 289  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 290  
      * not exist.
 291  
      * </p>
 292  
      * <p>
 293  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 294  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 295  
      * sync with that System property.
 296  
      * </p>
 297  
      *
 298  
      * @since Java 1.3
 299  
      */
 300  1
     public static final String JAVA_EXT_DIRS = getSystemProperty("java.ext.dirs");
 301  
 
 302  
     /**
 303  
      * <p>
 304  
      * The {@code java.home} System Property. Java installation directory.
 305  
      * </p>
 306  
      * <p>
 307  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 308  
      * not exist.
 309  
      * </p>
 310  
      * <p>
 311  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 312  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 313  
      * sync with that System property.
 314  
      * </p>
 315  
      *
 316  
      * @since Java 1.1
 317  
      */
 318  1
     public static final String JAVA_HOME = getSystemProperty(JAVA_HOME_KEY);
 319  
 
 320  
     /**
 321  
      * <p>
 322  
      * The {@code java.io.tmpdir} System Property. Default temp file path.
 323  
      * </p>
 324  
      * <p>
 325  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 326  
      * not exist.
 327  
      * </p>
 328  
      * <p>
 329  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 330  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 331  
      * sync with that System property.
 332  
      * </p>
 333  
      *
 334  
      * @since Java 1.2
 335  
      */
 336  1
     public static final String JAVA_IO_TMPDIR = getSystemProperty(JAVA_IO_TMPDIR_KEY);
 337  
 
 338  
     /**
 339  
      * <p>
 340  
      * The {@code java.library.path} System Property. List of paths to search when loading libraries.
 341  
      * </p>
 342  
      * <p>
 343  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 344  
      * not exist.
 345  
      * </p>
 346  
      * <p>
 347  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 348  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 349  
      * sync with that System property.
 350  
      * </p>
 351  
      *
 352  
      * @since Java 1.2
 353  
      */
 354  1
     public static final String JAVA_LIBRARY_PATH = getSystemProperty("java.library.path");
 355  
 
 356  
     /**
 357  
      * <p>
 358  
      * The {@code java.runtime.name} System Property. Java Runtime Environment name.
 359  
      * </p>
 360  
      * <p>
 361  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 362  
      * not exist.
 363  
      * </p>
 364  
      * <p>
 365  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 366  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 367  
      * sync with that System property.
 368  
      * </p>
 369  
      *
 370  
      * @since 2.0
 371  
      * @since Java 1.3
 372  
      */
 373  1
     public static final String JAVA_RUNTIME_NAME = getSystemProperty("java.runtime.name");
 374  
 
 375  
     /**
 376  
      * <p>
 377  
      * The {@code java.runtime.version} System Property. Java Runtime Environment version.
 378  
      * </p>
 379  
      * <p>
 380  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 381  
      * not exist.
 382  
      * </p>
 383  
      * <p>
 384  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 385  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 386  
      * sync with that System property.
 387  
      * </p>
 388  
      *
 389  
      * @since 2.0
 390  
      * @since Java 1.3
 391  
      */
 392  1
     public static final String JAVA_RUNTIME_VERSION = getSystemProperty("java.runtime.version");
 393  
 
 394  
     /**
 395  
      * <p>
 396  
      * The {@code java.specification.name} System Property. Java Runtime Environment specification name.
 397  
      * </p>
 398  
      * <p>
 399  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 400  
      * not exist.
 401  
      * </p>
 402  
      * <p>
 403  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 404  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 405  
      * sync with that System property.
 406  
      * </p>
 407  
      *
 408  
      * @since Java 1.2
 409  
      */
 410  1
     public static final String JAVA_SPECIFICATION_NAME = getSystemProperty("java.specification.name");
 411  
 
 412  
     /**
 413  
      * <p>
 414  
      * The {@code java.specification.vendor} System Property. Java Runtime Environment specification vendor.
 415  
      * </p>
 416  
      * <p>
 417  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 418  
      * not exist.
 419  
      * </p>
 420  
      * <p>
 421  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 422  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 423  
      * sync with that System property.
 424  
      * </p>
 425  
      *
 426  
      * @since Java 1.2
 427  
      */
 428  1
     public static final String JAVA_SPECIFICATION_VENDOR = getSystemProperty("java.specification.vendor");
 429  
 
 430  
     /**
 431  
      * <p>
 432  
      * The {@code java.specification.version} System Property. Java Runtime Environment specification version.
 433  
      * </p>
 434  
      * <p>
 435  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 436  
      * not exist.
 437  
      * </p>
 438  
      * <p>
 439  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 440  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 441  
      * sync with that System property.
 442  
      * </p>
 443  
      *
 444  
      * @since Java 1.3
 445  
      */
 446  1
     public static final String JAVA_SPECIFICATION_VERSION = getSystemProperty("java.specification.version");
 447  1
     private static final JavaVersion JAVA_SPECIFICATION_VERSION_AS_ENUM = JavaVersion.get(JAVA_SPECIFICATION_VERSION);
 448  
 
 449  
     /**
 450  
      * <p>
 451  
      * The {@code java.util.prefs.PreferencesFactory} System Property. A class name.
 452  
      * </p>
 453  
      * <p>
 454  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 455  
      * not exist.
 456  
      * </p>
 457  
      * <p>
 458  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 459  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 460  
      * sync with that System property.
 461  
      * </p>
 462  
      *
 463  
      * @since 2.1
 464  
      * @since Java 1.4
 465  
      */
 466  1
     public static final String JAVA_UTIL_PREFS_PREFERENCES_FACTORY =
 467  
         getSystemProperty("java.util.prefs.PreferencesFactory");
 468  
 
 469  
     /**
 470  
      * <p>
 471  
      * The {@code java.vendor} System Property. Java vendor-specific string.
 472  
      * </p>
 473  
      * <p>
 474  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 475  
      * not exist.
 476  
      * </p>
 477  
      * <p>
 478  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 479  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 480  
      * sync with that System property.
 481  
      * </p>
 482  
      *
 483  
      * @since Java 1.1
 484  
      */
 485  1
     public static final String JAVA_VENDOR = getSystemProperty("java.vendor");
 486  
 
 487  
     /**
 488  
      * <p>
 489  
      * The {@code java.vendor.url} System Property. Java vendor URL.
 490  
      * </p>
 491  
      * <p>
 492  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 493  
      * not exist.
 494  
      * </p>
 495  
      * <p>
 496  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 497  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 498  
      * sync with that System property.
 499  
      * </p>
 500  
      *
 501  
      * @since Java 1.1
 502  
      */
 503  1
     public static final String JAVA_VENDOR_URL = getSystemProperty("java.vendor.url");
 504  
 
 505  
     /**
 506  
      * <p>
 507  
      * The {@code java.version} System Property. Java version number.
 508  
      * </p>
 509  
      * <p>
 510  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 511  
      * not exist.
 512  
      * </p>
 513  
      * <p>
 514  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 515  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 516  
      * sync with that System property.
 517  
      * </p>
 518  
      *
 519  
      * @since Java 1.1
 520  
      */
 521  1
     public static final String JAVA_VERSION = getSystemProperty("java.version");
 522  
 
 523  
     /**
 524  
      * <p>
 525  
      * The {@code java.vm.info} System Property. Java Virtual Machine implementation info.
 526  
      * </p>
 527  
      * <p>
 528  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 529  
      * not exist.
 530  
      * </p>
 531  
      * <p>
 532  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 533  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 534  
      * sync with that System property.
 535  
      * </p>
 536  
      *
 537  
      * @since 2.0
 538  
      * @since Java 1.2
 539  
      */
 540  1
     public static final String JAVA_VM_INFO = getSystemProperty("java.vm.info");
 541  
 
 542  
     /**
 543  
      * <p>
 544  
      * The {@code java.vm.name} System Property. Java Virtual Machine implementation name.
 545  
      * </p>
 546  
      * <p>
 547  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 548  
      * not exist.
 549  
      * </p>
 550  
      * <p>
 551  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 552  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 553  
      * sync with that System property.
 554  
      * </p>
 555  
      *
 556  
      * @since Java 1.2
 557  
      */
 558  1
     public static final String JAVA_VM_NAME = getSystemProperty("java.vm.name");
 559  
 
 560  
     /**
 561  
      * <p>
 562  
      * The {@code java.vm.specification.name} System Property. Java Virtual Machine specification name.
 563  
      * </p>
 564  
      * <p>
 565  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 566  
      * not exist.
 567  
      * </p>
 568  
      * <p>
 569  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 570  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 571  
      * sync with that System property.
 572  
      * </p>
 573  
      *
 574  
      * @since Java 1.2
 575  
      */
 576  1
     public static final String JAVA_VM_SPECIFICATION_NAME = getSystemProperty("java.vm.specification.name");
 577  
 
 578  
     /**
 579  
      * <p>
 580  
      * The {@code java.vm.specification.vendor} System Property. Java Virtual Machine specification vendor.
 581  
      * </p>
 582  
      * <p>
 583  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 584  
      * not exist.
 585  
      * </p>
 586  
      * <p>
 587  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 588  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 589  
      * sync with that System property.
 590  
      * </p>
 591  
      *
 592  
      * @since Java 1.2
 593  
      */
 594  1
     public static final String JAVA_VM_SPECIFICATION_VENDOR = getSystemProperty("java.vm.specification.vendor");
 595  
 
 596  
     /**
 597  
      * <p>
 598  
      * The {@code java.vm.specification.version} System Property. Java Virtual Machine specification version.
 599  
      * </p>
 600  
      * <p>
 601  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 602  
      * not exist.
 603  
      * </p>
 604  
      * <p>
 605  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 606  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 607  
      * sync with that System property.
 608  
      * </p>
 609  
      *
 610  
      * @since Java 1.2
 611  
      */
 612  1
     public static final String JAVA_VM_SPECIFICATION_VERSION = getSystemProperty("java.vm.specification.version");
 613  
 
 614  
     /**
 615  
      * <p>
 616  
      * The {@code java.vm.vendor} System Property. Java Virtual Machine implementation vendor.
 617  
      * </p>
 618  
      * <p>
 619  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 620  
      * not exist.
 621  
      * </p>
 622  
      * <p>
 623  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 624  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 625  
      * sync with that System property.
 626  
      * </p>
 627  
      *
 628  
      * @since Java 1.2
 629  
      */
 630  1
     public static final String JAVA_VM_VENDOR = getSystemProperty("java.vm.vendor");
 631  
 
 632  
     /**
 633  
      * <p>
 634  
      * The {@code java.vm.version} System Property. Java Virtual Machine implementation version.
 635  
      * </p>
 636  
      * <p>
 637  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 638  
      * not exist.
 639  
      * </p>
 640  
      * <p>
 641  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 642  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 643  
      * sync with that System property.
 644  
      * </p>
 645  
      *
 646  
      * @since Java 1.2
 647  
      */
 648  1
     public static final String JAVA_VM_VERSION = getSystemProperty("java.vm.version");
 649  
 
 650  
     /**
 651  
      * <p>
 652  
      * The {@code line.separator} System Property. Line separator (<code>&quot;\n&quot;</code> on UNIX).
 653  
      * </p>
 654  
      * <p>
 655  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 656  
      * not exist.
 657  
      * </p>
 658  
      * <p>
 659  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 660  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 661  
      * sync with that System property.
 662  
      * </p>
 663  
      *
 664  
      * @since Java 1.1
 665  
      */
 666  1
     public static final String LINE_SEPARATOR = getSystemProperty("line.separator");
 667  
 
 668  
     /**
 669  
      * <p>
 670  
      * The {@code os.arch} System Property. Operating system architecture.
 671  
      * </p>
 672  
      * <p>
 673  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 674  
      * not exist.
 675  
      * </p>
 676  
      * <p>
 677  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 678  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 679  
      * sync with that System property.
 680  
      * </p>
 681  
      *
 682  
      * @since Java 1.1
 683  
      */
 684  1
     public static final String OS_ARCH = getSystemProperty("os.arch");
 685  
 
 686  
     /**
 687  
      * <p>
 688  
      * The {@code os.name} System Property. Operating system name.
 689  
      * </p>
 690  
      * <p>
 691  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 692  
      * not exist.
 693  
      * </p>
 694  
      * <p>
 695  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 696  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 697  
      * sync with that System property.
 698  
      * </p>
 699  
      *
 700  
      * @since Java 1.1
 701  
      */
 702  1
     public static final String OS_NAME = getSystemProperty("os.name");
 703  
 
 704  
     /**
 705  
      * <p>
 706  
      * The {@code os.version} System Property. Operating system version.
 707  
      * </p>
 708  
      * <p>
 709  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 710  
      * not exist.
 711  
      * </p>
 712  
      * <p>
 713  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 714  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 715  
      * sync with that System property.
 716  
      * </p>
 717  
      *
 718  
      * @since Java 1.1
 719  
      */
 720  1
     public static final String OS_VERSION = getSystemProperty("os.version");
 721  
 
 722  
     /**
 723  
      * <p>
 724  
      * The {@code path.separator} System Property. Path separator (<code>&quot;:&quot;</code> on UNIX).
 725  
      * </p>
 726  
      * <p>
 727  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 728  
      * not exist.
 729  
      * </p>
 730  
      * <p>
 731  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 732  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 733  
      * sync with that System property.
 734  
      * </p>
 735  
      *
 736  
      * @since Java 1.1
 737  
      */
 738  1
     public static final String PATH_SEPARATOR = getSystemProperty("path.separator");
 739  
 
 740  
     /**
 741  
      * <p>
 742  
      * The {@code user.country} or {@code user.region} System Property. User's country code, such as {@code GB}. First
 743  
      * in Java version 1.2 as {@code user.region}. Renamed to {@code user.country} in 1.4
 744  
      * </p>
 745  
      * <p>
 746  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 747  
      * not exist.
 748  
      * </p>
 749  
      * <p>
 750  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 751  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 752  
      * sync with that System property.
 753  
      * </p>
 754  
      *
 755  
      * @since 2.0
 756  
      * @since Java 1.2
 757  
      */
 758  1
     public static final String USER_COUNTRY = getSystemProperty("user.country") == null ?
 759  
             getSystemProperty("user.region") : getSystemProperty("user.country");
 760  
 
 761  
     /**
 762  
      * <p>
 763  
      * The {@code user.dir} System Property. User's current working directory.
 764  
      * </p>
 765  
      * <p>
 766  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 767  
      * not exist.
 768  
      * </p>
 769  
      * <p>
 770  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 771  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 772  
      * sync with that System property.
 773  
      * </p>
 774  
      *
 775  
      * @since Java 1.1
 776  
      */
 777  1
     public static final String USER_DIR = getSystemProperty(USER_DIR_KEY);
 778  
 
 779  
     /**
 780  
      * <p>
 781  
      * The {@code user.home} System Property. User's home directory.
 782  
      * </p>
 783  
      * <p>
 784  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 785  
      * not exist.
 786  
      * </p>
 787  
      * <p>
 788  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 789  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 790  
      * sync with that System property.
 791  
      * </p>
 792  
      *
 793  
      * @since Java 1.1
 794  
      */
 795  1
     public static final String USER_HOME = getSystemProperty(USER_HOME_KEY);
 796  
 
 797  
     /**
 798  
      * <p>
 799  
      * The {@code user.language} System Property. User's language code, such as {@code "en"}.
 800  
      * </p>
 801  
      * <p>
 802  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 803  
      * not exist.
 804  
      * </p>
 805  
      * <p>
 806  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 807  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 808  
      * sync with that System property.
 809  
      * </p>
 810  
      *
 811  
      * @since 2.0
 812  
      * @since Java 1.2
 813  
      */
 814  1
     public static final String USER_LANGUAGE = getSystemProperty("user.language");
 815  
 
 816  
     /**
 817  
      * <p>
 818  
      * The {@code user.name} System Property. User's account name.
 819  
      * </p>
 820  
      * <p>
 821  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 822  
      * not exist.
 823  
      * </p>
 824  
      * <p>
 825  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 826  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 827  
      * sync with that System property.
 828  
      * </p>
 829  
      *
 830  
      * @since Java 1.1
 831  
      */
 832  1
     public static final String USER_NAME = getSystemProperty("user.name");
 833  
 
 834  
     /**
 835  
      * <p>
 836  
      * The {@code user.timezone} System Property. For example: {@code "America/Los_Angeles"}.
 837  
      * </p>
 838  
      * <p>
 839  
      * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
 840  
      * not exist.
 841  
      * </p>
 842  
      * <p>
 843  
      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
 844  
      * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
 845  
      * sync with that System property.
 846  
      * </p>
 847  
      *
 848  
      * @since 2.1
 849  
      */
 850  1
     public static final String USER_TIMEZONE = getSystemProperty("user.timezone");
 851  
 
 852  
     // Java version checks
 853  
     // -----------------------------------------------------------------------
 854  
     // These MUST be declared after those above as they depend on the
 855  
     // values being set up
 856  
 
 857  
     /**
 858  
      * <p>
 859  
      * Is {@code true} if this is Java version 1.1 (also 1.1.x versions).
 860  
      * </p>
 861  
      * <p>
 862  
      * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
 863  
      * </p>
 864  
      */
 865  1
     public static final boolean IS_JAVA_1_1 = getJavaVersionMatches("1.1");
 866  
 
 867  
     /**
 868  
      * <p>
 869  
      * Is {@code true} if this is Java version 1.2 (also 1.2.x versions).
 870  
      * </p>
 871  
      * <p>
 872  
      * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
 873  
      * </p>
 874  
      */
 875  1
     public static final boolean IS_JAVA_1_2 = getJavaVersionMatches("1.2");
 876  
 
 877  
     /**
 878  
      * <p>
 879  
      * Is {@code true} if this is Java version 1.3 (also 1.3.x versions).
 880  
      * </p>
 881  
      * <p>
 882  
      * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
 883  
      * </p>
 884  
      */
 885  1
     public static final boolean IS_JAVA_1_3 = getJavaVersionMatches("1.3");
 886  
 
 887  
     /**
 888  
      * <p>
 889  
      * Is {@code true} if this is Java version 1.4 (also 1.4.x versions).
 890  
      * </p>
 891  
      * <p>
 892  
      * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
 893  
      * </p>
 894  
      */
 895  1
     public static final boolean IS_JAVA_1_4 = getJavaVersionMatches("1.4");
 896  
 
 897  
     /**
 898  
      * <p>
 899  
      * Is {@code true} if this is Java version 1.5 (also 1.5.x versions).
 900  
      * </p>
 901  
      * <p>
 902  
      * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
 903  
      * </p>
 904  
      */
 905  1
     public static final boolean IS_JAVA_1_5 = getJavaVersionMatches("1.5");
 906  
 
 907  
     /**
 908  
      * <p>
 909  
      * Is {@code true} if this is Java version 1.6 (also 1.6.x versions).
 910  
      * </p>
 911  
      * <p>
 912  
      * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
 913  
      * </p>
 914  
      */
 915  1
     public static final boolean IS_JAVA_1_6 = getJavaVersionMatches("1.6");
 916  
 
 917  
     /**
 918  
      * <p>
 919  
      * Is {@code true} if this is Java version 1.7 (also 1.7.x versions).
 920  
      * </p>
 921  
      * <p>
 922  
      * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
 923  
      * </p>
 924  
      *
 925  
      * @since 3.0
 926  
      */
 927  1
     public static final boolean IS_JAVA_1_7 = getJavaVersionMatches("1.7");
 928  
 
 929  
     /**
 930  
      * <p>
 931  
      * Is {@code true} if this is Java version 1.8 (also 1.8.x versions).
 932  
      * </p>
 933  
      * <p>
 934  
      * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
 935  
      * </p>
 936  
      *
 937  
      * @since 3.3.2
 938  
      */
 939  1
     public static final boolean IS_JAVA_1_8 = getJavaVersionMatches("1.8");
 940  
 
 941  
     /**
 942  
      * <p>
 943  
      * Is {@code true} if this is Java version 1.9 (also 1.9.x versions).
 944  
      * </p>
 945  
      * <p>
 946  
      * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
 947  
      * </p>
 948  
      *
 949  
      * @since 3.4
 950  
      */
 951  1
     public static final boolean IS_JAVA_1_9 = getJavaVersionMatches("1.9");
 952  
 
 953  
     // Operating system checks
 954  
     // -----------------------------------------------------------------------
 955  
     // These MUST be declared after those above as they depend on the
 956  
     // values being set up
 957  
     // OS names from http://www.vamphq.com/os.html
 958  
     // Selected ones included - please advise dev@commons.apache.org
 959  
     // if you want another added or a mistake corrected
 960  
 
 961  
     /**
 962  
      * <p>
 963  
      * Is {@code true} if this is AIX.
 964  
      * </p>
 965  
      * <p>
 966  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 967  
      * </p>
 968  
      *
 969  
      * @since 2.0
 970  
      */
 971  1
     public static final boolean IS_OS_AIX = getOSMatchesName("AIX");
 972  
 
 973  
     /**
 974  
      * <p>
 975  
      * Is {@code true} if this is HP-UX.
 976  
      * </p>
 977  
      * <p>
 978  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 979  
      * </p>
 980  
      *
 981  
      * @since 2.0
 982  
      */
 983  1
     public static final boolean IS_OS_HP_UX = getOSMatchesName("HP-UX");
 984  
 
 985  
     /**
 986  
      * <p>
 987  
      * Is {@code true} if this is IBM OS/400.
 988  
      * </p>
 989  
      * <p>
 990  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 991  
      * </p>
 992  
      *
 993  
      * @since 3.3
 994  
      */
 995  1
     public static final boolean IS_OS_400 = getOSMatchesName("OS/400");
 996  
 
 997  
     /**
 998  
      * <p>
 999  
      * Is {@code true} if this is Irix.
 1000  
      * </p>
 1001  
      * <p>
 1002  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1003  
      * </p>
 1004  
      *
 1005  
      * @since 2.0
 1006  
      */
 1007  1
     public static final boolean IS_OS_IRIX = getOSMatchesName("Irix");
 1008  
 
 1009  
     /**
 1010  
      * <p>
 1011  
      * Is {@code true} if this is Linux.
 1012  
      * </p>
 1013  
      * <p>
 1014  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1015  
      * </p>
 1016  
      *
 1017  
      * @since 2.0
 1018  
      */
 1019  1
     public static final boolean IS_OS_LINUX = getOSMatchesName("Linux") || getOSMatchesName("LINUX");
 1020  
 
 1021  
     /**
 1022  
      * <p>
 1023  
      * Is {@code true} if this is Mac.
 1024  
      * </p>
 1025  
      * <p>
 1026  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1027  
      * </p>
 1028  
      *
 1029  
      * @since 2.0
 1030  
      */
 1031  1
     public static final boolean IS_OS_MAC = getOSMatchesName("Mac");
 1032  
 
 1033  
     /**
 1034  
      * <p>
 1035  
      * Is {@code true} if this is Mac.
 1036  
      * </p>
 1037  
      * <p>
 1038  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1039  
      * </p>
 1040  
      *
 1041  
      * @since 2.0
 1042  
      */
 1043  1
     public static final boolean IS_OS_MAC_OSX = getOSMatchesName("Mac OS X");
 1044  
 
 1045  
     /**
 1046  
      * <p>
 1047  
      * Is {@code true} if this is Mac OS X Cheetah.
 1048  
      * </p>
 1049  
      * <p>
 1050  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1051  
      * </p>
 1052  
      *
 1053  
      * @since 3.4
 1054  
      */
 1055  1
     public static final boolean IS_OS_MAC_OSX_CHEETAH = getOSMatches("Mac OS X", "10.0");
 1056  
 
 1057  
     /**
 1058  
      * <p>
 1059  
      * Is {@code true} if this is Mac OS X Puma.
 1060  
      * </p>
 1061  
      * <p>
 1062  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1063  
      * </p>
 1064  
      *
 1065  
      * @since 3.4
 1066  
      */
 1067  1
     public static final boolean IS_OS_MAC_OSX_PUMA = getOSMatches("Mac OS X", "10.1");
 1068  
 
 1069  
     /**
 1070  
      * <p>
 1071  
      * Is {@code true} if this is Mac OS X Jaguar.
 1072  
      * </p>
 1073  
      * <p>
 1074  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1075  
      * </p>
 1076  
      *
 1077  
      * @since 3.4
 1078  
      */
 1079  1
     public static final boolean IS_OS_MAC_OSX_JAGUAR = getOSMatches("Mac OS X", "10.2");
 1080  
 
 1081  
     /**
 1082  
      * <p>
 1083  
      * Is {@code true} if this is Mac OS X Panther.
 1084  
      * </p>
 1085  
      * <p>
 1086  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1087  
      * </p>
 1088  
      *
 1089  
      * @since 3.4
 1090  
      */
 1091  1
     public static final boolean IS_OS_MAC_OSX_PANTHER = getOSMatches("Mac OS X", "10.3");
 1092  
 
 1093  
     /**
 1094  
      * <p>
 1095  
      * Is {@code true} if this is Mac OS X Tiger.
 1096  
      * </p>
 1097  
      * <p>
 1098  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1099  
      * </p>
 1100  
      *
 1101  
      * @since 3.4
 1102  
      */
 1103  1
     public static final boolean IS_OS_MAC_OSX_TIGER = getOSMatches("Mac OS X", "10.4");
 1104  
 
 1105  
     /**
 1106  
      * <p>
 1107  
      * Is {@code true} if this is Mac OS X Leopard.
 1108  
      * </p>
 1109  
      * <p>
 1110  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1111  
      * </p>
 1112  
      *
 1113  
      * @since 3.4
 1114  
      */
 1115  1
     public static final boolean IS_OS_MAC_OSX_LEOPARD = getOSMatches("Mac OS X", "10.5");
 1116  
 
 1117  
     /**
 1118  
      * <p>
 1119  
      * Is {@code true} if this is Mac OS X Snow Leopard.
 1120  
      * </p>
 1121  
      * <p>
 1122  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1123  
      * </p>
 1124  
      *
 1125  
      * @since 3.4
 1126  
      */
 1127  1
     public static final boolean IS_OS_MAC_OSX_SNOW_LEOPARD = getOSMatches("Mac OS X", "10.6");
 1128  
 
 1129  
     /**
 1130  
      * <p>
 1131  
      * Is {@code true} if this is Mac OS X Lion.
 1132  
      * </p>
 1133  
      * <p>
 1134  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1135  
      * </p>
 1136  
      *
 1137  
      * @since 3.4
 1138  
      */
 1139  1
     public static final boolean IS_OS_MAC_OSX_LION = getOSMatches("Mac OS X", "10.7");
 1140  
 
 1141  
     /**
 1142  
      * <p>
 1143  
      * Is {@code true} if this is Mac OS X Mountain Lion.
 1144  
      * </p>
 1145  
      * <p>
 1146  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1147  
      * </p>
 1148  
      *
 1149  
      * @since 3.4
 1150  
      */
 1151  1
     public static final boolean IS_OS_MAC_OSX_MOUNTAIN_LION = getOSMatches("Mac OS X", "10.8");
 1152  
 
 1153  
     /**
 1154  
      * <p>
 1155  
      * Is {@code true} if this is Mac OS X Mavericks.
 1156  
      * </p>
 1157  
      * <p>
 1158  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1159  
      * </p>
 1160  
      *
 1161  
      * @since 3.4
 1162  
      */
 1163  1
     public static final boolean IS_OS_MAC_OSX_MAVERICKS = getOSMatches("Mac OS X", "10.9");
 1164  
 
 1165  
     /**
 1166  
      * <p>
 1167  
      * Is {@code true} if this is Mac OS X Yosemite.
 1168  
      * </p>
 1169  
      * <p>
 1170  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1171  
      * </p>
 1172  
      *
 1173  
      * @since 3.4
 1174  
      */
 1175  1
     public static final boolean IS_OS_MAC_OSX_YOSEMITE = getOSMatches("Mac OS X", "10.10");
 1176  
 
 1177  
     /**
 1178  
      * <p>
 1179  
      * Is {@code true} if this is FreeBSD.
 1180  
      * </p>
 1181  
      * <p>
 1182  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1183  
      * </p>
 1184  
      *
 1185  
      * @since 3.1
 1186  
      */
 1187  1
     public static final boolean IS_OS_FREE_BSD = getOSMatchesName("FreeBSD");
 1188  
 
 1189  
     /**
 1190  
      * <p>
 1191  
      * Is {@code true} if this is OpenBSD.
 1192  
      * </p>
 1193  
      * <p>
 1194  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1195  
      * </p>
 1196  
      *
 1197  
      * @since 3.1
 1198  
      */
 1199  1
     public static final boolean IS_OS_OPEN_BSD = getOSMatchesName("OpenBSD");
 1200  
 
 1201  
     /**
 1202  
      * <p>
 1203  
      * Is {@code true} if this is NetBSD.
 1204  
      * </p>
 1205  
      * <p>
 1206  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1207  
      * </p>
 1208  
      *
 1209  
      * @since 3.1
 1210  
      */
 1211  1
     public static final boolean IS_OS_NET_BSD = getOSMatchesName("NetBSD");
 1212  
 
 1213  
     /**
 1214  
      * <p>
 1215  
      * Is {@code true} if this is OS/2.
 1216  
      * </p>
 1217  
      * <p>
 1218  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1219  
      * </p>
 1220  
      *
 1221  
      * @since 2.0
 1222  
      */
 1223  1
     public static final boolean IS_OS_OS2 = getOSMatchesName("OS/2");
 1224  
 
 1225  
     /**
 1226  
      * <p>
 1227  
      * Is {@code true} if this is Solaris.
 1228  
      * </p>
 1229  
      * <p>
 1230  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1231  
      * </p>
 1232  
      *
 1233  
      * @since 2.0
 1234  
      */
 1235  1
     public static final boolean IS_OS_SOLARIS = getOSMatchesName("Solaris");
 1236  
 
 1237  
     /**
 1238  
      * <p>
 1239  
      * Is {@code true} if this is SunOS.
 1240  
      * </p>
 1241  
      * <p>
 1242  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1243  
      * </p>
 1244  
      *
 1245  
      * @since 2.0
 1246  
      */
 1247  1
     public static final boolean IS_OS_SUN_OS = getOSMatchesName("SunOS");
 1248  
 
 1249  
     /**
 1250  
      * <p>
 1251  
      * Is {@code true} if this is a UNIX like system, as in any of AIX, HP-UX, Irix, Linux, MacOSX, Solaris or SUN OS.
 1252  
      * </p>
 1253  
      * <p>
 1254  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1255  
      * </p>
 1256  
      *
 1257  
      * @since 2.1
 1258  
      */
 1259  1
     public static final boolean IS_OS_UNIX = IS_OS_AIX || IS_OS_HP_UX || IS_OS_IRIX || IS_OS_LINUX || IS_OS_MAC_OSX
 1260  
             || IS_OS_SOLARIS || IS_OS_SUN_OS || IS_OS_FREE_BSD || IS_OS_OPEN_BSD || IS_OS_NET_BSD;
 1261  
 
 1262  
     /**
 1263  
      * <p>
 1264  
      * Is {@code true} if this is Windows.
 1265  
      * </p>
 1266  
      * <p>
 1267  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1268  
      * </p>
 1269  
      *
 1270  
      * @since 2.0
 1271  
      */
 1272  1
     public static final boolean IS_OS_WINDOWS = getOSMatchesName(OS_NAME_WINDOWS_PREFIX);
 1273  
 
 1274  
     /**
 1275  
      * <p>
 1276  
      * Is {@code true} if this is Windows 2000.
 1277  
      * </p>
 1278  
      * <p>
 1279  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1280  
      * </p>
 1281  
      *
 1282  
      * @since 2.0
 1283  
      */
 1284  1
     public static final boolean IS_OS_WINDOWS_2000 = getOSMatchesName(OS_NAME_WINDOWS_PREFIX + " 2000");
 1285  
 
 1286  
     /**
 1287  
      * <p>
 1288  
      * Is {@code true} if this is Windows 2003.
 1289  
      * </p>
 1290  
      * <p>
 1291  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1292  
      * </p>
 1293  
      *
 1294  
      * @since 3.1
 1295  
      */
 1296  1
     public static final boolean IS_OS_WINDOWS_2003 = getOSMatchesName(OS_NAME_WINDOWS_PREFIX + " 2003");
 1297  
 
 1298  
     /**
 1299  
      * <p>
 1300  
      * Is {@code true} if this is Windows Server 2008.
 1301  
      * </p>
 1302  
      * <p>
 1303  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1304  
      * </p>
 1305  
      *
 1306  
      * @since 3.1
 1307  
      */
 1308  1
     public static final boolean IS_OS_WINDOWS_2008 = getOSMatchesName(OS_NAME_WINDOWS_PREFIX + " Server 2008");
 1309  
 
 1310  
     /**
 1311  
      * <p>
 1312  
      * Is {@code true} if this is Windows Server 2012.
 1313  
      * </p>
 1314  
      * <p>
 1315  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1316  
      * </p>
 1317  
      *
 1318  
      * @since 3.4
 1319  
      */
 1320  1
     public static final boolean IS_OS_WINDOWS_2012 = getOSMatchesName(OS_NAME_WINDOWS_PREFIX + " Server 2012");
 1321  
 
 1322  
     /**
 1323  
      * <p>
 1324  
      * Is {@code true} if this is Windows 95.
 1325  
      * </p>
 1326  
      * <p>
 1327  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1328  
      * </p>
 1329  
      *
 1330  
      * @since 2.0
 1331  
      */
 1332  1
     public static final boolean IS_OS_WINDOWS_95 = getOSMatchesName(OS_NAME_WINDOWS_PREFIX + " 95");
 1333  
 
 1334  
     /**
 1335  
      * <p>
 1336  
      * Is {@code true} if this is Windows 98.
 1337  
      * </p>
 1338  
      * <p>
 1339  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1340  
      * </p>
 1341  
      *
 1342  
      * @since 2.0
 1343  
      */
 1344  1
     public static final boolean IS_OS_WINDOWS_98 = getOSMatchesName(OS_NAME_WINDOWS_PREFIX + " 98");
 1345  
 
 1346  
     /**
 1347  
      * <p>
 1348  
      * Is {@code true} if this is Windows ME.
 1349  
      * </p>
 1350  
      * <p>
 1351  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1352  
      * </p>
 1353  
      *
 1354  
      * @since 2.0
 1355  
      */
 1356  1
     public static final boolean IS_OS_WINDOWS_ME = getOSMatchesName(OS_NAME_WINDOWS_PREFIX + " Me");
 1357  
 
 1358  
     /**
 1359  
      * <p>
 1360  
      * Is {@code true} if this is Windows NT.
 1361  
      * </p>
 1362  
      * <p>
 1363  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1364  
      * </p>
 1365  
      *
 1366  
      * @since 2.0
 1367  
      */
 1368  1
     public static final boolean IS_OS_WINDOWS_NT = getOSMatchesName(OS_NAME_WINDOWS_PREFIX + " NT");
 1369  
 
 1370  
     /**
 1371  
      * <p>
 1372  
      * Is {@code true} if this is Windows XP.
 1373  
      * </p>
 1374  
      * <p>
 1375  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1376  
      * </p>
 1377  
      *
 1378  
      * @since 2.0
 1379  
      */
 1380  1
     public static final boolean IS_OS_WINDOWS_XP = getOSMatchesName(OS_NAME_WINDOWS_PREFIX + " XP");
 1381  
 
 1382  
     // -----------------------------------------------------------------------
 1383  
     /**
 1384  
      * <p>
 1385  
      * Is {@code true} if this is Windows Vista.
 1386  
      * </p>
 1387  
      * <p>
 1388  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1389  
      * </p>
 1390  
      *
 1391  
      * @since 2.4
 1392  
      */
 1393  1
     public static final boolean IS_OS_WINDOWS_VISTA = getOSMatchesName(OS_NAME_WINDOWS_PREFIX + " Vista");
 1394  
 
 1395  
     /**
 1396  
      * <p>
 1397  
      * Is {@code true} if this is Windows 7.
 1398  
      * </p>
 1399  
      * <p>
 1400  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1401  
      * </p>
 1402  
      *
 1403  
      * @since 3.0
 1404  
      */
 1405  1
     public static final boolean IS_OS_WINDOWS_7 = getOSMatchesName(OS_NAME_WINDOWS_PREFIX + " 7");
 1406  
 
 1407  
     /**
 1408  
      * <p>
 1409  
      * Is {@code true} if this is Windows 8.
 1410  
      * </p>
 1411  
      * <p>
 1412  
      * The field will return {@code false} if {@code OS_NAME} is {@code null}.
 1413  
      * </p>
 1414  
      *
 1415  
      * @since 3.2
 1416  
      */
 1417  1
     public static final boolean IS_OS_WINDOWS_8 = getOSMatchesName(OS_NAME_WINDOWS_PREFIX + " 8");
 1418  
 
 1419  
     /**
 1420  
      * <p>
 1421  
      * Gets the Java home directory as a {@code File}.
 1422  
      * </p>
 1423  
      *
 1424  
      * @return a directory
 1425  
      * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow
 1426  
      * access to the specified system property.
 1427  
      * @see System#getProperty(String)
 1428  
      * @since 2.1
 1429  
      */
 1430  
     public static File getJavaHome() {
 1431  1
         return new File(System.getProperty(JAVA_HOME_KEY));
 1432  
     }
 1433  
 
 1434  
     /**
 1435  
      * <p>
 1436  
      * Gets the Java IO temporary directory as a {@code File}.
 1437  
      * </p>
 1438  
      *
 1439  
      * @return a directory
 1440  
      * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow
 1441  
      * access to the specified system property.
 1442  
      * @see System#getProperty(String)
 1443  
      * @since 2.1
 1444  
      */
 1445  
     public static File getJavaIoTmpDir() {
 1446  1
         return new File(System.getProperty(JAVA_IO_TMPDIR_KEY));
 1447  
     }
 1448  
 
 1449  
     /**
 1450  
      * <p>
 1451  
      * Decides if the Java version matches.
 1452  
      * </p>
 1453  
      *
 1454  
      * @param versionPrefix the prefix for the java version
 1455  
      * @return true if matches, or false if not or can't determine
 1456  
      */
 1457  
     private static boolean getJavaVersionMatches(final String versionPrefix) {
 1458  9
         return isJavaVersionMatch(JAVA_SPECIFICATION_VERSION, versionPrefix);
 1459  
     }
 1460  
 
 1461  
     /**
 1462  
      * Decides if the operating system matches.
 1463  
      *
 1464  
      * @param osNamePrefix the prefix for the os name
 1465  
      * @param osVersionPrefix the prefix for the version
 1466  
      * @return true if matches, or false if not or can't determine
 1467  
      */
 1468  
     private static boolean getOSMatches(final String osNamePrefix, final String osVersionPrefix) {
 1469  11
         return isOSMatch(OS_NAME, OS_VERSION, osNamePrefix, osVersionPrefix);
 1470  
     }
 1471  
 
 1472  
     /**
 1473  
      * Decides if the operating system matches.
 1474  
      *
 1475  
      * @param osNamePrefix the prefix for the os name
 1476  
      * @return true if matches, or false if not or can't determine
 1477  
      */
 1478  
     private static boolean getOSMatchesName(final String osNamePrefix) {
 1479  27
         return isOSNameMatch(OS_NAME, osNamePrefix);
 1480  
     }
 1481  
 
 1482  
     // -----------------------------------------------------------------------
 1483  
     /**
 1484  
      * <p>
 1485  
      * Gets a System property, defaulting to {@code null} if the property cannot be read.
 1486  
      * </p>
 1487  
      * <p>
 1488  
      * If a {@code SecurityException} is caught, the return value is {@code null} and a message is written to
 1489  
      * {@code System.err}.
 1490  
      * </p>
 1491  
      *
 1492  
      * @param property the system property name
 1493  
      * @return the system property value or {@code null} if a security problem occurs
 1494  
      */
 1495  
     private static String getSystemProperty(final String property) {
 1496  
         try {
 1497  43
             return System.getProperty(property);
 1498  0
         } catch (final SecurityException ex) {
 1499  
             // we are not allowed to look at this property
 1500  0
             System.err.println("Caught a SecurityException reading the system property '" + property
 1501  
                     + "'; the SystemUtils property value will default to null.");
 1502  0
             return null;
 1503  
         }
 1504  
     }
 1505  
 
 1506  
     /**
 1507  
      * <p>
 1508  
      * Gets the user directory as a {@code File}.
 1509  
      * </p>
 1510  
      *
 1511  
      * @return a directory
 1512  
      * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow
 1513  
      * access to the specified system property.
 1514  
      * @see System#getProperty(String)
 1515  
      * @since 2.1
 1516  
      */
 1517  
     public static File getUserDir() {
 1518  1
         return new File(System.getProperty(USER_DIR_KEY));
 1519  
     }
 1520  
 
 1521  
     /**
 1522  
      * <p>
 1523  
      * Gets the user home directory as a {@code File}.
 1524  
      * </p>
 1525  
      *
 1526  
      * @return a directory
 1527  
      * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow
 1528  
      * access to the specified system property.
 1529  
      * @see System#getProperty(String)
 1530  
      * @since 2.1
 1531  
      */
 1532  
     public static File getUserHome() {
 1533  1
         return new File(System.getProperty(USER_HOME_KEY));
 1534  
     }
 1535  
 
 1536  
     /**
 1537  
      * Returns whether the {@link #JAVA_AWT_HEADLESS} value is {@code true}.
 1538  
      *
 1539  
      * @return {@code true} if {@code JAVA_AWT_HEADLESS} is {@code "true"}, {@code false} otherwise.
 1540  
      * @see #JAVA_AWT_HEADLESS
 1541  
      * @since 2.1
 1542  
      * @since Java 1.4
 1543  
      */
 1544  
     public static boolean isJavaAwtHeadless() {
 1545  2
         return JAVA_AWT_HEADLESS != null ? JAVA_AWT_HEADLESS.equals(Boolean.TRUE.toString()) : false;
 1546  
     }
 1547  
 
 1548  
     /**
 1549  
      * <p>
 1550  
      * Is the Java version at least the requested version.
 1551  
      * </p>
 1552  
      * <p>
 1553  
      * Example input:
 1554  
      * </p>
 1555  
      * <ul>
 1556  
      * <li>{@code 1.2f} to test for Java 1.2</li>
 1557  
      * <li>{@code 1.31f} to test for Java 1.3.1</li>
 1558  
      * </ul>
 1559  
      *
 1560  
      * @param requiredVersion the required version, for example 1.31f
 1561  
      * @return {@code true} if the actual version is equal or greater than the required version
 1562  
      */
 1563  
     public static boolean isJavaVersionAtLeast(final JavaVersion requiredVersion) {
 1564  4881
         return JAVA_SPECIFICATION_VERSION_AS_ENUM.atLeast(requiredVersion);
 1565  
     }
 1566  
 
 1567  
     /**
 1568  
      * <p>
 1569  
      * Decides if the Java version matches.
 1570  
      * </p>
 1571  
      * <p>
 1572  
      * This method is package private instead of private to support unit test invocation.
 1573  
      * </p>
 1574  
      *
 1575  
      * @param version the actual Java version
 1576  
      * @param versionPrefix the prefix for the expected Java version
 1577  
      * @return true if matches, or false if not or can't determine
 1578  
      */
 1579  
     static boolean isJavaVersionMatch(final String version, final String versionPrefix) {
 1580  113
         if (version == null) {
 1581  8
             return false;
 1582  
         }
 1583  105
         return version.startsWith(versionPrefix);
 1584  
     }
 1585  
 
 1586  
     /**
 1587  
      * Decides if the operating system matches.
 1588  
      * <p>
 1589  
      * This method is package private instead of private to support unit test invocation.
 1590  
      * </p>
 1591  
      *
 1592  
      * @param osName the actual OS name
 1593  
      * @param osVersion the actual OS version
 1594  
      * @param osNamePrefix the prefix for the expected OS name
 1595  
      * @param osVersionPrefix the prefix for the expected OS version
 1596  
      * @return true if matches, or false if not or can't determine
 1597  
      */
 1598  
     static boolean isOSMatch(final String osName, final String osVersion, final String osNamePrefix, final String osVersionPrefix) {
 1599  18
         if (osName == null || osVersion == null) {
 1600  1
             return false;
 1601  
         }
 1602  17
         return isOSNameMatch(osName, osNamePrefix) && isOSVersionMatch(osVersion, osVersionPrefix);
 1603  
     }
 1604  
 
 1605  
     /**
 1606  
      * Decides if the operating system matches.
 1607  
      * <p>
 1608  
      * This method is package private instead of private to support unit test invocation.
 1609  
      * </p>
 1610  
      *
 1611  
      * @param osName the actual OS name
 1612  
      * @param osNamePrefix the prefix for the expected OS name
 1613  
      * @return true if matches, or false if not or can't determine
 1614  
      */
 1615  
     static boolean isOSNameMatch(final String osName, final String osNamePrefix) {
 1616  49
         if (osName == null) {
 1617  1
             return false;
 1618  
         }
 1619  48
         return osName.startsWith(osNamePrefix);
 1620  
     }
 1621  
 
 1622  
     /**
 1623  
      * Decides if the operating system version matches.
 1624  
      * <p>
 1625  
      * This method is package private instead of private to support unit test invocation.
 1626  
      * </p>
 1627  
      *
 1628  
      * @param osVersion the actual OS version
 1629  
      * @param osVersionPrefix the prefix for the expected OS version
 1630  
      * @return true if matches, or false if not or can't determine
 1631  
      */
 1632  
     static boolean isOSVersionMatch(final String osVersion, final String osVersionPrefix) {
 1633  36
         if (StringUtils.isEmpty(osVersion)) {
 1634  2
             return false;
 1635  
         }
 1636  
         // Compare parts of the version string instead of using String.startsWith(String) because otherwise
 1637  
         // osVersionPrefix 10.1 would also match osVersion 10.10
 1638  34
         String[] versionPrefixParts = osVersionPrefix.split("\\.");
 1639  34
         String[] versionParts = osVersion.split("\\.");
 1640  81
         for (int i = 0; i < Math.min(versionPrefixParts.length, versionParts.length); i++) {
 1641  66
             if (!versionPrefixParts[i].equals(versionParts[i])) {
 1642  19
                 return false;
 1643  
             }
 1644  
         }
 1645  15
         return true;
 1646  
     }
 1647  
 
 1648  
     // -----------------------------------------------------------------------
 1649  
     /**
 1650  
      * <p>
 1651  
      * SystemUtils instances should NOT be constructed in standard programming. Instead, the class should be used as
 1652  
      * {@code SystemUtils.FILE_SEPARATOR}.
 1653  
      * </p>
 1654  
      * <p>
 1655  
      * This constructor is public to permit tools that require a JavaBean instance to operate.
 1656  
      * </p>
 1657  
      */
 1658  
     public SystemUtils() {
 1659  1
         super();
 1660  1
     }
 1661  
 
 1662  
 }