From 27c00dad0167dfc34504e5d045b34ef515f8b26a Mon Sep 17 00:00:00 2001 From: Roberto Cortez Date: Fri, 2 Sep 2022 08:52:04 +0100 Subject: [PATCH] Update SmallRye Config to 2.12.0 --- bom/application/pom.xml | 2 +- .../BuildTimeConfigurationReader.java | 4 +- .../arc/runtime/ConfigMappingCreator.java | 37 ++++++++++++++++++- integration-tests/smallrye-config/pom.xml | 9 ++--- .../it/smallrye/config/ConfigResource.java | 8 ++++ .../it/smallrye/config/QuarkusConfigTest.java | 31 ++++++++++++++++ .../smallrye/config/ServerResourceTest.java | 17 ++------- 7 files changed, 85 insertions(+), 23 deletions(-) create mode 100644 integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/QuarkusConfigTest.java diff --git a/bom/application/pom.xml b/bom/application/pom.xml index 794e3c4e0ad635..83e7b28af47312 100644 --- a/bom/application/pom.xml +++ b/bom/application/pom.xml @@ -40,7 +40,7 @@ 1.2 1.0 1.13.1 - 2.11.1 + 2.12.0 3.2.1 3.0.5 2.2.0 diff --git a/core/deployment/src/main/java/io/quarkus/deployment/configuration/BuildTimeConfigurationReader.java b/core/deployment/src/main/java/io/quarkus/deployment/configuration/BuildTimeConfigurationReader.java index 46030d8daf6a8c..c9ea61d5ae4af0 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/configuration/BuildTimeConfigurationReader.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/configuration/BuildTimeConfigurationReader.java @@ -404,7 +404,7 @@ ReadResult run() { // we always have to set the map entry ourselves Field field = matched.findField(); Converter converter = getConverter(config, field, ConverterType.of(field)); - map.put(key, config.convertValue(configValue.getNameProfiled(), configValue.getValue(), converter)); + map.put(key, config.convertValue(configValue, converter)); allBuildTimeValues.put(configValue.getNameProfiled(), configValue.getValue()); continue; } @@ -437,7 +437,7 @@ ReadResult run() { // we always have to set the map entry ourselves Field field = matched.findField(); Converter converter = getConverter(config, field, ConverterType.of(field)); - map.put(key, config.convertValue(configValue.getNameProfiled(), configValue.getValue(), converter)); + map.put(key, config.convertValue(configValue, converter)); // cache the resolved value allBuildTimeValues.put(configValue.getNameProfiled(), configValue.getValue()); buildTimeRunTimeValues.put(configValue.getNameProfiled(), configValue.getValue()); diff --git a/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/ConfigMappingCreator.java b/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/ConfigMappingCreator.java index 7cedbcb1c47e68..276b55345b2fe8 100644 --- a/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/ConfigMappingCreator.java +++ b/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/ConfigMappingCreator.java @@ -1,16 +1,19 @@ package io.quarkus.arc.runtime; -import static io.smallrye.config.inject.ConfigMappingInjectionBean.getPrefixFromInjectionPoint; - +import java.lang.annotation.Annotation; import java.util.Map; +import java.util.Optional; import javax.enterprise.context.spi.CreationalContext; +import javax.enterprise.inject.spi.Annotated; import javax.enterprise.inject.spi.InjectionPoint; import org.eclipse.microprofile.config.ConfigProvider; +import org.eclipse.microprofile.config.inject.ConfigProperties; import io.quarkus.arc.BeanCreator; import io.quarkus.arc.impl.InjectionPointProvider; +import io.smallrye.config.ConfigMapping; import io.smallrye.config.SmallRyeConfig; public class ConfigMappingCreator implements BeanCreator { @@ -27,4 +30,34 @@ public Object create(CreationalContext creationalContext, Map getPrefixFromInjectionPoint(final InjectionPoint injectionPoint) { + Annotated annotated = injectionPoint.getAnnotated(); + if (annotated != null) { + ConfigMapping configMapping = annotated.getAnnotation(ConfigMapping.class); + if (configMapping != null) { + if (!configMapping.prefix().isEmpty()) { + return Optional.of(configMapping.prefix()); + } + } + + ConfigProperties configProperties = annotated.getAnnotation(ConfigProperties.class); + if (configProperties != null) { + if (!ConfigProperties.UNCONFIGURED_PREFIX.equals(configProperties.prefix())) { + return Optional.of(configProperties.prefix()); + } + } + } + + for (Annotation qualifier : injectionPoint.getQualifiers()) { + if (qualifier instanceof ConfigProperties) { + ConfigProperties configPropertiesQualifier = (ConfigProperties) qualifier; + if (!ConfigProperties.UNCONFIGURED_PREFIX.equals(configPropertiesQualifier.prefix())) { + return Optional.of(configPropertiesQualifier.prefix()); + } + } + } + + return Optional.empty(); + } } diff --git a/integration-tests/smallrye-config/pom.xml b/integration-tests/smallrye-config/pom.xml index f8ae7033bfaad8..ece98c2440a4ca 100644 --- a/integration-tests/smallrye-config/pom.xml +++ b/integration-tests/smallrye-config/pom.xml @@ -25,11 +25,11 @@ io.quarkus - quarkus-resteasy + quarkus-resteasy-reactive io.quarkus - quarkus-resteasy-jackson + quarkus-resteasy-reactive-jackson @@ -80,7 +80,6 @@ test - io.quarkus @@ -110,7 +109,7 @@ io.quarkus - quarkus-resteasy-deployment + quarkus-resteasy-reactive-deployment ${project.version} pom test @@ -123,7 +122,7 @@ io.quarkus - quarkus-resteasy-jackson-deployment + quarkus-resteasy-reactive-jackson-deployment ${project.version} pom test diff --git a/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/ConfigResource.java b/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/ConfigResource.java index b8f2e3003ff644..8cb380f7d6f49e 100644 --- a/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/ConfigResource.java +++ b/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/ConfigResource.java @@ -8,6 +8,8 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.eclipse.microprofile.config.ConfigProvider; + import io.quarkus.runtime.annotations.RegisterForReflection; import io.smallrye.config.SmallRyeConfig; @@ -29,6 +31,12 @@ public Response profiles() { return Response.ok(config.getProfiles()).build(); } + @GET + @Path("/uuid") + public Response uuid() { + return Response.ok(ConfigProvider.getConfig().getConfigValue("quarkus.uuid")).build(); + } + @RegisterForReflection(targets = { org.eclipse.microprofile.config.ConfigValue.class, io.smallrye.config.ConfigValue.class diff --git a/integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/QuarkusConfigTest.java b/integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/QuarkusConfigTest.java new file mode 100644 index 00000000000000..ad4d81df86e096 --- /dev/null +++ b/integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/QuarkusConfigTest.java @@ -0,0 +1,31 @@ +package io.quarkus.it.smallrye.config; + +import static io.restassured.RestAssured.given; +import static javax.ws.rs.core.Response.Status.OK; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +public class QuarkusConfigTest { + @Test + void uuid() { + given() + .get("/config/{name}", "quarkus.uuid") + .then() + .statusCode(OK.getStatusCode()) + .body("value", is(notNullValue())) + .body("configSourceName", equalTo("DefaultValuesConfigSource")); + + given() + .get("/config/uuid") + .then() + .statusCode(OK.getStatusCode()) + .body("value", is(notNullValue())) + .body("configSourceName", equalTo("DefaultValuesConfigSource")); + } +} diff --git a/integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/ServerResourceTest.java b/integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/ServerResourceTest.java index 060c3bb661708c..63bfed5338bfc5 100644 --- a/integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/ServerResourceTest.java +++ b/integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/ServerResourceTest.java @@ -10,25 +10,13 @@ import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasSize; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import io.quarkus.test.junit.QuarkusTest; -import io.restassured.RestAssured; import io.restassured.http.Header; @QuarkusTest class ServerResourceTest { - @BeforeAll - static void beforeAll() { - RestAssured.filters( - (requestSpec, responseSpec, ctx) -> { - requestSpec.header(new Header(CONTENT_TYPE, APPLICATION_JSON)); - requestSpec.header(new Header(ACCEPT, APPLICATION_JSON)); - return ctx.next(requestSpec, responseSpec); - }); - } - @Test void mapping() { given() @@ -99,7 +87,10 @@ void info() { @Test void invalid() { - given().get("/server/validator/{prefix}", "cloud") + given() + .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) + .header(new Header(ACCEPT, APPLICATION_JSON)) + .get("/server/validator/{prefix}", "cloud") .then() .statusCode(OK.getStatusCode()) .body("errors", hasSize(9))