Skip to content

Commit

Permalink
Merge pull request #20827 from aloubyansky/2.4-backport
Browse files Browse the repository at this point in the history
The first batch of the 2.4 backports
  • Loading branch information
aloubyansky authored Oct 18, 2021
2 parents 1f33d46 + e856c85 commit ab47615
Show file tree
Hide file tree
Showing 127 changed files with 2,928 additions and 709 deletions.
15 changes: 10 additions & 5 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<opentelemetry.version>1.6.0</opentelemetry.version>
<opentelemetry-alpha.version>1.6.0-alpha</opentelemetry-alpha.version>
<jaeger.version>1.6.0</jaeger.version>
<quarkus-http.version>4.1.2</quarkus-http.version>
<quarkus-http.version>4.1.3</quarkus-http.version>
<micrometer.version>1.7.4</micrometer.version>
<google-auth.version>0.22.0</google-auth.version>
<microprofile-config-api.version>2.0</microprofile-config-api.version>
Expand All @@ -50,7 +50,7 @@
<smallrye-opentracing.version>2.0.1</smallrye-opentracing.version>
<smallrye-fault-tolerance.version>5.2.1</smallrye-fault-tolerance.version>
<smallrye-jwt.version>3.3.0</smallrye-jwt.version>
<smallrye-context-propagation.version>1.2.0</smallrye-context-propagation.version>
<smallrye-context-propagation.version>1.2.2</smallrye-context-propagation.version>
<smallrye-reactive-streams-operators.version>1.0.13</smallrye-reactive-streams-operators.version>
<smallrye-reactive-types-converter.version>2.6.0</smallrye-reactive-types-converter.version>
<smallrye-mutiny-vertx-binding.version>2.14.1</smallrye-mutiny-vertx-binding.version>
Expand Down Expand Up @@ -89,8 +89,8 @@
<commons-lang3.version>3.12.0</commons-lang3.version>
<commons-codec.version>1.15</commons-codec.version>
<classmate.version>1.5.1</classmate.version>
<hibernate-orm.version>5.6.0.CR1</hibernate-orm.version>
<hibernate-reactive.version>1.0.0.CR9</hibernate-reactive.version>
<hibernate-orm.version>5.6.0.Final</hibernate-orm.version>
<hibernate-reactive.version>1.0.0.CR10</hibernate-reactive.version>
<hibernate-validator.version>6.2.0.Final</hibernate-validator.version>
<hibernate-search.version>6.0.6.Final</hibernate-search.version>
<narayana.version>5.12.0.Final</narayana.version>
Expand Down Expand Up @@ -133,7 +133,7 @@
<netty.version>4.1.68.Final</netty.version>
<reactive-streams.version>1.0.3</reactive-streams.version>
<jboss-logging.version>3.4.2.Final</jboss-logging.version>
<mutiny.version>1.1.1</mutiny.version>
<mutiny.version>1.1.2</mutiny.version>
<kafka2.version>2.8.1</kafka2.version>
<zookeeper.version>3.5.7</zookeeper.version>
<!-- Scala is used by Kafka so we need to choose a compatible version -->
Expand Down Expand Up @@ -5457,6 +5457,11 @@
<goals>
<goal>flatten-platform-bom</goal>
</goals>
<configuration>
<excludeArtifactKeys>
<key>junit:junit</key> <!-- comes from the jackson-bom -->
</excludeArtifactKeys>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
2 changes: 2 additions & 0 deletions build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<!-- Align various dependencies that are not really part of the bom-->
<findbugs.version>3.0.2</findbugs.version>
<jsoup.version>1.14.2</jsoup.version>
<junit4.version>4.13.2</junit4.version>
<wagon-provider-api.version>3.4.3</wagon-provider-api.version>

<!-- The image to use for tests that run Keycloak -->
Expand Down Expand Up @@ -117,6 +118,7 @@
<webjar.font-awesome.version>5.15.2</webjar.font-awesome.version>
<webjar.jquery.version>3.5.1</webjar.jquery.version>
<webjar.codemirror.version>5.62.0</webjar.codemirror.version>
<webjar.mermaid.version>8.9.1</webjar.mermaid.version>

