Changeset 13647 in josm for trunk/src/org/openstreetmap/josm/tools/Utils.java
- Timestamp:
- 2018-04-19T20:37:16+02:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Utils.java
r13597 r13647 887 887 */ 888 888 public static File getJosmTempDir() { 889 String tmpDir = System.getProperty("java.io.tmpdir");889 String tmpDir = getSystemProperty("java.io.tmpdir"); 890 890 if (tmpDir == null) { 891 891 return null; … … 1268 1268 1269 1269 /** 1270 * Gets the value of the specified environment variable. 1271 * An environment variable is a system-dependent external named value. 1272 * @param name name the name of the environment variable 1273 * @return the string value of the variable; 1274 * {@code null} if the variable is not defined in the system environment or if a security exception occurs. 1275 * @see System#getenv(String) 1276 * @since 13647 1277 */ 1278 public static String getSystemEnv(String name) { 1279 try { 1280 return System.getenv(name); 1281 } catch (SecurityException e) { 1282 Logging.log(Logging.LEVEL_ERROR, "Unable to get system env", e); 1283 return null; 1284 } 1285 } 1286 1287 /** 1288 * Gets the system property indicated by the specified key. 1289 * @param key the name of the system property. 1290 * @return the string value of the system property; 1291 * {@code null} if there is no property with that key or if a security exception occurs. 1292 * @see System#getProperty(String) 1293 * @since 13647 1294 */ 1295 public static String getSystemProperty(String key) { 1296 try { 1297 return System.getProperty(key); 1298 } catch (SecurityException e) { 1299 Logging.log(Logging.LEVEL_ERROR, "Unable to get system property", e); 1300 return null; 1301 } 1302 } 1303 1304 /** 1270 1305 * Updates a given system property. 1271 1306 * @param key The property key … … 1276 1311 public static String updateSystemProperty(String key, String value) { 1277 1312 if (value != null) { 1278 String old = System.setProperty(key, value); 1279 if (Logging.isDebugEnabled() && !value.equals(old)) { 1280 if (!key.toLowerCase(Locale.ENGLISH).contains("password")) { 1281 Logging.debug("System property '" + key + "' set to '" + value + "'. Old value was '" + old + '\''); 1282 } else { 1283 Logging.debug("System property '" + key + "' changed."); 1313 try { 1314 String old = System.setProperty(key, value); 1315 if (Logging.isDebugEnabled() && !value.equals(old)) { 1316 if (!key.toLowerCase(Locale.ENGLISH).contains("password")) { 1317 Logging.debug("System property '" + key + "' set to '" + value + "'. Old value was '" + old + '\''); 1318 } else { 1319 Logging.debug("System property '" + key + "' changed."); 1320 } 1284 1321 } 1285 } 1286 return old; 1322 return old; 1323 } catch (SecurityException e) { 1324 // Don't call Logging class, it may not be fully initialized yet 1325 System.err.println("Unable to update system property: " + e.getMessage()); 1326 } 1287 1327 } 1288 1328 return null; … … 1592 1632 */ 1593 1633 public static int getJavaVersion() { 1594 String version = System.getProperty("java.version");1634 String version = getSystemProperty("java.version"); 1595 1635 if (version.startsWith("1.")) { 1596 1636 version = version.substring(2); … … 1613 1653 */ 1614 1654 public static int getJavaUpdate() { 1615 String version = System.getProperty("java.version");1655 String version = getSystemProperty("java.version"); 1616 1656 if (version.startsWith("1.")) { 1617 1657 version = version.substring(2); … … 1643 1683 */ 1644 1684 public static int getJavaBuild() { 1645 String version = System.getProperty("java.runtime.version");1685 String version = getSystemProperty("java.runtime.version"); 1646 1686 int bPos = version.indexOf('b'); 1647 1687 int pPos = version.indexOf('+'); … … 1757 1797 try { 1758 1798 return new ScriptEngineManager(null).getEngineByName("JavaScript"); 1759 } catch (SecurityException e) {1760 Logging. error(e);1799 } catch (SecurityException | ExceptionInInitializerError e) { 1800 Logging.log(Logging.LEVEL_ERROR, "Unable to get JavaScript engine", e); 1761 1801 return null; 1762 1802 } … … 1789 1829 FileTime jarTime = Files.readAttributes(jarFile, BasicFileAttributes.class).lastModifiedTime(); 1790 1830 // Copy it to temp directory (hopefully free of exclamation mark) if needed (missing or older jar) 1791 Path jarCopy = Paths.get( System.getProperty("java.io.tmpdir")).resolve(filename);1831 Path jarCopy = Paths.get(getSystemProperty("java.io.tmpdir")).resolve(filename); 1792 1832 if (!jarCopy.toFile().exists() || 1793 1833 Files.readAttributes(jarCopy, BasicFileAttributes.class).lastModifiedTime().compareTo(jarTime) < 0) {
Note:
See TracChangeset
for help on using the changeset viewer.