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 12, 2019
1 parent c5f6666 commit fbb3176
Show file tree
Hide file tree
Showing 87 changed files with 4,096 additions and 3,950 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.0</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.19</smallrye-open-api.version>
Expand Down Expand Up @@ -1067,6 +1067,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,7 +38,10 @@
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.QuarkusConfigFactory;
import io.smallrye.config.PropertiesConfigSource;
import io.smallrye.config.SmallRyeConfig;
import io.smallrye.config.SmallRyeConfigBuilder;
import io.smallrye.config.SmallRyeConfigProviderResolver;

/**
Expand Down Expand Up @@ -110,20 +115,26 @@ 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");
if (Files.exists(configPath)) {
try {
ConfigBuilder builder = SmallRyeConfigProviderResolver.instance().getBuilder()
SmallRyeConfigBuilder builder = new SmallRyeConfigBuilder()
.addDefaultSources()
.addDiscoveredConverters()
.addDiscoveredSources()
.withSources(new PropertiesConfigSource(config.toUri().toURL()));
.withSources(new PropertiesConfigSource(configPath.toUri().toURL()));

if (configCustomizer != null) {
configCustomizer.accept(builder);
}
SmallRyeConfigProviderResolver.instance().registerConfig(builder.build(),
Thread.currentThread().getContextClassLoader());
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;
}
249 changes: 113 additions & 136 deletions core/deployment/src/main/java/io/quarkus/deployment/ExtensionLoader.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.quarkus.deployment;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
Expand All @@ -19,7 +21,7 @@ static class JniConfig {
* Paths of library to load.
*/
@ConfigItem
List<String> libraryPaths;
Optional<List<String>> libraryPaths;

/**
* Enable JNI support.
Expand All @@ -30,8 +32,8 @@ static class JniConfig {

@BuildStep
void setupJni(BuildProducer<JniBuildItem> jniProducer) {
if ((jni.enable) || !jni.libraryPaths.isEmpty()) {
jniProducer.produce(new JniBuildItem(jni.libraryPaths));
if ((jni.enable) || jni.libraryPaths.isPresent()) {
jniProducer.produce(new JniBuildItem(jni.libraryPaths.orElse(Collections.emptyList())));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
import io.quarkus.builder.item.SimpleBuildItem;
import io.quarkus.deployment.configuration.ConfigurationError;

/**
* @deprecated Do not use this class anymore, instead try {@code ConfigProvider.getConfig.getValue()} instead.
*/
@Deprecated
public final class QuarkusConfig extends SimpleBuildItem {

public static final QuarkusConfig INSTANCE = new QuarkusConfig();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.quarkus.deployment.builditem;

import java.util.Optional;

import io.quarkus.builder.item.SimpleBuildItem;

public final class ApplicationInfoBuildItem extends SimpleBuildItem {
Expand All @@ -9,16 +11,16 @@ public final class ApplicationInfoBuildItem extends SimpleBuildItem {
private final String name;
private final String version;

public ApplicationInfoBuildItem(String name, String version) {
this.name = name;
this.version = version;
public ApplicationInfoBuildItem(Optional<String> name, Optional<String> version) {
this.name = name.orElse(UNSET_VALUE);
this.version = version.orElse(UNSET_VALUE);
}

public String getName() {
return name == null ? UNSET_VALUE : name;
return name;
}

public String getVersion() {
return version == null ? UNSET_VALUE : version;
return version;
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.quarkus.deployment.builditem;

import io.quarkus.builder.item.SimpleBuildItem;
import io.quarkus.deployment.configuration.BuildTimeConfigurationReader;

/**
* The build item which carries the build time configuration.
*/
public final class ConfigurationBuildItem extends SimpleBuildItem {
private final BuildTimeConfigurationReader.ReadResult readResult;

public ConfigurationBuildItem(final BuildTimeConfigurationReader.ReadResult readResult) {
this.readResult = readResult;
}

public BuildTimeConfigurationReader.ReadResult getReadResult() {
return readResult;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.quarkus.deployment.builditem;

import java.util.Map;

import io.quarkus.builder.item.SimpleBuildItem;

/**
* A build item that carries all the "fake" run time config objects for use by recorders.
*/
public final class RunTimeConfigurationProxyBuildItem extends SimpleBuildItem {
private final Map<Class<?>, Object> objects;

public RunTimeConfigurationProxyBuildItem(final Map<Class<?>, Object> objects) {
this.objects = objects;
}

public Object getProxyObjectFor(Class<?> clazz) {
return objects.get(clazz);
}
}

This file was deleted.

Loading

0 comments on commit fbb3176

Please sign in to comment.