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 16, 2024
1 parent d7b84f6 commit 78045ea
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 387 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.9.0</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 @@ -6,13 +6,11 @@
import static io.quarkus.deployment.util.ReflectUtil.toError;
import static io.quarkus.deployment.util.ReflectUtil.typeOfParameter;
import static io.quarkus.deployment.util.ReflectUtil.unwrapInvocationTargetException;
import static io.quarkus.runtime.configuration.PropertiesUtil.filterPropertiesInRoots;
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 @@ -79,9 +77,8 @@
import io.smallrye.config.ConfigMappings.ConfigClassWithPrefix;
import io.smallrye.config.ConfigValue;
import io.smallrye.config.Converters;
import io.smallrye.config.DefaultValuesConfigSource;
import io.smallrye.config.EnvConfigSource;
import io.smallrye.config.KeyMap;
import io.smallrye.config.KeyMapBackedConfigSource;
import io.smallrye.config.ProfileConfigSourceInterceptor;
import io.smallrye.config.PropertiesConfigSource;
import io.smallrye.config.SecretKeys;
Expand Down Expand Up @@ -386,25 +383,21 @@ public List<ConfigClassWithPrefix> getBuildTimeVisibleMappings() {
public SmallRyeConfig initConfiguration(LaunchMode launchMode, Properties buildSystemProps,
Map<String, String> platformProperties) {
// now prepare & load the build configuration
final SmallRyeConfigBuilder builder = ConfigUtils.configBuilder(false, launchMode);
SmallRyeConfigBuilder builder = ConfigUtils.configBuilder(false, launchMode);
if (classLoader != null) {
builder.forClassLoader(classLoader);
}

final DefaultValuesConfigurationSource ds1 = new DefaultValuesConfigurationSource(getBuildTimePatternMap());
final DefaultValuesConfigurationSource ds2 = new DefaultValuesConfigurationSource(getBuildTimeRunTimePatternMap());
final PropertiesConfigSource pcs = new PropertiesConfigSource(buildSystemProps, "Build system");
DefaultValuesConfigurationSource ds1 = new DefaultValuesConfigurationSource(getBuildTimePatternMap());
DefaultValuesConfigurationSource ds2 = new DefaultValuesConfigurationSource(getBuildTimeRunTimePatternMap());
PropertiesConfigSource pcs = new PropertiesConfigSource(buildSystemProps, "Build system");
if (platformProperties.isEmpty()) {
builder.withSources(ds1, ds2, pcs);
} else {
final KeyMap<String> props = new KeyMap<>(platformProperties.size());
for (Map.Entry<String, String> prop : platformProperties.entrySet()) {
props.findOrAdd(new io.smallrye.config.NameIterator(prop.getKey())).putRootValue(prop.getValue());
}
final KeyMapBackedConfigSource platformConfigSource = new KeyMapBackedConfigSource("Quarkus platform",
// Our default value configuration source is using an ordinal of Integer.MIN_VALUE
// (see io.quarkus.deployment.configuration.DefaultValuesConfigurationSource)
Integer.MIN_VALUE + 1000, props);
// Our default value configuration source is using an ordinal of Integer.MIN_VALUE
// (see io.quarkus.deployment.configuration.DefaultValuesConfigurationSource)
DefaultValuesConfigSource platformConfigSource = new DefaultValuesConfigSource(platformProperties,
"Quarkus platform", Integer.MIN_VALUE + 1000);
builder.withSources(ds1, ds2, platformConfigSource, pcs);
}

Expand Down Expand Up @@ -536,7 +529,7 @@ ReadResult run() {
}

NameIterator ni = new NameIterator(propertyName);
if (ni.hasNext() && PropertiesUtil.isPropertyInRoot(registeredRoots, ni)) {
if (ni.hasNext() && PropertiesUtil.isPropertyInRoots(propertyName, registeredRoots)) {
// build time patterns
Container matched = buildTimePatternMap.match(ni);
boolean knownProperty = matched != null;
Expand Down Expand Up @@ -1051,7 +1044,7 @@ private Set<String> getAllProperties(final Set<String> registeredRoots) {
unprofiledProperty = property.substring(profileDot + 1);
}
}
if (filterPropertiesInRoots(List.of(unprofiledProperty), registeredRoots).iterator().hasNext()) {
if (PropertiesUtil.isPropertyInRoots(unprofiledProperty, registeredRoots)) {
sourcesProperties.add(property);
}
}
Expand Down Expand Up @@ -1130,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 Expand Up @@ -1166,7 +1158,7 @@ public String getValue(final String propertyName) {
return config.getConfigValue(propertyName).getValue();
}
return null;
};
}
});
return builder.build();
}
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -76,34 +76,47 @@ public static Iterable<String> filterPropertiesInRoots(final Iterable<String> pr
continue;
}

for (String root : roots) {
// if property is less than the root no way to match
if (property.length() < root.length()) {
continue;
}

// if it is the same, then it can still map with parent name
if (property.equals(root)) {
matchedProperties.add(property);
break;
} else if (property.length() == root.length()) {
continue;
}

// foo.bar
// foo.bar."baz"
// foo.bar[0]
char c = property.charAt(root.length());
if ((c == '.') || c == '[') {
if (property.startsWith(root)) {
matchedProperties.add(property);
}
}
if (isPropertyInRoots(property, roots)) {
matchedProperties.add(property);
}
}
return matchedProperties;
}

public static boolean isPropertyInRoots(final String property, final Set<String> roots) {
for (String root : roots) {
if (isPropertyInRoot(property, root)) {
return true;
}
}
return false;
}

public static boolean isPropertyInRoot(final String property, final String root) {
// if property is less than the root no way to match
if (property.length() < root.length()) {
return false;
}

// if it is the same, then it can still map with parent name
if (property.equals(root)) {
return true;
}

if (property.length() == root.length()) {
return false;
}

// foo.bar
// foo.bar."baz"
// foo.bar[0]
char c = property.charAt(root.length());
if ((c == '.') || c == '[') {
return property.startsWith(root);
}
return false;
}

public static boolean isPropertyQuarkusCompoundName(NameIterator propertyName) {
return propertyName.getName().startsWith("\"quarkus.");
}
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,8 +5,7 @@
public class SystemOnlySourcesConfigBuilder implements ConfigBuilder {
@Override
public SmallRyeConfigBuilder configBuilder(final SmallRyeConfigBuilder builder) {
builder.getSourceProviders().clear();
return builder;
return builder.setAddDefaultSources(false).addSystemSources();
}

@Override
Expand Down
Loading

0 comments on commit 78045ea

Please sign in to comment.