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 * https://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; 020import java.nio.file.Path; 021import java.nio.file.Paths; 022 023/** 024 * Helpers for {@link System}. 025 * 026 * <p> 027 * If a system property cannot be read due to security restrictions, the corresponding field in this class will be set to {@code null} and a message will be 028 * written to {@code System.err}. 029 * </p> 030 * <p> 031 * #ThreadSafe# 032 * </p> 033 * 034 * @since 1.0 035 * @see SystemProperties 036 */ 037public class SystemUtils { 038 039 /** 040 * The prefix String for all Windows OS. 041 */ 042 private static final String OS_NAME_WINDOWS_PREFIX = "Windows"; 043 044 // System property constants 045 // ----------------------------------------------------------------------- 046 // These MUST be declared first. Other constants depend on this. 047 048 /** 049 * A constant for the System Property {@code file.encoding}. 050 * 051 * <p> 052 * File encoding, such as {@code Cp1252}. 053 * </p> 054 * <p> 055 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 056 * </p> 057 * <p> 058 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 059 * called after this class is loaded, the value will be out of sync with that System property. 060 * </p> 061 * 062 * @see SystemProperties#getFileEncoding() 063 * @since 2.0 064 * @since Java 1.2 065 */ 066 public static final String FILE_ENCODING = SystemProperties.getFileEncoding(); 067 068 /** 069 * A constant for the System Property {@code file.separator}. 070 * <p> 071 * The file separator is: 072 * </p> 073 * <ul> 074 * <li>{@code "/"} on Unix</li> 075 * <li>{@code "\"} on Windows.</li> 076 * </ul> 077 * 078 * <p> 079 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 080 * </p> 081 * <p> 082 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 083 * called after this class is loaded, the value will be out of sync with that System property. 084 * </p> 085 * 086 * @see SystemProperties#getFileSeparator() 087 * @since Java 1.1 088 * @deprecated Use {@link File#separator}, since it is guaranteed to be a string containing a single character and it does not require a privilege check. 089 */ 090 @Deprecated 091 public static final String FILE_SEPARATOR = SystemProperties.getFileSeparator(); 092 093 /** 094 * A constant for the System Property {@code java.awt.fonts}. 095 * 096 * <p> 097 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 098 * </p> 099 * <p> 100 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 101 * called after this class is loaded, the value will be out of sync with that System property. 102 * </p> 103 * 104 * @see SystemProperties#getJavaAwtFonts() 105 * @since 2.1 106 * @deprecated Deprecated without replacement. 107 */ 108 @Deprecated 109 public static final String JAVA_AWT_FONTS = SystemProperties.getJavaAwtFonts(); 110 111 /** 112 * A constant for the System Property {@code java.awt.graphicsenv}. 113 * 114 * <p> 115 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 116 * </p> 117 * <p> 118 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 119 * called after this class is loaded, the value will be out of sync with that System property. 120 * </p> 121 * 122 * @see SystemProperties#getJavaAwtGraphicsenv() 123 * @since 2.1 124 * @deprecated Deprecated without replacement. 125 */ 126 @Deprecated 127 public static final String JAVA_AWT_GRAPHICSENV = SystemProperties.getJavaAwtGraphicsenv(); 128 129 /** 130 * A constant for the System Property {@code java.awt.headless}. The value of this property is the String {@code "true"} or {@code "false"}. 131 * 132 * <p> 133 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 134 * </p> 135 * <p> 136 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 137 * called after this class is loaded, the value will be out of sync with that System property. 138 * </p> 139 * 140 * @see #isJavaAwtHeadless() 141 * @see SystemProperties#getJavaAwtHeadless() 142 * @since 2.1 143 * @since Java 1.4 144 * @deprecated Deprecated without replacement. 145 */ 146 @Deprecated 147 public static final String JAVA_AWT_HEADLESS = SystemProperties.getJavaAwtHeadless(); 148 149 /** 150 * A constant for the System Property {@code java.awt.printerjob}. 151 * 152 * <p> 153 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 154 * </p> 155 * <p> 156 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 157 * called after this class is loaded, the value will be out of sync with that System property. 158 * </p> 159 * 160 * @see SystemProperties#getJavaAwtPrinterjob() 161 * @since 2.1 162 * @deprecated Deprecated without replacement. 163 */ 164 @Deprecated 165 public static final String JAVA_AWT_PRINTERJOB = SystemProperties.getJavaAwtPrinterjob(); 166 167 /** 168 * A constant for the System Property {@code java.class.path}. Java class path. 169 * 170 * <p> 171 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 172 * </p> 173 * <p> 174 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 175 * called after this class is loaded, the value will be out of sync with that System property. 176 * </p> 177 * 178 * @see SystemProperties#getJavaClassPath() 179 * @since Java 1.1 180 */ 181 public static final String JAVA_CLASS_PATH = SystemProperties.getJavaClassPath(); 182 183 /** 184 * A constant for the System Property {@code java.class.version}. Java class format version number. 185 * 186 * <p> 187 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 188 * </p> 189 * <p> 190 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 191 * called after this class is loaded, the value will be out of sync with that System property. 192 * </p> 193 * 194 * @see SystemProperties#getJavaClassVersion() 195 * @since Java 1.1 196 */ 197 public static final String JAVA_CLASS_VERSION = SystemProperties.getJavaClassVersion(); 198 199 /** 200 * A constant for the System Property {@code java.compiler}. Name of JIT compiler to use. First in JDK version 1.2. Not used in Sun JDKs after 1.2. 201 * 202 * <p> 203 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 204 * </p> 205 * <p> 206 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 207 * called after this class is loaded, the value will be out of sync with that System property. 208 * </p> 209 * 210 * @see SystemProperties#getJavaCompiler() 211 * @since Java 1.2. Not used in Sun versions after 1.2. 212 * @deprecated Deprecated without replacement; see https://bugs.openjdk.org/browse/JDK-8305998 213 */ 214 @Deprecated 215 public static final String JAVA_COMPILER = SystemProperties.getJavaCompiler(); 216 217 /** 218 * A constant for the System Property {@code java.endorsed.dirs}. Path of endorsed directory or directories. 219 * 220 * <p> 221 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 222 * </p> 223 * <p> 224 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 225 * called after this class is loaded, the value will be out of sync with that System property. 226 * </p> 227 * 228 * @see SystemProperties#getJavaEndorsedDirs() 229 * @since Java 1.4 230 * @deprecated Deprecated without replacement. 231 */ 232 @Deprecated 233 public static final String JAVA_ENDORSED_DIRS = SystemProperties.getJavaEndorsedDirs(); 234 235 /** 236 * A constant for the System Property {@code java.ext.dirs}. Path of extension directory or directories. 237 * 238 * <p> 239 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 240 * </p> 241 * <p> 242 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 243 * called after this class is loaded, the value will be out of sync with that System property. 244 * </p> 245 * 246 * @see SystemProperties#getJavaExtDirs() 247 * @since Java 1.3 248 * @deprecated Deprecated without replacement. 249 */ 250 @Deprecated 251 public static final String JAVA_EXT_DIRS = SystemProperties.getJavaExtDirs(); 252 253 /** 254 * A constant for the System Property {@code java.home}. Java installation directory. 255 * 256 * <p> 257 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 258 * </p> 259 * <p> 260 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 261 * called after this class is loaded, the value will be out of sync with that System property. 262 * </p> 263 * 264 * @see SystemProperties#getJavaHome() 265 * @since Java 1.1 266 */ 267 public static final String JAVA_HOME = SystemProperties.getJavaHome(); 268 269 /** 270 * A constant for the System Property {@code java.io.tmpdir}. Default temp file path. 271 * 272 * <p> 273 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 274 * </p> 275 * <p> 276 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 277 * called after this class is loaded, the value will be out of sync with that System property. 278 * </p> 279 * 280 * @see SystemProperties#getJavaIoTmpdir() 281 * @since Java 1.2 282 */ 283 public static final String JAVA_IO_TMPDIR = SystemProperties.getJavaIoTmpdir(); 284 285 /** 286 * A constant for the System Property {@code java.library.path}. List of paths to search when loading libraries. 287 * 288 * <p> 289 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 290 * </p> 291 * <p> 292 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 293 * called after this class is loaded, the value will be out of sync with that System property. 294 * </p> 295 * 296 * @see SystemProperties#getJavaLibraryPath() 297 * @since Java 1.2 298 */ 299 public static final String JAVA_LIBRARY_PATH = SystemProperties.getJavaLibraryPath(); 300 301 /** 302 * A constant for the System Property {@code java.runtime.name}. Java Runtime Environment name. 303 * 304 * <p> 305 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 306 * </p> 307 * <p> 308 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 309 * called after this class is loaded, the value will be out of sync with that System property. 310 * </p> 311 * 312 * @see SystemProperties#getJavaRuntimeName() 313 * @since 2.0 314 * @since Java 1.3 315 */ 316 public static final String JAVA_RUNTIME_NAME = SystemProperties.getJavaRuntimeName(); 317 318 /** 319 * A constant for the System Property {@code java.runtime.version}. Java Runtime Environment version. 320 * 321 * <p> 322 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 323 * </p> 324 * <p> 325 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 326 * called after this class is loaded, the value will be out of sync with that System property. 327 * </p> 328 * 329 * @see SystemProperties#getJavaRuntimeVersion() 330 * @since 2.0 331 * @since Java 1.3 332 */ 333 public static final String JAVA_RUNTIME_VERSION = SystemProperties.getJavaRuntimeVersion(); 334 335 /** 336 * A constant for the System Property {@code java.specification.name}. Java Runtime Environment specification name. 337 * 338 * <p> 339 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 340 * </p> 341 * <p> 342 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 343 * called after this class is loaded, the value will be out of sync with that System property. 344 * </p> 345 * 346 * @see SystemProperties#getJavaSpecificationName() 347 * @since Java 1.2 348 */ 349 public static final String JAVA_SPECIFICATION_NAME = SystemProperties.getJavaSpecificationName(); 350 351 /** 352 * A constant for the System Property {@code java.specification.vendor}. Java Runtime Environment specification vendor. 353 * 354 * <p> 355 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 356 * </p> 357 * <p> 358 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 359 * called after this class is loaded, the value will be out of sync with that System property. 360 * </p> 361 * 362 * @see SystemProperties#getJavaSpecificationVendor() 363 * @since Java 1.2 364 */ 365 public static final String JAVA_SPECIFICATION_VENDOR = SystemProperties.getJavaSpecificationVendor(); 366 367 /** 368 * A constant for the System Property {@code java.specification.version}. Java Runtime Environment specification version. 369 * 370 * <p> 371 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 372 * </p> 373 * <p> 374 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 375 * called after this class is loaded, the value will be out of sync with that System property. 376 * </p> 377 * 378 * @see SystemProperties#getJavaSpecificationVersion() 379 * @since Java 1.3 380 */ 381 public static final String JAVA_SPECIFICATION_VERSION = SystemProperties.getJavaSpecificationVersion(); 382 383 /** 384 * A constant for the Java version, may be null. 385 */ 386 static final JavaVersion JAVA_SPECIFICATION_VERSION_ENUM = JavaVersion.get(JAVA_SPECIFICATION_VERSION); 387 388 /** 389 * A constant for the System Property {@code java.util.prefs.PreferencesFactory}. A class name. 390 * 391 * <p> 392 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 393 * </p> 394 * <p> 395 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 396 * called after this class is loaded, the value will be out of sync with that System property. 397 * </p> 398 * 399 * @see SystemProperties#getJavaUtilPrefsPreferencesFactory() 400 * @since 2.1 401 * @since Java 1.4 402 */ 403 public static final String JAVA_UTIL_PREFS_PREFERENCES_FACTORY = SystemProperties.getJavaUtilPrefsPreferencesFactory(); 404 405 /** 406 * A constant for the System Property {@code java.vendor}. Java vendor-specific string. 407 * 408 * <p> 409 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 410 * </p> 411 * <p> 412 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 413 * called after this class is loaded, the value will be out of sync with that System property. 414 * </p> 415 * 416 * @see SystemProperties#getJavaVendor() 417 * @since Java 1.1 418 */ 419 public static final String JAVA_VENDOR = SystemProperties.getJavaVendor(); 420 421 /** 422 * A constant for the System Property {@code java.vendor.url}. Java vendor URL. 423 * 424 * <p> 425 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 426 * </p> 427 * <p> 428 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 429 * called after this class is loaded, the value will be out of sync with that System property. 430 * </p> 431 * 432 * @see SystemProperties#getJavaVendorUrl() 433 * @since Java 1.1 434 */ 435 public static final String JAVA_VENDOR_URL = SystemProperties.getJavaVendorUrl(); 436 437 /** 438 * A constant for the System Property {@code java.version}. Java version number. 439 * 440 * <p> 441 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 442 * </p> 443 * <p> 444 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 445 * called after this class is loaded, the value will be out of sync with that System property. 446 * </p> 447 * 448 * @see SystemProperties#getJavaVersion() 449 * @since Java 1.1 450 */ 451 public static final String JAVA_VERSION = SystemProperties.getJavaVersion(); 452 453 /** 454 * A constant for the System Property {@code java.vm.info}. Java Virtual Machine implementation info. 455 * 456 * <p> 457 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 458 * </p> 459 * <p> 460 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 461 * called after this class is loaded, the value will be out of sync with that System property. 462 * </p> 463 * 464 * @see SystemProperties#getJavaVmInfo() 465 * @since 2.0 466 * @since Java 1.2 467 */ 468 public static final String JAVA_VM_INFO = SystemProperties.getJavaVmInfo(); 469 470 /** 471 * A constant for the System Property {@code java.vm.name}. Java Virtual Machine implementation name. 472 * 473 * <p> 474 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 475 * </p> 476 * <p> 477 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 478 * called after this class is loaded, the value will be out of sync with that System property. 479 * </p> 480 * 481 * @see SystemProperties#getJavaVmName() 482 * @since Java 1.2 483 */ 484 public static final String JAVA_VM_NAME = SystemProperties.getJavaVmName(); 485 486 /** 487 * A constant for the System Property {@code java.vm.specification.name}. Java Virtual Machine specification name. 488 * 489 * <p> 490 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 491 * </p> 492 * <p> 493 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 494 * called after this class is loaded, the value will be out of sync with that System property. 495 * </p> 496 * 497 * @see SystemProperties#getJavaVmSpecificationName() 498 * @since Java 1.2 499 */ 500 public static final String JAVA_VM_SPECIFICATION_NAME = SystemProperties.getJavaVmSpecificationName(); 501 502 /** 503 * A constant for the System Property {@code java.vm.specification.vendor}. Java Virtual Machine specification vendor. 504 * 505 * <p> 506 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 507 * </p> 508 * <p> 509 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 510 * called after this class is loaded, the value will be out of sync with that System property. 511 * </p> 512 * 513 * @see SystemProperties#getJavaVmSpecificationVendor() 514 * @since Java 1.2 515 */ 516 public static final String JAVA_VM_SPECIFICATION_VENDOR = SystemProperties.getJavaVmSpecificationVendor(); 517 518 /** 519 * A constant for the System Property {@code java.vm.specification.version}. Java Virtual Machine specification version. 520 * 521 * <p> 522 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 523 * </p> 524 * <p> 525 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 526 * called after this class is loaded, the value will be out of sync with that System property. 527 * </p> 528 * 529 * @see SystemProperties#getJavaVmSpecificationVersion() 530 * @since Java 1.2 531 */ 532 public static final String JAVA_VM_SPECIFICATION_VERSION = SystemProperties.getJavaVmSpecificationVersion(); 533 534 /** 535 * A constant for the System Property {@code java.vm.vendor}. Java Virtual Machine implementation vendor. 536 * 537 * <p> 538 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 539 * </p> 540 * <p> 541 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 542 * called after this class is loaded, the value will be out of sync with that System property. 543 * </p> 544 * 545 * @see SystemProperties#getJavaVmVendor() 546 * @since Java 1.2 547 */ 548 public static final String JAVA_VM_VENDOR = SystemProperties.getJavaVmVendor(); 549 550 /** 551 * A constant for the System Property {@code java.vm.version}. Java Virtual Machine implementation version. 552 * 553 * <p> 554 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 555 * </p> 556 * <p> 557 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 558 * called after this class is loaded, the value will be out of sync with that System property. 559 * </p> 560 * 561 * @see SystemProperties#getJavaVmVersion() 562 * @since Java 1.2 563 */ 564 public static final String JAVA_VM_VERSION = SystemProperties.getJavaVmVersion(); 565 566 /** 567 * A constant for the System Property {@code line.separator}. Line separator ({@code "\n"} on Unix). 568 * 569 * <p> 570 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 571 * </p> 572 * <p> 573 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 574 * called after this class is loaded, the value will be out of sync with that System property. 575 * </p> 576 * 577 * @see SystemProperties#getLineSeparator() 578 * @since Java 1.1 579 * @deprecated Use {@link System#lineSeparator()} instead, since it does not require a privilege check. 580 */ 581 @Deprecated 582 public static final String LINE_SEPARATOR = SystemProperties.getLineSeparator(); 583 584 /** 585 * A constant for the System Property {@code os.arch}. Operating system architecture. 586 * 587 * <p> 588 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 589 * </p> 590 * <p> 591 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 592 * called after this class is loaded, the value will be out of sync with that System property. 593 * </p> 594 * 595 * @see SystemProperties#getOsArch() 596 * @since Java 1.1 597 */ 598 public static final String OS_ARCH = SystemProperties.getOsArch(); 599 600 /** 601 * A constant for the System Property {@code os.name}. Operating system name. 602 * 603 * <p> 604 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 605 * </p> 606 * <p> 607 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 608 * called after this class is loaded, the value will be out of sync with that System property. 609 * </p> 610 * 611 * @see SystemProperties#getOsName() 612 * @since Java 1.1 613 */ 614 public static final String OS_NAME = SystemProperties.getOsName(); 615 616 /** 617 * A constant for the System Property {@code os.version}. Operating system version. 618 * 619 * <p> 620 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 621 * </p> 622 * <p> 623 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 624 * called after this class is loaded, the value will be out of sync with that System property. 625 * </p> 626 * 627 * @see SystemProperties#getOsVersion() 628 * @since Java 1.1 629 */ 630 public static final String OS_VERSION = SystemProperties.getOsVersion(); 631 632 /** 633 * A constant for the System Property {@code path.separator}. Path separator ({@code ":"} on Unix). 634 * 635 * <p> 636 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 637 * </p> 638 * <p> 639 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 640 * called after this class is loaded, the value will be out of sync with that System property. 641 * </p> 642 * 643 * @see SystemProperties#getPathSeparator() 644 * @since Java 1.1 645 * @deprecated Use {@link File#pathSeparator}, since it is guaranteed to be a string containing a single character and it does not require a privilege 646 * check. 647 */ 648 @Deprecated 649 public static final String PATH_SEPARATOR = SystemProperties.getPathSeparator(); 650 651 /** 652 * A constant for the System Property {@code user.country} or {@code user.region}. User's country code, such as {@code "GB"}. First in Java version 1.2 as 653 * {@code user.region}. Renamed to {@code user.country} in 1.4 654 * 655 * <p> 656 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 657 * </p> 658 * <p> 659 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 660 * called after this class is loaded, the value will be out of sync with that System property. 661 * </p> 662 * 663 * @since 2.0 664 * @since Java 1.2 665 */ 666 public static final String USER_COUNTRY = SystemProperties.getProperty(SystemProperties.USER_COUNTRY, 667 () -> SystemProperties.getProperty(SystemProperties.USER_REGION)); 668 669 /** 670 * A constant for the System Property {@code user.dir}. User's current working directory. 671 * 672 * <p> 673 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 674 * </p> 675 * <p> 676 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 677 * called after this class is loaded, the value will be out of sync with that System property. 678 * </p> 679 * 680 * @see SystemProperties#getUserDir() 681 * @since Java 1.1 682 */ 683 public static final String USER_DIR = SystemProperties.getUserDir(); 684 685 /** 686 * A constant for the System Property {@code user.home}. User's home directory. 687 * 688 * <p> 689 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 690 * </p> 691 * <p> 692 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 693 * called after this class is loaded, the value will be out of sync with that System property. 694 * </p> 695 * 696 * @see SystemProperties#getUserHome() 697 * @since Java 1.1 698 */ 699 public static final String USER_HOME = SystemProperties.getUserHome(); 700 701 /** 702 * A constant for the System Property {@code user.language}. User's language code, such as {@code "en"}. 703 * 704 * <p> 705 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 706 * </p> 707 * <p> 708 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 709 * called after this class is loaded, the value will be out of sync with that System property. 710 * </p> 711 * 712 * @see SystemProperties#getUserLanguage() 713 * @since 2.0 714 * @since Java 1.2 715 */ 716 public static final String USER_LANGUAGE = SystemProperties.getUserLanguage(); 717 718 /** 719 * A constant for the System Property {@code user.name}. User's account name. 720 * 721 * <p> 722 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 723 * </p> 724 * <p> 725 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 726 * called after this class is loaded, the value will be out of sync with that System property. 727 * </p> 728 * 729 * @see SystemProperties#getUserName() 730 * @since Java 1.1 731 */ 732 public static final String USER_NAME = SystemProperties.getUserName(); 733 734 /** 735 * A constant for the System Property {@code user.timezone}. For example: {@code "America/Los_Angeles"}. 736 * 737 * <p> 738 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 739 * </p> 740 * <p> 741 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 742 * called after this class is loaded, the value will be out of sync with that System property. 743 * </p> 744 * 745 * @see SystemProperties#getUserTimezone() 746 * @since 2.1 747 */ 748 public static final String USER_TIMEZONE = SystemProperties.getUserTimezone(); 749 750 // Java version checks 751 // ----------------------------------------------------------------------- 752 // These MUST be declared after those above as they depend on the 753 // values being set up 754 755 /** 756 * The constant {@code true} if this is Java version 1.1 (also 1.1.x versions). 757 * <p> 758 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 759 * </p> 760 * <p> 761 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 762 * </p> 763 * <p> 764 * This value is initialized when the class is loaded. 765 * </p> 766 */ 767 public static final boolean IS_JAVA_1_1 = getJavaVersionMatches("1.1"); 768 769 /** 770 * The constant {@code true} if this is Java version 1.2 (also 1.2.x versions). 771 * <p> 772 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 773 * </p> 774 * <p> 775 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 776 * </p> 777 * <p> 778 * This value is initialized when the class is loaded. 779 * </p> 780 */ 781 public static final boolean IS_JAVA_1_2 = getJavaVersionMatches("1.2"); 782 783 /** 784 * The constant {@code true} if this is Java version 1.3 (also 1.3.x versions). 785 * <p> 786 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 787 * </p> 788 * <p> 789 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 790 * </p> 791 * <p> 792 * This value is initialized when the class is loaded. 793 * </p> 794 */ 795 public static final boolean IS_JAVA_1_3 = getJavaVersionMatches("1.3"); 796 797 /** 798 * The constant {@code true} if this is Java version 1.4 (also 1.4.x versions). 799 * <p> 800 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 801 * </p> 802 * <p> 803 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 804 * </p> 805 * <p> 806 * This value is initialized when the class is loaded. 807 * </p> 808 */ 809 public static final boolean IS_JAVA_1_4 = getJavaVersionMatches("1.4"); 810 811 /** 812 * The constant {@code true} if this is Java version 1.5 (also 1.5.x versions). 813 * <p> 814 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 815 * </p> 816 * <p> 817 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 818 * </p> 819 * <p> 820 * This value is initialized when the class is loaded. 821 * </p> 822 */ 823 public static final boolean IS_JAVA_1_5 = getJavaVersionMatches("1.5"); 824 825 /** 826 * The constant {@code true} if this is Java version 1.6 (also 1.6.x versions). 827 * <p> 828 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 829 * </p> 830 * <p> 831 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 832 * </p> 833 * <p> 834 * This value is initialized when the class is loaded. 835 * </p> 836 */ 837 public static final boolean IS_JAVA_1_6 = getJavaVersionMatches("1.6"); 838 839 /** 840 * The constant {@code true} if this is Java version 1.7 (also 1.7.x versions). 841 * <p> 842 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 843 * </p> 844 * <p> 845 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 846 * </p> 847 * <p> 848 * This value is initialized when the class is loaded. 849 * </p> 850 * 851 * @since 3.0 852 */ 853 public static final boolean IS_JAVA_1_7 = getJavaVersionMatches("1.7"); 854 855 /** 856 * The constant {@code true} if this is Java version 1.8 (also 1.8.x versions). 857 * <p> 858 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 859 * </p> 860 * <p> 861 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 862 * </p> 863 * <p> 864 * This value is initialized when the class is loaded. 865 * </p> 866 * 867 * @since 3.3.2 868 */ 869 public static final boolean IS_JAVA_1_8 = getJavaVersionMatches("1.8"); 870 871 /** 872 * The constant {@code true} if this is Java version 1.9 (also 1.9.x versions). 873 * <p> 874 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 875 * </p> 876 * <p> 877 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 878 * </p> 879 * <p> 880 * This value is initialized when the class is loaded. 881 * </p> 882 * 883 * @since 3.4 884 * @deprecated As of release 3.5, replaced by {@link #IS_JAVA_9}. 885 */ 886 @Deprecated 887 public static final boolean IS_JAVA_1_9 = getJavaVersionMatches("9"); 888 889 /** 890 * The constant {@code true} if this is Java version 9 (also 9.x versions). 891 * <p> 892 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 893 * </p> 894 * <p> 895 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 896 * </p> 897 * <p> 898 * This value is initialized when the class is loaded. 899 * </p> 900 * 901 * @since 3.5 902 */ 903 public static final boolean IS_JAVA_9 = getJavaVersionMatches("9"); 904 905 /** 906 * The constant {@code true} if this is Java version 10 (also 10.x versions). 907 * <p> 908 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 909 * </p> 910 * <p> 911 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 912 * </p> 913 * <p> 914 * This value is initialized when the class is loaded. 915 * </p> 916 * 917 * @since 3.7 918 */ 919 public static final boolean IS_JAVA_10 = getJavaVersionMatches("10"); 920 921 /** 922 * The constant {@code true} if this is Java version 11 (also 11.x versions). 923 * <p> 924 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 925 * </p> 926 * <p> 927 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 928 * </p> 929 * <p> 930 * This value is initialized when the class is loaded. 931 * </p> 932 * 933 * @since 3.8 934 */ 935 public static final boolean IS_JAVA_11 = getJavaVersionMatches("11"); 936 937 /** 938 * The constant {@code true} if this is Java version 12 (also 12.x versions). 939 * <p> 940 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 941 * </p> 942 * <p> 943 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 944 * </p> 945 * <p> 946 * This value is initialized when the class is loaded. 947 * </p> 948 * 949 * @since 3.9 950 */ 951 public static final boolean IS_JAVA_12 = getJavaVersionMatches("12"); 952 953 /** 954 * The constant {@code true} if this is Java version 13 (also 13.x versions). 955 * <p> 956 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 957 * </p> 958 * <p> 959 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 960 * </p> 961 * <p> 962 * This value is initialized when the class is loaded. 963 * </p> 964 * 965 * @since 3.9 966 */ 967 public static final boolean IS_JAVA_13 = getJavaVersionMatches("13"); 968 969 /** 970 * The constant {@code true} if this is Java version 14 (also 14.x versions). 971 * <p> 972 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 973 * </p> 974 * <p> 975 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 976 * </p> 977 * <p> 978 * This value is initialized when the class is loaded. 979 * </p> 980 * 981 * @since 3.10 982 */ 983 public static final boolean IS_JAVA_14 = getJavaVersionMatches("14"); 984 985 /** 986 * The constant {@code true} if this is Java version 15 (also 15.x versions). 987 * <p> 988 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 989 * </p> 990 * <p> 991 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 992 * </p> 993 * <p> 994 * This value is initialized when the class is loaded. 995 * </p> 996 * 997 * @since 3.10 998 */ 999 public static final boolean IS_JAVA_15 = getJavaVersionMatches("15"); 1000 1001 /** 1002 * The constant {@code true} if this is Java version 16 (also 16.x versions). 1003 * <p> 1004 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 1005 * </p> 1006 * <p> 1007 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 1008 * </p> 1009 * <p> 1010 * This value is initialized when the class is loaded. 1011 * </p> 1012 * 1013 * @since 3.13.0 1014 */ 1015 public static final boolean IS_JAVA_16 = getJavaVersionMatches("16"); 1016 1017 /** 1018 * The constant {@code true} if this is Java version 17 (also 17.x versions). 1019 * <p> 1020 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 1021 * </p> 1022 * <p> 1023 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 1024 * </p> 1025 * <p> 1026 * This value is initialized when the class is loaded. 1027 * </p> 1028 * 1029 * @since 3.13.0 1030 */ 1031 public static final boolean IS_JAVA_17 = getJavaVersionMatches("17"); 1032 1033 /** 1034 * The constant {@code true} if this is Java version 18 (also 18.x versions). 1035 * <p> 1036 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 1037 * </p> 1038 * <p> 1039 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 1040 * </p> 1041 * <p> 1042 * This value is initialized when the class is loaded. 1043 * </p> 1044 * 1045 * @since 3.13.0 1046 */ 1047 public static final boolean IS_JAVA_18 = getJavaVersionMatches("18"); 1048 1049 /** 1050 * The constant {@code true} if this is Java version 19 (also 19.x versions). 1051 * <p> 1052 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 1053 * </p> 1054 * <p> 1055 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 1056 * </p> 1057 * <p> 1058 * This value is initialized when the class is loaded. 1059 * </p> 1060 * 1061 * @since 3.13.0 1062 */ 1063 public static final boolean IS_JAVA_19 = getJavaVersionMatches("19"); 1064 1065 /** 1066 * The constant {@code true} if this is Java version 20 (also 20.x versions). 1067 * <p> 1068 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 1069 * </p> 1070 * <p> 1071 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 1072 * </p> 1073 * <p> 1074 * This value is initialized when the class is loaded. 1075 * </p> 1076 * 1077 * @since 3.13.0 1078 */ 1079 public static final boolean IS_JAVA_20 = getJavaVersionMatches("20"); 1080 1081 /** 1082 * The constant {@code true} if this is Java version 21 (also 21.x versions). 1083 * <p> 1084 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 1085 * </p> 1086 * <p> 1087 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 1088 * </p> 1089 * <p> 1090 * This value is initialized when the class is loaded. 1091 * </p> 1092 * 1093 * @since 3.13.0 1094 */ 1095 public static final boolean IS_JAVA_21 = getJavaVersionMatches("21"); 1096 1097 /** 1098 * The constant {@code true} if this is Java version 22 (also 22.x versions). 1099 * <p> 1100 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 1101 * </p> 1102 * <p> 1103 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 1104 * </p> 1105 * <p> 1106 * This value is initialized when the class is loaded. 1107 * </p> 1108 * 1109 * @since 3.15.0 1110 */ 1111 public static final boolean IS_JAVA_22 = getJavaVersionMatches("22"); 1112 1113 /** 1114 * The constant {@code true} if this is Java version 23 (also 23.x versions). 1115 * <p> 1116 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 1117 * </p> 1118 * <p> 1119 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 1120 * </p> 1121 * <p> 1122 * This value is initialized when the class is loaded. 1123 * </p> 1124 * 1125 * @since 3.18.0 1126 */ 1127 public static final boolean IS_JAVA_23 = getJavaVersionMatches("23"); 1128 1129 /** 1130 * The constant {@code true} if this is Java version 24 (also 24.x versions). 1131 * <p> 1132 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 1133 * </p> 1134 * <p> 1135 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 1136 * </p> 1137 * <p> 1138 * This value is initialized when the class is loaded. 1139 * </p> 1140 * 1141 * @since 3.18.0 1142 */ 1143 public static final boolean IS_JAVA_24 = getJavaVersionMatches("24"); 1144 1145 /** 1146 * The constant {@code true} if this is Java version 25 (also 25.x versions). 1147 * <p> 1148 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 1149 * </p> 1150 * <p> 1151 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 1152 * </p> 1153 * <p> 1154 * This value is initialized when the class is loaded. 1155 * </p> 1156 * 1157 * @since 3.20.0 1158 */ 1159 public static final boolean IS_JAVA_25 = getJavaVersionMatches("25"); 1160 1161 /** 1162 * The constant {@code true} if this is Java version 26 (also 26.x versions). 1163 * <p> 1164 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 1165 * </p> 1166 * <p> 1167 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 1168 * </p> 1169 * <p> 1170 * This value is initialized when the class is loaded. 1171 * </p> 1172 * 1173 * @since 3.20.0 1174 */ 1175 public static final boolean IS_JAVA_26 = getJavaVersionMatches("26"); 1176 1177 /** 1178 * The constant {@code true} if this is Java version 27 (also 27.x versions). 1179 * <p> 1180 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 1181 * </p> 1182 * <p> 1183 * The field will return {@code false} if {@link #JAVA_SPECIFICATION_VERSION} is {@code null}. 1184 * </p> 1185 * <p> 1186 * This value is initialized when the class is loaded. 1187 * </p> 1188 * 1189 * @since 3.21.0 1190 */ 1191 public static final boolean IS_JAVA_27 = getJavaVersionMatches("27"); 1192 1193 // Operating system checks 1194 // ----------------------------------------------------------------------- 1195 // These MUST be declared after those above as they depend on the 1196 // values being set up 1197 // Please advise dev@commons.apache.org if you want another added 1198 // or a mistake corrected 1199 1200 /** 1201 * The constant {@code true} if this is AIX. 1202 * <p> 1203 * The result depends on the value of the {@link #OS_NAME} constant. 1204 * </p> 1205 * <p> 1206 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1207 * </p> 1208 * <p> 1209 * This value is initialized when the class is loaded. 1210 * </p> 1211 * 1212 * @since 2.0 1213 */ 1214 public static final boolean IS_OS_AIX = getOsNameMatches("AIX"); 1215 1216 /** 1217 * The constant {@code true} if this is Android. 1218 * 1219 * <p> 1220 * See https://developer.android.com/reference/java/lang/System#getProperties(). 1221 * </p> 1222 * <p> 1223 * This value is initialized when the class is loaded. 1224 * </p> 1225 * 1226 * @since 3.15.0 1227 */ 1228 public static final boolean IS_OS_ANDROID = Strings.CS.contains(SystemProperties.getJavaVendor(), "Android"); 1229 1230 /** 1231 * The constant {@code true} if this is HP-UX. 1232 * <p> 1233 * The result depends on the value of the {@link #OS_NAME} constant. 1234 * </p> 1235 * <p> 1236 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1237 * </p> 1238 * <p> 1239 * This value is initialized when the class is loaded. 1240 * </p> 1241 * 1242 * @since 2.0 1243 */ 1244 public static final boolean IS_OS_HP_UX = getOsNameMatches("HP-UX"); 1245 1246 /** 1247 * The constant {@code true} if this is IBM OS/400. 1248 * <p> 1249 * The result depends on the value of the {@link #OS_NAME} constant. 1250 * </p> 1251 * <p> 1252 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1253 * </p> 1254 * <p> 1255 * This value is initialized when the class is loaded. 1256 * </p> 1257 * 1258 * @since 3.3 1259 */ 1260 public static final boolean IS_OS_400 = getOsNameMatches("OS/400"); 1261 1262 /** 1263 * The constant {@code true} if this is Irix. 1264 * <p> 1265 * The result depends on the value of the {@link #OS_NAME} constant. 1266 * </p> 1267 * <p> 1268 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1269 * </p> 1270 * <p> 1271 * This value is initialized when the class is loaded. 1272 * </p> 1273 * 1274 * @since 2.0 1275 */ 1276 public static final boolean IS_OS_IRIX = getOsNameMatches("Irix"); 1277 1278 /** 1279 * The constant {@code true} if this is Linux. 1280 * <p> 1281 * The result depends on the value of the {@link #OS_NAME} constant. 1282 * </p> 1283 * <p> 1284 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1285 * </p> 1286 * <p> 1287 * This value is initialized when the class is loaded. 1288 * </p> 1289 * 1290 * @since 2.0 1291 */ 1292 public static final boolean IS_OS_LINUX = getOsNameMatches("Linux"); 1293 1294 /** 1295 * The constant {@code true} if this is Mac. 1296 * <p> 1297 * The result depends on the value of the {@link #OS_NAME} constant. 1298 * </p> 1299 * <p> 1300 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1301 * </p> 1302 * <p> 1303 * This value is initialized when the class is loaded. 1304 * </p> 1305 * 1306 * @since 2.0 1307 */ 1308 public static final boolean IS_OS_MAC = getOsNameMatches("Mac"); 1309 1310 /** 1311 * The constant {@code true} if this is Mac. 1312 * <p> 1313 * The result depends on the value of the {@link #OS_NAME} constant. 1314 * </p> 1315 * <p> 1316 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1317 * </p> 1318 * <p> 1319 * This value is initialized when the class is loaded. 1320 * </p> 1321 * 1322 * @since 2.0 1323 */ 1324 public static final boolean IS_OS_MAC_OSX = getOsNameMatches("Mac OS X"); 1325 1326 /** 1327 * The constant {@code true} if this is macOS X Cheetah. 1328 * <p> 1329 * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants. 1330 * </p> 1331 * <p> 1332 * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}. 1333 * </p> 1334 * <p> 1335 * This value is initialized when the class is loaded. 1336 * </p> 1337 * 1338 * @since 3.4 1339 */ 1340 public static final boolean IS_OS_MAC_OSX_CHEETAH = getOsMatches("Mac OS X", "10.0"); 1341 1342 /** 1343 * The constant {@code true} if this is macOS X Puma. 1344 * <p> 1345 * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants. 1346 * </p> 1347 * <p> 1348 * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}. 1349 * </p> 1350 * <p> 1351 * This value is initialized when the class is loaded. 1352 * </p> 1353 * 1354 * @since 3.4 1355 */ 1356 public static final boolean IS_OS_MAC_OSX_PUMA = getOsMatches("Mac OS X", "10.1"); 1357 1358 /** 1359 * The constant {@code true} if this is macOS X Jaguar. 1360 * <p> 1361 * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants. 1362 * </p> 1363 * <p> 1364 * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}. 1365 * </p> 1366 * <p> 1367 * This value is initialized when the class is loaded. 1368 * </p> 1369 * 1370 * @since 3.4 1371 */ 1372 public static final boolean IS_OS_MAC_OSX_JAGUAR = getOsMatches("Mac OS X", "10.2"); 1373 1374 /** 1375 * The constant {@code true} if this is macOS X Panther. 1376 * <p> 1377 * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants. 1378 * </p> 1379 * <p> 1380 * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}. 1381 * </p> 1382 * <p> 1383 * This value is initialized when the class is loaded. 1384 * </p> 1385 * 1386 * @since 3.4 1387 */ 1388 public static final boolean IS_OS_MAC_OSX_PANTHER = getOsMatches("Mac OS X", "10.3"); 1389 1390 /** 1391 * The constant {@code true} if this is macOS X Tiger. 1392 * <p> 1393 * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants. 1394 * </p> 1395 * <p> 1396 * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}. 1397 * </p> 1398 * <p> 1399 * This value is initialized when the class is loaded. 1400 * </p> 1401 * 1402 * @since 3.4 1403 */ 1404 public static final boolean IS_OS_MAC_OSX_TIGER = getOsMatches("Mac OS X", "10.4"); 1405 1406 /** 1407 * The constant {@code true} if this is macOS X Leopard. 1408 * <p> 1409 * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants. 1410 * </p> 1411 * <p> 1412 * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}. 1413 * </p> 1414 * <p> 1415 * This value is initialized when the class is loaded. 1416 * </p> 1417 * 1418 * @since 3.4 1419 */ 1420 public static final boolean IS_OS_MAC_OSX_LEOPARD = getOsMatches("Mac OS X", "10.5"); 1421 1422 /** 1423 * The constant {@code true} if this is macOS X Snow Leopard. 1424 * <p> 1425 * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants. 1426 * </p> 1427 * <p> 1428 * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}. 1429 * </p> 1430 * <p> 1431 * This value is initialized when the class is loaded. 1432 * </p> 1433 * 1434 * @since 3.4 1435 */ 1436 public static final boolean IS_OS_MAC_OSX_SNOW_LEOPARD = getOsMatches("Mac OS X", "10.6"); 1437 1438 /** 1439 * The constant {@code true} if this is macOS X Lion. 1440 * <p> 1441 * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants. 1442 * </p> 1443 * <p> 1444 * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}. 1445 * </p> 1446 * <p> 1447 * This value is initialized when the class is loaded. 1448 * </p> 1449 * 1450 * @since 3.4 1451 */ 1452 public static final boolean IS_OS_MAC_OSX_LION = getOsMatches("Mac OS X", "10.7"); 1453 1454 /** 1455 * The constant {@code true} if this is macOS X Mountain Lion. 1456 * <p> 1457 * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants. 1458 * </p> 1459 * <p> 1460 * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}. 1461 * </p> 1462 * <p> 1463 * This value is initialized when the class is loaded. 1464 * </p> 1465 * 1466 * @since 3.4 1467 */ 1468 public static final boolean IS_OS_MAC_OSX_MOUNTAIN_LION = getOsMatches("Mac OS X", "10.8"); 1469 1470 /** 1471 * The constant {@code true} if this is macOS X Mavericks. 1472 * <p> 1473 * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants. 1474 * </p> 1475 * <p> 1476 * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}. 1477 * </p> 1478 * <p> 1479 * This value is initialized when the class is loaded. 1480 * </p> 1481 * 1482 * @since 3.4 1483 */ 1484 public static final boolean IS_OS_MAC_OSX_MAVERICKS = getOsMatches("Mac OS X", "10.9"); 1485 1486 /** 1487 * The constant {@code true} if this is macOS X Yosemite. 1488 * <p> 1489 * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants. 1490 * </p> 1491 * <p> 1492 * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}. 1493 * </p> 1494 * <p> 1495 * This value is initialized when the class is loaded. 1496 * </p> 1497 * 1498 * @since 3.4 1499 */ 1500 public static final boolean IS_OS_MAC_OSX_YOSEMITE = getOsMatches("Mac OS X", "10.10"); 1501 1502 /** 1503 * The constant {@code true} if this is macOS X El Capitan. 1504 * <p> 1505 * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants. 1506 * </p> 1507 * <p> 1508 * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}. 1509 * </p> 1510 * <p> 1511 * This value is initialized when the class is loaded. 1512 * </p> 1513 * 1514 * @since 3.5 1515 */ 1516 public static final boolean IS_OS_MAC_OSX_EL_CAPITAN = getOsMatches("Mac OS X", "10.11"); 1517 1518 /** 1519 * The constant {@code true} if this is macOS X Sierra. 1520 * <p> 1521 * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants. 1522 * </p> 1523 * <p> 1524 * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}. 1525 * </p> 1526 * <p> 1527 * This value is initialized when the class is loaded. 1528 * </p> 1529 * 1530 * @since 3.12.0 1531 */ 1532 public static final boolean IS_OS_MAC_OSX_SIERRA = getOsMatches("Mac OS X", "10.12"); 1533 1534 /** 1535 * The constant {@code true} if this is macOS X High Sierra. 1536 * <p> 1537 * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants. 1538 * </p> 1539 * <p> 1540 * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}. 1541 * </p> 1542 * <p> 1543 * This value is initialized when the class is loaded. 1544 * </p> 1545 * 1546 * @since 3.12.0 1547 */ 1548 public static final boolean IS_OS_MAC_OSX_HIGH_SIERRA = getOsMatches("Mac OS X", "10.13"); 1549 1550 /** 1551 * The constant {@code true} if this is macOS X Mojave. 1552 * <p> 1553 * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants. 1554 * </p> 1555 * <p> 1556 * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}. 1557 * </p> 1558 * <p> 1559 * This value is initialized when the class is loaded. 1560 * </p> 1561 * 1562 * @since 3.12.0 1563 */ 1564 public static final boolean IS_OS_MAC_OSX_MOJAVE = getOsMatches("Mac OS X", "10.14"); 1565 1566 /** 1567 * The constant {@code true} if this is macOS X Catalina. 1568 * 1569 * <p> 1570 * The field will return {@code false} if {@code OS_NAME} is {@code null}. 1571 * </p> 1572 * <p> 1573 * This value is initialized when the class is loaded. 1574 * </p> 1575 * 1576 * @since 3.12.0 1577 */ 1578 public static final boolean IS_OS_MAC_OSX_CATALINA = getOsMatches("Mac OS X", "10.15"); 1579 1580 /** 1581 * The constant {@code true} if this is macOS X Big Sur. 1582 * <p> 1583 * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants. 1584 * </p> 1585 * <p> 1586 * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}. 1587 * </p> 1588 * <p> 1589 * This value is initialized when the class is loaded. 1590 * </p> 1591 * 1592 * @since 3.12.0 1593 */ 1594 public static final boolean IS_OS_MAC_OSX_BIG_SUR = getOsMatches("Mac OS X", "11"); 1595 1596 /** 1597 * The constant {@code true} if this is macOS X Monterey. 1598 * <p> 1599 * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants. 1600 * </p> 1601 * <p> 1602 * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}. 1603 * </p> 1604 * <p> 1605 * This value is initialized when the class is loaded. 1606 * </p> 1607 * 1608 * @since 3.13.0 1609 */ 1610 public static final boolean IS_OS_MAC_OSX_MONTEREY = getOsMatches("Mac OS X", "12"); 1611 1612 /** 1613 * The constant {@code true} if this is macOS X Ventura. 1614 * <p> 1615 * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants. 1616 * </p> 1617 * <p> 1618 * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}. 1619 * </p> 1620 * <p> 1621 * This value is initialized when the class is loaded. 1622 * </p> 1623 * 1624 * @since 3.13.0 1625 */ 1626 public static final boolean IS_OS_MAC_OSX_VENTURA = getOsMatches("Mac OS X", "13"); 1627 1628 /** 1629 * The constant {@code true} if this is macOS X Sonoma. 1630 * <p> 1631 * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants. 1632 * </p> 1633 * <p> 1634 * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}. 1635 * </p> 1636 * <p> 1637 * This value is initialized when the class is loaded. 1638 * </p> 1639 * 1640 * @since 3.15.0 1641 */ 1642 public static final boolean IS_OS_MAC_OSX_SONOMA = getOsMatches("Mac OS X", "14"); 1643 1644 /** 1645 * The constant {@code true} if this is macOS X Sequoia. 1646 * <p> 1647 * The value depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants. 1648 * </p> 1649 * <p> 1650 * The value is {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}. 1651 * </p> 1652 * <p> 1653 * This value is initialized when the class is loaded. 1654 * </p> 1655 * 1656 * @since 3.18.0 1657 */ 1658 public static final boolean IS_OS_MAC_OSX_SEQUOIA = getOsMatches("Mac OS X", "15"); 1659 1660 /** 1661 * The constant {@code true} if this is FreeBSD. 1662 * <p> 1663 * The result depends on the value of the {@link #OS_NAME} constant. 1664 * </p> 1665 * <p> 1666 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1667 * </p> 1668 * <p> 1669 * This value is initialized when the class is loaded. 1670 * </p> 1671 * 1672 * @since 3.1 1673 */ 1674 public static final boolean IS_OS_FREE_BSD = getOsNameMatches("FreeBSD"); 1675 1676 /** 1677 * The constant {@code true} if this is OpenBSD. 1678 * <p> 1679 * The result depends on the value of the {@link #OS_NAME} constant. 1680 * </p> 1681 * <p> 1682 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1683 * </p> 1684 * <p> 1685 * This value is initialized when the class is loaded. 1686 * </p> 1687 * 1688 * @since 3.1 1689 */ 1690 public static final boolean IS_OS_OPEN_BSD = getOsNameMatches("OpenBSD"); 1691 1692 /** 1693 * The constant {@code true} if this is NetBSD. 1694 * <p> 1695 * The result depends on the value of the {@link #OS_NAME} constant. 1696 * </p> 1697 * <p> 1698 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1699 * </p> 1700 * <p> 1701 * This value is initialized when the class is loaded. 1702 * </p> 1703 * 1704 * @since 3.1 1705 */ 1706 public static final boolean IS_OS_NET_BSD = getOsNameMatches("NetBSD"); 1707 1708 /** 1709 * The constant {@code true} if this is Netware. 1710 * <p> 1711 * The result depends on the value of the {@link #OS_NAME} constant. 1712 * </p> 1713 * <p> 1714 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1715 * </p> 1716 * <p> 1717 * This value is initialized when the class is loaded. 1718 * </p> 1719 * 1720 * @since 3.19.0 1721 */ 1722 public static final boolean IS_OS_NETWARE = getOsNameMatches("Netware"); 1723 1724 /** 1725 * The constant {@code true} if this is OS/2. 1726 * <p> 1727 * The result depends on the value of the {@link #OS_NAME} constant. 1728 * </p> 1729 * <p> 1730 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1731 * </p> 1732 * <p> 1733 * This value is initialized when the class is loaded. 1734 * </p> 1735 * 1736 * @since 2.0 1737 */ 1738 public static final boolean IS_OS_OS2 = getOsNameMatches("OS/2"); 1739 1740 /** 1741 * The constant {@code true} if this is Solaris. 1742 * <p> 1743 * The result depends on the value of the {@link #OS_NAME} constant. 1744 * </p> 1745 * <p> 1746 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1747 * </p> 1748 * <p> 1749 * This value is initialized when the class is loaded. 1750 * </p> 1751 * 1752 * @since 2.0 1753 */ 1754 public static final boolean IS_OS_SOLARIS = getOsNameMatches("Solaris"); 1755 1756 /** 1757 * The constant {@code true} if this is SunOS. 1758 * <p> 1759 * The result depends on the value of the {@link #OS_NAME} constant. 1760 * </p> 1761 * <p> 1762 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1763 * </p> 1764 * <p> 1765 * This value is initialized when the class is loaded. 1766 * </p> 1767 * 1768 * @since 2.0 1769 */ 1770 public static final boolean IS_OS_SUN_OS = getOsNameMatches("SunOS"); 1771 1772 /** 1773 * The constant {@code true} if this is a Unix like system, as in any of AIX, HP-UX, Irix, Linux, MacOSX, Solaris or SUN OS. 1774 * 1775 * <p> 1776 * The field will return {@code false} if {@code OS_NAME} is {@code null}. 1777 * </p> 1778 * <p> 1779 * This value is initialized when the class is loaded. 1780 * </p> 1781 * 1782 * @since 2.1 1783 */ 1784 public static final boolean IS_OS_UNIX = IS_OS_AIX || IS_OS_HP_UX || IS_OS_IRIX || IS_OS_LINUX || IS_OS_MAC_OSX || IS_OS_SOLARIS || IS_OS_SUN_OS 1785 || IS_OS_FREE_BSD || IS_OS_OPEN_BSD || IS_OS_NET_BSD; 1786 1787 /** 1788 * The constant {@code true} if this is Windows. 1789 * <p> 1790 * The result depends on the value of the {@link #OS_NAME} constant. 1791 * </p> 1792 * <p> 1793 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1794 * </p> 1795 * <p> 1796 * This value is initialized when the class is loaded. 1797 * </p> 1798 * 1799 * @since 2.0 1800 */ 1801 public static final boolean IS_OS_WINDOWS = getOsNameMatches(OS_NAME_WINDOWS_PREFIX); 1802 1803 /** 1804 * The constant {@code true} if this is Windows 2000. 1805 * <p> 1806 * The result depends on the value of the {@link #OS_NAME} constant. 1807 * </p> 1808 * <p> 1809 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1810 * </p> 1811 * <p> 1812 * This value is initialized when the class is loaded. 1813 * </p> 1814 * 1815 * @since 2.0 1816 */ 1817 public static final boolean IS_OS_WINDOWS_2000 = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " 2000"); 1818 1819 /** 1820 * The constant {@code true} if this is Windows 2003. 1821 * <p> 1822 * The result depends on the value of the {@link #OS_NAME} constant. 1823 * </p> 1824 * <p> 1825 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1826 * </p> 1827 * <p> 1828 * This value is initialized when the class is loaded. 1829 * </p> 1830 * 1831 * @since 3.1 1832 */ 1833 public static final boolean IS_OS_WINDOWS_2003 = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " 2003"); 1834 1835 /** 1836 * The constant {@code true} if this is Windows Server 2008. 1837 * <p> 1838 * The result depends on the value of the {@link #OS_NAME} constant. 1839 * </p> 1840 * <p> 1841 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1842 * </p> 1843 * <p> 1844 * This value is initialized when the class is loaded. 1845 * </p> 1846 * 1847 * @since 3.1 1848 */ 1849 public static final boolean IS_OS_WINDOWS_2008 = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " Server 2008"); 1850 1851 /** 1852 * The constant {@code true} if this is Windows Server 2012. 1853 * <p> 1854 * The result depends on the value of the {@link #OS_NAME} constant. 1855 * </p> 1856 * <p> 1857 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1858 * </p> 1859 * <p> 1860 * This value is initialized when the class is loaded. 1861 * </p> 1862 * 1863 * @since 3.4 1864 */ 1865 public static final boolean IS_OS_WINDOWS_2012 = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " Server 2012"); 1866 1867 /** 1868 * The constant {@code true} if this is Windows 95. 1869 * <p> 1870 * The result depends on the value of the {@link #OS_NAME} constant. 1871 * </p> 1872 * <p> 1873 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1874 * </p> 1875 * <p> 1876 * This value is initialized when the class is loaded. 1877 * </p> 1878 * 1879 * @since 2.0 1880 */ 1881 public static final boolean IS_OS_WINDOWS_95 = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " 95"); 1882 1883 /** 1884 * The constant {@code true} if this is Windows 98. 1885 * <p> 1886 * The result depends on the value of the {@link #OS_NAME} constant. 1887 * </p> 1888 * <p> 1889 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1890 * </p> 1891 * <p> 1892 * This value is initialized when the class is loaded. 1893 * </p> 1894 * 1895 * @since 2.0 1896 */ 1897 public static final boolean IS_OS_WINDOWS_98 = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " 98"); 1898 1899 /** 1900 * The constant {@code true} if this is Windows ME. 1901 * <p> 1902 * The result depends on the value of the {@link #OS_NAME} constant. 1903 * </p> 1904 * <p> 1905 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1906 * </p> 1907 * <p> 1908 * This value is initialized when the class is loaded. 1909 * </p> 1910 * 1911 * @since 2.0 1912 */ 1913 public static final boolean IS_OS_WINDOWS_ME = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " Me"); 1914 1915 /** 1916 * The constant {@code true} if this is Windows NT. 1917 * <p> 1918 * The result depends on the value of the {@link #OS_NAME} constant. 1919 * </p> 1920 * <p> 1921 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1922 * </p> 1923 * <p> 1924 * This value is initialized when the class is loaded. 1925 * </p> 1926 * 1927 * @since 2.0 1928 */ 1929 public static final boolean IS_OS_WINDOWS_NT = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " NT"); 1930 1931 /** 1932 * The constant {@code true} if this is Windows XP. 1933 * <p> 1934 * The result depends on the value of the {@link #OS_NAME} constant. 1935 * </p> 1936 * <p> 1937 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1938 * </p> 1939 * <p> 1940 * This value is initialized when the class is loaded. 1941 * </p> 1942 * 1943 * @since 2.0 1944 */ 1945 public static final boolean IS_OS_WINDOWS_XP = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " XP"); 1946 1947 /** 1948 * The constant {@code true} if this is Windows Vista. 1949 * <p> 1950 * The result depends on the value of the {@link #OS_NAME} constant. 1951 * </p> 1952 * <p> 1953 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1954 * </p> 1955 * <p> 1956 * This value is initialized when the class is loaded. 1957 * </p> 1958 * 1959 * @since 2.4 1960 */ 1961 public static final boolean IS_OS_WINDOWS_VISTA = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " Vista"); 1962 1963 /** 1964 * The constant {@code true} if this is Windows 7. 1965 * <p> 1966 * The result depends on the value of the {@link #OS_NAME} constant. 1967 * </p> 1968 * <p> 1969 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1970 * </p> 1971 * <p> 1972 * This value is initialized when the class is loaded. 1973 * </p> 1974 * 1975 * @since 3.0 1976 */ 1977 public static final boolean IS_OS_WINDOWS_7 = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " 7"); 1978 1979 /** 1980 * The constant {@code true} if this is Windows 8. 1981 * <p> 1982 * The result depends on the value of the {@link #OS_NAME} constant. 1983 * </p> 1984 * <p> 1985 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 1986 * </p> 1987 * <p> 1988 * This value is initialized when the class is loaded. 1989 * </p> 1990 * 1991 * @since 3.2 1992 */ 1993 public static final boolean IS_OS_WINDOWS_8 = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " 8"); 1994 1995 /** 1996 * The constant {@code true} if this is Windows 10. 1997 * <p> 1998 * The result depends on the value of the {@link #OS_NAME} constant. 1999 * </p> 2000 * <p> 2001 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 2002 * </p> 2003 * <p> 2004 * This value is initialized when the class is loaded. 2005 * </p> 2006 * 2007 * @since 3.5 2008 */ 2009 public static final boolean IS_OS_WINDOWS_10 = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " 10"); 2010 2011 /** 2012 * The constant {@code true} if this is Windows 11. 2013 * <p> 2014 * The result depends on the value of the {@link #OS_NAME} constant. 2015 * </p> 2016 * <p> 2017 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 2018 * </p> 2019 * <p> 2020 * OpenJDK fixed the return value for {@code os.name} on Windows 11 to versions 8, 11, and 17: 2021 * </p> 2022 * <ul> 2023 * <li>Affects Java versions 7u321, 8u311, 11.0.13-oracle, 17.0.1: https://bugs.openjdk.org/browse/JDK-8274737</li> 2024 * <li>Fixed in OpenJDK commit https://github.com/openjdk/jdk/commit/97ea9dd2f24f9f1fb9b9345a4202a825ee28e014</li> 2025 * </ul> 2026 * <p> 2027 * This value is initialized when the class is loaded. 2028 * </p> 2029 * 2030 * @since 3.13.0 2031 */ 2032 public static final boolean IS_OS_WINDOWS_11 = getOsNameMatches(OS_NAME_WINDOWS_PREFIX + " 11"); 2033 2034 /** 2035 * The constant {@code true} if this is z/OS. 2036 * <p> 2037 * The result depends on the value of the {@link #OS_NAME} constant. 2038 * </p> 2039 * <p> 2040 * The field will return {@code false} if {@link #OS_NAME} is {@code null}. 2041 * </p> 2042 * <p> 2043 * This value is initialized when the class is loaded. 2044 * </p> 2045 * 2046 * @since 3.5 2047 */ 2048 // Values on a z/OS system I tested (Gary Gregory - 2016-03-12) 2049 // os.arch = s390x 2050 // os.encoding = ISO8859_1 2051 // os.name = z/OS 2052 // os.version = 02.02.00 2053 public static final boolean IS_OS_ZOS = getOsNameMatches("z/OS"); 2054 2055 /** 2056 * The System property key for the user home directory. 2057 */ 2058 public static final String USER_HOME_KEY = "user.home"; 2059 2060 /** 2061 * The System property key for the user name. 2062 * 2063 * @deprecated Use {@link SystemProperties#USER_NAME}. 2064 */ 2065 @Deprecated 2066 public static final String USER_NAME_KEY = "user.name"; 2067 2068 /** 2069 * The System property key for the user directory. 2070 * 2071 * @deprecated Use {@link SystemProperties#USER_DIR}. 2072 */ 2073 @Deprecated 2074 public static final String USER_DIR_KEY = "user.dir"; 2075 2076 /** 2077 * The System property key for the Java IO temporary directory. 2078 * 2079 * @deprecated Use {@link SystemProperties#JAVA_IO_TMPDIR}. 2080 */ 2081 @Deprecated 2082 public static final String JAVA_IO_TMPDIR_KEY = "java.io.tmpdir"; 2083 2084 /** 2085 * The System property key for the Java home directory. 2086 * 2087 * @deprecated Use {@link SystemProperties#JAVA_HOME}. 2088 */ 2089 @Deprecated 2090 public static final String JAVA_HOME_KEY = "java.home"; 2091 2092 /** 2093 * A constant for the System Property {@code awt.toolkit}. 2094 * 2095 * <p> 2096 * Holds a class name, on Windows XP this is {@code sun.awt.windows.WToolkit}. 2097 * </p> 2098 * <p> 2099 * <strong>On platforms without a GUI, this value is {@code null}.</strong> 2100 * </p> 2101 * <p> 2102 * Defaults to {@code null} if the runtime does not have security access to read this property or the property does not exist. 2103 * </p> 2104 * <p> 2105 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or {@link System#setProperties(java.util.Properties)} is 2106 * called after this class is loaded, the value will be out of sync with that System property. 2107 * </p> 2108 * 2109 * @since 2.1 2110 * @see SystemProperties#getAwtToolkit() 2111 * @deprecated Deprecated without replacement. 2112 */ 2113 @Deprecated 2114 public static final String AWT_TOOLKIT = SystemProperties.getAwtToolkit(); 2115 2116 /** 2117 * Gets an environment variable, defaulting to {@code defaultValue} if the variable cannot be read. 2118 * 2119 * <p> 2120 * If a {@link SecurityException} is caught, the return value is {@code defaultValue} and a message is written to {@code System.err}. 2121 * </p> 2122 * 2123 * @param name the environment variable name. 2124 * @param defaultValue the default value. 2125 * @return the environment variable value or {@code defaultValue} if a security problem occurs. 2126 * @since 3.8 2127 */ 2128 public static String getEnvironmentVariable(final String name, final String defaultValue) { 2129 try { 2130 final String value = System.getenv(name); 2131 return value == null ? defaultValue : value; 2132 } catch (final SecurityException ex) { 2133 // we are not allowed to look at this property 2134 // System.err.println("Caught a SecurityException reading the environment variable '" + name + "'."); 2135 return defaultValue; 2136 } 2137 } 2138 2139 /** 2140 * Gets the host name from an environment variable ({@code COMPUTERNAME} on Windows, {@code HOSTNAME} elsewhere). 2141 * 2142 * <p> 2143 * If you want to know what the network stack says is the host name, you should use {@code InetAddress.getLocalHost().getHostName()}. 2144 * </p> 2145 * 2146 * @return the host name. Will be {@code null} if the environment variable is not defined. 2147 * @since 3.6 2148 */ 2149 public static String getHostName() { 2150 return IS_OS_WINDOWS ? System.getenv("COMPUTERNAME") : System.getenv("HOSTNAME"); 2151 } 2152 2153 /** 2154 * Gets the current Java home directory as a {@link File}. 2155 * 2156 * @return a directory. 2157 * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow access to the specified system property. 2158 * @see SystemProperties#getJavaHome() 2159 * @since 2.1 2160 */ 2161 public static File getJavaHome() { 2162 return new File(SystemProperties.getJavaHome()); 2163 } 2164 2165 /** 2166 * Gets the current Java home directory as a {@link File}. 2167 * 2168 * @return a directory. 2169 * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow access to the specified system property. 2170 * @see SystemProperties#getJavaHome() 2171 * @since 3.18.0 2172 */ 2173 public static Path getJavaHomePath() { 2174 return Paths.get(SystemProperties.getJavaHome()); 2175 } 2176 2177 /** 2178 * Gets the current Java IO temporary directory as a {@link File}. 2179 * 2180 * @return a directory. 2181 * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow access to the specified system property. 2182 * @see SystemProperties#getJavaIoTmpdir() 2183 * @since 2.1 2184 */ 2185 public static File getJavaIoTmpDir() { 2186 return new File(SystemProperties.getJavaIoTmpdir()); 2187 } 2188 2189 /** 2190 * Gets the current Java IO temporary directory as a {@link Path}. 2191 * 2192 * @return a directory. 2193 * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow access to the specified system property. 2194 * @see SystemProperties#getJavaIoTmpdir() 2195 * @since 3.18.0 2196 */ 2197 public static Path getJavaIoTmpDirPath() { 2198 return Paths.get(SystemProperties.getJavaIoTmpdir()); 2199 } 2200 2201 /** 2202 * Tests if the Java version matches the version we are running. 2203 * <p> 2204 * The result depends on the value of the {@link #JAVA_SPECIFICATION_VERSION} constant. 2205 * </p> 2206 * 2207 * @param versionPrefix the prefix for the Java version. 2208 * @return true if matches, or false if not or can't determine. 2209 */ 2210 private static boolean getJavaVersionMatches(final String versionPrefix) { 2211 return isJavaVersionMatch(JAVA_SPECIFICATION_VERSION, versionPrefix); 2212 } 2213 2214 /** 2215 * Tests if the operating system matches the given name prefix and version prefix. 2216 * <p> 2217 * The result depends on the value of the {@link #OS_NAME} and {@link #OS_VERSION} constants. 2218 * </p> 2219 * <p> 2220 * The method returns {@code false} if {@link #OS_NAME} or {@link #OS_VERSION} is {@code null}. 2221 * </p> 2222 * 2223 * @param osNamePrefix the prefix for the OS name. 2224 * @param osVersionPrefix the prefix for the version. 2225 * @return true if matches, or false if not or can't determine. 2226 */ 2227 private static boolean getOsMatches(final String osNamePrefix, final String osVersionPrefix) { 2228 return isOsMatch(OS_NAME, OS_VERSION, osNamePrefix, osVersionPrefix); 2229 } 2230 2231 /** 2232 * Tests if the operating system matches the given string with a case-insensitive comparison. 2233 * <p> 2234 * The result depends on the value of the {@link #OS_NAME} constant. 2235 * </p> 2236 * <p> 2237 * The method returns {@code false} if {@link #OS_NAME} is {@code null}. 2238 * </p> 2239 * 2240 * @param osNamePrefix the prefix for the OS name. 2241 * @return true if matches, or false if not or can't determine. 2242 */ 2243 private static boolean getOsNameMatches(final String osNamePrefix) { 2244 return isOsNameMatch(OS_NAME, osNamePrefix); 2245 } 2246 2247 /** 2248 * Gets the current user directory as a {@link File}. 2249 * <p> 2250 * The result is based on the system property {@value SystemProperties#USER_DIR}. 2251 * </p> 2252 * 2253 * @return a directory. 2254 * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow access to the specified system property. 2255 * @see SystemProperties#getUserDir() 2256 * @since 2.1 2257 */ 2258 public static File getUserDir() { 2259 return new File(SystemProperties.getUserDir()); 2260 } 2261 2262 /** 2263 * Gets the current user directory as a {@link Path}. 2264 * <p> 2265 * The result is based on the system property {@value SystemProperties#USER_DIR}. 2266 * </p> 2267 * 2268 * @return a directory. 2269 * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow access to the specified system property. 2270 * @see SystemProperties#getUserDir() 2271 * @since 3.18.0 2272 */ 2273 public static Path getUserDirPath() { 2274 return Paths.get(SystemProperties.getUserDir()); 2275 } 2276 2277 /** 2278 * Gets the current user home directory as a {@link File}. 2279 * <p> 2280 * The result is based on the system property {@value SystemProperties#USER_HOME}. 2281 * </p> 2282 * 2283 * @return a directory. 2284 * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow access to the specified system property. 2285 * @see SystemProperties#getUserHome() 2286 * @since 2.1 2287 */ 2288 public static File getUserHome() { 2289 return new File(SystemProperties.getUserHome()); 2290 } 2291 2292 /** 2293 * Gets the current user home directory as a {@link Path}. 2294 * <p> 2295 * The result is based on the system property {@value SystemProperties#USER_HOME}. 2296 * </p> 2297 * 2298 * @return a directory. 2299 * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow access to the specified system property. 2300 * @see SystemProperties#getUserHome() 2301 * @since 3.18.0 2302 */ 2303 public static Path getUserHomePath() { 2304 return Paths.get(SystemProperties.getUserHome()); 2305 } 2306 2307 /** 2308 * Gets the current user name. 2309 * <p> 2310 * The result is based on the system property {@value SystemProperties#USER_NAME}. 2311 * </p> 2312 * 2313 * @return a name. 2314 * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow access to the specified system property. 2315 * @see SystemProperties#getUserName() 2316 * @since 3.10 2317 * @deprecated Use {@link SystemProperties#getUserName()}. 2318 */ 2319 @Deprecated 2320 public static String getUserName() { 2321 return SystemProperties.getUserName(); 2322 } 2323 2324 /** 2325 * Gets the user name. 2326 * <p> 2327 * The result is based on the system property {@value SystemProperties#USER_NAME}. 2328 * </p> 2329 * 2330 * @param defaultValue A default value. 2331 * @return a name. 2332 * @throws SecurityException if a security manager exists and its {@code checkPropertyAccess} method doesn't allow access to the specified system property. 2333 * @see SystemProperties#getUserName() 2334 * @since 3.10 2335 * @deprecated Use {@link SystemProperties#getUserName(String)}. 2336 */ 2337 @Deprecated 2338 public static String getUserName(final String defaultValue) { 2339 return SystemProperties.getUserName(defaultValue); 2340 } 2341 2342 /** 2343 * Tests whether the {@link #JAVA_AWT_HEADLESS} value is {@code true}. 2344 * <p> 2345 * The result is based on the system property {@value SystemProperties#JAVA_AWT_HEADLESS}. 2346 * </p> 2347 * 2348 * @return {@code true} if {@code JAVA_AWT_HEADLESS} is {@code "true"}, {@code false} otherwise. 2349 * @see #JAVA_AWT_HEADLESS 2350 * @since 2.1 2351 * @since Java 1.4 2352 * @deprecated Deprecated without replacement. 2353 */ 2354 @Deprecated 2355 public static boolean isJavaAwtHeadless() { 2356 return Boolean.TRUE.toString().equals(JAVA_AWT_HEADLESS); 2357 } 2358 2359 /** 2360 * Tests whether the Java version is at least the requested version. 2361 * <p> 2362 * The result is based on the system property saved in {@link #JAVA_SPECIFICATION_VERSION}. 2363 * </p> 2364 * 2365 * @param requiredVersion the required version, for example 1.31f. 2366 * @return {@code true} if the actual version is equal or greater than the required version. 2367 */ 2368 public static boolean isJavaVersionAtLeast(final JavaVersion requiredVersion) { 2369 return JAVA_SPECIFICATION_VERSION_ENUM != null && JAVA_SPECIFICATION_VERSION_ENUM.atLeast(requiredVersion); 2370 } 2371 2372 /** 2373 * Tests whether the Java version is at most the requested version. 2374 * <p> 2375 * The result is based on the system property saved in {@link #JAVA_SPECIFICATION_VERSION}. 2376 * </p> 2377 * 2378 * @param requiredVersion the required version, for example 1.31f. 2379 * @return {@code true} if the actual version is equal or less than the required version. 2380 * @since 3.9 2381 */ 2382 public static boolean isJavaVersionAtMost(final JavaVersion requiredVersion) { 2383 return JAVA_SPECIFICATION_VERSION_ENUM != null && JAVA_SPECIFICATION_VERSION_ENUM.atMost(requiredVersion); 2384 } 2385 2386 /** 2387 * Tests whether the Java version matches. 2388 * 2389 * <p> 2390 * This method is package private instead of private to support unit test invocation. 2391 * </p> 2392 * 2393 * @param version the actual Java version. 2394 * @param versionPrefix the prefix for the expected Java version. 2395 * @return true if matches, or false if not or can't determine. 2396 */ 2397 static boolean isJavaVersionMatch(final String version, final String versionPrefix) { 2398 if (version == null) { 2399 return false; 2400 } 2401 return version.startsWith(versionPrefix); 2402 } 2403 2404 /** 2405 * Tests whether the operating system matches. 2406 * <p> 2407 * This method is package private instead of private to support unit test invocation. 2408 * </p> 2409 * 2410 * @param osName the actual OS name. 2411 * @param osVersion the actual OS version. 2412 * @param osNamePrefix the prefix for the expected OS name. 2413 * @param osVersionPrefix the prefix for the expected OS version. 2414 * @return true if matches, or false if not or can't determine. 2415 */ 2416 static boolean isOsMatch(final String osName, final String osVersion, final String osNamePrefix, final String osVersionPrefix) { 2417 if (osName == null || osVersion == null) { 2418 return false; 2419 } 2420 return isOsNameMatch(osName, osNamePrefix) && isOsVersionMatch(osVersion, osVersionPrefix); 2421 } 2422 2423 /** 2424 * Tests whether the operating system matches with a case-insensitive comparison. 2425 * <p> 2426 * This method is package private instead of private to support unit test invocation. 2427 * </p> 2428 * 2429 * @param osName the actual OS name. 2430 * @param osNamePrefix the prefix for the expected OS name. 2431 * @return true for a case-insensitive match, or false if not. 2432 */ 2433 static boolean isOsNameMatch(final String osName, final String osNamePrefix) { 2434 if (osName == null) { 2435 return false; 2436 } 2437 return Strings.CI.startsWith(osName, osNamePrefix); 2438 } 2439 2440 /** 2441 * Tests whether the operating system version matches. 2442 * <p> 2443 * This method is package private instead of private to support unit test invocation. 2444 * </p> 2445 * 2446 * @param osVersion the actual OS version. 2447 * @param osVersionPrefix the prefix for the expected OS version. 2448 * @return true if matches, or false if not or can't determine. 2449 */ 2450 static boolean isOsVersionMatch(final String osVersion, final String osVersionPrefix) { 2451 if (StringUtils.isEmpty(osVersion)) { 2452 return false; 2453 } 2454 // Compare parts of the version string instead of using String.startsWith(String) because otherwise 2455 // osVersionPrefix 10.1 would also match osVersion 10.10 2456 final String[] versionPrefixParts = JavaVersion.split(osVersionPrefix); 2457 final String[] versionParts = JavaVersion.split(osVersion); 2458 for (int i = 0; i < Math.min(versionPrefixParts.length, versionParts.length); i++) { 2459 if (!versionPrefixParts[i].equals(versionParts[i])) { 2460 return false; 2461 } 2462 } 2463 return true; 2464 } 2465 2466 /** 2467 * SystemUtils instances shouldn't be constructed in standard programming. Instead, elements should be accessed directly, for example 2468 * {@code SystemUtils.FILE_SEPARATOR}. 2469 * 2470 * <p> 2471 * This constructor is public to permit tools that require a JavaBean instance to operate. 2472 * </p> 2473 */ 2474 public SystemUtils() { 2475 } 2476 2477}