Skip to content

Commit

Permalink
Update SmallRye Config to 2.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez committed Sep 2, 2022
1 parent 09b5d07 commit 64b2b36
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 35 deletions.
16 changes: 3 additions & 13 deletions bom/application/pom.xml
Expand Up @@ -40,7 +40,7 @@
<microprofile-jwt.version>1.2</microprofile-jwt.version>
<microprofile-lra.version>1.0</microprofile-lra.version>
<smallrye-common.version>1.13.1</smallrye-common.version>
<smallrye-config.version>2.11.1</smallrye-config.version>
<smallrye-config.version>2.12.0</smallrye-config.version>
<smallrye-health.version>3.2.1</smallrye-health.version>
<smallrye-metrics.version>3.0.5</smallrye-metrics.version>
<smallrye-open-api.version>2.2.0</smallrye-open-api.version>
Expand Down Expand Up @@ -76,7 +76,7 @@
<jboss-jaxb-api_2.3_spec.version>2.0.0.Final</jboss-jaxb-api_2.3_spec.version>
<asm.version>9.3</asm.version>
<commons-io.version>2.11.0</commons-io.version>
<jboss-metadata-web.version>15.1.0.Final</jboss-metadata-web.version>
<jboss-metadata-web.version>15.0.0.Final</jboss-metadata-web.version>
<maven-toolchain.version>3.0-alpha-2</maven-toolchain.version>
<plexus-utils.version>3.3.0</plexus-utils.version>
<plexus-component-annotations.version>2.1.0</plexus-component-annotations.version>
Expand Down Expand Up @@ -156,7 +156,7 @@
<maven-invoker.version>3.2.0</maven-invoker.version>
<awaitility.version>4.2.0</awaitility.version>
<jboss-logmanager.version>1.0.10</jboss-logmanager.version>
<flyway.version>9.2.1</flyway.version>
<flyway.version>9.2.0</flyway.version>
<yasson.version>1.0.11</yasson.version>
<liquibase.version>4.15.0</liquibase.version>
<snakeyaml.version>1.31</snakeyaml.version>
Expand Down Expand Up @@ -885,16 +885,6 @@
<artifactId>quarkus-keycloak-admin-client-reactive-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-keycloak-admin-client-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-keycloak-admin-client-common-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-flyway</artifactId>
Expand Down
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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());
Expand Down
@@ -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<Object> {
Expand All @@ -27,4 +30,34 @@ public Object create(CreationalContext<Object> creationalContext, Map<String, Ob
SmallRyeConfig config = (SmallRyeConfig) ConfigProvider.getConfig();
return config.getConfigMapping(interfaceType, getPrefixFromInjectionPoint(injectionPoint).orElse(prefix));
}

private static Optional<String> 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();
}
}
9 changes: 4 additions & 5 deletions integration-tests/smallrye-config/pom.xml
Expand Up @@ -25,11 +25,11 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
<artifactId>quarkus-resteasy-reactive</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
<artifactId>quarkus-resteasy-reactive-jackson</artifactId>
</dependency>
<!-- Add opentracing to ensure that it works in native when undertow isn't present -->
<!-- See https://github.com/quarkusio/quarkus/issues/14966 -->
Expand Down Expand Up @@ -80,7 +80,6 @@
<scope>test</scope>
</dependency>


<!-- Minimal test dependencies to *-deployment artifacts for consistent build order -->
<dependency>
<groupId>io.quarkus</groupId>
Expand Down Expand Up @@ -110,7 +109,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-deployment</artifactId>
<artifactId>quarkus-resteasy-reactive-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
Expand All @@ -123,7 +122,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson-deployment</artifactId>
<artifactId>quarkus-resteasy-reactive-jackson-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
Expand Down
Expand Up @@ -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;

Expand All @@ -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
Expand Down
@@ -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"));
}
}
Expand Up @@ -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()
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 64b2b36

Please sign in to comment.