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 27c00da
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 23 deletions.
2 changes: 1 addition & 1 deletion bom/application/pom.xml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
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 27c00da

Please sign in to comment.