From 64e2190b1a1aabe3ba9cc8d8fa77ad7f294f0c7b Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Tue, 11 Jul 2023 14:39:54 +1200 Subject: [PATCH] Fix where load by props or command line args or indirection does not load FILE if RESOURCE found These 3 load options call through to loadWithExtensionCheck() and that was NOT going to load FILE if the RESOURCE had been found. Generally this is not an issue as these load options generally are not used with BOTH a RESOURCE and FILE properties source. However, this changes loadWithExtensionCheck() such that it will always try to load FILE source even if a RESOURCE source was found. The thinking here is that FILE source is externally configured and when provided is expected to override any default properties defined in RESOURCE sources which come with the application - in this sense it means config should always load a FILE source if there is one. --- avaje-config/src/main/java/io/avaje/config/InitialLoader.java | 4 ++-- .../src/test/java/io/avaje/config/InitialLoaderTest.java | 1 + avaje-config/src/test/resources/test-dummy.properties | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 avaje-config/src/test/resources/test-dummy.properties 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 aaa7785..1745b07 100644 --- a/avaje-config/src/main/java/io/avaje/config/InitialLoader.java +++ b/avaje-config/src/main/java/io/avaje/config/InitialLoader.java @@ -268,9 +268,9 @@ private void loadViaSystemProperty() { boolean loadWithExtensionCheck(String fileName) { if (fileName.endsWith("yaml") || fileName.endsWith("yml")) { - return loadYamlPath(fileName, RESOURCE) || loadYamlPath(fileName, FILE); + return loadYamlPath(fileName, RESOURCE) | loadYamlPath(fileName, FILE); } else if (fileName.endsWith("properties")) { - return loadProperties(fileName, RESOURCE) || loadProperties(fileName, FILE); + return loadProperties(fileName, RESOURCE) | loadProperties(fileName, FILE); } else { throw new IllegalArgumentException("Expecting only yaml or properties file but got [" + fileName + "]"); } 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 d6d0c9a..26eaa29 100644 --- a/avaje-config/src/test/java/io/avaje/config/InitialLoaderTest.java +++ b/avaje-config/src/test/java/io/avaje/config/InitialLoaderTest.java @@ -48,6 +48,7 @@ void loadWithExtensionCheck() { assertThat(properties.get("dummy.yaml.bar").value()).isEqualTo("baz"); assertThat(properties.get("dummy.yml.foo").value()).isEqualTo("bar"); assertThat(properties.get("dummy.properties.foo").value()).isEqualTo("bar"); + assertThat(properties.get("dummy.properties.a").value()).isEqualTo("fromResource"); } @Test diff --git a/avaje-config/src/test/resources/test-dummy.properties b/avaje-config/src/test/resources/test-dummy.properties new file mode 100644 index 0000000..f05ca45 --- /dev/null +++ b/avaje-config/src/test/resources/test-dummy.properties @@ -0,0 +1,2 @@ +dummy.properties.a=fromResource +dummy.properties.foo=bazz