Skip to content

Commit 74d4a73

Browse files
authored
Improve InitialLoadContext loadedResources key - for unique loaded resources (#180)
* Add missing JSpecify @nullable * Improve InitialLoadContext loadedResources key - for unique loaded resources
1 parent 1cd2461 commit 74d4a73

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

avaje-config/src/main/java/io/avaje/config/CoreEntry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ void put(String key, CoreEntry value) {
188188
entryMap.put(key, value);
189189
}
190190

191-
void put(String key, String value, String source) {
191+
void put(String key, @Nullable String value, String source) {
192192
entryMap.put(key, CoreEntry.of(value, source));
193193
}
194194

avaje-config/src/main/java/io/avaje/config/InitialLoadContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ InputStream resource(String resourcePath, InitialLoader.Source source) {
8888
if (source == InitialLoader.Source.RESOURCE) {
8989
is = resourceStream(resourcePath);
9090
if (is != null) {
91-
loadedResources.add("resource:" + resourcePath);
91+
loadedResources.add(source.key(resourcePath));
9292
}
9393
} else {
9494
File file = new File(resourcePath);
9595
if (file.exists()) {
9696
try {
9797
is = new FileInputStream(file);
98-
loadedResources.add("file:" + resourcePath);
98+
loadedResources.add(source.key(resourcePath));
9999
loadedFiles.add(file);
100100
} catch (FileNotFoundException e) {
101101
throw new UncheckedIOException(e);

avaje-config/src/main/java/io/avaje/config/InitialLoader.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ static Configuration.ExpressionEval evalFor(Properties properties) {
3535

3636
enum Source {
3737
RESOURCE,
38-
FILE
38+
FILE;
39+
String key(String path) {
40+
return name().toLowerCase() + ':' + path;
41+
}
3942
}
4043

4144
private final ConfigurationLog log;
@@ -298,7 +301,7 @@ private boolean loadCustom(String resourcePath, Source source) {
298301
boolean loadCustomExtension(String resourcePath, ConfigParser parser, Source source) {
299302
try (InputStream is = resource(resourcePath, source)) {
300303
if (is != null) {
301-
var sourceName = (source == RESOURCE ? "resource:" : "file:") + resourcePath;
304+
var sourceName = source.key(resourcePath);
302305
parser.load(is).forEach((k, v) -> loadContext.put(k, v, sourceName));
303306
return true;
304307
}
@@ -311,7 +314,7 @@ boolean loadCustomExtension(String resourcePath, ConfigParser parser, Source sou
311314
boolean loadProperties(String resourcePath, Source source) {
312315
try (InputStream is = resource(resourcePath, source)) {
313316
if (is != null) {
314-
loadProperties(is, (source == RESOURCE ? "resource:" : "file") + resourcePath);
317+
loadProperties(is, source.key(resourcePath));
315318
return true;
316319
}
317320
} catch (IOException e) {

0 commit comments

Comments
 (0)