PageRenderTime 55ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/example/src/main/java/org/apache/commons/lang3/SystemUtils.java

https://bitbucket.org/Ranmanli/prfl
Java | 1455 lines | 144 code | 99 blank | 1212 comment | 21 complexity | b21cdfcfbcc50894972a2be4bf611e38 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

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

Large files files are truncated, but you can click here to view the full file