Skip to content

Commit

Permalink
Merge pull request #35326 from gsmet/3.3.0-backports-1
Browse files Browse the repository at this point in the history
3.3.0 backports 1
  • Loading branch information
gsmet authored Aug 15, 2023
2 parents 1a62276 + 8324fc5 commit b5b6233
Show file tree
Hide file tree
Showing 62 changed files with 1,737 additions and 197 deletions.
22 changes: 14 additions & 8 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
<bouncycastle.tls.fips.version>1.0.16</bouncycastle.tls.fips.version>
<expressly.version>5.0.0</expressly.version>
<findbugs.version>3.0.2</findbugs.version>
<jakarta.authentication-api>3.0.0</jakarta.authentication-api>
<jakarta.authorization-api.version>2.1.0</jakarta.authorization-api.version>
<jakarta.el-api.version>5.0.1</jakarta.el-api.version>
<jakarta.json-api.version>2.1.2</jakarta.json-api.version>
<jakarta.ws.rs-api.version>3.1.0</jakarta.ws.rs-api.version>
<jandex.version>3.1.2</jandex.version>
<javax.annotation-api.version>1.3.2</javax.annotation-api.version>
<javax.inject.version>1</javax.inject.version>
Expand Down Expand Up @@ -57,7 +52,7 @@
<microprofile-openapi.version>3.1.1</microprofile-openapi.version>
<smallrye-common.version>2.1.0</smallrye-common.version>
<smallrye-config.version>3.3.3</smallrye-config.version>
<smallrye-health.version>4.0.2</smallrye-health.version>
<smallrye-health.version>4.0.4</smallrye-health.version>
<smallrye-metrics.version>4.0.0</smallrye-metrics.version>
<smallrye-open-api.version>3.5.0</smallrye-open-api.version>
<smallrye-graphql.version>2.3.0</smallrye-graphql.version>
Expand All @@ -72,16 +67,22 @@
<smallrye-stork.version>2.3.1</smallrye-stork.version>
<jakarta.activation.version>2.1.2</jakarta.activation.version>
<jakarta.annotation-api.version>2.1.1</jakarta.annotation-api.version>
<jakarta.authentication-api>3.0.0</jakarta.authentication-api>
<jakarta.authorization-api.version>2.1.0</jakarta.authorization-api.version>
<jakarta.el-api.version>5.0.1</jakarta.el-api.version>
<jakarta.enterprise.cdi-api.version>4.0.1</jakarta.enterprise.cdi-api.version>
<jakarta.inject-api.version>2.0.1</jakarta.inject-api.version>
<jakarta.interceptor-api.version>2.1.0</jakarta.interceptor-api.version>
<jakarta.json-api.version>2.1.2</jakarta.json-api.version>
<jakarta.json.bind-api.version>3.0.0</jakarta.json.bind-api.version>
<jakarta.mail.version>2.0.1</jakarta.mail.version>
<jakarta.persistence-api.version>3.1.0</jakarta.persistence-api.version>
<jakarta.resource-api.version>2.1.0</jakarta.resource-api.version>
<jakarta.servlet-api.version>6.0.0</jakarta.servlet-api.version>
<jakarta.transaction-api.version>2.0.1</jakarta.transaction-api.version>
<jakarta.validation-api.version>3.0.2</jakarta.validation-api.version>
<jakarta.websocket-api.version>2.1.1</jakarta.websocket-api.version>
<jakarta.ws.rs-api.version>3.1.0</jakarta.ws.rs-api.version>
<jakarta.xml.bind-api.version>4.0.0</jakarta.xml.bind-api.version>
<jaxb-runtime.version>4.0.3</jaxb-runtime.version>
<asm.version>9.5</asm.version>
Expand Down Expand Up @@ -125,7 +126,7 @@
<httpasync.version>4.1.5</httpasync.version>
<cronutils.version>9.2.1</cronutils.version>
<quartz.version>2.3.2</quartz.version>
<h2.version>2.1.214</h2.version> <!-- When updating, needs to be matched in io.quarkus.hibernate.orm.runtime.config.DialectVersions -->
<h2.version>2.2.220</h2.version> <!-- When updating, needs to be matched in io.quarkus.hibernate.orm.runtime.config.DialectVersions -->
<postgresql-jdbc.version>42.6.0</postgresql-jdbc.version>
<mariadb-jdbc.version>3.1.4</mariadb-jdbc.version>
<mysql-jdbc.version>8.0.30</mysql-jdbc.version>
Expand All @@ -138,7 +139,7 @@
<rest-assured.version>5.3.0</rest-assured.version>
<junit.jupiter.version>5.9.3</junit.jupiter.version>
<junit-pioneer.version>1.5.0</junit-pioneer.version>
<infinispan.version>14.0.11.Final</infinispan.version>
<infinispan.version>14.0.13.Final</infinispan.version>
<infinispan.protostream.version>4.6.2.Final</infinispan.protostream.version>
<caffeine.version>3.1.5</caffeine.version>
<netty.version>4.1.94.Final</netty.version>
Expand Down Expand Up @@ -4574,6 +4575,11 @@
<artifactId>jakarta.persistence-api</artifactId>
<version>${jakarta.persistence-api.version}</version>
</dependency>
<dependency>
<groupId>jakarta.resource</groupId>
<artifactId>jakarta.resource-api</artifactId>
<version>${jakarta.resource-api.version}</version>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.quarkus.bootstrap.prebuild.CodeGenException;
import io.quarkus.deployment.codegen.CodeGenData;
import io.quarkus.deployment.configuration.BuildTimeConfigurationReader;
import io.quarkus.deployment.configuration.tracker.ConfigTrackingValueTransformer;
import io.quarkus.deployment.dev.DevModeContext;
import io.quarkus.deployment.dev.DevModeContext.ModuleInfo;
import io.quarkus.maven.dependency.ResolvedDependency;
Expand Down Expand Up @@ -185,6 +186,43 @@ public static boolean trigger(ClassLoader deploymentClassLoader,
});
}

