From 14ca92ccad8573998dd0d4d5c98864a5176188d8 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Thu, 10 Jun 2021 20:06:29 +1000 Subject: [PATCH] Improve mvn quarkus:test output - Display test output by default - Display banner if configured --- .../deployment/dev/IsolatedTestModeMain.java | 8 +++----- .../deployment/dev/testing/TestHandler.java | 19 +++++++++++++++++++ .../runtime/logging/LoggingSetupRecorder.java | 6 +++++- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/IsolatedTestModeMain.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/IsolatedTestModeMain.java index b57517a484cd9..6659b7496766f 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/IsolatedTestModeMain.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/IsolatedTestModeMain.java @@ -17,6 +17,7 @@ import io.quarkus.bootstrap.app.AugmentAction; import io.quarkus.bootstrap.app.CuratedApplication; import io.quarkus.bootstrap.runner.Timing; +import io.quarkus.deployment.builditem.ConsoleFormatterBannerBuildItem; import io.quarkus.deployment.dev.testing.TestHandler; import io.quarkus.deployment.dev.testing.TestSetupBuildItem; import io.quarkus.deployment.dev.testing.TestSupport; @@ -25,7 +26,6 @@ import io.quarkus.dev.spi.DevModeType; import io.quarkus.dev.spi.HotReplacementSetup; import io.quarkus.runner.bootstrap.AugmentActionImpl; -import io.quarkus.runtime.logging.LoggingSetupRecorder; /** * The main entry point of quarkus:test @@ -41,6 +41,7 @@ public class IsolatedTestModeMain extends IsolatedDevModeMain { private RuntimeUpdatesProcessor setupRuntimeCompilation(DevModeContext context, Path applicationRoot) throws Exception { + System.setProperty("quarkus.test.display-test-output", "true"); if (!context.getAllModules().isEmpty()) { ServiceLoader serviceLoader = ServiceLoader.load(CompilationProvider.class); List compilationProviders = new ArrayList<>(); @@ -125,16 +126,13 @@ public void accept(CuratedApplication o, Map params) { } try { augmentAction.performCustomBuild(TestHandler.class.getName(), null, TestSetupBuildItem.class.getName(), - LoggingSetupBuildItem.class.getName()); + LoggingSetupBuildItem.class.getName(), ConsoleFormatterBannerBuildItem.class.getName()); } catch (Throwable t) { //logging may not have been started, this is more reliable System.err.println("Failed to start quarkus test mode"); t.printStackTrace(); System.exit(1); } - //we don't actually start the app - //so logging would not be enabled - LoggingSetupRecorder.handleFailedStart(); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestHandler.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestHandler.java index c810bbb68ce9f..63dbb3185ba00 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestHandler.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestHandler.java @@ -2,13 +2,32 @@ import java.util.function.BiConsumer; +import org.jboss.logging.Logger; + +import io.quarkus.banner.BannerConfig; import io.quarkus.builder.BuildResult; +import io.quarkus.deployment.steps.BannerProcessor; import io.quarkus.dev.console.QuarkusConsole; +import io.quarkus.runtime.BannerRecorder; +import io.quarkus.runtime.BannerRuntimeConfig; +import io.quarkus.runtime.configuration.ConfigInstantiator; +import io.quarkus.runtime.logging.LoggingSetupRecorder; public class TestHandler implements BiConsumer { @Override public void accept(Object o, BuildResult buildResult) { QuarkusConsole.start(); TestSupport.instance().get().start(); + + //we don't actually start the app + //so logging would not be enabled + BannerConfig bannerConfig = new BannerConfig(); + BannerRuntimeConfig bannerRuntimeConfig = new BannerRuntimeConfig(); + ConfigInstantiator.handleObject(bannerConfig); + ConfigInstantiator.handleObject(bannerRuntimeConfig); + LoggingSetupRecorder.handleFailedStart(new BannerProcessor() + .recordBanner(new BannerRecorder(), bannerConfig, bannerRuntimeConfig).getBannerSupplier()); + Logger.getLogger("io.quarkus.test").info("Quarkus continuous testing mode started"); + } } diff --git a/core/runtime/src/main/java/io/quarkus/runtime/logging/LoggingSetupRecorder.java b/core/runtime/src/main/java/io/quarkus/runtime/logging/LoggingSetupRecorder.java index ab69e93e89cd6..3fd7f1c3e1220 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/logging/LoggingSetupRecorder.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/logging/LoggingSetupRecorder.java @@ -54,12 +54,16 @@ public LoggingSetupRecorder() { @SuppressWarnings("unused") //called via reflection, as it is in an isolated CL public static void handleFailedStart() { + handleFailedStart(new RuntimeValue<>(Optional.empty())); + } + + public static void handleFailedStart(RuntimeValue>> banner) { LogConfig config = new LogConfig(); ConfigInstantiator.handleObject(config); LogBuildTimeConfig buildConfig = new LogBuildTimeConfig(); ConfigInstantiator.handleObject(buildConfig); new LoggingSetupRecorder().initializeLogging(config, buildConfig, Collections.emptyList(), Collections.emptyList(), - Collections.emptyList(), null); + Collections.emptyList(), banner); } public void initializeLogging(LogConfig config, LogBuildTimeConfig buildConfig,