Skip to content

Commit 9f99117

Browse files
committed
Move logging to @ConfigMapping
1 parent 72297fb commit 9f99117

File tree

24 files changed

+767
-846
lines changed

24 files changed

+767
-846
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package io.quarkus.deployment.configuration;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
6+
import io.quarkus.runtime.LaunchMode;
7+
import io.quarkus.runtime.console.ConsoleRuntimeConfig;
8+
import io.quarkus.runtime.logging.LogBuildTimeConfig;
9+
import io.quarkus.runtime.logging.LogRuntimeConfig;
10+
import io.quarkus.runtime.logging.LoggingSetupRecorder;
11+
import io.smallrye.config.SmallRyeConfigBuilder;
12+
import io.smallrye.config.SmallRyeConfigBuilderCustomizer;
13+
14+
/**
15+
* Even if the Log and Console mappings are marked as runtime, they are also used during build time.
16+
* <p>
17+
* We cannot register the mappings in the core runtime module because {@link io.smallrye.config.SmallRyeConfig}
18+
* requires ASM to load the mappings. When we run a Quarkus test, Quarkus will generate the bytecode for the mappings,
19+
* so we don't need ASM. In a non-Quarkus tests, ASM must be present in the classpath, which we want
20+
* to avoid (even if they are in the test scope). The logging mappings shouldn't be loaded when running a non-Quarkus
21+
* test because they are not required.
22+
*
23+
* @see LoggingSetupRecorder#initializeBuildTimeLogging(LogRuntimeConfig, LogBuildTimeConfig, ConsoleRuntimeConfig, Map, List,
24+
* LaunchMode)
25+
*/
26+
public class BuildTimeConfigBuilderCustomizer implements SmallRyeConfigBuilderCustomizer {
27+
@Override
28+
public void configBuilder(final SmallRyeConfigBuilder builder) {
29+
builder.withMapping(LogBuildTimeConfig.class)
30+
.withMapping(LogRuntimeConfig.class)
31+
.withMapping(ConsoleRuntimeConfig.class);
32+
}
33+
}

core/deployment/src/main/java/io/quarkus/deployment/configuration/BuildTimeConfigurationReader.java

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import static io.quarkus.deployment.util.ReflectUtil.toError;
77
import static io.quarkus.deployment.util.ReflectUtil.typeOfParameter;
88
import static io.quarkus.deployment.util.ReflectUtil.unwrapInvocationTargetException;
9-
import static io.quarkus.runtime.configuration.PropertiesUtil.isPropertyInRoots;
109
import static io.smallrye.config.ConfigMappings.ConfigClassWithPrefix.configClassWithPrefix;
1110
import static io.smallrye.config.Expressions.withoutExpansion;
1211
import static io.smallrye.config.SmallRyeConfig.SMALLRYE_CONFIG_PROFILE;
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,42 @@
11
package io.quarkus.deployment.console;
22

3-
import io.quarkus.runtime.annotations.ConfigItem;
4-
import io.quarkus.runtime.annotations.ConfigRoot;
3+
import java.util.Optional;
54

