Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ protected SystemPropertiesSupport() {
properties = new Properties();
savedProperties = new HashMap<>();
readOnlySavedProperties = Collections.unmodifiableMap(savedProperties);
lazyRuntimeValues = new HashMap<>();

for (String key : HOSTED_PROPERTIES) {
String value = System.getProperty(key);
Expand Down Expand Up @@ -114,19 +115,18 @@ protected SystemPropertiesSupport() {
initializeProperty("java.awt.printerjob", System.getProperty("java.awt.printerjob"));
}

lazyRuntimeValues = new HashMap<>();
lazyRuntimeValues.put("user.name", this::userName);
lazyRuntimeValues.put("user.home", this::userHome);
lazyRuntimeValues.put("user.dir", this::userDir);
lazyRuntimeValues.put("java.io.tmpdir", this::tmpdirValue);
lazyRuntimeValues.put("os.version", this::osVersionValue);
lazyRuntimeValues.put("java.vm.version", VM::getVersion);
initializeLazyProperty("user.name", this::userName);
initializeLazyProperty("user.home", this::userHome);
initializeLazyProperty("user.dir", this::userDir);
initializeLazyProperty("java.io.tmpdir", this::tmpdirValue);
initializeLazyProperty("os.version", this::osVersionValue);
initializeLazyProperty("java.vm.version", VM::getVersion);

String targetName = System.getProperty("svm.targetName");
if (targetName != null) {
initializeProperty("os.name", targetName);
} else {
lazyRuntimeValues.put("os.name", this::osNameValue);
initializeLazyProperty("os.name", this::osNameValue);
}

String targetArch = System.getProperty("svm.targetArch");
Expand Down Expand Up @@ -188,6 +188,14 @@ public void initializeProperty(String key, String value) {
properties.setProperty(key, value);
}

/**
* Lazily initializes a property at runtime when it is first requested, based on the supplier's
* return value.
*/
public void initializeLazyProperty(String key, Supplier<String> value) {
lazyRuntimeValues.put(key, value);
}

public String setProperty(String key, String value) {
/*
* The return value of setProperty is the previous value of the key, so we need to ensure
Expand Down