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

MP Config 2.0 Support #13620

Merged
merged 1 commit into from
Dec 10, 2020
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
13 changes: 13 additions & 0 deletions .mvn/extensions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<extensions>
<extension>
<groupId>org.srcdeps.mvn</groupId>
<artifactId>srcdeps-maven-local-repository</artifactId>
<version>4.0.0</version>
</extension>
<extension>
<groupId>org.srcdeps.mvn</groupId>
<artifactId>srcdeps-maven-enforcer</artifactId>
<version>4.0.0</version>
</extension>
</extensions>
radcortez marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 3 additions & 3 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<bouncycastle.version>1.67</bouncycastle.version>
<bouncycastle.fips.version>1.0.2</bouncycastle.fips.version>
<jandex.version>2.2.2.Final</jandex.version>
<resteasy.version>4.5.8.Final</resteasy.version>
<resteasy.version>4.6.0-SNAPSHOT</resteasy.version>
<opentracing.version>0.31.0</opentracing.version>
<opentracing-jaxrs.version>0.4.1</opentracing-jaxrs.version>
<opentracing-web-servlet-filter.version>0.2.3</opentracing-web-servlet-filter.version>
Expand All @@ -31,14 +31,14 @@
<threetenbp.version>1.4.3</threetenbp.version>
<micrometer.version>1.6.1</micrometer.version> <!-- when updating, verify if com.google.auth should not be updated too -->
<google-auth.version>0.22.0</google-auth.version>
<microprofile-config-api.version>1.4</microprofile-config-api.version>
<microprofile-config-api.version>2.0</microprofile-config-api.version>
<microprofile-metrics-api.version>2.3</microprofile-metrics-api.version>
<microprofile-context-propagation.version>1.0.1</microprofile-context-propagation.version>
<microprofile-opentracing-api.version>1.3.3</microprofile-opentracing-api.version>
<microprofile-reactive-streams-operators.version>1.0.1</microprofile-reactive-streams-operators.version>
<microprofile-rest-client.version>1.4.1</microprofile-rest-client.version>
<smallrye-common.version>1.5.0</smallrye-common.version>
<smallrye-config.version>1.9.3</smallrye-config.version>
<smallrye-config.version>2.0.0-RC3</smallrye-config.version>
<smallrye-health.version>2.2.5</smallrye-health.version>
<smallrye-metrics.version>2.4.4</smallrye-metrics.version>
<smallrye-open-api.version>2.0.16</smallrye-open-api.version>
Expand Down
2 changes: 1 addition & 1 deletion build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