6-
@ConfigRoot
7-
public class ConsoleConfig {
5+
import io.quarkus.runtime.annotations.ConfigPhase;
6+
import io.quarkus.runtime.annotations.ConfigRoot;
7+
import io.smallrye.config.ConfigMapping;
8+
import io.smallrye.config.WithDefault;
89

10+
@ConfigMapping(prefix = "quarkus.console")
11+
@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
12+
public interface ConsoleConfig {
913
/**
1014
* If test results and status should be displayed in the console.
1115
* <p>
1216
* If this is false results can still be viewed in the dev console.
1317
*/
14-
@ConfigItem(defaultValue = "true")
15-
public boolean enabled;
18+
@WithDefault("true")
19+
boolean enabled();
1620

1721
/**
1822
* Disables the ability to enter input on the console.
1923
*/
20-
@ConfigItem(defaultValue = "false")
21-
public boolean disableInput;
24+
@WithDefault("false")
25+
boolean disableInput();
2226

2327
/**
2428
* Disable the testing status/prompt message at the bottom of the console
2529
* and log these messages to STDOUT instead.
2630
* <p>
2731
* Use this option if your terminal does not support ANSI escape sequences.
2832
*/
29-
@ConfigItem(defaultValue = "false")
30-
public boolean basic;
33+
@WithDefault("false")
34+
boolean basic();
3135

36+
/**
37+
* If color should be enabled or disabled.
38+
* <p>
39+
* If this is not present then an attempt will be made to guess if the terminal supports color
40+
*/
41+
Optional<Boolean> color();
3242
}

core/deployment/src/main/java/io/quarkus/deployment/console/ConsoleHelper.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,19 @@
1111
import io.quarkus.deployment.dev.testing.TestConfig;
1212
import io.quarkus.dev.console.BasicConsole;
1313
import io.quarkus.dev.console.QuarkusConsole;
14-
import io.quarkus.runtime.console.ConsoleRuntimeConfig;
15-
import io.quarkus.runtime.util.ColorSupport;
1614

1715
public class ConsoleHelper {
1816

19-
public static synchronized void installConsole(TestConfig config, ConsoleConfig consoleConfig,
20-
ConsoleRuntimeConfig consoleRuntimeConfig, io.quarkus.runtime.logging.ConsoleConfig logConfig, boolean test) {
17+
public static synchronized void installConsole(TestConfig config, ConsoleConfig consoleConfig, boolean test) {
2118
if (QuarkusConsole.installed) {
2219
return;
2320
}
24-
boolean colorEnabled = ColorSupport.isColorEnabled(consoleRuntimeConfig, logConfig);
21+
boolean colorEnabled = consoleConfig.color().orElse(QuarkusConsole.hasColorSupport());
2522
QuarkusConsole.installed = true;
2623
//if there is no color we need a basic console
2724
//note that we never enable input for tests
2825
//surefire communicates of stdin, so this can mess with it
29-
boolean inputSupport = !test && !config.disableConsoleInput.orElse(consoleConfig.disableInput);
26+
boolean inputSupport = !test && !config.disableConsoleInput.orElse(consoleConfig.disableInput());
3027
if (!inputSupport) {
3128
//note that in this case we don't hold onto anything from this class loader
3229
//which is important for the test suite
@@ -37,7 +34,7 @@ public static synchronized void installConsole(TestConfig config, ConsoleConfig
3734
new TerminalConnection(new Consumer<Connection>() {
3835
@Override
3936
public void accept(Connection connection) {
40-
if (connection.supportsAnsi() && !config.basicConsole.orElse(consoleConfig.basic)) {
37+
if (connection.supportsAnsi() && !config.basicConsole.orElse(consoleConfig.basic())) {
4138
QuarkusConsole.INSTANCE = new AeshConsole(connection);
4239
} else {
4340
LinkedBlockingDeque<Integer> queue = new LinkedBlockingDeque<>();

core/deployment/src/main/java/io/quarkus/deployment/console/ConsoleProcessor.java

+7-16
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.aesh.command.CommandException;
1919
import org.aesh.command.CommandResult;
2020
import org.aesh.command.invocation.CommandInvocation;
21-
import org.eclipse.microprofile.config.ConfigProvider;
2221
import org.jboss.logging.Logger;
2322

2423
import io.quarkus.deployment.Capabilities;
@@ -41,7 +40,6 @@
4140
import io.quarkus.deployment.ide.EffectiveIdeBuildItem;
4241
import io.quarkus.deployment.ide.Ide;
4342
import io.quarkus.dev.console.QuarkusConsole;
44-
import io.quarkus.runtime.console.ConsoleRuntimeConfig;
4543

4644
public class ConsoleProcessor {
4745

@@ -59,25 +57,18 @@ public class ConsoleProcessor {
5957
*/
6058
@BuildStep(onlyIf = IsDevelopment.class)
6159
@Produce(TestSetupBuildItem.class)
62-
ConsoleInstalledBuildItem setupConsole(TestConfig config,
63-
BuildProducer<TestListenerBuildItem> testListenerBuildItemBuildProducer,
64-
LaunchModeBuildItem launchModeBuildItem, ConsoleConfig consoleConfig) {
60+
ConsoleInstalledBuildItem setupConsole(
61+
final TestConfig config,
62+
final ConsoleConfig consoleConfig,
63+
final LaunchModeBuildItem launchModeBuildItem,
64+
final BuildProducer<TestListenerBuildItem> testListenerBuildItemBuildProducer) {
6565

6666
if (consoleInstalled) {
6767
return ConsoleInstalledBuildItem.INSTANCE;
6868
}
6969
consoleInstalled = true;
70-
if (config.console.orElse(consoleConfig.enabled)) {
71-
//this is a bit of a hack, but we can't just inject this normally
72-
//this is a runtime property value, but also a build time property value
73-
//as when running in dev mode they are both basically equivalent
74-
ConsoleRuntimeConfig consoleRuntimeConfig = new ConsoleRuntimeConfig();
75-
consoleRuntimeConfig.color = ConfigProvider.getConfig().getOptionalValue("quarkus.console.color", Boolean.class);
76-
io.quarkus.runtime.logging.ConsoleConfig loggingConsoleConfig = new io.quarkus.runtime.logging.ConsoleConfig();
77-
loggingConsoleConfig.color = ConfigProvider.getConfig().getOptionalValue("quarkus.console.color",
78-
Boolean.class);
79-
ConsoleHelper.installConsole(config, consoleConfig, consoleRuntimeConfig, loggingConsoleConfig,
80-
launchModeBuildItem.isTest());
70+
if (config.console.orElse(consoleConfig.enabled())) {
71+
ConsoleHelper.installConsole(config, consoleConfig, launchModeBuildItem.isTest());
8172
ConsoleStateManager.init(QuarkusConsole.INSTANCE, launchModeBuildItem.getDevModeType().get());
8273
//note that this bit needs to be refactored so it is no longer tied to continuous testing
8374
if (TestSupport.instance().isEmpty() || config.continuousTesting == TestConfig.Mode.DISABLED

0 commit comments

Comments
 (0)