Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
31 changes: 22 additions & 9 deletions avaje-config/src/main/java/io/avaje/config/InitialLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ void loadViaCommandLine(String[] args) {

private void loadCommandLineArg(String arg) {
if (isValidExtension(arg)) {
loadViaPaths(arg);
for (String path : splitPaths(arg)) {
loadWithExtensionCheck(loadContext.eval(path));
}
}
}

Expand Down Expand Up @@ -188,12 +190,29 @@ private boolean loadTest() {
}

/**
* Load configuration defined by a <em>load.properties</em> entry in properties file.
* Recursively Load configuration defined by a <em>load.properties</em> entry in properties file.
*/
private void loadViaIndirection() {
String paths = loadContext.indirectLocation();
if (paths != null) {
loadViaPaths(paths);
var stack = new ArrayDeque<String>();
splitAndAddPaths(stack, paths);
String path;
while ((path = stack.poll()) != null) {
loadWithExtensionCheck(loadContext.eval(path));
var newPath = loadContext.indirectLocation();
if (!paths.equals(newPath)) {
paths = newPath;
splitAndAddPaths(stack, paths);
}
}
}
}

private void splitAndAddPaths(ArrayDeque<String> stack, String paths) {
var split = splitPaths(paths);
for (int i = split.length - 1; i >= 0; i--) {
stack.addFirst(split[i]);
}
}

Expand All @@ -218,12 +237,6 @@ private void loadViaProfiles(Source source) {
}
}

private void loadViaPaths(String paths) {
for (String path : splitPaths(paths)) {
loadWithExtensionCheck(loadContext.eval(path));
}
}

int size() {
return loadContext.size();
}
Expand Down
12 changes: 12 additions & 0 deletions avaje-config/src/test/java/io/avaje/config/InitialLoaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,16 @@ void load_withSuppressTestResource() {
System.clearProperty("suppressTestResource");
}
}

@Test
void load_withLoadPropertyChain() {
InitialLoader loader = newInitialLoader();
loader.loadWithExtensionCheck("test-properties/chain/main.properties");
var properties = evalFor(loader.load());
assertThat(properties.get("value.a").value()).isEqualTo("true");
assertThat(properties.get("value.b").value()).isEqualTo("true");
assertThat(properties.get("value.c").value()).isEqualTo("true");
assertThat(properties.get("value.d").value()).isEqualTo("true");
assertThat(properties.get("override").value()).isEqualTo("d");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
value.a=true
override=a
load.properties=test-properties/chain/c.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
value.b=true
override=b
load.properties=test-properties/chain/c.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
value.c=true
override=c
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
value.d=true
override=d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
load.properties=test-properties/chain/a.properties test-properties/chain/b.properties, test-properties/chain/d.properties