Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 1 addition & 10 deletions phoenixd-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,7 @@
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>
<version>${commons.configuration2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons.lang3.version}</version>
</dependency>
<!-- No external runtime dependencies required for configuration reading -->
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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('.', '_');
Expand All @@ -33,29 +33,41 @@
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<String> keys() {
List<String> result = new ArrayList<>();
Iterator<String> 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<String> names = properties.stringPropertyNames();
String prefixDot = prefix + ".";
for (String key : names) {
if (key.startsWith(prefixDot)) {
result.add(key.substring(prefixDot.length()));
}
}
return result;
Expand Down Expand Up @@ -97,7 +109,7 @@

public boolean getBoolean(@NonNull String key) {
String value = resolve(key);
return value != null ? Boolean.parseBoolean(value) : false;

Check warning on line 112 in phoenixd-base/src/main/java/xyz/tcheeric/phoenixd/common/rest/util/Configuration.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Simplifiable conditional expression

`value != null ? Boolean.parseBoolean(value) : false` can be simplified to 'value != null \&\& Boolean.parseBoolean(value)'
}

public String get(@NonNull String key, @NonNull String defaultValue) {
Expand All @@ -109,4 +121,4 @@
String value = resolve(key);
return value != null ? Boolean.parseBoolean(value) : defaultValue;
}
}
}
Loading