Skip to content

Commit

Permalink
Introduce new configuration framework and update SmallRye Config version
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlloyd committed Nov 20, 2019
1 parent fe5a2de commit e9acf37
Show file tree
Hide file tree
Showing 90 changed files with 4,312 additions and 3,969 deletions.
7 changes: 6 additions & 1 deletion bom/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<microprofile-opentracing-api.version>1.3.1</microprofile-opentracing-api.version>
<microprofile-reactive-streams-operators.version>1.0</microprofile-reactive-streams-operators.version>
<microprofile-rest-client.version>1.3.4</microprofile-rest-client.version>
<smallrye-config.version>1.3.9</smallrye-config.version>
<smallrye-config.version>1.4.1</smallrye-config.version>
<smallrye-health.version>2.1.0</smallrye-health.version>
<smallrye-metrics.version>2.3.0</smallrye-metrics.version>
<smallrye-open-api.version>1.1.20</smallrye-open-api.version>
Expand Down Expand Up @@ -1073,6 +1073,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-config-common</artifactId>
<version>${smallrye-config.version}</version>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-health</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import java.util.Properties;
import java.util.function.Consumer;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.spi.ConfigBuilder;
import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
import org.jboss.logging.Logger;

import io.quarkus.bootstrap.BootstrapDependencyProcessingException;
Expand All @@ -36,8 +38,11 @@
import io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem;
import io.quarkus.deployment.pkg.builditem.JarBuildItem;
import io.quarkus.deployment.pkg.builditem.NativeImageBuildItem;
import io.quarkus.runtime.configuration.ConfigUtils;
import io.quarkus.runtime.configuration.QuarkusConfigFactory;
import io.smallrye.config.PropertiesConfigSource;
import io.smallrye.config.SmallRyeConfigProviderResolver;
import io.smallrye.config.SmallRyeConfig;
import io.smallrye.config.SmallRyeConfigBuilder;

/**
* This phase consumes {@link CurateOutcome} and processes
Expand Down Expand Up @@ -110,32 +115,25 @@ public AugmentOutcome run(CurateOutcome appState, CuratedApplicationCreator ctx)
}
//first lets look for some config, as it is not on the current class path
//and we need to load it to run the build process
Path config = configDir.resolve("application.properties");
if (Files.exists(config)) {
Path configPath = configDir.resolve("application.properties");
SmallRyeConfigBuilder configBuilder = ConfigUtils.configBuilder();
if (Files.exists(configPath)) {
try {
ConfigBuilder builder = SmallRyeConfigProviderResolver.instance().getBuilder()
.addDefaultSources()
.addDiscoveredConverters()
.addDiscoveredSources()
.withSources(new PropertiesConfigSource(config.toUri().toURL()));

if (configCustomizer != null) {
configCustomizer.accept(builder);
}
SmallRyeConfigProviderResolver.instance().registerConfig(builder.build(),
Thread.currentThread().getContextClassLoader());
} catch (Exception e) {
throw new RuntimeException(e);
configBuilder.withSources(new PropertiesConfigSource(configPath.toUri().toURL()));
} catch (IOException e) {
throw new IllegalArgumentException("Failed to convert config URL", e);
}
} else if (configCustomizer != null) {
ConfigBuilder builder = SmallRyeConfigProviderResolver.instance().getBuilder()
.addDefaultSources()
.addDiscoveredConverters()
.addDiscoveredSources();

configCustomizer.accept(builder);
SmallRyeConfigProviderResolver.instance().registerConfig(builder.build(),
Thread.currentThread().getContextClassLoader());
}
if (configCustomizer != null) {
configCustomizer.accept(configBuilder);
}
final SmallRyeConfig config = configBuilder.build();
QuarkusConfigFactory.setConfig(config);
final ConfigProviderResolver cpr = ConfigProviderResolver.instance();
final Config existing = cpr.getConfig();
if (existing != config) {
cpr.releaseConfig(existing);
// subsequent calls will get the new config
}

final AppModelResolver depResolver = appState.getArtifactResolver();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.regex.Pattern;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
import org.jboss.logging.Logger;

import io.quarkus.bootstrap.BootstrapDependencyProcessingException;
Expand All @@ -40,8 +41,11 @@
import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
import io.quarkus.deployment.util.FileUtil;
import io.quarkus.runtime.LaunchMode;
import io.quarkus.runtime.configuration.ConfigUtils;
import io.quarkus.runtime.configuration.QuarkusConfigFactory;
import io.smallrye.config.PropertiesConfigSource;
import io.smallrye.config.SmallRyeConfigProviderResolver;
import io.smallrye.config.SmallRyeConfig;
import io.smallrye.config.SmallRyeConfigBuilder;

/**
* This phase generates an example configuration file
Expand All @@ -65,12 +69,16 @@ public Path run(CurateOutcome appState, CuratedApplicationCreator creator) throw
//TODO: do we actually need to load this config? Does it affect resolution?
if (Files.exists(configFile)) {
try {
Config built = SmallRyeConfigProviderResolver.instance().getBuilder()
.addDefaultSources()
.addDiscoveredConverters()
.addDiscoveredSources()
.withSources(new PropertiesConfigSource(configFile.toUri().toURL())).build();
SmallRyeConfigProviderResolver.instance().registerConfig(built, Thread.currentThread().getContextClassLoader());
SmallRyeConfigBuilder builder = ConfigUtils.configBuilder()
.withSources(new PropertiesConfigSource(configFile.toUri().toURL()));
final SmallRyeConfig config = builder.build();
QuarkusConfigFactory.setConfig(config);
final ConfigProviderResolver cpr = ConfigProviderResolver.instance();
final Config existing = cpr.getConfig();
if (existing != config) {
cpr.releaseConfig(existing);
// subsequent calls will get the new config
}
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.quarkus.deployment;

import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
Expand All @@ -12,12 +14,12 @@ public class ApplicationConfig {
* If not set, defaults to the name of the project.
*/
@ConfigItem
public String name;
public Optional<String> name;

/**
* The version of the application.
* If not set, defaults to the version of the project
*/
@ConfigItem
public String version;
public Optional<String> version;
}
Loading

0 comments on commit e9acf37

Please sign in to comment.