Skip to content

Commit ea35a80

Browse files
authored
Merge pull request #52 from 398ja/fix/config-without-commons-0.1.2
fix/config-without-commons-0.1.2
2 parents 85191b2 + 89206c2 commit ea35a80

3 files changed

Lines changed: 27 additions & 25 deletions

File tree

AGENTS.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ A simple Java client for ACINQ's [phoenixd REST API](https://phoenix.acinq.co/se
1515
- [Design Patterns](https://github.com/iluwatar/java-design-patterns)
1616
- Follow design patterns as described in the book, whenever possible.
1717
- When commiting code, follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification.
18-
- When adding new features, ensure they are compliant with the Cashu specification (NUTs) provided above.
1918

2019
## Documentation
2120

phoenixd-base/pom.xml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,7 @@
2424
<version>${lombok.version}</version>
2525
<scope>provided</scope>
2626
</dependency>
27-
<dependency>
28-
<groupId>org.apache.commons</groupId>
29-
<artifactId>commons-configuration2</artifactId>
30-
<version>${commons.configuration2.version}</version>
31-
</dependency>
32-
<dependency>
33-
<groupId>org.apache.commons</groupId>
34-
<artifactId>commons-lang3</artifactId>
35-
<version>${commons.lang3.version}</version>
36-
</dependency>
27+
<!-- No external runtime dependencies required for configuration reading -->
3728
<dependency>
3829
<groupId>commons-beanutils</groupId>
3930
<artifactId>commons-beanutils</artifactId>

phoenixd-base/src/main/java/xyz/tcheeric/phoenixd/common/rest/util/Configuration.java

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
import lombok.NonNull;
55
import lombok.RequiredArgsConstructor;
66
import lombok.SneakyThrows;
7-
import org.apache.commons.configuration2.PropertiesConfiguration;
8-
import org.apache.commons.configuration2.builder.fluent.Configurations;
97

8+
import java.io.InputStream;
109
import java.net.URL;
1110
import java.util.ArrayList;
12-
import java.util.Iterator;
1311
import java.util.List;
12+
import java.util.Properties;
13+
import java.util.Set;
1414

1515
@RequiredArgsConstructor
1616
@Data
1717
public class Configuration {
1818

1919
private final @NonNull String prefix;
20-
private final PropertiesConfiguration properties;
20+
private final Properties properties;
2121

2222
private String envKey(@NonNull String key) {
2323
return (prefix + "_" + key).toUpperCase().replace('.', '_');
@@ -33,29 +33,41 @@ private String resolve(@NonNull String key) {
3333
if (env != null) {
3434
return env;
3535
}
36-
return properties.getString(prefix + "." + key, null);
36+
return properties.getProperty(prefix + "." + key);
3737
}
3838

3939
@SneakyThrows
4040
public Configuration(@NonNull String prefix, @NonNull URL fileUrl) {
4141
this.prefix = prefix;
42-
this.properties = new Configurations().properties(fileUrl);
42+
this.properties = new Properties();
43+
try (InputStream in = fileUrl.openStream()) {
44+
if (in != null) {
45+
this.properties.load(in);
46+
}
47+
}
4348
}
4449

4550
@SneakyThrows
4651
public Configuration(@NonNull String prefix) {
4752
this.prefix = prefix;
48-
this.properties = new Configurations().properties(getClass().getResource("/app.properties"));
53+
this.properties = new Properties();
54+
URL resource = getClass().getResource("/app.properties");
55+
if (resource != null) {
56+
try (InputStream in = resource.openStream()) {
57+
if (in != null) {
58+
this.properties.load(in);
59+
}
60+
}
61+
}
4962
}
5063

5164
public List<String> keys() {
5265
List<String> result = new ArrayList<>();
53-
Iterator<String> keysIterator = properties.getKeys(prefix);
54-
while (keysIterator.hasNext()) {
55-
String key = keysIterator.next();
56-
if (key.startsWith(prefix + ".")) {
57-
String strippedKey = key.substring(prefix.length() + 1); // +1 for the dot
58-
result.add(strippedKey);
66+
Set<String> names = properties.stringPropertyNames();
67+
String prefixDot = prefix + ".";
68+
for (String key : names) {
69+
if (key.startsWith(prefixDot)) {
70+
result.add(key.substring(prefixDot.length()));
5971
}
6072
}
6173
return result;
@@ -109,4 +121,4 @@ public boolean getBoolean(@NonNull String key, boolean defaultValue) {
109121
String value = resolve(key);
110122
return value != null ? Boolean.parseBoolean(value) : defaultValue;
111123
}
112-
}
124+
}

0 commit comments

Comments
 (0)