Skip to content

Commit

Permalink
add possibility to override config via system properties
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbata committed Mar 25, 2024
1 parent d55bfd0 commit 66c308f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main/java/jpass/util/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>
* Each configuration property can by overridden by system properties,
* with the {@code jpass.} prefix.
* </p>
*
* @author Gabor_Bata
*/
Expand Down Expand Up @@ -75,7 +81,8 @@ private File getConfigurationFolderPath() {

private <T> T getValue(String key, T defaultValue, Class<T> type) {
T value = defaultValue;
String prop = properties.getProperty(key);
Optional<String> 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);
Expand Down

0 comments on commit 66c308f

Please sign in to comment.