From 63811358d1e5dce925baf9054d75cb6a3e5669af Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Mon, 5 Apr 2021 11:21:23 +1000 Subject: [PATCH] More improvement --- .../java/io/quarkus/deployment/TestConfig.java | 2 +- .../deployment/dev/console/AeshConsole.java | 6 ++++++ .../deployment/dev/console/QuarkusConsole.java | 2 +- .../dev/testing/runner/JunitTestRunner.java | 14 ++++++++++++-- .../deployment/dev/testing/runner/TestRunner.java | 12 ++++++++++-- .../dev/testing/runner/TestTracingProcessor.java | 13 +++++++++++-- .../src/main/java/io/quarkus/maven/DevMojo.java | 2 ++ 7 files changed, 43 insertions(+), 8 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/TestConfig.java b/core/deployment/src/main/java/io/quarkus/deployment/TestConfig.java index de12e6be059ca..aacc479bf6ca8 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/TestConfig.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/TestConfig.java @@ -42,7 +42,7 @@ public class TestConfig { * Defaults to 'slow' */ @ConfigItem(defaultValue = "slow") - public List excludeTags; + public Optional> excludeTags; /** * Disable the testing status/prompt message at the bottom of the console diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/console/AeshConsole.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/console/AeshConsole.java index 37f8df3d98c3c..df69407c4feaf 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/console/AeshConsole.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/console/AeshConsole.java @@ -22,6 +22,12 @@ public AeshConsole(Connection connection) { this.connection = connection; connection.openNonBlocking(); setup(connection); + Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { + @Override + public void run() { + connection.close(); + } + }, "Console Shutdown Hoot")); } private synchronized AeshConsole setStatusMessage(String statusMessage) { diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/console/QuarkusConsole.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/console/QuarkusConsole.java index 1be120c3b658a..fd8388d84cd4e 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/console/QuarkusConsole.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/console/QuarkusConsole.java @@ -43,7 +43,7 @@ public void popInputHandler() { public abstract void write(byte[] buf, int off, int len); - public static void installConsole(TestConfig config) { + public static synchronized void installConsole(TestConfig config) { if (installed) { return; } diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/runner/JunitTestRunner.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/runner/JunitTestRunner.java index bdc24175f1f9d..ba395f9e6a5ba 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/runner/JunitTestRunner.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/runner/JunitTestRunner.java @@ -158,6 +158,15 @@ public void quarkusStarting() { @Override public void executionStarted(TestIdentifier testIdentifier) { + String className = ""; + if (testIdentifier.getSource().isPresent()) { + if (testIdentifier.getSource().get() instanceof MethodSource) { + className = ((MethodSource) testIdentifier.getSource().get()).getClassName(); + } else if (testIdentifier.getSource().get() instanceof ClassSource) { + className = ((ClassSource) testIdentifier.getSource().get()).getClassName(); + } + } + listener.testStarted(testIdentifier, className); waitTillResumed(); touchedClasses.push(Collections.synchronizedSet(new HashSet<>())); } @@ -387,9 +396,9 @@ public String apply(Class aClass) { ClassInfo def = index.getClassByName(DotName.createSimple(aClass.getName())); AnnotationInstance testProfile = def.classAnnotation(DotName.createSimple("io.quarkus.test.junit.TestProfile")); if (testProfile == null) { - return ""; + return "$$" + aClass.getName(); } - return testProfile.value().asClass().name().toString(); + return testProfile.value().asClass().name().toString() + "$$" + aClass.getName(); } })); return ret; @@ -413,6 +422,7 @@ public interface TestListener { void runAborted(); + void testStarted(TestIdentifier testIdentifier, String className); } private class TestLogCapturingHandler implements Predicate { diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/runner/TestRunner.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/runner/TestRunner.java index 605363abf1423..95f980ec78dc0 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/runner/TestRunner.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/runner/TestRunner.java @@ -9,6 +9,7 @@ import org.jboss.logging.Logger; import org.junit.platform.engine.TestExecutionResult; +import org.junit.platform.launcher.TestIdentifier; import org.opentest4j.TestAbortedException; import io.quarkus.bootstrap.app.CuratedApplication; @@ -238,8 +239,6 @@ public void testComplete(TestResult result) { skipped.incrementAndGet(); } methodCount.incrementAndGet(); - promptHandler.setStatus("Running " + methodCount.get() + "/" + totalNoTests - + (failureCount.get() == 0 ? "." : ". " + failureCount + " failures so far.")); } @Override @@ -250,6 +249,15 @@ public void runComplete(TestRunResults results) { @Override public void runAborted() { } + + @Override + public void testStarted(TestIdentifier testIdentifier, String className) { + promptHandler.setStatus("Running " + methodCount.get() + "/" + totalNoTests + + (failureCount.get() == 0 ? "." + : ". " + failureCount + " failures so far.") + + " Running: " + + className + "#" + testIdentifier.getDisplayName()); + } }) .build(); if (paused) { diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/runner/TestTracingProcessor.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/runner/TestTracingProcessor.java index 4f85522e4996c..57f8c5c0d12c2 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/runner/TestTracingProcessor.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/runner/TestTracingProcessor.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.function.BiFunction; +import io.quarkus.deployment.IsDevelopment; import org.jboss.jandex.ClassInfo; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.MethodVisitor; @@ -41,10 +42,18 @@ LogCleanupFilterBuildItem handle() { return new LogCleanupFilterBuildItem("org.junit.platform.launcher.core.EngineDiscoveryOrchestrator", "0 containers"); } + @BuildStep(onlyIf= IsDevelopment.class) + ServiceStartBuildItem setupConsole(TestConfig config) { + if (RuntimeUpdatesProcessor.INSTANCE == null || config.enabled == TestConfig.Mode.DISABLED) { + return null; + } + QuarkusConsole.installConsole(config); + return null; + } + @BuildStep(onlyIfNot = IsNormal.class) @Produce(LogHandlerBuildItem.class) ServiceStartBuildItem startTesting(TestConfig config) { - QuarkusConsole.installConsole(config); if (RuntimeUpdatesProcessor.INSTANCE == null || config.enabled == TestConfig.Mode.DISABLED) { return null; } @@ -55,7 +64,7 @@ ServiceStartBuildItem startTesting(TestConfig config) { RuntimeUpdatesProcessor.INSTANCE.getTestSupport().stop(); } RuntimeUpdatesProcessor.INSTANCE.getTestSupport().setTags(config.includeTags.orElse(Collections.emptyList()), - config.excludeTags); + config.excludeTags.orElse(Collections.emptyList())); return null; } diff --git a/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java index 0ee37eb01c3d6..0f49a6f7e14bf 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java @@ -342,6 +342,8 @@ public void execute() throws MojoFailureException, MojoExecutionException { if (System.currentTimeMillis() > nextCheck) { nextCheck = System.currentTimeMillis() + 100; if (!runner.alive()) { + //reset the terminal + System.out.println("\u001B[0m"); if (runner.exitValue() != 0) { throw new MojoExecutionException("Dev mode process did not complete successfully"); }