    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017package org.apache.commons.lang3;
    018
    019import java.io.File;
    020
    021/**
    022 * <p>
    023 * Helpers for {@code java.lang.System}.
    024 * </p>
    025 * <p>
    026 * If a system property cannot be read due to security restrictions, the corresponding field in this class will be set
    027 * to {@code null} and a message will be written to {@code System.err}.
    028 * </p>
    029 * <p>
    030 * #ThreadSafe#
    031 * </p>
    032 *
    033 * @since 1.0
    034 */
    035public class SystemUtils {
    036
    037    /**
    038     * The prefix String for all Windows OS.
    039     */
    040    private static final String OS_NAME_WINDOWS_PREFIX = "Windows";
    041
    042    // System property constants
    043    // -----------------------------------------------------------------------
    044    // These MUST be declared first. Other constants depend on this.
    045
    046    /**
    047     * The System property key for the user home directory.
    048     */
    049    private static final String USER_HOME_KEY = "user.home";
    050
    051    /**
    052     * The System property key for the user name.
    053     */
    054    private static final String USER_NAME_KEY = "user.name";
    055
    056    /**
    057     * The System property key for the user directory.
    058     */
    059    private static final String USER_DIR_KEY = "user.dir";
    060
    061    /**
    062     * The System property key for the Java IO temporary directory.
    063     */
    064    private static final String JAVA_IO_TMPDIR_KEY = "java.io.tmpdir";
    065
    066    /**
    067     * The System property key for the Java home directory.
    068     */
    069    private static final String JAVA_HOME_KEY = "java.home";
    070
    071    /**
    072     * <p>
    073     * The {@code awt.toolkit} System Property.
    074     * </p>
    075     * <p>
    076     * Holds a class name, on Windows XP this is {@code sun.awt.windows.WToolkit}.
    077     * </p>
    078     * <p>
    079     * <b>On platforms without a GUI, this value is {@code null}.</b>
    080     * </p>
    081     * <p>
    082     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    083     * not exist.
    084     * </p>
    085     * <p>
    086     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    087     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    088     * sync with that System property.
    089     * </p>
    090     *
    091     * @since 2.1
    092     */
    093    public static final String AWT_TOOLKIT = getSystemProperty("awt.toolkit");
    094
    095    /**
    096     * <p>
    097     * The {@code file.encoding} System Property.
    098     * </p>
    099     * <p>
    100     * File encoding, such as {@code Cp1252}.
    101     * </p>
    102     * <p>
    103     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    104     * not exist.
    105     * </p>
    106     * <p>
    107     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    108     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    109     * sync with that System property.
    110     * </p>
    111     *
    112     * @since 2.0
    113     * @since Java 1.2
    114     */
    115    public static final String FILE_ENCODING = getSystemProperty("file.encoding");
    116
    117    /**
    118     * <p>
    119     * The {@code file.separator} System Property.
    120     * The file separator is:
    121     * </p>
    122     * <ul>
    123     * <li>{@code "/"} on UNIX</li>
    124     * <li>{@code "\"} on Windows.</li>
    125     * </ul>
    126     *
    127     * <p>
    128     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    129     * not exist.
    130     * </p>
    131     * <p>
    132     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    133     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    134     * sync with that System property.
    135     * </p>
    136     *
    137     * @deprecated Use {@link File#separator}, since it is guaranteed to be a
    138     *             string containing a single character and it does not require a privilege check.
    139     * @since Java 1.1
    140     */
    141    @Deprecated
    142    public static final String FILE_SEPARATOR = getSystemProperty("file.separator");
    143
    144    /**
    145     * <p>
    146     * The {@code java.awt.fonts} System Property.
    147     * </p>
    148     * <p>
    149     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    150     * not exist.
    151     * </p>
    152     * <p>
    153     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    154     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    155     * sync with that System property.
    156     * </p>
    157     *
    158     * @since 2.1
    159     */
    160    public static final String JAVA_AWT_FONTS = getSystemProperty("java.awt.fonts");
    161
    162    /**
    163     * <p>
    164     * The {@code java.awt.graphicsenv} System Property.
    165     * </p>
    166     * <p>
    167     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    168     * not exist.
    169     * </p>
    170     * <p>
    171     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    172     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    173     * sync with that System property.
    174     * </p>
    175     *
    176     * @since 2.1
    177     */
    178    public static final String JAVA_AWT_GRAPHICSENV = getSystemProperty("java.awt.graphicsenv");
    179
    180    /**
    181     * <p>
    182     * The {@code java.awt.headless} System Property. The value of this property is the String {@code "true"} or
    183     * {@code "false"}.
    184     * </p>
    185     * <p>
    186     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    187     * not exist.
    188     * </p>
    189     * <p>
    190     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    191     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    192     * sync with that System property.
    193     * </p>
    194     *
    195     * @see #isJavaAwtHeadless()
    196     * @since 2.1
    197     * @since Java 1.4
    198     */
    199    public static final String JAVA_AWT_HEADLESS = getSystemProperty("java.awt.headless");
    200
    201    /**
    202     * <p>
    203     * The {@code java.awt.printerjob} System Property.
    204     * </p>
    205     * <p>
    206     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    207     * not exist.
    208     * </p>
    209     * <p>
    210     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    211     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    212     * sync with that System property.
    213     * </p>
    214     *
    215     * @since 2.1
    216     */
    217    public static final String JAVA_AWT_PRINTERJOB = getSystemProperty("java.awt.printerjob");
    218
    219    /**
    220     * <p>
    221     * The {@code java.class.path} System Property. Java class path.
    222     * </p>
    223     * <p>
    224     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    225     * not exist.
    226     * </p>
    227     * <p>
    228     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    229     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    230     * sync with that System property.
    231     * </p>
    232     *
    233     * @since Java 1.1
    234     */
    235    public static final String JAVA_CLASS_PATH = getSystemProperty("java.class.path");
    236
    237    /**
    238     * <p>
    239     * The {@code java.class.version} System Property. Java class format version number.
    240     * </p>
    241     * <p>
    242     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    243     * not exist.
    244     * </p>
    245     * <p>
    246     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    247     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    248     * sync with that System property.
    249     * </p>
    250     *
    251     * @since Java 1.1
    252     */
    253    public static final String JAVA_CLASS_VERSION = getSystemProperty("java.class.version");
    254
    255    /**
    256     * <p>
    257     * The {@code java.compiler} System Property. Name of JIT compiler to use. First in JDK version 1.2. Not used in Sun
    258     * JDKs after 1.2.
    259     * </p>
    260     * <p>
    261     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    262     * not exist.
    263     * </p>
    264     * <p>
    265     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    266     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    267     * sync with that System property.
    268     * </p>
    269     *
    270     * @since Java 1.2. Not used in Sun versions after 1.2.
    271     */
    272    public static final String JAVA_COMPILER = getSystemProperty("java.compiler");
    273
    274    /**
    275     * <p>
    276     * The {@code java.endorsed.dirs} System Property. Path of endorsed directory or directories.
    277     * </p>
    278     * <p>
    279     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    280     * not exist.
    281     * </p>
    282     * <p>
    283     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    284     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    285     * sync with that System property.
    286     * </p>
    287     *
    288     * @since Java 1.4
    289     */
    290    public static final String JAVA_ENDORSED_DIRS = getSystemProperty("java.endorsed.dirs");
    291
    292    /**
    293     * <p>
    294     * The {@code java.ext.dirs} System Property. Path of extension directory or directories.
    295     * </p>
    296     * <p>
    297     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    298     * not exist.
    299     * </p>
    300     * <p>
    301     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    302     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    303     * sync with that System property.
    304     * </p>
    305     *
    306     * @since Java 1.3
    307     */
    308    public static final String JAVA_EXT_DIRS = getSystemProperty("java.ext.dirs");
    309
    310    /**
    311     * <p>
    312     * The {@code java.home} System Property. Java installation directory.
    313     * </p>
    314     * <p>
    315     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    316     * not exist.
    317     * </p>
    318     * <p>
    319     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    320     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    321     * sync with that System property.
    322     * </p>
    323     *
    324     * @since Java 1.1
    325     */
    326    public static final String JAVA_HOME = getSystemProperty(JAVA_HOME_KEY);
    327
    328    /**
    329     * <p>
    330     * The {@code java.io.tmpdir} System Property. Default temp file path.
    331     * </p>
    332     * <p>
    333     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    334     * not exist.
    335     * </p>
    336     * <p>
    337     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    338     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    339     * sync with that System property.
    340     * </p>
    341     *
    342     * @since Java 1.2
    343     */
    344    public static final String JAVA_IO_TMPDIR = getSystemProperty(JAVA_IO_TMPDIR_KEY);
    345
    346    /**
    347     * <p>
    348     * The {@code java.library.path} System Property. List of paths to search when loading libraries.
    349     * </p>
    350     * <p>
    351     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    352     * not exist.
    353     * </p>
    354     * <p>
    355     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    356     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    357     * sync with that System property.
    358     * </p>
    359     *
    360     * @since Java 1.2
    361     */
    362    public static final String JAVA_LIBRARY_PATH = getSystemProperty("java.library.path");
    363
    364    /**
    365     * <p>
    366     * The {@code java.runtime.name} System Property. Java Runtime Environment name.
    367     * </p>
    368     * <p>
    369     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    370     * not exist.
    371     * </p>
    372     * <p>
    373     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    374     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    375     * sync with that System property.
    376     * </p>
    377     *
    378     * @since 2.0
    379     * @since Java 1.3
    380     */
    381    public static final String JAVA_RUNTIME_NAME = getSystemProperty("java.runtime.name");
    382
    383    /**
    384     * <p>
    385     * The {@code java.runtime.version} System Property. Java Runtime Environment version.
    386     * </p>
    387     * <p>
    388     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    389     * not exist.
    390     * </p>
    391     * <p>
    392     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    393     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    394     * sync with that System property.
    395     * </p>
    396     *
    397     * @since 2.0
    398     * @since Java 1.3
    399     */
    400    public static final String JAVA_RUNTIME_VERSION = getSystemProperty("java.runtime.version");
    401
    402    /**
    403     * <p>
    404     * The {@code java.specification.name} System Property. Java Runtime Environment specification name.
    405     * </p>
    406     * <p>
    407     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    408     * not exist.
    409     * </p>
    410     * <p>
    411     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    412     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    413     * sync with that System property.
    414     * </p>
    415     *
    416     * @since Java 1.2
    417     */
    418    public static final String JAVA_SPECIFICATION_NAME = getSystemProperty("java.specification.name");
    419
    420    /**
    421     * <p>
    422     * The {@code java.specification.vendor} System Property. Java Runtime Environment specification vendor.
    423     * </p>
    424     * <p>
    425     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    426     * not exist.
    427     * </p>
    428     * <p>
    429     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    430     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    431     * sync with that System property.
    432     * </p>
    433     *
    434     * @since Java 1.2
    435     */
    436    public static final String JAVA_SPECIFICATION_VENDOR = getSystemProperty("java.specification.vendor");
    437
    438    /**
    439     * <p>
    440     * The {@code java.specification.version} System Property. Java Runtime Environment specification version.
    441     * </p>
    442     * <p>
    443     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    444     * not exist.
    445     * </p>
    446     * <p>
    447     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    448     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    449     * sync with that System property.
    450     * </p>
    451     *
    452     * @since Java 1.3
    453     */
    454    public static final String JAVA_SPECIFICATION_VERSION = getSystemProperty("java.specification.version");
    455    private static final JavaVersion JAVA_SPECIFICATION_VERSION_AS_ENUM = JavaVersion.get(JAVA_SPECIFICATION_VERSION);
    456
    457    /**
    458     * <p>
    459     * The {@code java.util.prefs.PreferencesFactory} System Property. A class name.
    460     * </p>
    461     * <p>
    462     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    463     * not exist.
    464     * </p>
    465     * <p>
    466     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    467     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    468     * sync with that System property.
    469     * </p>
    470     *
    471     * @since 2.1
    472     * @since Java 1.4
    473     */
    474    public static final String JAVA_UTIL_PREFS_PREFERENCES_FACTORY =
    475        getSystemProperty("java.util.prefs.PreferencesFactory");
    476
    477    /**
    478     * <p>
    479     * The {@code java.vendor} System Property. Java vendor-specific string.
    480     * </p>
    481     * <p>
    482     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    483     * not exist.
    484     * </p>
    485     * <p>
    486     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    487     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    488     * sync with that System property.
    489     * </p>
    490     *
    491     * @since Java 1.1
    492     */
    493    public static final String JAVA_VENDOR = getSystemProperty("java.vendor");
    494
    495    /**
    496     * <p>
    497     * The {@code java.vendor.url} System Property. Java vendor URL.
    498     * </p>
    499     * <p>
    500     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    501     * not exist.
    502     * </p>
    503     * <p>
    504     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    505     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    506     * sync with that System property.
    507     * </p>
    508     *
    509     * @since Java 1.1
    510     */
    511    public static final String JAVA_VENDOR_URL = getSystemProperty("java.vendor.url");
    512
    513    /**
    514     * <p>
    515     * The {@code java.version} System Property. Java version number.
    516     * </p>
    517     * <p>
    518     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    519     * not exist.
    520     * </p>
    521     * <p>
    522     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    523     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    524     * sync with that System property.
    525     * </p>
    526     *
    527     * @since Java 1.1
    528     */
    529    public static final String JAVA_VERSION = getSystemProperty("java.version");
    530
    531    /**
    532     * <p>
    533     * The {@code java.vm.info} System Property. Java Virtual Machine implementation info.
    534     * </p>
    535     * <p>
    536     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    537     * not exist.
    538     * </p>
    539     * <p>
    540     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    541     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    542     * sync with that System property.
    543     * </p>
    544     *
    545     * @since 2.0
    546     * @since Java 1.2
    547     */
    548    public static final String JAVA_VM_INFO = getSystemProperty("java.vm.info");
    549
    550    /**
    551     * <p>
    552     * The {@code java.vm.name} System Property. Java Virtual Machine implementation name.
    553     * </p>
    554     * <p>
    555     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    556     * not exist.
    557     * </p>
    558     * <p>
    559     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    560     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    561     * sync with that System property.
    562     * </p>
    563     *
    564     * @since Java 1.2
    565     */
    566    public static final String JAVA_VM_NAME = getSystemProperty("java.vm.name");
    567
    568    /**
    569     * <p>
    570     * The {@code java.vm.specification.name} System Property. Java Virtual Machine specification name.
    571     * </p>
    572     * <p>
    573     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    574     * not exist.
    575     * </p>
    576     * <p>
    577     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    578     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    579     * sync with that System property.
    580     * </p>
    581     *
    582     * @since Java 1.2
    583     */
    584    public static final String JAVA_VM_SPECIFICATION_NAME = getSystemProperty("java.vm.specification.name");
    585
    586    /**
    587     * <p>
    588     * The {@code java.vm.specification.vendor} System Property. Java Virtual Machine specification vendor.
    589     * </p>
    590     * <p>
    591     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    592     * not exist.
    593     * </p>
    594     * <p>
    595     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    596     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    597     * sync with that System property.
    598     * </p>
    599     *
    600     * @since Java 1.2
    601     */
    602    public static final String JAVA_VM_SPECIFICATION_VENDOR = getSystemProperty("java.vm.specification.vendor");
    603
    604    /**
    605     * <p>
    606     * The {@code java.vm.specification.version} System Property. Java Virtual Machine specification version.
    607     * </p>
    608     * <p>
    609     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    610     * not exist.
    611     * </p>
    612     * <p>
    613     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    614     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    615     * sync with that System property.
    616     * </p>
    617     *
    618     * @since Java 1.2
    619     */
    620    public static final String JAVA_VM_SPECIFICATION_VERSION = getSystemProperty("java.vm.specification.version");
    621
    622    /**
    623     * <p>
    624     * The {@code java.vm.vendor} System Property. Java Virtual Machine implementation vendor.
    625     * </p>
    626     * <p>
    627     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    628     * not exist.
    629     * </p>
    630     * <p>
    631     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    632     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    633     * sync with that System property.
    634     * </p>
    635     *
    636     * @since Java 1.2
    637     */
    638    public static final String JAVA_VM_VENDOR = getSystemProperty("java.vm.vendor");
    639
    640    /**
    641     * <p>
    642     * The {@code java.vm.version} System Property. Java Virtual Machine implementation version.
    643     * </p>
    644     * <p>
    645     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    646     * not exist.
    647     * </p>
    648     * <p>
    649     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    650     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    651     * sync with that System property.
    652     * </p>
    653     *
    654     * @since Java 1.2
    655     */
    656    public static final String JAVA_VM_VERSION = getSystemProperty("java.vm.version");
    657
    658    /**
    659     * <p>
    660     * The {@code line.separator} System Property. Line separator ({@code &quot;\n&quot;} on UNIX).
    661     * </p>
    662     * <p>
    663     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    664     * not exist.
    665     * </p>
    666     * <p>
    667     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    668     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    669     * sync with that System property.
    670     * </p>
    671     *
    672     * @deprecated Use {@link System#lineSeparator()} instead, since it does not require a privilege check.
    673     * @since Java 1.1
    674     */
    675    @Deprecated
    676    public static final String LINE_SEPARATOR = getSystemProperty("line.separator");
    677
    678    /**
    679     * <p>
    680     * The {@code os.arch} System Property. Operating system architecture.
    681     * </p>
    682     * <p>
    683     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    684     * not exist.
    685     * </p>
    686     * <p>
    687     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    688     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    689     * sync with that System property.
    690     * </p>
    691     *
    692     * @since Java 1.1
    693     */
    694    public static final String OS_ARCH = getSystemProperty("os.arch");
    695
    696    /**
    697     * <p>
    698     * The {@code os.name} System Property. Operating system name.
    699     * </p>
    700     * <p>
    701     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    702     * not exist.
    703     * </p>
    704     * <p>
    705     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    706     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    707     * sync with that System property.
    708     * </p>
    709     *
    710     * @since Java 1.1
    711     */
    712    public static final String OS_NAME = getSystemProperty("os.name");
    713
    714    /**
    715     * <p>
    716     * The {@code os.version} System Property. Operating system version.
    717     * </p>
    718     * <p>
    719     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    720     * not exist.
    721     * </p>
    722     * <p>
    723     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    724     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    725     * sync with that System property.
    726     * </p>
    727     *
    728     * @since Java 1.1
    729     */
    730    public static final String OS_VERSION = getSystemProperty("os.version");
    731
    732    /**
    733     * <p>
    734     * The {@code path.separator} System Property. Path separator ({@code &quot;:&quot;} on UNIX).
    735     * </p>
    736     * <p>
    737     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    738     * not exist.
    739     * </p>
    740     * <p>
    741     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    742     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    743     * sync with that System property.
    744     * </p>
    745     *
    746     * @deprecated Use {@link File#pathSeparator}, since it is guaranteed to be a
    747     *             string containing a single character and it does not require a privilege check.
    748     * @since Java 1.1
    749     */
    750    @Deprecated
    751    public static final String PATH_SEPARATOR = getSystemProperty("path.separator");
    752
    753    /**
    754     * <p>
    755     * The {@code user.country} or {@code user.region} System Property. User's country code, such as {@code GB}. First
    756     * in Java version 1.2 as {@code user.region}. Renamed to {@code user.country} in 1.4
    757     * </p>
    758     * <p>
    759     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    760     * not exist.
    761     * </p>
    762     * <p>
    763     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    764     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    765     * sync with that System property.
    766     * </p>
    767     *
    768     * @since 2.0
    769     * @since Java 1.2
    770     */
    771    public static final String USER_COUNTRY = getSystemProperty("user.country") == null ?
    772            getSystemProperty("user.region") : getSystemProperty("user.country");
    773
    774    /**
    775     * <p>
    776     * The {@code user.dir} System Property. User's current working directory.
    777     * </p>
    778     * <p>
    779     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    780     * not exist.
    781     * </p>
    782     * <p>
    783     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    784     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    785     * sync with that System property.
    786     * </p>
    787     *
    788     * @since Java 1.1
    789     */
    790    public static final String USER_DIR = getSystemProperty(USER_DIR_KEY);
    791
    792    /**
    793     * <p>
    794     * The {@code user.home} System Property. User's home directory.
    795     * </p>
    796     * <p>
    797     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    798     * not exist.
    799     * </p>
    800     * <p>
    801     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    802     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    803     * sync with that System property.
    804     * </p>
    805     *
    806     * @since Java 1.1
    807     */
    808    public static final String USER_HOME = getSystemProperty(USER_HOME_KEY);
    809
    810    /**
    811     * <p>
    812     * The {@code user.language} System Property. User's language code, such as {@code "en"}.
    813     * </p>
    814     * <p>
    815     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    816     * not exist.
    817     * </p>
    818     * <p>
    819     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    820     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    821     * sync with that System property.
    822     * </p>
    823     *
    824     * @since 2.0
    825     * @since Java 1.2
    826     */
    827    public static final String USER_LANGUAGE = getSystemProperty("user.language");
    828
    829    /**
    830     * <p>
    831     * The {@code user.name} System Property. User's account name.
    832     * </p>
    833     * <p>
    834     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    835     * not exist.
    836     * </p>
    837     * <p>
    838     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    839     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    840     * sync with that System property.
    841     * </p>
    842     *
    843     * @since Java 1.1
    844     */
    845    public static final String USER_NAME = getSystemProperty(USER_NAME_KEY);
    846
    847    /**
    848     * <p>
    849     * The {@code user.timezone} System Property. For example: {@code "America/Los_Angeles"}.
    850     * </p>
    851     * <p>
    852     * Defaults to {@code null} if the runtime does not have security access to read this property or the property does
    853     * not exist.
    854     * </p>
    855     * <p>
    856     * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or
    857     * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of
    858     * sync with that System property.
    859     * </p>
    860     *
    861     * @since 2.1
    862     */
    863    public static final String USER_TIMEZONE = getSystemProperty("user.timezone");
    864
    865    // Java version checks
    866    // -----------------------------------------------------------------------
    867    // These MUST be declared after those above as they depend on the
    868    // values being set up
    869
    870    /**
    871     * <p>
    872     * Is {@code true} if this is Java version 1.1 (also 1.1.x versions).
    873     * </p>
    874     * <p>
    875     * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
    876     * </p>
    877     */
    878    public static final boolean IS_JAVA_1_1 = getJavaVersionMatches("1.1");
    879
    880    /**
    881     * <p>
    882     * Is {@code true} if this is Java version 1.2 (also 1.2.x versions).
    883     * </p>
    884     * <p>
    885     * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
    886     * </p>
    887     */
    888    public static final boolean IS_JAVA_1_2 = getJavaVersionMatches("1.2");
    889
    890    /**
    891     * <p>
    892     * Is {@code true} if this is Java version 1.3 (also 1.3.x versions).
    893     * </p>
    894     * <p>
    895     * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
    896     * </p>
    897     */
    898    public static final boolean IS_JAVA_1_3 = getJavaVersionMatches("1.3");
    899
    900    /**
    901     * <p>
    902     * Is {@code true} if this is Java version 1.4 (also 1.4.x versions).
    903     * </p>
    904     * <p>
    905     * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
    906     * </p>
    907     */
    908    public static final boolean IS_JAVA_1_4 = getJavaVersionMatches("1.4");
    909
    910    /**
    911     * <p>
    912     * Is {@code true} if this is Java version 1.5 (also 1.5.x versions).
    913     * </p>
    914     * <p>
    915     * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
    916     * </p>
    917     */
    918    public static final boolean IS_JAVA_1_5 = getJavaVersionMatches("1.5");
    919
    920    /**
    921     * <p>
    922     * Is {@code true} if this is Java version 1.6 (also 1.6.x versions).
    923     * </p>
    924     * <p>
    925     * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
    926     * </p>
    927     */
    928    public static final boolean IS_JAVA_1_6 = getJavaVersionMatches("1.6");
    929
    930    /**
    931     * <p>
    932     * Is {@code true} if this is Java version 1.7 (also 1.7.x versions).
    933     * </p>
    934     * <p>
    935     * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
    936     * </p>
    937     *
    938     * @since 3.0
    939     */
    940    public static final boolean IS_JAVA_1_7 = getJavaVersionMatches("1.7");
    941
    942    /**
    943     * <p>
    944     * Is {@code true} if this is Java version 1.8 (also 1.8.x versions).
    945     * </p>
    946     * <p>
    947     * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
    948     * </p>
    949     *
    950     * @since 3.3.2
    951     */
    952    public static final boolean IS_JAVA_1_8 = getJavaVersionMatches("1.8");
    953
    954    /**
    955     * <p>
    956     * Is {@code true} if this is Java version 1.9 (also 1.9.x versions).
    957     * </p>
    958     * <p>
    959     * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
    960     * </p>
    961     *
    962     * @since 3.4
    963     *
    964     * @deprecated As of release 3.5, replaced by {@link #IS_JAVA_9}
    965     */
    966    @Deprecated
    967    public static final boolean IS_JAVA_1_9 = getJavaVersionMatches("9");
    968
    969    /**
    970     * <p>
    971     * Is {@code true} if this is Java version 9 (also 9.x versions).
    972     * </p>
    973     * <p>
    974     * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
    975     * </p>
    976     *
    977     * @since 3.5
    978     */
    979    public static final boolean IS_JAVA_9 = getJavaVersionMatches("9");
    980
    981    /**
    982     * <p>
    983     * Is {@code true} if this is Java version 10 (also 10.x versions).
    984     * </p>
    985     * <p>
    986     * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
    987     * </p>
    988     *
    989     * @since 3.7
    990     */
    991    public static final boolean IS_JAVA_10 = getJavaVersionMatches("10");
    992
    993    /**
    994     * <p>
    995     * Is {@code true} if this is Java version 11 (also 11.x versions).
    996     * </p>
    997     * <p>
    998     * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
    999     * </p>
    1000     *
    1001     * @since 3.8
    1002     */
    1003    public static final boolean IS_JAVA_11 = getJavaVersionMatches("11");
    1004
    1005    /**
    1006     * <p>
    1007     * Is {@code true} if this is Java version 12 (also 12.x versions).
    1008     * </p>
    1009     * <p>
    1010     * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
    1011     * </p>
    1012     *
    1013     * @since 3.9
    1014     */
    1015    public static final boolean IS_JAVA_12 = getJavaVersionMatches("12");
    1016
    1017    /**
    1018     * <p>
    1019     * Is {@code true} if this is Java version 13 (also 13.x versions).
    1020     * </p>
    1021     * <p>
    1022     * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
    1023     * </p>
    1024     *
    1025     * @since 3.9
    1026     */
    1027    public static final boolean IS_JAVA_13 = getJavaVersionMatches("13");
    1028
    1029    /**
    1030     * <p>
    1031     * Is {@code true} if this is Java version 14 (also 14.x versions).
    1032     * </p>
    1033     * <p>
    1034     * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
    1035     * </p>
    1036     *
    1037     * @since 3.10
    1038     */
    1039    public static final boolean IS_JAVA_14 = getJavaVersionMatches("14");
    1040
    1041    /**
    1042     * <p>
    1043     * Is {@code true} if this is Java version 15 (also 15.x versions).
    1044     * </p>
    1045     * <p>
    1046     * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
    1047     * </p>
    1048     *
    1049     * @since 3.10
    1050     */
    1051    public static final boolean IS_JAVA_15 = getJavaVersionMatches("15");
    1052
    1053    // Operating system checks
    1054    // -----------------------------------------------------------------------
    1055    // These MUST be declared after those above as they depend on the
    1056    // values being set up
    1057    // OS names from http://www.vamphq.com/os.html
    1058    // Selected ones included - please advise dev@commons.apache.org
    1059    // if you want another added or a mistake corrected
    1060
    1061    /**
    1062     * <p>
    1063     * Is {@code true} if this is AIX.
    1064     * </p>
    1065     * <p>
    1066     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1067     * </p>
    1068     *
    1069     * @since 2.0
    1070     */
    1071    public static final boolean IS_OS_AIX = getOsMatchesName("AIX");
    1072
    1073    /**
    1074     * <p>
    1075     * Is {@code true} if this is HP-UX.
    1076     * </p>
    1077     * <p>
    1078     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1079     * </p>
    1080     *
    1081     * @since 2.0
    1082     */
    1083    public static final boolean IS_OS_HP_UX = getOsMatchesName("HP-UX");
    1084
    1085    /**
    1086     * <p>
    1087     * Is {@code true} if this is IBM OS/400.
    1088     * </p>
    1089     * <p>
    1090     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1091     * </p>
    1092     *
    1093     * @since 3.3
    1094     */
    1095    public static final boolean IS_OS_400 = getOsMatchesName("OS/400");
    1096
    1097    /**
    1098     * <p>
    1099     * Is {@code true} if this is Irix.
    1100     * </p>
    1101     * <p>
    1102     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1103     * </p>
    1104     *
    1105     * @since 2.0
    1106     */
    1107    public static final boolean IS_OS_IRIX = getOsMatchesName("Irix");
    1108
    1109    /**
    1110     * <p>
    1111     * Is {@code true} if this is Linux.
    1112     * </p>
    1113     * <p>
    1114     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1115     * </p>
    1116     *
    1117     * @since 2.0
    1118     */
    1119    public static final boolean IS_OS_LINUX = getOsMatchesName("Linux") || getOsMatchesName("LINUX");
    1120
    1121    /**
    1122     * <p>
    1123     * Is {@code true} if this is Mac.
    1124     * </p>
    1125     * <p>
    1126     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1127     * </p>
    1128     *
    1129     * @since 2.0
    1130     */
    1131    public static final boolean IS_OS_MAC = getOsMatchesName("Mac");
    1132
    1133    /**
    1134     * <p>
    1135     * Is {@code true} if this is Mac.
    1136     * </p>
    1137     * <p>
    1138     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1139     * </p>
    1140     *
    1141     * @since 2.0
    1142     */
    1143    public static final boolean IS_OS_MAC_OSX = getOsMatchesName("Mac OS X");
    1144
    1145    /**
    1146     * <p>
    1147     * Is {@code true} if this is Mac OS X Cheetah.
    1148     * </p>
    1149     * <p>
    1150     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1151     * </p>
    1152     *
    1153     * @since 3.4
    1154     */
    1155    public static final boolean IS_OS_MAC_OSX_CHEETAH = getOsMatches("Mac OS X", "10.0");
    1156
    1157    /**
    1158     * <p>
    1159     * Is {@code true} if this is Mac OS X Puma.
    1160     * </p>
    1161     * <p>
    1162     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1163     * </p>
    1164     *
    1165     * @since 3.4
    1166     */
    1167    public static final boolean IS_OS_MAC_OSX_PUMA = getOsMatches("Mac OS X", "10.1");
    1168
    1169    /**
    1170     * <p>
    1171     * Is {@code true} if this is Mac OS X Jaguar.
    1172     * </p>
    1173     * <p>
    1174     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1175     * </p>
    1176     *
    1177     * @since 3.4
    1178     */
    1179    public static final boolean IS_OS_MAC_OSX_JAGUAR = getOsMatches("Mac OS X", "10.2");
    1180
    1181    /**
    1182     * <p>
    1183     * Is {@code true} if this is Mac OS X Panther.
    1184     * </p>
    1185     * <p>
    1186     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1187     * </p>
    1188     *
    1189     * @since 3.4
    1190     */
    1191    public static final boolean IS_OS_MAC_OSX_PANTHER = getOsMatches("Mac OS X", "10.3");
    1192
    1193    /**
    1194     * <p>
    1195     * Is {@code true} if this is Mac OS X Tiger.
    1196     * </p>
    1197     * <p>
    1198     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1199     * </p>
    1200     *
    1201     * @since 3.4
    1202     */
    1203    public static final boolean IS_OS_MAC_OSX_TIGER = getOsMatches("Mac OS X", "10.4");
    1204
    1205    /**
    1206     * <p>
    1207     * Is {@code true} if this is Mac OS X Leopard.
    1208     * </p>
    1209     * <p>
    1210     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1211     * </p>
    1212     *
    1213     * @since 3.4
    1214     */
    1215    public static final boolean IS_OS_MAC_OSX_LEOPARD = getOsMatches("Mac OS X", "10.5");
    1216
    1217    /**
    1218     * <p>
    1219     * Is {@code true} if this is Mac OS X Snow Leopard.
    1220     * </p>
    1221     * <p>
    1222     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1223     * </p>
    1224     *
    1225     * @since 3.4
    1226     */
    1227    public static final boolean IS_OS_MAC_OSX_SNOW_LEOPARD = getOsMatches("Mac OS X", "10.6");
    1228
    1229    /**
    1230     * <p>
    1231     * Is {@code true} if this is Mac OS X Lion.
    1232     * </p>
    1233     * <p>
    1234     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1235     * </p>
    1236     *
    1237     * @since 3.4
    1238     */
    1239    public static final boolean IS_OS_MAC_OSX_LION = getOsMatches("Mac OS X", "10.7");
    1240
    1241    /**
    1242     * <p>
    1243     * Is {@code true} if this is Mac OS X Mountain Lion.
    1244     * </p>
    1245     * <p>
    1246     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1247     * </p>
    1248     *
    1249     * @since 3.4
    1250     */
    1251    public static final boolean IS_OS_MAC_OSX_MOUNTAIN_LION = getOsMatches("Mac OS X", "10.8");
    1252
    1253    /**
    1254     * <p>
    1255     * Is {@code true} if this is Mac OS X Mavericks.
    1256     * </p>
    1257     * <p>
    1258     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1259     * </p>
    1260     *
    1261     * @since 3.4
    1262     */
    1263    public static final boolean IS_OS_MAC_OSX_MAVERICKS = getOsMatches("Mac OS X", "10.9");
    1264
    1265    /**
    1266     * <p>
    1267     * Is {@code true} if this is Mac OS X Yosemite.
    1268     * </p>
    1269     * <p>
    1270     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1271     * </p>
    1272     *
    1273     * @since 3.4
    1274     */
    1275    public static final boolean IS_OS_MAC_OSX_YOSEMITE = getOsMatches("Mac OS X", "10.10");
    1276
    1277    /**
    1278     * <p>
    1279     * Is {@code true} if this is Mac OS X El Capitan.
    1280     * </p>
    1281     * <p>
    1282     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1283     * </p>
    1284     *
    1285     * @since 3.5
    1286     */
    1287    public static final boolean IS_OS_MAC_OSX_EL_CAPITAN = getOsMatches("Mac OS X", "10.11");
    1288
    1289    /**
    1290     * <p>
    1291     * Is {@code true} if this is Mac OS X Sierra.
    1292     * </p>
    1293     * <p>
    1294     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1295     * </p>
    1296     *
    1297     * @since 3.12.0
    1298     */
    1299    public static final boolean IS_OS_MAC_OSX_SIERRA = getOsMatches("Mac OS X", "10.12");
    1300
    1301    /**
    1302     * <p>
    1303     * Is {@code true} if this is Mac OS X High Sierra.
    1304     * </p>
    1305     * <p>
    1306     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1307     * </p>
    1308     *
    1309     * @since 3.12.0
    1310     */
    1311    public static final boolean IS_OS_MAC_OSX_HIGH_SIERRA = getOsMatches("Mac OS X", "10.13");
    1312
    1313    /**
    1314     * <p>
    1315     * Is {@code true} if this is Mac OS X Mojave.
    1316     * </p>
    1317     * <p>
    1318     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1319     * </p>
    1320     *
    1321     * @since 3.12.0
    1322     */
    1323    public static final boolean IS_OS_MAC_OSX_MOJAVE = getOsMatches("Mac OS X", "10.14");
    1324
    1325    /**
    1326     * <p>
    1327     * Is {@code true} if this is Mac OS X Catalina.
    1328     * </p>
    1329     * <p>
    1330     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1331     * </p>
    1332     *
    1333     * @since 3.12.0
    1334     */
    1335    public static final boolean IS_OS_MAC_OSX_CATALINA = getOsMatches("Mac OS X", "10.15");
    1336
    1337    /**
    1338     * <p>
    1339     * Is {@code true} if this is Mac OS X Big Sur.
    1340     * </p>
    1341     * <p>
    1342     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1343     * </p>
    1344     *
    1345     * @since 3.12.0
    1346     */
    1347    public static final boolean IS_OS_MAC_OSX_BIG_SUR = getOsMatches("Mac OS X", "10.16");
    1348
    1349    /**
    1350     * <p>
    1351     * Is {@code true} if this is FreeBSD.
    1352     * </p>
    1353     * <p>
    1354     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1355     * </p>
    1356     *
    1357     * @since 3.1
    1358     */
    1359    public static final boolean IS_OS_FREE_BSD = getOsMatchesName("FreeBSD");
    1360
    1361    /**
    1362     * <p>
    1363     * Is {@code true} if this is OpenBSD.
    1364     * </p>
    1365     * <p>
    1366     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1367     * </p>
    1368     *
    1369     * @since 3.1
    1370     */
    1371    public static final boolean IS_OS_OPEN_BSD = getOsMatchesName("OpenBSD");
    1372
    1373    /**
    1374     * <p>
    1375     * Is {@code true} if this is NetBSD.
    1376     * </p>
    1377     * <p>
    1378     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1379     * </p>
    1380     *
    1381     * @since 3.1
    1382     */
    1383    public static final boolean IS_OS_NET_BSD = getOsMatchesName("NetBSD");
    1384
    1385    /**
    1386     * <p>
    1387     * Is {@code true} if this is OS/2.
    1388     * </p>
    1389     * <p>
    1390     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1391     * </p>
    1392     *
    1393     * @since 2.0
    1394     */
    1395    public static final boolean IS_OS_OS2 = getOsMatchesName("OS/2");
    1396
    1397    /**
    1398     * <p>
    1399     * Is {@code true} if this is Solaris.
    1400     * </p>
    1401     * <p>
    1402     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1403     * </p>
    1404     *
    1405     * @since 2.0
    1406     */
    1407    public static final boolean IS_OS_SOLARIS = getOsMatchesName("Solaris");
    1408
    1409    /**
    1410     * <p>
    1411     * Is {@code true} if this is SunOS.
    1412     * </p>
    1413     * <p>
    1414     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1415     * </p>
    1416     *
    1417     * @since 2.0
    1418     */
    1419    public static final boolean IS_OS_SUN_OS = getOsMatchesName("SunOS");
    1420
    1421    /**
    1422     * <p>
    1423     * Is {@code true} if this is a UNIX like system, as in any of AIX, HP-UX, Irix, Linux, MacOSX, Solaris or SUN OS.
    1424     * </p>
    1425     * <p>
    1426     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1427     * </p>
    1428     *
    1429     * @since 2.1
    1430     */
    1431    public static final boolean IS_OS_UNIX = IS_OS_AIX || IS_OS_HP_UX || IS_OS_IRIX || IS_OS_LINUX || IS_OS_MAC_OSX
    1432            || IS_OS_SOLARIS || IS_OS_SUN_OS || IS_OS_FREE_BSD || IS_OS_OPEN_BSD || IS_OS_NET_BSD;
    1433
    1434    /**
    1435     * <p>
    1436     * Is {@code true} if this is Windows.
    1437     * </p>
    1438     * <p>
    1439     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1440     * </p>
    1441     *
    1442     * @since 2.0
    1443     */
    1444    public static final boolean IS_OS_WINDOWS = getOsMatchesName(OS_NAME_WINDOWS_PREFIX);
    1445
    1446    /**
    1447     * <p>
    1448     * Is {@code true} if this is Windows 2000.
    1449     * </p>
    1450     * <p>
    1451     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1452     * </p>
    1453     *
    1454     * @since 2.0
    1455     */
    1456    public static final boolean IS_OS_WINDOWS_2000 = getOsMatchesName(OS_NAME_WINDOWS_PREFIX + " 2000");
    1457
    1458    /**
    1459     * <p>
    1460     * Is {@code true} if this is Windows 2003.
    1461     * </p>
    1462     * <p>
    1463     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1464     * </p>
    1465     *
    1466     * @since 3.1
    1467     */
    1468    public static final boolean IS_OS_WINDOWS_2003 = getOsMatchesName(OS_NAME_WINDOWS_PREFIX + " 2003");
    1469
    1470    /**
    1471     * <p>
    1472     * Is {@code true} if this is Windows Server 2008.
    1473     * </p>
    1474     * <p>
    1475     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1476     * </p>
    1477     *
    1478     * @since 3.1
    1479     */
    1480    public static final boolean IS_OS_WINDOWS_2008 = getOsMatchesName(OS_NAME_WINDOWS_PREFIX + " Server 2008");
    1481
    1482    /**
    1483     * <p>
    1484     * Is {@code true} if this is Windows Server 2012.
    1485     * </p>
    1486     * <p>
    1487     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1488     * </p>
    1489     *
    1490     * @since 3.4
    1491     */
    1492    public static final boolean IS_OS_WINDOWS_2012 = getOsMatchesName(OS_NAME_WINDOWS_PREFIX + " Server 2012");
    1493
    1494    /**
    1495     * <p>
    1496     * Is {@code true} if this is Windows 95.
    1497     * </p>
    1498     * <p>
    1499     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1500     * </p>
    1501     *
    1502     * @since 2.0
    1503     */
    1504    public static final boolean IS_OS_WINDOWS_95 = getOsMatchesName(OS_NAME_WINDOWS_PREFIX + " 95");
    1505
    1506    /**
    1507     * <p>
    1508     * Is {@code true} if this is Windows 98.
    1509     * </p>
    1510     * <p>
    1511     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1512     * </p>
    1513     *
    1514     * @since 2.0
    1515     */
    1516    public static final boolean IS_OS_WINDOWS_98 = getOsMatchesName(OS_NAME_WINDOWS_PREFIX + " 98");
    1517
    1518    /**
    1519     * <p>
    1520     * Is {@code true} if this is Windows ME.
    1521     * </p>
    1522     * <p>
    1523     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1524     * </p>
    1525     *
    1526     * @since 2.0
    1527     */
    1528    public static final boolean IS_OS_WINDOWS_ME = getOsMatchesName(OS_NAME_WINDOWS_PREFIX + " Me");
    1529
    1530    /**
    1531     * <p>
    1532     * Is {@code true} if this is Windows NT.
    1533     * </p>
    1534     * <p>
    1535     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1536     * </p>
    1537     *
    1538     * @since 2.0
    1539     */
    1540    public static final boolean IS_OS_WINDOWS_NT = getOsMatchesName(OS_NAME_WINDOWS_PREFIX + " NT");
    1541
    1542    /**
    1543     * <p>
    1544     * Is {@code true} if this is Windows XP.
    1545     * </p>
    1546     * <p>
    1547     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1548     * </p>
    1549     *
    1550     * @since 2.0
    1551     */
    1552    public static final boolean IS_OS_WINDOWS_XP = getOsMatchesName(OS_NAME_WINDOWS_PREFIX + " XP");
    1553
    1554    // -----------------------------------------------------------------------
    1555    /**
    1556     * <p>
    1557     * Is {@code true} if this is Windows Vista.
    1558     * </p>
    1559     * <p>
    1560     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1561     * </p>
    1562     *
    1563     * @since 2.4
    1564     */
    1565    public static final boolean IS_OS_WINDOWS_VISTA = getOsMatchesName(OS_NAME_WINDOWS_PREFIX + " Vista");
    1566
    1567    /**
    1568     * <p>
    1569     * Is {@code true} if this is Windows 7.
    1570     * </p>
    1571     * <p>
    1572     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1573     * </p>
    1574     *
    1575     * @since 3.0
    1576     */
    1577    public static final boolean IS_OS_WINDOWS_7 = getOsMatchesName(OS_NAME_WINDOWS_PREFIX + " 7");
    1578
    1579    /**
    1580     * <p>
    1581     * Is {@code true} if this is Windows 8.
    1582     * </p>
    1583     * <p>
    1584     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1585     * </p>
    1586     *
    1587     * @since 3.2
    1588     */
    1589    public static final boolean IS_OS_WINDOWS_8 = getOsMatchesName(OS_NAME_WINDOWS_PREFIX + " 8");
    1590
    1591    /**
    1592     * <p>
    1593     * Is {@code true} if this is Windows 10.
    1594     * </p>
    1595     * <p>
    1596     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1597     * </p>
    1598     *
    1599     * @since 3.5
    1600     */
    1601    public static final boolean IS_OS_WINDOWS_10 = getOsMatchesName(OS_NAME_WINDOWS_PREFIX + " 10");
    1602
    1603    /**
    1604     * <p>
    1605     * Is {@code true} if this is z/OS.
    1606     * </p>
    1607     * <p>
    1608     * The field will return {@code false} if {@code OS_NAME} is {@code null}.
    1609     * </p>
    1610     *
    1611     * @since 3.5
    1612     */
    1613    // Values on a z/OS system I tested (Gary Gregory - 2016-03-12)
    1614    // os.arch = s390x
    1615    // os.encoding = ISO8859_1
    1616    // os.name = z/OS
    1617    // os.version = 02.02.00
    1618    public static final boolean IS_OS_ZOS = getOsMatchesName("z/OS");
    1619
    1620    /**
    1621     * <p>
    1622     * Gets an environment variable, defaulting to {@code defaultValue} if the variable cannot be read.
    1623     * </p>
    1624     * <p>
    1625     * If a {@code SecurityException} is caught, the return value is {@code defaultValue} and a message is written to
    1626     * {@code System.err}.
    1627     * </p>
    1628     *
    1629     * @param name
    1630     *            the environment variable name
    1631     * @param defaultValue
    1632     *            the default value
    1633     * @return the environment variable value or {@code defaultValue} if a security problem occurs
    1634     * @since 3.8
    1635     */
    1636    public static String getEnvironmentVariable(final String name, final String defaultValue) {
    1637        try {
    1638            final String value = System.getenv(name);
    1639            return value == null ? defaultValue : value;
    1640        } catch (final SecurityException ex) {
    1641            // we are not allowed to look at this property
    1642            // System.err.println("Caught a SecurityException reading the environment variable '" + name + "'.");
    1643            return defaultValue;
    1644        }
    1645    }
    1646
    1647    /**
    1648     * Gets the host name from an environment variable
    1649     * (COMPUTERNAME on Windows, HOSTNAME elsewhere).
    1650     *
    1651     * <p>
    1652     * If you want to know what the network stack says is the host name, you should use {@code InetAddress.getLocalHost().getHostName()}.
    1653     * </p>
    1654     *
    1655     * @return the host name. Will be {@code null} if the environment variable is not defined.
    1656     * @since 3.6
    1657     */
    1658    public static String getHostName() {
    1659        return IS_OS_WINDOWS ? System.getenv("COMPUTERNAME") : System.getenv("HOSTNAME");
    1660    }
    1661
    1662    /**
    1663     * <p>
    1664     * Gets the Java home directory as a {@code File}.
    1665     * </p>
    1666     *
    1667     * @return a directory
    1668     * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow
    1669     * access to the specified system property.
    1670     * @see System#getProperty(String)
    1671     * @since 2.1
    1672     */
    1673    public static File getJavaHome() {
    1674        return new File(System.getProperty(JAVA_HOME_KEY));
    1675    }
    1676
    1677    /**
    1678     * <p>
    1679     * Gets the Java IO temporary directory as a {@code File}.
    1680     * </p>
    1681     *
    1682     * @return a directory
    1683     * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow
    1684     * access to the specified system property.
    1685     * @see System#getProperty(String)
    1686     * @since 2.1
    1687     */
    1688    public static File getJavaIoTmpDir() {
    1689        return new File(System.getProperty(JAVA_IO_TMPDIR_KEY));
    1690    }
    1691
    1692    /**
    1693     * <p>
    1694     * Decides if the Java version matches.
    1695     * </p>
    1696     *
    1697     * @param versionPrefix the prefix for the java version
    1698     * @return true if matches, or false if not or can't determine
    1699     */
    1700    private static boolean getJavaVersionMatches(final String versionPrefix) {
    1701        return isJavaVersionMatch(JAVA_SPECIFICATION_VERSION, versionPrefix);
    1702    }
    1703
    1704    /**
    1705     * Decides if the operating system matches.
    1706     *
    1707     * @param osNamePrefix the prefix for the OS name
    1708     * @param osVersionPrefix the prefix for the version
    1709     * @return true if matches, or false if not or can't determine
    1710     */
    1711    private static boolean getOsMatches(final String osNamePrefix, final String osVersionPrefix) {
    1712        return isOSMatch(OS_NAME, OS_VERSION, osNamePrefix, osVersionPrefix);
    1713    }
    1714
    1715    /**
    1716     * Decides if the operating system matches.
    1717     *
    1718     * @param osNamePrefix the prefix for the OS name
    1719     * @return true if matches, or false if not or can't determine
    1720     */
    1721    private static boolean getOsMatchesName(final String osNamePrefix) {
    1722        return isOSNameMatch(OS_NAME, osNamePrefix);
    1723    }
    1724
    1725    // -----------------------------------------------------------------------
    1726    /**
    1727     * <p>
    1728     * Gets a System property, defaulting to {@code null} if the property cannot be read.
    1729     * </p>
    1730     * <p>
    1731     * If a {@code SecurityException} is caught, the return value is {@code null} and a message is written to
    1732     * {@code System.err}.
    1733     * </p>
    1734     *
    1735     * @param property the system property name
    1736     * @return the system property value or {@code null} if a security problem occurs
    1737     */
    1738    private static String getSystemProperty(final String property) {
    1739        try {
    1740            return System.getProperty(property);
    1741        } catch (final SecurityException ex) {
    1742            // we are not allowed to look at this property
    1743            // System.err.println("Caught a SecurityException reading the system property '" + property
    1744            // + "'; the SystemUtils property value will default to null.");
    1745            return null;
    1746        }
    1747    }
    1748
    1749    /**
    1750     * <p>
    1751     * Gets the user directory as a {@code File}.
    1752     * </p>
    1753     *
    1754     * @return a directory
    1755     * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow
    1756     * access to the specified system property.
    1757     * @see System#getProperty(String)
    1758     * @since 2.1
    1759     */
    1760    public static File getUserDir() {
    1761        return new File(System.getProperty(USER_DIR_KEY));
    1762    }
    1763
    1764    /**
    1765     * <p>
    1766     * Gets the user home directory as a {@code File}.
    1767     * </p>
    1768     *
    1769     * @return a directory
    1770     * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow
    1771     * access to the specified system property.
    1772     * @see System#getProperty(String)
    1773     * @since 2.1
    1774     */
    1775    public static File getUserHome() {
    1776        return new File(System.getProperty(USER_HOME_KEY));
    1777    }
    1778
    1779    /**
    1780     * <p>
    1781     * Gets the user name.
    1782     * </p>
    1783     *
    1784     * @return a name
    1785     * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow
    1786     * access to the specified system property.
    1787     * @see System#getProperty(String)
    1788     * @since 3.10
    1789     */
    1790    public static String getUserName() {
    1791        return System.getProperty(USER_NAME_KEY);
    1792    }
    1793
    1794    /**
    1795     * <p>
    1796     * Gets the user name.
    1797     * </p>
    1798     *
    1799     * @param defaultValue A default value.
    1800     * @return a name
    1801     * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow
    1802     * access to the specified system property.
    1803     * @see System#getProperty(String)
    1804     * @since 3.10
    1805     */
    1806    public static String getUserName(final String defaultValue) {
    1807        return System.getProperty(USER_NAME_KEY, defaultValue);
    1808    }
    1809
    1810    /**
    1811     * Returns whether the {@link #JAVA_AWT_HEADLESS} value is {@code true}.
    1812     *
    1813     * @return {@code true} if {@code JAVA_AWT_HEADLESS} is {@code "true"}, {@code false} otherwise.
    1814     * @see #JAVA_AWT_HEADLESS
    1815     * @since 2.1
    1816     * @since Java 1.4
    1817     */
    1818    public static boolean isJavaAwtHeadless() {
    1819        return Boolean.TRUE.toString().equals(JAVA_AWT_HEADLESS);
    1820    }
    1821
    1822    /**
    1823     * <p>
    1824     * Is the Java version at least the requested version.
    1825     * </p>
    1826     * <p>
    1827     *
    1828     * @param requiredVersion the required version, for example 1.31f
    1829     * @return {@code true} if the actual version is equal or greater than the required version
    1830     */
    1831    public static boolean isJavaVersionAtLeast(final JavaVersion requiredVersion) {
    1832        return JAVA_SPECIFICATION_VERSION_AS_ENUM.atLeast(requiredVersion);
    1833    }
    1834
    1835    /**
    1836     * <p>
    1837     * Is the Java version at most the requested version.
    1838     * </p>
    1839     * <p>
    1840     * Example input:
    1841     * </p>
    1842     *
    1843     * @param requiredVersion the required version, for example 1.31f
    1844     * @return {@code true} if the actual version is equal or less than the required version
    1845     * @since 3.9
    1846     */
    1847    public static boolean isJavaVersionAtMost(final JavaVersion requiredVersion) {
    1848        return JAVA_SPECIFICATION_VERSION_AS_ENUM.atMost(requiredVersion);
    1849    }
    1850
    1851    /**
    1852     * <p>
    1853     * Decides if the Java version matches.
    1854     * </p>
    1855     * <p>
    1856     * This method is package private instead of private to support unit test invocation.
    1857     * </p>
    1858     *
    1859     * @param version the actual Java version
    1860     * @param versionPrefix the prefix for the expected Java version
    1861     * @return true if matches, or false if not or can't determine
    1862     */
    1863    static boolean isJavaVersionMatch(final String version, final String versionPrefix) {
    1864        if (version == null) {
    1865            return false;
    1866        }
    1867        return version.startsWith(versionPrefix);
    1868    }
    1869
    1870    /**
    1871     * Decides if the operating system matches.
    1872     * <p>
    1873     * This method is package private instead of private to support unit test invocation.
    1874     * </p>
    1875     *
    1876     * @param osName the actual OS name
    1877     * @param osVersion the actual OS version
    1878     * @param osNamePrefix the prefix for the expected OS name
    1879     * @param osVersionPrefix the prefix for the expected OS version
    1880     * @return true if matches, or false if not or can't determine
    1881     */
    1882    static boolean isOSMatch(final String osName, final String osVersion, final String osNamePrefix, final String osVersionPrefix) {
    1883        if (osName == null || osVersion == null) {
    1884            return false;
    1885        }
    1886        return isOSNameMatch(osName, osNamePrefix) && isOSVersionMatch(osVersion, osVersionPrefix);
    1887    }
    1888
    1889    /**
    1890     * Decides if the operating system matches.
    1891     * <p>
    1892     * This method is package private instead of private to support unit test invocation.
    1893     * </p>
    1894     *
    1895     * @param osName the actual OS name
    1896     * @param osNamePrefix the prefix for the expected OS name
    1897     * @return true if matches, or false if not or can't determine
    1898     */
    1899    static boolean isOSNameMatch(final String osName, final String osNamePrefix) {
    1900        if (osName == null) {
    1901            return false;
    1902        }
    1903        return osName.startsWith(osNamePrefix);
    1904    }
    1905
    1906    /**
    1907     * Decides if the operating system version matches.
    1908     * <p>
    1909     * This method is package private instead of private to support unit test invocation.
    1910     * </p>
    1911     *
    1912     * @param osVersion the actual OS version
    1913     * @param osVersionPrefix the prefix for the expected OS version
    1914     * @return true if matches, or false if not or can't determine
    1915     */
    1916    static boolean isOSVersionMatch(final String osVersion, final String osVersionPrefix) {
    1917        if (StringUtils.isEmpty(osVersion)) {
    1918            return false;
    1919        }
    1920        // Compare parts of the version string instead of using String.startsWith(String) because otherwise
    1921        // osVersionPrefix 10.1 would also match osVersion 10.10
    1922        final String[] versionPrefixParts = osVersionPrefix.split("\\.");
    1923        final String[] versionParts = osVersion.split("\\.");
    1924        for (int i = 0; i < Math.min(versionPrefixParts.length, versionParts.length); i++) {
    1925            if (!versionPrefixParts[i].equals(versionParts[i])) {
    1926                return false;
    1927            }
    1928        }
    1929        return true;
    1930    }
    1931
    1932    // -----------------------------------------------------------------------
    1933    /**
    1934     * <p>
    1935     * SystemUtils instances should NOT be constructed in standard programming. Instead, the class should be used as
    1936     * {@code SystemUtils.FILE_SEPARATOR}.
    1937     * </p>
    1938     * <p>
    1939     * This constructor is public to permit tools that require a JavaBean instance to operate.
    1940     * </p>
    1941     */
    1942    public SystemUtils() {
    1943    }
    1944
    1945}