Skip to content

Commit b35fbcf

Browse files
committed
evaluate load.properties
1 parent c33f82d commit b35fbcf

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
package io.avaje.config;
22

3-
import io.avaje.config.CoreEntry.CoreMap;
4-
import org.jspecify.annotations.Nullable;
5-
6-
import java.io.*;
3+
import java.io.File;
4+
import java.io.FileInputStream;
5+
import java.io.FileNotFoundException;
6+
import java.io.InputStream;
7+
import java.io.UncheckedIOException;
78
import java.lang.System.Logger.Level;
89
import java.util.ArrayList;
910
import java.util.LinkedHashSet;
1011
import java.util.List;
1112
import java.util.Set;
13+
import java.util.StringJoiner;
14+
15+
import org.jspecify.annotations.Nullable;
16+
17+
import io.avaje.config.CoreEntry.CoreMap;
1218

1319
/**
1420
* Manages the underlying map of properties we are gathering.
@@ -127,9 +133,7 @@ CoreMap entryMap() {
127133
return map;
128134
}
129135

130-
/**
131-
* Read the special properties that can point to an external properties source.
132-
*/
136+
/** Read the special properties that can point to an external properties source. */
133137
String indirectLocation() {
134138
String location = System.getProperty("load.properties");
135139
if (location != null) {
@@ -139,7 +143,12 @@ String indirectLocation() {
139143
if (indirectLocation == null) {
140144
indirectLocation = map.get("load.properties.override");
141145
}
142-
return indirectLocation == null ? null : indirectLocation.value();
146+
var result = indirectLocation == null ? null : indirectLocation.value();
147+
if (result != null && indirectLocation.needsEvaluation()) {
148+
result = eval(result);
149+
map.put("load.properties", result, "");
150+
}
151+
return result;
143152
}
144153

145154
String profiles() {

avaje-config/src/test/java/io/avaje/config/InitialLoaderTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@ void loadViaCommandLine_localFile() {
120120
assertEquals(1, loader.size());
121121
}
122122

123+
@Test
124+
void loadViaIndirection_Profiles() {
125+
InitialLoader loader = newInitialLoader();
126+
loader.entryMap().put("getsuga", "tensho.properties", "test");
127+
loader
128+
.entryMap()
129+
.put("load.properties", "${getsuga},application-test-${avaje.profiles}.properties", "test");
130+
loader.loadViaIndirection();
131+
132+
assertEquals(loader.entryMap().get("load.properties").value(), "tensho.properties");
133+
}
134+
123135
@Test
124136
void load_withSuppressTestResource() {
125137
//application-test.yaml is loaded when suppressTestResource is not set to true

0 commit comments

Comments
 (0)