Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve InitialLoadContext loadedResources key - for unique loaded resources #180

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion avaje-config/src/main/java/io/avaje/config/CoreEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void put(String key, CoreEntry value) {
entryMap.put(key, value);
}

void put(String key, String value, String source) {
void put(String key, @Nullable String value, String source) {
entryMap.put(key, CoreEntry.of(value, source));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ InputStream resource(String resourcePath, InitialLoader.Source source) {
if (source == InitialLoader.Source.RESOURCE) {
is = resourceStream(resourcePath);
if (is != null) {
loadedResources.add("resource:" + resourcePath);
loadedResources.add(source.key(resourcePath));
}
} else {
File file = new File(resourcePath);
if (file.exists()) {
try {
is = new FileInputStream(file);
loadedResources.add("file:" + resourcePath);
loadedResources.add(source.key(resourcePath));
loadedFiles.add(file);
} catch (FileNotFoundException e) {
throw new UncheckedIOException(e);
Expand Down
9 changes: 6 additions & 3 deletions avaje-config/src/main/java/io/avaje/config/InitialLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ static Configuration.ExpressionEval evalFor(Properties properties) {

enum Source {
RESOURCE,
FILE
FILE;
String key(String path) {
return name().toLowerCase() + ':' + path;
}
}

private final ConfigurationLog log;
Expand Down Expand Up @@ -298,7 +301,7 @@ private boolean loadCustom(String resourcePath, Source source) {
boolean loadCustomExtension(String resourcePath, ConfigParser parser, Source source) {
try (InputStream is = resource(resourcePath, source)) {
if (is != null) {
var sourceName = (source == RESOURCE ? "resource:" : "file:") + resourcePath;
var sourceName = source.key(resourcePath);
parser.load(is).forEach((k, v) -> loadContext.put(k, v, sourceName));
return true;
}
Expand All @@ -311,7 +314,7 @@ boolean loadCustomExtension(String resourcePath, ConfigParser parser, Source sou
boolean loadProperties(String resourcePath, Source source) {
try (InputStream is = resource(resourcePath, source)) {
if (is != null) {
loadProperties(is, (source == RESOURCE ? "resource:" : "file") + resourcePath);
loadProperties(is, source.key(resourcePath));
return true;
}
} catch (IOException e) {
Expand Down