diff --git a/deployment/pom.xml b/deployment/pom.xml index 14ba0f5..5e7fe91 100644 --- a/deployment/pom.xml +++ b/deployment/pom.xml @@ -29,7 +29,7 @@ io.quarkus - quarkus-resteasy-reactive-deployment + quarkus-rest-deployment test diff --git a/deployment/src/main/java/io/quarkiverse/wiremock/devservice/LogPublisher.java b/deployment/src/main/java/io/quarkiverse/wiremock/devservice/LogPublisher.java new file mode 100644 index 0000000..ca7a2de --- /dev/null +++ b/deployment/src/main/java/io/quarkiverse/wiremock/devservice/LogPublisher.java @@ -0,0 +1,39 @@ +package io.quarkiverse.wiremock.devservice; + +import java.util.concurrent.SubmissionPublisher; +import java.util.logging.Handler; +import java.util.logging.LogRecord; + +/** + * Publish Logs + */ +public class LogPublisher extends SubmissionPublisher { + + public void publishLog(String logMessage) { + this.submit(logMessage); + } + + public static class LogHandler extends Handler { + private final LogPublisher logPublisher; + + public LogHandler(LogPublisher logPublisher) { + this.logPublisher = logPublisher; + } + + @Override + public void publish(LogRecord record) { + String message = record.getMessage(); + logPublisher.publishLog(message); + } + + @Override + public void flush() { + // No-op + } + + @Override + public void close() throws SecurityException { + // No-op + } + } +} \ No newline at end of file diff --git a/deployment/src/main/java/io/quarkiverse/wiremock/devservice/WireMockServerProcessor.java b/deployment/src/main/java/io/quarkiverse/wiremock/devservice/WireMockServerProcessor.java index 0837dc6..e2a2298 100644 --- a/deployment/src/main/java/io/quarkiverse/wiremock/devservice/WireMockServerProcessor.java +++ b/deployment/src/main/java/io/quarkiverse/wiremock/devservice/WireMockServerProcessor.java @@ -10,6 +10,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -34,6 +35,7 @@ import io.quarkus.deployment.builditem.LiveReloadBuildItem; import io.quarkus.deployment.dev.devservices.DevServiceDescriptionBuildItem; import io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig; +import io.quarkus.devui.spi.buildtime.FooterLogBuildItem; import io.quarkus.runtime.configuration.ConfigurationException; class WireMockServerProcessor { @@ -54,7 +56,8 @@ FeatureBuildItem feature() { @BuildStep(onlyIf = { WireMockServerEnabled.class, GlobalDevServicesConfig.Enabled.class }) DevServicesResultBuildItem setup(LaunchModeBuildItem launchMode, LiveReloadBuildItem liveReload, CuratedApplicationShutdownBuildItem shutdown, WireMockServerBuildTimeConfig config, - BuildProducer configErrors) { + BuildProducer configErrors, + BuildProducer footerLogProducer) { LOGGER.debugf("Quarkus launch mode [%s]", launchMode.getLaunchMode()); @@ -74,7 +77,13 @@ DevServicesResultBuildItem setup(LaunchModeBuildItem launchMode, LiveReloadBuild } if (devService == null) { - devService = startWireMockDevService(config); + if (launchMode.getLaunchMode().isDevOrTest()) { + LogPublisher logPublisher = new LogPublisher(); + devService = startWireMockDevService(config, Optional.of(logPublisher)); + footerLogProducer.produce(new FooterLogBuildItem("WireMock", () -> logPublisher)); + } else { + devService = startWireMockDevService(config, Optional.empty()); + } } return devService.toBuildItem(); } @@ -98,7 +107,8 @@ void watchWireMockConfigFiles(WireMockServerBuildTimeConfig config, } } - private static RunningDevService startWireMockDevService(WireMockServerBuildTimeConfig config) { + private static RunningDevService startWireMockDevService(WireMockServerBuildTimeConfig config, + Optional logPublisher) { final WireMockConfiguration configuration = options() .globalTemplating(config.globalResponseTemplating()) @@ -113,6 +123,11 @@ private static RunningDevService startWireMockDevService(WireMockServerBuildTime configuration.usingFilesUnderDirectory(config.effectiveFileMapping()); } + if (logPublisher.isPresent()) { + java.util.logging.Logger wireMockLogger = java.util.logging.Logger.getLogger("com.github.tomakehurst.wiremock"); + wireMockLogger.addHandler(new LogPublisher.LogHandler(logPublisher.get())); + } + final WireMockServer server = new WireMockServer(configuration); server.start(); LOGGER.debugf("WireMock server listening on port [%s]", server.port()); diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index dd9d2e1..99a3971 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -11,11 +11,11 @@ io.quarkus - quarkus-resteasy-reactive + quarkus-rest io.quarkus - quarkus-rest-client-reactive + quarkus-rest-client io.quarkiverse.wiremock diff --git a/pom.xml b/pom.xml index 693bb44..22226cc 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 17 UTF-8 UTF-8 - 3.8.5 + 999-SNAPSHOT 3.6.0