Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bootstrap Config to use default Config Sources (System and Env) #24673

Merged
merged 1 commit into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ public void run() {
ResultHandle bootstrapBuilder = null;
if (bootstrapConfigSetupNeeded()) {
bootstrapBuilder = readBootstrapConfig.invokeStaticMethod(CU_CONFIG_BUILDER_WITH_ADD_DISCOVERED_AND_BOOTSRAP,
readBootstrapConfig.load(false), readBootstrapConfig.load(true), readBootstrapConfig.load(false),
readBootstrapConfig.load(true), readBootstrapConfig.load(true), readBootstrapConfig.load(false),
readBootstrapConfig.load(launchMode));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ public static SmallRyeConfigBuilder configBuilder(final boolean runTime, final b
if (launchMode.isDevOrTest() && (runTime || bootstrap)) {
builder.withSources(new RuntimeOverrideConfigSource(classLoader));
}
if (runTime) {
if (runTime || bootstrap) {
builder.addDefaultSources();
builder.withDefaultValue(UUID_KEY, UUID.randomUUID().toString());
builder.withSources(new DotEnvConfigSourceProvider());
builder.withSources(
new PropertiesConfigSource(loadRuntimeDefaultValues(), "Runtime Defaults", Integer.MIN_VALUE + 50));
} else {
List<ConfigSource> sources = new ArrayList<>();
sources.addAll(classPathSources(META_INF_MICROPROFILE_CONFIG_PROPERTIES, classLoader));
Expand All @@ -121,10 +123,6 @@ public static SmallRyeConfigBuilder configBuilder(final boolean runTime, final b
if (addDiscovered) {
builder.addDiscoveredSources();
}
if (runTime || bootstrap) {
Map<String, String> runtimeDefaults = loadRuntimeDefaultValues();
builder.withSources(new PropertiesConfigSource(runtimeDefaults, "Runtime Defaults", Integer.MIN_VALUE + 50));
}
return builder;
}

Expand Down
37 changes: 36 additions & 1 deletion integration-tests/bootstrap-config/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-integration-test-bootstrap-config-extension</artifactId>
<version>999-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -62,13 +66,31 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<configuration>
<systemProperties>
<quarkus.config.locations>config.properties</quarkus.config.locations>
</systemProperties>
</configuration>
<executions>
<execution>
<goals>
Expand All @@ -81,6 +103,16 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<quarkus.dummy.map.system>system</quarkus.dummy.map.system>
<quarkus.config.locations>config.properties</quarkus.config.locations>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>

Expand Down Expand Up @@ -110,6 +142,9 @@
<goal>verify</goal>
</goals>
<configuration>
<environmentVariables>
<QUARKUS_DUMMY_MAP_SYSTEM>system</QUARKUS_DUMMY_MAP_SYSTEM>
</environmentVariables>
<systemPropertyVariables>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
</systemPropertyVariables>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.quarkus.it.bootstrap.config;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import io.quarkus.runtime.annotations.RegisterForReflection;
import io.smallrye.config.SmallRyeConfig;

@Path("/config")
@Produces(MediaType.APPLICATION_JSON)
public class ConfigResource {
@Inject
SmallRyeConfig config;

@GET
@Path("/{name}")
public Response configValue(@PathParam("name") final String name) {
return Response.ok(config.getConfigValue(name)).build();
}

@RegisterForReflection(targets = {
org.eclipse.microprofile.config.ConfigValue.class,
io.smallrye.config.ConfigValue.class
})
public static class ConfigValueReflection {

}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
quarkus.dummy.name=foo
quarkus.application.name=dummy
quarkus.dummy.times=9
quarkus.dummy.map.key=value
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
quarkus.dummy.map.locations=locations
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package io.quarkus.it.bootstrap.config;

import static io.restassured.RestAssured.given;
import static javax.ws.rs.core.Response.Status.OK;
import static org.hamcrest.Matchers.equalTo;

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
class ConfigResourceTest {
@Test
void bootstrap() {
given()
.get("/config/{name}", "quarkus.dummy.name")
.then()
.statusCode(OK.getStatusCode())
.body("value", equalTo("foo"))
.body("configSourceName", equalTo("bootstrap"));

given()
.get("/config/{name}", "quarkus.dummy.times")
.then()
.statusCode(OK.getStatusCode())
.body("value", equalTo("9"))
.body("configSourceName", equalTo("bootstrap"));

given()
.get("/config/{name}", "quarkus.dummy.map.key")
.then()
.statusCode(OK.getStatusCode())
.body("value", equalTo("value"))
.body("configSourceName", equalTo("bootstrap"));

given()
.get("/config/{name}", "quarkus.dummy.map.system")
.then()
.statusCode(OK.getStatusCode())
.body("value", equalTo("system"))
.body("configSourceName", equalTo("bootstrap"));
}

@Test
void locations() {
given()
.get("/config/{name}", "quarkus.dummy.map.locations")
.then()
.statusCode(OK.getStatusCode())
.body("value", equalTo("locations"))
.body("configSourceName", equalTo("bootstrap"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import io.quarkus.test.junit.QuarkusIntegrationTest;

@QuarkusIntegrationTest
class GreetingResourceTestIT extends GreetingResourceTest {
class ConfigResourceTestIT extends ConfigResourceTest {
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@
import io.quarkus.it.bootstrap.config.extension.DummyBootstrapRecorder;
import io.quarkus.it.bootstrap.config.extension.DummyBootstrapRecorder2;
import io.quarkus.it.bootstrap.config.extension.DummyConfig;
import io.quarkus.runtime.ApplicationConfig;

public class DummyBootstrapConfigBuildStep {

@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
public RunTimeConfigurationSourceValueBuildItem dummyRecorder(DummyBootstrapRecorder recorder, DummyConfig dummyConfig,
ApplicationConfig applicationConfig) {
return new RunTimeConfigurationSourceValueBuildItem(recorder.create(dummyConfig, applicationConfig));
public RunTimeConfigurationSourceValueBuildItem dummyRecorder(DummyBootstrapRecorder recorder, DummyConfig dummyConfig) {
return new RunTimeConfigurationSourceValueBuildItem(recorder.create(dummyConfig));
}

@BuildStep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

import org.eclipse.microprofile.config.spi.ConfigSourceProvider;

import io.quarkus.runtime.ApplicationConfig;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.Recorder;

@Recorder
public class DummyBootstrapRecorder {

public RuntimeValue<ConfigSourceProvider> create(DummyConfig dummyConfig, ApplicationConfig applicationConfig) {
return new RuntimeValue<>(new DummyConfigSourceProvider(dummyConfig, applicationConfig));
public RuntimeValue<ConfigSourceProvider> create(DummyConfig dummyConfig) {
return new RuntimeValue<>(new DummyConfigSourceProvider(dummyConfig));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.quarkus.it.bootstrap.config.extension;

import java.util.Map;

import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
Expand All @@ -17,4 +20,19 @@ public class DummyConfig {
*/
@ConfigItem(defaultValue = "2")
public Integer times;

/**
* dummy map
*/
@ConfigItem(name = "map")
public Map<String, MapConfig> map;

@ConfigGroup
public static class MapConfig {
/**
* dummy value
*/
@ConfigItem(name = ConfigItem.PARENT)
public String value;
}
}
Loading