From b35fbcf530e0a68a7a693200b692e44f7396d11e Mon Sep 17 00:00:00 2001 From: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Mon, 14 Oct 2024 17:59:05 -0400 Subject: [PATCH 1/2] evaluate load.properties --- .../io/avaje/config/InitialLoadContext.java | 25 +++++++++++++------ .../io/avaje/config/InitialLoaderTest.java | 12 +++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) 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/test/java/io/avaje/config/InitialLoaderTest.java b/avaje-config/src/test/java/io/avaje/config/InitialLoaderTest.java index 11cc2f17..5de31a5a 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},application-test-${avaje.profiles}.properties", "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 From 38ebdc2d042e9db4e069501a577cc99f21942eaa Mon Sep 17 00:00:00 2001 From: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Mon, 14 Oct 2024 18:03:42 -0400 Subject: [PATCH 2/2] fix test --- avaje-config/src/main/java/io/avaje/config/InitialLoader.java | 2 +- .../src/test/java/io/avaje/config/InitialLoaderTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 5de31a5a..cc937342 100644 --- a/avaje-config/src/test/java/io/avaje/config/InitialLoaderTest.java +++ b/avaje-config/src/test/java/io/avaje/config/InitialLoaderTest.java @@ -126,7 +126,7 @@ void loadViaIndirection_Profiles() { loader.entryMap().put("getsuga", "tensho.properties", "test"); loader .entryMap() - .put("load.properties", "${getsuga},application-test-${avaje.profiles}.properties", "test"); + .put("load.properties", "${getsuga}", "test"); loader.loadViaIndirection(); assertEquals(loader.entryMap().get("load.properties").value(), "tensho.properties");