<!-- MicroProfile TCK versions -->
<microprofile-health-api.version>2.2</microprofile-health-api.version>
<microprofile-config-api.version>1.4</microprofile-config-api.version>
<microprofile-config-api.version>2.0</microprofile-config-api.version>
<microprofile-metrics-api.version>2.3.2</microprofile-metrics-api.version>
<microprofile-fault-tolerance-api.version>2.1.1</microprofile-fault-tolerance-api.version>
<microprofile-reactive-messaging-api.version>1.0</microprofile-reactive-messaging-api.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ private Converter<?> getConverter(SmallRyeConfig config, Field field, ConverterT
throw toError(e);
}
} else {
converter = config.getConverter(leaf.getLeafType());
converter = config.requireConverter(leaf.getLeafType());
}
} else if (valueType instanceof LowerBoundCheckOf) {
// todo: add in bounds checker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Collections;
import java.util.Map;
import java.util.Set;

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

Expand All @@ -23,6 +24,10 @@ public Map<String, String> getProperties() {
return Collections.emptyMap();
}

public Set<String> getPropertyNames() {
return Collections.emptySet();
}

public String getValue(final String propertyName) {
if (!propertyName.startsWith("quarkus.")) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.Serializable;
import java.util.Collections;
import java.util.Map;
import java.util.Set;

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

Expand All @@ -19,6 +20,10 @@ public Map<String, String> getProperties() {
return Collections.emptyMap();
}

public Set<String> getPropertyNames() {
return Collections.emptySet();
}

public String getValue(final String propertyName) {
return getValue(new NameIterator(propertyName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,11 @@ public abstract class ApplicationPropertiesConfigSource extends PropertiesConfig
private static final long serialVersionUID = -4694780118527396798L;

static final String APPLICATION_PROPERTIES = "application.properties";
static final String MP_PROPERTIES = "META-INF/microprofile-config.properties";

ApplicationPropertiesConfigSource(InputStream is, int ordinal) {
super(readProperties(is), APPLICATION_PROPERTIES, ordinal);
}

ApplicationPropertiesConfigSource(InputStream is, String nm, int ordinal) {
super(readProperties(is), nm, ordinal);
}

private static Map<String, String> readProperties(final InputStream is) {
if (is == null) {
return Collections.emptyMap();
Expand Down Expand Up @@ -72,29 +67,6 @@ private static InputStream openStream() {
}
}

/**
* Config that makes sure that the MP config in the application takes precedence over any other on the class path
*/
public static final class MpConfigInJar extends ApplicationPropertiesConfigSource {
public MpConfigInJar() {
super(openStream(), MP_PROPERTIES, 240);
}

private static InputStream openStream() {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if (cl == null) {
cl = ApplicationPropertiesConfigSource.class.getClassLoader();
}
InputStream is;
if (cl == null) {
is = ClassLoader.getSystemResourceAsStream(MP_PROPERTIES);
} else {
is = cl.getResourceAsStream(MP_PROPERTIES);
}
return is;
}
}

public static final class InFileSystem extends ApplicationPropertiesConfigSource {
public InFileSystem() {
super(openStream(), 260);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private static Converter<?> getConverterFor(Type type) {
} else if (rawType == List.class) {
return Converters.newCollectionConverter(getConverterFor(typeOfParameter(type, 0)), ArrayList::new);
} else {
return config.getConverter(rawTypeOf(type));
return config.requireConverter(rawTypeOf(type));
}
}

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

import static io.smallrye.config.SmallRyeConfigBuilder.META_INF_MICROPROFILE_CONFIG_PROPERTIES;
import static io.smallrye.config.SmallRyeConfigBuilder.WEB_INF_MICROPROFILE_CONFIG_PROPERTIES;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -31,6 +34,8 @@
import org.eclipse.microprofile.config.spi.ConfigSourceProvider;
import org.jboss.logging.Logger;

import io.smallrye.config.ProfileConfigSourceInterceptor;
import io.smallrye.config.PropertiesConfigSourceProvider;
import io.smallrye.config.SmallRyeConfigBuilder;

/**
Expand Down Expand Up @@ -69,22 +74,18 @@ public static SmallRyeConfigBuilder configBuilder(final boolean runTime, final b
final SmallRyeConfigBuilder builder = new SmallRyeConfigBuilder();
final ApplicationPropertiesConfigSource.InFileSystem inFileSystem = new ApplicationPropertiesConfigSource.InFileSystem();
final ApplicationPropertiesConfigSource.InJar inJar = new ApplicationPropertiesConfigSource.InJar();
final ApplicationPropertiesConfigSource.MpConfigInJar mpConfig = new ApplicationPropertiesConfigSource.MpConfigInJar();
builder.withSources(inFileSystem, inJar, mpConfig, new DotEnvConfigSource());
builder.withProfile(ProfileManager.getActiveProfile());
builder.withSources(inFileSystem, inJar, new DotEnvConfigSource());
builder.withDefaultValue(ProfileConfigSourceInterceptor.SMALLRYE_PROFILE, ProfileManager.getActiveProfile());
builder.addDefaultInterceptors();
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (runTime) {
builder.addDefaultSources();
} else {
final List<ConfigSource> sources = new ArrayList<>();
sources.addAll(
new QuarkusPropertiesConfigSourceProvider("META-INF/microprofile-config.properties", true, classLoader)
.getConfigSources(classLoader));
// required by spec...
sources.addAll(
new QuarkusPropertiesConfigSourceProvider("WEB-INF/classes/META-INF/microprofile-config.properties", true,
classLoader).getConfigSources(classLoader));
sources.addAll(new PropertiesConfigSourceProvider(META_INF_MICROPROFILE_CONFIG_PROPERTIES, classLoader)
.getConfigSources(classLoader));
sources.addAll(new PropertiesConfigSourceProvider(WEB_INF_MICROPROFILE_CONFIG_PROPERTIES, classLoader)
.getConfigSources(classLoader));
sources.add(new EnvConfigSource());
sources.add(new SysPropConfigSource());
builder.withSources(sources);
Expand Down Expand Up @@ -140,6 +141,10 @@ public Map<String, String> getProperties() {
return Collections.emptyMap();
}

public Set<String> getPropertyNames() {
return Collections.emptySet();
}

public String getValue(final String propertyName) {
String val = cache.get(propertyName);
if (val != null) {
Expand Down Expand Up @@ -213,6 +218,11 @@ public Map<String, String> getProperties() {
return output;
}

@Override
public Set<String> getPropertyNames() {
return getProperties().keySet();
}

public String getValue(final String propertyName) {
return System.getProperty(propertyName);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,21 @@ public byte[] getClassBytes() {
return null;
}
}

@TargetClass(className = "io.smallrye.config.ConfigMappingClass")
static final class Target_ConfigMappingClass {
@Alias
static ClassValue<Target_ConfigMappingClass> cv = null;

// ClassValue is substituted by a regular ConcurrentHashMap - java.lang.ClassValue.get(JavaLangSubstitutions.java:514)
@Substitute
public static Target_ConfigMappingClass getConfigurationClass(Class<?> classType) {
Assert.checkNotNullParam("classType", classType);
try {
return cv.get(classType);
} catch (NullPointerException e) {
return null;
}
}
}
}
Loading