Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
25 changes: 17 additions & 8 deletions avaje-config/src/main/java/io/avaje/config/InitialLoadContext.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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) {
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private boolean loadTest() {
/**
* Load configuration defined by a <em>load.properties</em> entry in properties file.
*/
private void loadViaIndirection() {
void loadViaIndirection() {
String paths = loadContext.indirectLocation();
if (paths != null) {
loadViaPaths(paths);
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 @@ -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
Expand Down