diff --git a/AGENTS.md b/AGENTS.md index 8187777..c169f1c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -15,7 +15,6 @@ A simple Java client for ACINQ's [phoenixd REST API](https://phoenix.acinq.co/se - [Design Patterns](https://github.com/iluwatar/java-design-patterns) - Follow design patterns as described in the book, whenever possible. - When commiting code, follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification. -- When adding new features, ensure they are compliant with the Cashu specification (NUTs) provided above. ## Documentation diff --git a/phoenixd-base/pom.xml b/phoenixd-base/pom.xml index f682413..9945008 100644 --- a/phoenixd-base/pom.xml +++ b/phoenixd-base/pom.xml @@ -24,16 +24,7 @@ ${lombok.version} provided - - org.apache.commons - commons-configuration2 - ${commons.configuration2.version} - - - org.apache.commons - commons-lang3 - ${commons.lang3.version} - + commons-beanutils commons-beanutils diff --git a/phoenixd-base/src/main/java/xyz/tcheeric/phoenixd/common/rest/util/Configuration.java b/phoenixd-base/src/main/java/xyz/tcheeric/phoenixd/common/rest/util/Configuration.java index 45dca8b..ff4b2ff 100644 --- a/phoenixd-base/src/main/java/xyz/tcheeric/phoenixd/common/rest/util/Configuration.java +++ b/phoenixd-base/src/main/java/xyz/tcheeric/phoenixd/common/rest/util/Configuration.java @@ -4,20 +4,20 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; -import org.apache.commons.configuration2.PropertiesConfiguration; -import org.apache.commons.configuration2.builder.fluent.Configurations; +import java.io.InputStream; import java.net.URL; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; +import java.util.Properties; +import java.util.Set; @RequiredArgsConstructor @Data public class Configuration { private final @NonNull String prefix; - private final PropertiesConfiguration properties; + private final Properties properties; private String envKey(@NonNull String key) { return (prefix + "_" + key).toUpperCase().replace('.', '_'); @@ -33,29 +33,41 @@ private String resolve(@NonNull String key) { if (env != null) { return env; } - return properties.getString(prefix + "." + key, null); + return properties.getProperty(prefix + "." + key); } @SneakyThrows public Configuration(@NonNull String prefix, @NonNull URL fileUrl) { this.prefix = prefix; - this.properties = new Configurations().properties(fileUrl); + this.properties = new Properties(); + try (InputStream in = fileUrl.openStream()) { + if (in != null) { + this.properties.load(in); + } + } } @SneakyThrows public Configuration(@NonNull String prefix) { this.prefix = prefix; - this.properties = new Configurations().properties(getClass().getResource("/app.properties")); + this.properties = new Properties(); + URL resource = getClass().getResource("/app.properties"); + if (resource != null) { + try (InputStream in = resource.openStream()) { + if (in != null) { + this.properties.load(in); + } + } + } } public List keys() { List result = new ArrayList<>(); - Iterator keysIterator = properties.getKeys(prefix); - while (keysIterator.hasNext()) { - String key = keysIterator.next(); - if (key.startsWith(prefix + ".")) { - String strippedKey = key.substring(prefix.length() + 1); // +1 for the dot - result.add(strippedKey); + Set names = properties.stringPropertyNames(); + String prefixDot = prefix + "."; + for (String key : names) { + if (key.startsWith(prefixDot)) { + result.add(key.substring(prefixDot.length())); } } return result; @@ -109,4 +121,4 @@ public boolean getBoolean(@NonNull String key, boolean defaultValue) { String value = resolve(key); return value != null ? Boolean.parseBoolean(value) : defaultValue; } -} \ No newline at end of file +}