diff --git a/avaje-config/src/main/java/io/avaje/config/InitialLoadContext.java b/avaje-config/src/main/java/io/avaje/config/InitialLoadContext.java index 5c0fbd90..a04e6d59 100644 --- a/avaje-config/src/main/java/io/avaje/config/InitialLoadContext.java +++ b/avaje-config/src/main/java/io/avaje/config/InitialLoadContext.java @@ -1,14 +1,20 @@ package io.avaje.config; -import io.avaje.config.CoreEntry.CoreMap; -import org.jspecify.annotations.Nullable; - -import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.io.UncheckedIOException; import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; +import java.util.StringJoiner; + +import org.jspecify.annotations.Nullable; + +import io.avaje.config.CoreEntry.CoreMap; /** * Manages the underlying map of properties we are gathering. @@ -127,9 +133,7 @@ CoreMap entryMap() { return map; } - /** - * Read the special properties that can point to an external properties source. - */ + /** Read the special properties that can point to an external properties source. */ String indirectLocation() { String location = System.getProperty("load.properties"); if (location != null) { @@ -139,7 +143,12 @@ String indirectLocation() { if (indirectLocation == null) { indirectLocation = map.get("load.properties.override"); } - return indirectLocation == null ? null : indirectLocation.value(); + var result = indirectLocation == null ? null : indirectLocation.value(); + if (result != null && indirectLocation.needsEvaluation()) { + result = eval(result); + map.put("load.properties", result, ""); + } + return result; } String profiles() { diff --git a/avaje-config/src/main/java/io/avaje/config/InitialLoader.java b/avaje-config/src/main/java/io/avaje/config/InitialLoader.java index dbfa651d..97cb5ce6 100644 --- a/avaje-config/src/main/java/io/avaje/config/InitialLoader.java +++ b/avaje-config/src/main/java/io/avaje/config/InitialLoader.java @@ -190,7 +190,7 @@ private boolean loadTest() { /** * Load configuration defined by a load.properties entry in properties file. */ - private void loadViaIndirection() { + void loadViaIndirection() { String paths = loadContext.indirectLocation(); if (paths != null) { loadViaPaths(paths); diff --git a/avaje-config/src/test/java/io/avaje/config/InitialLoaderTest.java b/avaje-config/src/test/java/io/avaje/config/InitialLoaderTest.java index 11cc2f17..cc937342 100644 --- a/avaje-config/src/test/java/io/avaje/config/InitialLoaderTest.java +++ b/avaje-config/src/test/java/io/avaje/config/InitialLoaderTest.java @@ -120,6 +120,18 @@ void loadViaCommandLine_localFile() { assertEquals(1, loader.size()); } + @Test + void loadViaIndirection_Profiles() { + InitialLoader loader = newInitialLoader(); + loader.entryMap().put("getsuga", "tensho.properties", "test"); + loader + .entryMap() + .put("load.properties", "${getsuga}", "test"); + loader.loadViaIndirection(); + + assertEquals(loader.entryMap().get("load.properties").value(), "tensho.properties"); + } + @Test void load_withSuppressTestResource() { //application-test.yaml is loaded when suppressTestResource is not set to true