From 66c308fdcbf897e19b4b0afe3c81d87d9dc30ce8 Mon Sep 17 00:00:00 2001 From: Gabor Bata Date: Mon, 25 Mar 2024 10:31:33 +0100 Subject: [PATCH] add possibility to override config via system properties --- src/main/java/jpass/util/Configuration.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/jpass/util/Configuration.java b/src/main/java/jpass/util/Configuration.java index d1f0010..3fc3bf2 100644 --- a/src/main/java/jpass/util/Configuration.java +++ b/src/main/java/jpass/util/Configuration.java @@ -31,12 +31,18 @@ import java.io.File; import java.io.FileInputStream; import java.io.InputStream; +import java.util.Optional; import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; /** - * Class for loading configurations from {@code jpass.properties}. + * Class for loading configurations from {@code jpass.properties} or system properties. + * + *

+ * Each configuration property can by overridden by system properties, + * with the {@code jpass.} prefix. + *

* * @author Gabor_Bata */ @@ -75,7 +81,8 @@ private File getConfigurationFolderPath() { private T getValue(String key, T defaultValue, Class type) { T value = defaultValue; - String prop = properties.getProperty(key); + Optional systemProp = Optional.ofNullable(System.getProperty(String.format("jpass.%s", key))); + String prop = systemProp.orElseGet(() -> properties.getProperty(key)); if (prop != null) { try { value = type.getConstructor(String.class).newInstance(prop);