Skip to content

Commit

Permalink
Update SmallRye Config to 3.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez committed Jul 15, 2024
1 parent 3645db6 commit ae7846c
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 311 deletions.
2 changes: 1 addition & 1 deletion bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<microprofile-lra.version>2.0</microprofile-lra.version>
<microprofile-openapi.version>3.1.1</microprofile-openapi.version>
<smallrye-common.version>2.5.0</smallrye-common.version>
<smallrye-config.version>3.8.3</smallrye-config.version>
<smallrye-config.version>3.8.4-SNAPSHOT</smallrye-config.version>
<smallrye-health.version>4.1.0</smallrye-health.version>
<smallrye-metrics.version>4.0.0</smallrye-metrics.version>
<smallrye-open-api.version>3.10.0</smallrye-open-api.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
import static io.quarkus.runtime.configuration.PropertiesUtil.isPropertyInRoots;
import static io.smallrye.config.ConfigMappings.ConfigClassWithPrefix.configClassWithPrefix;
import static io.smallrye.config.Expressions.withoutExpansion;
import static io.smallrye.config.PropertiesConfigSourceProvider.classPathSources;
import static io.smallrye.config.SmallRyeConfig.SMALLRYE_CONFIG_PROFILE;
import static io.smallrye.config.SmallRyeConfig.SMALLRYE_CONFIG_PROFILE_PARENT;
import static io.smallrye.config.SmallRyeConfigBuilder.META_INF_MICROPROFILE_CONFIG_PROPERTIES;
import static java.util.stream.Collectors.toSet;