/**
* Initializes an application build time configuration and returns current values of properties
* passed in as {@code originalProperties}.
*
* @param appModel application model
* @param launchMode launch mode
* @param buildSystemProps build system (or project) properties
* @param deploymentClassLoader build classloader
* @param originalProperties properties to read from the initialized configuration
* @return current values of the passed in original properties
*/
public static Properties readCurrentConfigValues(ApplicationModel appModel, String launchMode,
Properties buildSystemProps,
QuarkusClassLoader deploymentClassLoader, Properties originalProperties) {
Config config = null;
try {
config = getConfig(appModel, LaunchMode.valueOf(launchMode), buildSystemProps, deploymentClassLoader);
} catch (CodeGenException e) {
throw new RuntimeException("Failed to load application configuration", e);
}
var valueTransformer = ConfigTrackingValueTransformer.newInstance(config);
final Properties currentValues = new Properties(originalProperties.size());
for (var originalProp : originalProperties.entrySet()) {
var name = originalProp.getKey().toString();
var currentValue = config.getConfigValue(name);
final String current = valueTransformer.transform(name, currentValue);
if (!originalProp.getValue().equals(current)) {
log.info("Option " + name + " has changed since the last build from "
+ originalProp.getValue() + " to " + current);
}
if (current != null) {
currentValues.put(name, current);
}
}
return currentValues;
}