<!-- revapi API check -->
<revapi-maven-plugin.version>0.12.1</revapi-maven-plugin.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.function.Function;
import java.util.function.Supplier;

import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.logging.Logger;

import io.quarkus.deployment.console.StartupLogCompressor;
Expand Down Expand Up @@ -125,20 +126,23 @@ public Result get() {
private static class DockerBinaryStrategy implements Strategy {

private final boolean silent;
private final String binary;

private DockerBinaryStrategy(boolean silent) {
this.silent = silent;
this.binary = ConfigProvider.getConfig().getOptionalValue("quarkus.docker.executable-name", String.class)
.orElse("docker");
}

@Override
public Result get() {
try {
if (!ExecUtil.execSilent("docker", "-v")) {
LOGGER.warn("'docker -v' returned an error code. Make sure your Docker binary is correct");
if (!ExecUtil.execSilent(binary, "-v")) {
LOGGER.warnf("'%s -v' returned an error code. Make sure your Docker binary is correct", binary);
return Result.UNKNOWN;
}
} catch (Exception e) {
LOGGER.warnf("No Docker binary found or general error: %s", e);
LOGGER.warnf("No %s binary found or general error: %s", binary, e);
return Result.UNKNOWN;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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.smallrye.config.SmallRyeConfig.SMALLRYE_CONFIG_PROFILE;
import static java.util.stream.Collectors.toSet;

import java.lang.reflect.Constructor;
Expand Down Expand Up @@ -56,6 +57,7 @@
import io.quarkus.runtime.configuration.ConfigurationException;
import io.quarkus.runtime.configuration.HyphenateEnumConverter;
import io.quarkus.runtime.configuration.NameIterator;
import io.quarkus.runtime.configuration.ProfileManager;
import io.quarkus.runtime.configuration.PropertiesUtil;
import io.smallrye.config.Converters;
import io.smallrye.config.EnvConfigSource;
Expand Down Expand Up @@ -374,7 +376,7 @@ ReadResult run() {
if (matched != null) {
// it's a specified run-time default (record for later)
specifiedRunTimeDefaultValues.put(propertyName, Expressions.withoutExpansion(
() -> config.getOptionalValue(propertyName, String.class).orElse("")));
() -> runtimeDefaultsConfig.getOptionalValue(propertyName, String.class).orElse("")));

continue;
}
Expand All @@ -392,6 +394,10 @@ ReadResult run() {
() -> runtimeDefaultsConfig.getOptionalValue(propertyName, String.class).orElse("")));
}
}

filterActiveProfileProperties(buildTimeRunTimeVisibleValues);
filterActiveProfileProperties(specifiedRunTimeDefaultValues);

return new ReadResult(objectsByRootClass, specifiedRunTimeDefaultValues, buildTimeRunTimeVisibleValues,
allBuildTimeValues,
buildTimePatternMap, buildTimeRunTimePatternMap, bootstrapPatternMap, runTimePatternMap, allRoots,
Expand Down Expand Up @@ -728,12 +734,12 @@ private Converter<?> getConverter(SmallRyeConfig config, Field field, ConverterT
}

/**
* We collect all properties from ConfigSources, because Config#getPropertyNames exclude the active profiled
* properties, meaning that the property is written in the default config source unprofiled. This may cause
* issues if we run with a different profile and fallback to defaults.
* We collect all properties from eligible ConfigSources, because Config#getPropertyNames exclude the active
* profiled properties, meaning that the property is written in the default config source without the profile
* prefix. This may cause issues if we run with a different profile and fallback to defaults.
*
* We also filter the properties coming from the System with the registered roots, because we don't want to
* record properties set by the compiling JVM (or other properties set that are only related to the build).
* record properties set by the compiling JVM (or other properties that are only related to the build).
*/
private Set<String> getAllProperties(final Set<String> registeredRoots) {
Set<String> properties = new HashSet<>();
Expand All @@ -757,17 +763,21 @@ private Set<String> getAllProperties(final Set<String> registeredRoots) {

/**
* Use this Config instance to record the specified runtime default values. We cannot use the main Config
* instance because it may record values coming from the EnvSource in build time. We do exclude the properties
* coming from the EnvSource, but a call to getValue may still provide values coming from the EnvSource, so we
* need to exclude it from sources when recoding values.
* instance because it may record values coming from the EnvSource in build time. Environment variable values
* may be completely different between build and runtime, so it doesn't make sense to record these.
*
* We do exclude the properties coming from the EnvSource, but a call to getValue may still provide a result
* coming from the EnvSource, so we need to exclude it from the sources when recording values for runtime.
*
* We also do not want to completely exclude the EnvSource, because it may provide values for the build. This
* is only specific when recording the defaults.
*
* @return a new SmallRye instance without the EnvSources.
*/
private SmallRyeConfig getConfigForRuntimeDefaults() {
SmallRyeConfigBuilder builder = ConfigUtils.emptyConfigBuilder();
SmallRyeConfigBuilder builder = new SmallRyeConfigBuilder();
builder.withDefaultValue(SMALLRYE_CONFIG_PROFILE, ProfileManager.getActiveProfile());
builder.addDefaultInterceptors();
for (ConfigSource configSource : config.getConfigSources()) {
if (configSource instanceof EnvConfigSource) {
continue;
Expand All @@ -776,6 +786,17 @@ private SmallRyeConfig getConfigForRuntimeDefaults() {
}
return builder.build();
}

private void filterActiveProfileProperties(final Map<String, String> properties) {
Set<String> propertiesToRemove = new HashSet<>();
for (String property : properties.keySet()) {
String profiledProperty = "%" + ProfileManager.getActiveProfile() + "." + property;
if (properties.containsKey(profiledProperty)) {
propertiesToRemove.add(property);
}
}
properties.keySet().removeAll(propertiesToRemove);
}
}

public static final class ReadResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ public void addIndexDependencyPaths(List<IndexDependencyBuildItem> indexDependen
GACTV.TYPE_JAR);
final ResolvedDependency artifact = userMap.get(key);
if (artifact == null) {
userMap.keySet().forEach(k -> System.out.println(" - " + k.getClass().getSimpleName() + " " + k));
throw new RuntimeException(
"Could not resolve artifact " + key + " among the runtime dependencies of the application");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ TransformedClassesBuildItem handleClassTransformation(List<BytecodeTransformerBu
if (!i.isCacheable()) {
nonCacheable.add(i.getClassToTransform());
}
classReaderOptions.put(i.getClassToTransform(), i.getClassReaderOptions());
classReaderOptions.merge(i.getClassToTransform(), i.getClassReaderOptions(),
// class reader options are bit flags (see org.objectweb.asm.ClassReader)
(oldValue, newValue) -> oldValue | newValue);
}
QuarkusClassLoader cl = (QuarkusClassLoader) Thread.currentThread().getContextClassLoader();
Map<String, Path> transformedToArchive = new ConcurrentHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.util.concurrent.locks.Lock;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;

import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.Any;
Expand All @@ -19,8 +21,10 @@
import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
import org.graalvm.nativeimage.ImageInfo;
import org.jboss.logging.Logger;
import org.jboss.logmanager.handlers.AsyncHandler;
import org.wildfly.common.lock.Locks;

import io.quarkus.bootstrap.logging.InitialConfigurator;
import io.quarkus.bootstrap.runner.RunnerClassLoader;
import io.quarkus.runtime.configuration.ConfigurationException;
import io.quarkus.runtime.configuration.ProfileManager;
Expand Down Expand Up @@ -205,6 +209,7 @@ public static void run(Application application, Class<? extends QuarkusApplicati
} else {
applicationLogger.errorv(rootCause, "Failed to start application (with profile {0})",
ProfileManager.getActiveProfile());
ensureConsoleLogsDrained();
}
}
stateLock.lock();
Expand Down Expand Up @@ -234,6 +239,38 @@ public static void run(Application application, Class<? extends QuarkusApplicati
(exitCodeHandler == null ? defaultExitCodeHandler : exitCodeHandler).accept(getExitCode(), null); //this may not be called if shutdown was initiated by a signal
}

// this is needed only when async console logging is enabled
private static void ensureConsoleLogsDrained() {
AsyncHandler asyncHandler = null;
for (Handler handler : InitialConfigurator.DELAYED_HANDLER.getHandlers()) {
if (handler instanceof AsyncHandler) {
asyncHandler = (AsyncHandler) handler;
Handler[] nestedHandlers = asyncHandler.getHandlers();
boolean foundNestedConsoleHandler = false;
for (Handler nestedHandler : nestedHandlers) {
if (nestedHandler instanceof ConsoleHandler) {
foundNestedConsoleHandler = true;
break;
}
}
if (!foundNestedConsoleHandler) {
asyncHandler = null;
}
}
if (asyncHandler != null) {
break;
}
}
if (asyncHandler != null) {
try {
// all we can do is wait because the thread that takes records off the queue is a daemon thread and there is no way to interact with its lifecycle
Thread.sleep(200);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}

/**
* Run some background cleanup once after the application has booted.
* This will not be invoked for command mode, as it's not worth it for a short lived process.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ quarkus.arc.unremovable-types[0]=foo

### Do not record env values in build time
bt.do.not.record=properties
%test.bt.profile.record=properties

### prefix
my.prefix.prop=1234
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.BufferedReader;
Expand All @@ -17,12 +18,12 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import javax.inject.Inject;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.eclipse.microprofile.config.spi.ConfigSource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
Expand All @@ -43,6 +44,7 @@
import io.quarkus.extest.runtime.config.named.PrefixNamedConfig;
import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;
import io.smallrye.config.SmallRyeConfig;

/**
* Test driver for the test-extension
Expand All @@ -58,7 +60,7 @@ public class ConfiguredBeanTest {
.addAsResource("application.properties"));

@Inject
Config config;
SmallRyeConfig config;
@Inject
ConfiguredBean configuredBean;

Expand Down Expand Up @@ -330,36 +332,28 @@ public void testBuiltTimeNamedMapWithProfiles() {

@Test
public void testConfigDefaultValuesSourceOrdinal() {
ConfigSource defaultValues = null;
for (ConfigSource configSource : config.getConfigSources()) {
if (configSource.getName().contains("PropertiesConfigSource[source=Specified default values]")) {
defaultValues = configSource;
break;
}
}
assertNotNull(defaultValues);
Optional<ConfigSource> source = config.getConfigSource("PropertiesConfigSource[source=Specified default values]");
assertTrue(source.isPresent());
ConfigSource defaultValues = source.get();

assertEquals(Integer.MIN_VALUE + 100, defaultValues.getOrdinal());

// Should be the first
ConfigSource applicationProperties = config.getConfigSources().iterator().next();
assertNotNull(applicationProperties);
assertEquals(1000, applicationProperties.getOrdinal());

assertEquals("1234", defaultValues.getValue("my.prop"));
assertEquals("1234", defaultValues.getValue("%test.my.prop"));
assertNull(defaultValues.getValue("my.prop"));
assertEquals("1234", applicationProperties.getValue("my.prop"));
}

@Test
public void testProfileDefaultValuesSource() {
ConfigSource defaultValues = null;
for (ConfigSource configSource : config.getConfigSources()) {
if (configSource.getName().contains("PropertiesConfigSource[source=Specified default values]")) {
defaultValues = configSource;
break;
}
}
assertNotNull(defaultValues);
assertEquals("1234", defaultValues.getValue("my.prop"));
Optional<ConfigSource> source = config.getConfigSource("PropertiesConfigSource[source=Specified default values]");
assertTrue(source.isPresent());
ConfigSource defaultValues = source.get();

assertEquals("1234", defaultValues.getValue("%prod.my.prop"));
assertEquals("5678", defaultValues.getValue("%dev.my.prop"));
assertEquals("1234", defaultValues.getValue("%test.my.prop"));
Expand Down
Loading

0 comments on commit ab47615

Please sign in to comment.