< prev index next >
src/java.base/share/classes/jdk/internal/util/SystemProps.java
Print this page
rev 52935 : 8215159: Improve initial setup of system Properties
Reviewed-by: mchung, rriggs
*** 24,34 ****
*/
package jdk.internal.util;
import java.lang.annotation.Native;
! import java.util.Properties;
/**
* System Property initialization for internal use only
* Retrieves the platform, JVM, and command line properties,
* applies initial defaults and returns the Properties instance
--- 24,36 ----
*/
package jdk.internal.util;
import java.lang.annotation.Native;
! import java.util.Collections;
! import java.util.HashMap;
! import java.util.Map;
/**
* System Property initialization for internal use only
* Retrieves the platform, JVM, and command line properties,
* applies initial defaults and returns the Properties instance
*** 45,60 ****
* Note: Build-defined properties such as versions and vendor information
* are initialized by VersionProps.java-template.
*
* @return a Properties instance initialized with all of the properties
*/
! public static Properties initProperties() {
// Initially, cmdProperties only includes -D and props from the VM
Raw raw = new Raw();
! Properties props = raw.cmdProperties();
! String javaHome = props.getProperty("java.home");
assert javaHome != null : "java.home not set";
putIfAbsent(props, "user.home", raw.propDefault(Raw._user_home_NDX));
putIfAbsent(props, "user.dir", raw.propDefault(Raw._user_dir_NDX));
putIfAbsent(props, "user.name", raw.propDefault(Raw._user_name_NDX));
--- 47,63 ----
* Note: Build-defined properties such as versions and vendor information
* are initialized by VersionProps.java-template.
*
* @return a Properties instance initialized with all of the properties
*/
! public static Map<String, String> initProperties() {
!
// Initially, cmdProperties only includes -D and props from the VM
Raw raw = new Raw();
! HashMap<String, String> props = raw.cmdProperties();
! String javaHome = props.get("java.home");
assert javaHome != null : "java.home not set";
putIfAbsent(props, "user.home", raw.propDefault(Raw._user_home_NDX));
putIfAbsent(props, "user.dir", raw.propDefault(Raw._user_dir_NDX));
putIfAbsent(props, "user.name", raw.propDefault(Raw._user_name_NDX));
*** 119,129 ****
* Puts the property if it is non-null
* @param props the Properties
* @param key the key
* @param value the value
*/
! private static void put(Properties props, String key, String value) {
if (value != null) {
props.put(key, value);
}
}
--- 122,132 ----
* Puts the property if it is non-null
* @param props the Properties
* @param key the key
* @param value the value
*/
! private static void put(HashMap<String, String> props, String key, String value) {
if (value != null) {
props.put(key, value);
}
}
*** 131,141 ****
* Puts the property if it is non-null and is not already in the Properties.
* @param props the Properties
* @param key the key
* @param value the value
*/
! private static void putIfAbsent(Properties props, String key, String value) {
if (value != null) {
props.putIfAbsent(key, value);
}
}
--- 134,144 ----
* Puts the property if it is non-null and is not already in the Properties.
* @param props the Properties
* @param key the key
* @param value the value
*/
! private static void putIfAbsent(HashMap<String, String> props, String key, String value) {
if (value != null) {
props.putIfAbsent(key, value);
}
}
*** 146,159 ****
*
* @param base the base property name
* @param display the display value for the base
* @param format the format value for the base
*/
! private static void fillI18nProps(Properties cmdProps, String base, String display,
String format) {
// Do not override command line setting
! String baseValue = cmdProps.getProperty(base);
if (baseValue != null) {
return; // Do not override value from the command line
}
// Not overridden on the command line; define the properties if there are platform defined values
--- 149,164 ----
*
* @param base the base property name
* @param display the display value for the base
* @param format the format value for the base
*/
! private static void fillI18nProps(HashMap<String, String> cmdProps,
! String base,
! String display,
String format) {
// Do not override command line setting
! String baseValue = cmdProps.get(base);
if (baseValue != null) {
return; // Do not override value from the command line
}
// Not overridden on the command line; define the properties if there are platform defined values
*** 162,180 ****
baseValue = display;
}
/* user.xxx.display property */
String disp = base.concat(".display");
! String dispValue = cmdProps.getProperty(disp);
if (dispValue == null && display != null && !display.equals(baseValue)) {
// Create the property only if different from the base property
cmdProps.put(disp, display);
}
/* user.xxx.format property */
String fmt = base.concat(".format");
! String fmtValue = cmdProps.getProperty(fmt);
if (fmtValue == null && format != null && !format.equals(baseValue)) {
// Create the property only if different than the base property
cmdProps.put(fmt, format);
}
}
--- 167,185 ----
baseValue = display;
}
/* user.xxx.display property */
String disp = base.concat(".display");
! String dispValue = cmdProps.get(disp);
if (dispValue == null && display != null && !display.equals(baseValue)) {
// Create the property only if different from the base property
cmdProps.put(disp, display);
}
/* user.xxx.format property */
String fmt = base.concat(".format");
! String fmtValue = cmdProps.get(fmt);
if (fmtValue == null && format != null && !format.equals(baseValue)) {
// Create the property only if different than the base property
cmdProps.put(fmt, format);
}
}
*** 253,271 ****
* defined by name and value.
* The Properties instance is sized to include the fixed properties.
*
* @return return a Properties instance of the command line and VM options
*/
! private Properties cmdProperties() {
String[] vmProps = vmProperties();
! int nProps = vmProps.length / 2;
! var cmdProps = new Properties(nProps + Raw.FIXED_LENGTH);
! for (int i = 0; i < nProps; i++) {
! String k = vmProps[i * 2];
if (k != null) {
! String v = vmProps[i * 2 + 1];
! cmdProps.setProperty(k, v != null ? v : "");
} else {
// no more key/value pairs
break;
}
}
--- 258,275 ----
* defined by name and value.
* The Properties instance is sized to include the fixed properties.
*
* @return return a Properties instance of the command line and VM options
*/
! private HashMap<String, String> cmdProperties() {
String[] vmProps = vmProperties();
! var cmdProps = new HashMap<String, String>((vmProps.length / 2) + Raw.FIXED_LENGTH);
! for (int i = 0; i < vmProps.length;) {
! String k = vmProps[i++];
if (k != null) {
! String v = vmProps[i++];
! cmdProps.put(k, v != null ? v : "");
} else {
// no more key/value pairs
break;
}
}
< prev index next >