From 74e2236f5edbdc7c1aa5b6a57e521d8b7af22c99 Mon Sep 17 00:00:00 2001 From: Roberto Cortez Date: Tue, 3 Dec 2024 21:33:56 +0000 Subject: [PATCH] Do not discover properties resource in the classpath since they are already recorded during build time --- .../configuration/RuntimeConfigBuilder.java | 16 +++++++++++++--- .../configuration/StaticInitConfigBuilder.java | 17 ++++++++++++++--- .../test/TestConfigBuilderCustomizer.java | 18 ++++++++++++++++++ ...lrye.config.SmallRyeConfigBuilderCustomizer | 1 + 4 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 test-framework/junit5-internal/src/main/java/io/quarkus/test/TestConfigBuilderCustomizer.java create mode 100644 test-framework/junit5-internal/src/main/resources/META-INF/services/io.smallrye.config.SmallRyeConfigBuilderCustomizer diff --git a/core/runtime/src/main/java/io/quarkus/runtime/configuration/RuntimeConfigBuilder.java b/core/runtime/src/main/java/io/quarkus/runtime/configuration/RuntimeConfigBuilder.java index 5415f6e4d521ca..2a077bfbc36695 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/configuration/RuntimeConfigBuilder.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/configuration/RuntimeConfigBuilder.java @@ -1,5 +1,8 @@ package io.quarkus.runtime.configuration; +import static io.smallrye.config.PropertiesConfigSourceLoader.inFileSystem; + +import java.nio.file.Paths; import java.util.UUID; import io.smallrye.config.SmallRyeConfigBuilder; @@ -14,13 +17,20 @@ public void configBuilder(final SmallRyeConfigBuilder builder) { new QuarkusConfigBuilderCustomizer().configBuilder(builder); builder.withDefaultValue("quarkus.uuid", UUID.randomUUID().toString()); - builder.forClassLoader(Thread.currentThread().getContextClassLoader()) + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + builder.forClassLoader(classLoader) .addDefaultInterceptors() - .addDefaultSources(); + .addSystemSources(); + + if (!builder.isAddDefaultSources() && !builder.isAddPropertiesSources()) { + builder.withSources(inFileSystem( + Paths.get(System.getProperty("user.dir"), "config", "application.properties").toUri().toString(), 260, + classLoader)); + } } @Override public int priority() { - return Integer.MIN_VALUE; + return Integer.MIN_VALUE + 10; } } diff --git a/core/runtime/src/main/java/io/quarkus/runtime/configuration/StaticInitConfigBuilder.java b/core/runtime/src/main/java/io/quarkus/runtime/configuration/StaticInitConfigBuilder.java index a2bdbb63aef1de..968f3b567c030a 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/configuration/StaticInitConfigBuilder.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/configuration/StaticInitConfigBuilder.java @@ -1,5 +1,9 @@ package io.quarkus.runtime.configuration; +import static io.smallrye.config.PropertiesConfigSourceLoader.inFileSystem; + +import java.nio.file.Paths; + import io.smallrye.config.SmallRyeConfigBuilder; import io.smallrye.config.SmallRyeConfigBuilderCustomizer; @@ -11,13 +15,20 @@ public class StaticInitConfigBuilder implements SmallRyeConfigBuilderCustomizer public void configBuilder(final SmallRyeConfigBuilder builder) { new QuarkusConfigBuilderCustomizer().configBuilder(builder); - builder.forClassLoader(Thread.currentThread().getContextClassLoader()) + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + builder.forClassLoader(classLoader) .addDefaultInterceptors() - .addDefaultSources(); + .addSystemSources(); + + if (!builder.isAddDefaultSources() && !builder.isAddPropertiesSources()) { + builder.withSources(inFileSystem( + Paths.get(System.getProperty("user.dir"), "config", "application.properties").toUri().toString(), 260, + classLoader)); + } } @Override public int priority() { - return Integer.MIN_VALUE; + return Integer.MIN_VALUE + 10; } } diff --git a/test-framework/junit5-internal/src/main/java/io/quarkus/test/TestConfigBuilderCustomizer.java b/test-framework/junit5-internal/src/main/java/io/quarkus/test/TestConfigBuilderCustomizer.java new file mode 100644 index 00000000000000..5bafa3929d58aa --- /dev/null +++ b/test-framework/junit5-internal/src/main/java/io/quarkus/test/TestConfigBuilderCustomizer.java @@ -0,0 +1,18 @@ +package io.quarkus.test; + +import io.quarkus.runtime.annotations.StaticInitSafe; +import io.smallrye.config.SmallRyeConfigBuilder; +import io.smallrye.config.SmallRyeConfigBuilderCustomizer; + +@StaticInitSafe +public class TestConfigBuilderCustomizer implements SmallRyeConfigBuilderCustomizer { + @Override + public void configBuilder(final SmallRyeConfigBuilder builder) { + builder.addPropertiesSources(); + } + + @Override + public int priority() { + return Integer.MIN_VALUE; + } +} diff --git a/test-framework/junit5-internal/src/main/resources/META-INF/services/io.smallrye.config.SmallRyeConfigBuilderCustomizer b/test-framework/junit5-internal/src/main/resources/META-INF/services/io.smallrye.config.SmallRyeConfigBuilderCustomizer new file mode 100644 index 00000000000000..cbb67b072a4611 --- /dev/null +++ b/test-framework/junit5-internal/src/main/resources/META-INF/services/io.smallrye.config.SmallRyeConfigBuilderCustomizer @@ -0,0 +1 @@ +io.quarkus.test.TestConfigBuilderCustomizer