public static Config getConfig(ApplicationModel appModel, LaunchMode launchMode, Properties buildSystemProps,
QuarkusClassLoader deploymentClassLoader) throws CodeGenException {
final Map<String, List<String>> unavailableConfigServices = getUnavailableConfigServices(appModel.getAppArtifact(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import io.quarkus.deployment.configuration.matching.FieldContainer;
import io.quarkus.deployment.configuration.matching.MapContainer;
import io.quarkus.deployment.configuration.matching.PatternMapBuilder;
import io.quarkus.deployment.configuration.tracker.ConfigTrackingInterceptor;
import io.quarkus.deployment.configuration.type.ArrayOf;
import io.quarkus.deployment.configuration.type.CollectionOf;
import io.quarkus.deployment.configuration.type.ConverterType;
Expand Down Expand Up @@ -122,6 +123,8 @@ private static List<Class<?>> collectConfigRoots(ClassLoader classLoader) throws
final Set<String> deprecatedProperties;
final Set<String> deprecatedRuntimeProperties;

final ConfigTrackingInterceptor buildConfigTracker;

/**
* Initializes a new instance with located configuration root classes on the classpath
* of a given classloader.
Expand Down Expand Up @@ -233,6 +236,8 @@ private BuildTimeConfigurationReader(ClassLoader classLoader, final List<Class<?

deprecatedProperties = getDeprecatedProperties(allRoots);
deprecatedRuntimeProperties = getDeprecatedProperties(runTimeRoots);

buildConfigTracker = new ConfigTrackingInterceptor();
}

private static void processClass(ClassDefinition.Builder builder, Class<?> clazz,
Expand Down Expand Up @@ -399,11 +404,15 @@ public SmallRyeConfig initConfiguration(LaunchMode launchMode, Properties buildS
for (ConfigClassWithPrefix mapping : getBuildTimeVisibleMappings()) {
builder.withMapping(mapping.getKlass(), mapping.getPrefix());
}
return builder.build();

builder.withInterceptors(buildConfigTracker);
var config = builder.build();
buildConfigTracker.configure(config);
return config;
}

public ReadResult readConfiguration(final SmallRyeConfig config) {
return SecretKeys.doUnlocked(() -> new ReadOperation(config).run());
return SecretKeys.doUnlocked(() -> new ReadOperation(config, buildConfigTracker).run());
}

private Set<String> getDeprecatedProperties(Iterable<RootDefinition> rootDefinitions) {
Expand Down Expand Up @@ -459,6 +468,7 @@ private void collectDeprecatedConfigItems(ClassMember classMember, Set<String> d

final class ReadOperation {
final SmallRyeConfig config;
final ConfigTrackingInterceptor buildConfigTracker;
final Set<String> processedNames = new HashSet<>();

final Map<Class<?>, Object> objectsByClass = new HashMap<>();
Expand All @@ -468,8 +478,9 @@ final class ReadOperation {

final Map<ConverterType, Converter<?>> convByType = new HashMap<>();

ReadOperation(final SmallRyeConfig config) {
ReadOperation(final SmallRyeConfig config, ConfigTrackingInterceptor buildConfigTracker) {
this.config = config;
this.buildConfigTracker = buildConfigTracker;
}

ReadResult run() {
Expand Down Expand Up @@ -662,6 +673,7 @@ ReadResult run() {
.setRunTimeMappings(runTimeMappings)
.setUnknownBuildProperties(unknownBuildProperties)
.setDeprecatedRuntimeProperties(deprecatedRuntimeProperties)
.setBuildConfigTracker(buildConfigTracker)
.createReadResult();
}

Expand Down Expand Up @@ -1129,6 +1141,7 @@ public static final class ReadResult {

final Set<String> unknownBuildProperties;
final Set<String> deprecatedRuntimeProperties;
final ConfigTrackingInterceptor.ReadOptionsProvider readOptionsProvider;

public ReadResult(final Builder builder) {
this.objectsByClass = builder.getObjectsByClass();
Expand All @@ -1151,6 +1164,8 @@ public ReadResult(final Builder builder) {

this.unknownBuildProperties = builder.getUnknownBuildProperties();
this.deprecatedRuntimeProperties = builder.deprecatedRuntimeProperties;
this.readOptionsProvider = builder.buildConfigTracker == null ? null
: builder.buildConfigTracker.getReadOptionsProvider();
}

private static Map<Class<?>, RootDefinition> rootsToMap(Builder builder) {
Expand Down Expand Up @@ -1243,6 +1258,10 @@ public Object requireObjectForClass(Class<?> clazz) {
return obj;
}

public ConfigTrackingInterceptor.ReadOptionsProvider getReadOptionsProvider() {
return readOptionsProvider;
}

static class Builder {
private Map<Class<?>, Object> objectsByClass;
private Map<String, String> allBuildTimeValues;
Expand All @@ -1257,6 +1276,7 @@ static class Builder {
private List<ConfigClassWithPrefix> runTimeMappings;
private Set<String> unknownBuildProperties;
private Set<String> deprecatedRuntimeProperties;
private ConfigTrackingInterceptor buildConfigTracker;

Map<Class<?>, Object> getObjectsByClass() {
return objectsByClass;
Expand Down Expand Up @@ -1371,6 +1391,11 @@ Builder setDeprecatedRuntimeProperties(Set<String> deprecatedRuntimeProperties)
return this;
}

Builder setBuildConfigTracker(ConfigTrackingInterceptor buildConfigTracker) {
this.buildConfigTracker = buildConfigTracker;
return this;
}

ReadResult createReadResult() {
return new ReadResult(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package io.quarkus.deployment.configuration.tracker;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.regex.Pattern;

import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.quarkus.util.GlobUtil;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;

/**
* Configuration options for application build time configuration usage tracking
* and dumping.
*/
@ConfigMapping(prefix = "quarkus.config-tracking")
@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
public interface ConfigTrackingConfig {

/**
* Whether configuration dumping is enabled
*/
@WithDefault("false")
boolean enabled();

/**
* Directory in which the configuration dump should be stored.
* If not configured the {@code .quarkus} directory under the project directory will be used.
*/
Optional<Path> directory();

/**
* File in which the configuration dump should be stored. If not configured, the {@link #filePrefix} and
* {@link #fileSuffix} will be used to generate the final file name.
* If the configured file path is absolute, the {@link #directory} option will be ignored. Otherwise,
* the path will be considered relative to the {@link #directory}.
*/
Optional<Path> file();

/**
* File name prefix. This option will be ignored in case {@link #file} is configured.
*/
@WithDefault("quarkus")
String filePrefix();

/**
* File name suffix. This option will be ignored in case {@link #file} is configured.
*/
@WithDefault("-config-dump")
String fileSuffix();

/**
* A list of config properties that should be excluded from the report.
* GLOB patterns could be used instead of property names.
*/
Optional<List<String>> exclude();

/**
* Translates the value of {@link #exclude} to a list of {@link java.util.regex.Pattern}.
*
* @return list of patterns created from {@link #exclude}
*/
default List<Pattern> getExcludePatterns() {
return toPatterns(exclude());
}

/**
* A list of config properties whose values should be hashed in the report.
* The values will be hashed using SHA-512 algorithm.
* GLOB patterns could be used instead of property names.
*/
Optional<List<String>> hashOptions();

/**
* Translates the value of {@link #hashOptions()} to a list of {@link java.util.regex.Pattern}.
*
* @return list of patterns created from {@link #hashOptions()}
*/
default List<Pattern> getHashOptionsPatterns() {
return toPatterns(hashOptions());
}

static List<Pattern> toPatterns(Optional<List<String>> globs) {
if (globs.isEmpty()) {
return List.of();
}
var list = globs.get();
final List<Pattern> patterns = new ArrayList<>(list.size());
for (var s : list) {
patterns.add(Pattern.compile(GlobUtil.toRegexPattern(s)));
}
return patterns;
}

/**
* Whether to use a {@code ~} as an alias for user home directory in path values
*/
@WithDefault("true")
boolean useUserHomeAliasInPaths();
}
Loading

0 comments on commit b5b6233

Please sign in to comment.