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