import java.io.IOException;
Expand Down Expand Up @@ -1125,8 +1123,7 @@ private SmallRyeConfig getConfigForRuntimeRecording() {
builder.setAddDefaultSources(false)
// Customizers may duplicate sources, but not much we can do about it, we need to run them
.addDiscoveredCustomizers()
// Read microprofile-config.properties, because we disabled the default sources
.withSources(classPathSources(META_INF_MICROPROFILE_CONFIG_PROPERTIES, classLoader));
.addPropertiesSources();

// TODO - Should we reset quarkus.config.location to not record from these sources?
for (ConfigSource configSource : config.getConfigSources()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
import io.quarkus.dev.testing.TestWatchedFiles;
import io.quarkus.maven.dependency.ResolvedDependency;
import io.quarkus.paths.PathList;
import io.quarkus.runtime.configuration.ApplicationPropertiesConfigSourceLoader;
import io.smallrye.config.DotEnvConfigSourceProvider;
import io.smallrye.config.SmallRyeConfig;
import io.smallrye.config.SmallRyeConfigBuilder;

Expand Down Expand Up @@ -565,11 +563,7 @@ private void handleApplicationPropertiesChange() {
}

private static SmallRyeConfig getMinimalConfig() {
return new SmallRyeConfigBuilder()
.addDefaultSources()
.withSources(new ApplicationPropertiesConfigSourceLoader.InFileSystem())
.withSources(new ApplicationPropertiesConfigSourceLoader.InClassPath())
.withSources(new DotEnvConfigSourceProvider()).build();
return new SmallRyeConfigBuilder().addDefaultSources().build();
}

private Optional<List<String>> getTrimmedListFromConfig(SmallRyeConfig updatedConfig, String property) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.eclipse.microprofile.config.spi.ConfigSource;

import io.quarkus.runtime.LaunchMode;
import io.smallrye.config.DotEnvConfigSourceProvider;
import io.smallrye.config.SmallRyeConfig;
import io.smallrye.config.SmallRyeConfigBuilder;

Expand Down Expand Up @@ -81,10 +80,7 @@ public static SmallRyeConfigBuilder emptyConfigBuilder() {
.addDefaultInterceptors()
.addDiscoveredInterceptors()
.addDiscoveredSecretKeysHandlers()
.addDefaultSources()
.withSources(new ApplicationPropertiesConfigSourceLoader.InFileSystem())
.withSources(new ApplicationPropertiesConfigSourceLoader.InClassPath())
.withSources(new DotEnvConfigSourceProvider());
.addDefaultSources();
}

public static List<String> getProfiles() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.UUID;

import io.smallrye.config.DotEnvConfigSourceProvider;
import io.smallrye.config.SmallRyeConfigBuilder;
import io.smallrye.config.SmallRyeConfigBuilderCustomizer;

Expand All @@ -17,10 +16,7 @@ public void configBuilder(final SmallRyeConfigBuilder builder) {

builder.forClassLoader(Thread.currentThread().getContextClassLoader())
.addDefaultInterceptors()
.addDefaultSources()
.withSources(new ApplicationPropertiesConfigSourceLoader.InFileSystem())
.withSources(new ApplicationPropertiesConfigSourceLoader.InClassPath())
.withSources(new DotEnvConfigSourceProvider());
.addDefaultSources();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.quarkus.runtime.configuration;

import io.smallrye.config.DotEnvConfigSourceProvider;
import io.smallrye.config.SmallRyeConfigBuilder;
import io.smallrye.config.SmallRyeConfigBuilderCustomizer;

Expand All @@ -14,10 +13,7 @@ public void configBuilder(final SmallRyeConfigBuilder builder) {

builder.forClassLoader(Thread.currentThread().getContextClassLoader())
.addDefaultInterceptors()
.addDefaultSources()
.withSources(new ApplicationPropertiesConfigSourceLoader.InFileSystem())
.withSources(new ApplicationPropertiesConfigSourceLoader.InClassPath())
.withSources(new DotEnvConfigSourceProvider());
.addDefaultSources();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
public class SystemOnlySourcesConfigBuilder implements ConfigBuilder {
@Override
public SmallRyeConfigBuilder configBuilder(final SmallRyeConfigBuilder builder) {
// TODO - Adjust
builder.getSourceProviders().clear();
return builder;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package io.quarkus.gradle.tasks;

import static io.smallrye.config.SmallRyeConfigBuilder.META_INF_MICROPROFILE_CONFIG_PROPERTIES;
import static java.util.Collections.*;
import static java.util.Collections.emptyMap;
import static java.util.Collections.emptySet;
import static java.util.Collections.unmodifiableMap;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
Expand All @@ -16,25 +15,17 @@
import java.util.Set;
import java.util.function.Supplier;

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

import com.google.common.annotations.VisibleForTesting;

import io.quarkus.deployment.configuration.ClassLoadingConfig;
import io.quarkus.deployment.configuration.ConfigCompatibility;
import io.quarkus.deployment.pkg.NativeConfig;
import io.quarkus.deployment.pkg.PackageConfig;
import io.quarkus.runtime.configuration.ApplicationPropertiesConfigSourceLoader;
import io.quarkus.runtime.configuration.ConfigUtils;
import io.smallrye.config.AbstractLocationConfigSourceLoader;
import io.smallrye.config.EnvConfigSource;
import io.smallrye.config.Expressions;
import io.smallrye.config.PropertiesConfigSource;
import io.smallrye.config.PropertiesConfigSourceProvider;
import io.smallrye.config.SmallRyeConfig;
import io.smallrye.config.common.utils.ConfigSourceUtil;
import io.smallrye.config.source.yaml.YamlConfigSource;
import io.smallrye.config.source.yaml.YamlConfigSourceLoader;

/**
* Helper that bundles the various sources of config options for the Gradle plugin: system environment, system properties,
Expand All @@ -50,56 +41,41 @@ public final class EffectiveConfig {
private final Map<String, String> values;

private EffectiveConfig(Builder builder) {
List<ConfigSource> configSources = new ArrayList<>();
// TODO add io.quarkus.runtime.configuration.DefaultsConfigSource ?
// TODO leverage io.quarkus.runtime.configuration.ProfileManager ?

// Effective "ordinals" for the config sources:
// (see also https://quarkus.io/guides/config-reference#configuration-sources)
// 600 -> forcedProperties
// 500 -> taskProperties
// 400 -> System.getProperties()
// 300 -> System.getenv()
// 400 -> System.getProperties() (provided by default sources)
// 300 -> System.getenv() (provided by default sources)
// 290 -> quarkusBuildProperties
// 280 -> projectProperties
// 255 -> application,(yaml|yml) (in classpath/source)
// 250 -> application.properties (in classpath/source)
// 100 -> microprofile.properties (in classpath/source)
// 265 -> application.(yaml/yml) in config folder
// 260 -> application.properties in config folder (provided by default sources)
// 255 -> application.(yaml|yml) in classpath
// 250 -> application.properties in classpath (provided by default sources)
// 110 -> microprofile.(yaml|yml) in classpath
// 100 -> microprofile.properties in classpath (provided by default sources)
// 0 -> fallback config source for error workaround (see below)

configSources.add(new PropertiesConfigSource(builder.forcedProperties, "forcedProperties", 600));
configSources.add(new PropertiesConfigSource(asStringMap(builder.taskProperties), "taskProperties", 500));
configSources.add(new PropertiesConfigSource(ConfigSourceUtil.propertiesToMap(System.getProperties()),
"System.getProperties()", 400));
configSources.add(new EnvConfigSource(300) {
});
configSources.add(new PropertiesConfigSource(builder.buildProperties, "quarkusBuildProperties", 290));
configSources.add(new PropertiesConfigSource(asStringMap(builder.projectProperties), "projectProperties", 280));

ClassLoader classLoader = toUrlClassloader(builder.sourceDirectories);
ApplicationPropertiesConfigSourceLoader.InClassPath applicationProperties = new ApplicationPropertiesConfigSourceLoader.InClassPath();
configSources.addAll(applicationProperties.getConfigSources(classLoader));
ApplicationYamlConfigSourceLoader.InClassPath applicationYaml = new ApplicationYamlConfigSourceLoader.InClassPath();
configSources.addAll(applicationYaml.getConfigSources(classLoader));
configSources
.addAll(PropertiesConfigSourceProvider.classPathSources(META_INF_MICROPROFILE_CONFIG_PROPERTIES, classLoader));

// todo: this is due to ApplicationModel#getPlatformProperties not being included in the effective config
configSources.add(new PropertiesConfigSource(Map.of("platform.quarkus.native.builder-image", "<<ignored>>"),
"NativeConfig#builderImage", 0));

this.config = ConfigUtils.emptyConfigBuilder()
.setAddDiscoveredSecretKeysHandlers(false)
// We add our own sources for environment, system-properties and microprofile-config
// .properties,
// no need to include those twice.
.setAddDefaultSources(false)
.forClassLoader(toUrlClassloader(builder.sourceDirectories))
.withSources(new PropertiesConfigSource(builder.forcedProperties, "forcedProperties", 600))
.withSources(new PropertiesConfigSource(asStringMap(builder.taskProperties), "taskProperties", 500))
.addSystemSources()
.withSources(new PropertiesConfigSource(builder.buildProperties, "quarkusBuildProperties", 290))
.withSources(new PropertiesConfigSource(asStringMap(builder.projectProperties), "projectProperties", 280))
.withSources(new YamlConfigSourceLoader.InFileSystem())
.withSources(new YamlConfigSourceLoader.InClassPath())
.addPropertiesSources()
// todo: this is due to ApplicationModel#getPlatformProperties not being included in the effective config
.withSources(new PropertiesConfigSource(Map.of("platform.quarkus.native.builder-image", "<<ignored>>"),
"NativeConfig#builderImage", 0))
.withDefaultValues(builder.defaultProperties)
.withSources(configSources)
.withProfile(builder.profile)
.withMapping(PackageConfig.class)
.withMapping(NativeConfig.class)
.withInterceptors(ConfigCompatibility.FrontEnd.instance(), ConfigCompatibility.BackEnd.instance())
.setAddDiscoveredSecretKeysHandlers(false)
.build();
this.values = generateFullConfigMap(config);
}
Expand Down Expand Up @@ -203,35 +179,4 @@ private static ClassLoader toUrlClassloader(Set<File> sourceDirectories) {
}
return new URLClassLoader(urls.toArray(new URL[0]));
}

// Copied from quarkus-config-yaml. May be replaced by adding the quarkus-config-yaml dependency
public static class ApplicationYamlConfigSourceLoader extends AbstractLocationConfigSourceLoader {
@Override
protected String[] getFileExtensions() {
return new String[] {
"yaml",
"yml"
};
}

@Override
protected ConfigSource loadConfigSource(final URL url, final int ordinal) throws IOException {
return new YamlConfigSource(url, ordinal);
}

public static class InClassPath extends ApplicationYamlConfigSourceLoader implements ConfigSourceProvider {
@Override
public List<ConfigSource> getConfigSources(final ClassLoader classLoader) {
List<ConfigSource> configSources = new ArrayList<>();
configSources.addAll(loadConfigSources("application.yaml", 255, classLoader));
configSources.addAll(loadConfigSources("application.yml", 255, classLoader));
return configSources;
}

@Override
protected List<ConfigSource> tryFileSystem(final URI uri, final int ordinal) {
return new ArrayList<>();
}
}
}
}

This file was deleted.

Loading

0 comments on commit ae7846c

Please sign in to comment.