From 86aa972f5677dbb142ec42a5b9cae3b588986bc5 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Thu, 10 Jun 2021 15:31:12 +1000 Subject: [PATCH] Improve compile error message This makes it appear in the status message. Also fixes console bugs if the status message is large, or the console is small. --- .../dev/JavaCompilationProvider.java | 8 +- .../deployment/dev/console/AeshConsole.java | 100 +++++++++++------- .../dev/testing/TestConsoleHandler.java | 5 + .../deployment/dev/testing/TestListener.java | 4 + .../deployment/dev/testing/TestRunner.java | 13 ++- 5 files changed, 87 insertions(+), 43 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/JavaCompilationProvider.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/JavaCompilationProvider.java index 487a874b6f9af..ee6c58c19ac07 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/JavaCompilationProvider.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/JavaCompilationProvider.java @@ -72,7 +72,13 @@ public void compile(Set filesToCompile, Context context) { compilerFlags.toList(), null, sources); if (!task.call()) { - throw new RuntimeException("Compilation failed" + diagnostics.getDiagnostics()); + StringBuilder sb = new StringBuilder("\u001B[91mCompilation Failed:"); + for (Diagnostic i : diagnostics.getDiagnostics()) { + sb.append("\n"); + sb.append(i.toString()); + } + sb.append("\u001b[0m"); + throw new RuntimeException(sb.toString()); } logDiagnostics(diagnostics); 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 e490f6fcd7631..561aab966edea 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 @@ -23,6 +23,12 @@ public class AeshConsole extends QuarkusConsole { private String promptMessage; private int totalStatusLines = 0; private int lastWriteCursorX; + /** + * if the status area has gotten big then small again + * this tracks how many lines of blank space we have + * so we start writing in the correct place. + */ + private int bottomBlankSpace = 0; /** * The write queue *

@@ -68,20 +74,33 @@ private AeshConsole setStatusMessage(String statusMessage) { } else { newLines += 3; } - if (newLines > totalStatusLines) { - for (int i = 0; i < newLines - totalStatusLines; ++i) { - buffer.append("\n"); - } - } this.statusMessage = statusMessage; - this.totalStatusLines = newLines; - printStatusAndPrompt(buffer); - writeQueue.add(buffer.toString()); + updatePromptOnChange(buffer, newLines); } deadlockSafeWrite(); return this; } + private void updatePromptOnChange(StringBuilder buffer, int newLines) { + if (newLines > totalStatusLines) { + StringBuilder nb = new StringBuilder(); + for (int i = 0; i < newLines - totalStatusLines; ++i) { + if (bottomBlankSpace > 0) { + bottomBlankSpace--; + } else { + nb.append("\n"); + } + } + writeQueue.add(nb.toString()); + deadlockSafeWrite(); + } else if (newLines < totalStatusLines) { + bottomBlankSpace = bottomBlankSpace + (totalStatusLines - newLines); + } + this.totalStatusLines = newLines; + printStatusAndPrompt(buffer); + writeQueue.add(buffer.toString()); + } + public AeshInputHolder createHolder(InputHandler inputHandler) { return new AeshInputHolder(inputHandler); } @@ -103,15 +122,8 @@ private AeshConsole setPromptMessage(String promptMessage) { } else { newLines += 3; } - if (newLines > totalStatusLines) { - for (int i = 0; i < newLines - totalStatusLines; ++i) { - buffer.append("\n"); - } - } this.promptMessage = promptMessage; - this.totalStatusLines = newLines; - printStatusAndPrompt(buffer); - writeQueue.add(buffer.toString()); + updatePromptOnChange(buffer, newLines); } deadlockSafeWrite(); return this; @@ -207,10 +219,13 @@ public void run() { private void printStatusAndPrompt(StringBuilder buffer) { if (totalStatusLines == 0) { return; + } else if (totalStatusLines < size.getHeight()) { + //if the console is tiny we don't do this + clearStatusMessages(buffer); + gotoLine(buffer, size.getHeight() - totalStatusLines); + } else { + bottomBlankSpace = 0; } - - clearStatusMessages(buffer); - gotoLine(buffer, size.getHeight() - totalStatusLines); buffer.append("\n--\n"); if (statusMessage != null) { buffer.append(statusMessage); @@ -267,11 +282,11 @@ public void write(String s) { } } if (totalStatusLines == 0) { + bottomBlankSpace = 0; //just to be safe, will only happen if status is added then removed, which is not really likely writeQueue.add(s); } else { clearStatusMessages(buffer); int cursorPos = lastWriteCursorX; - gotoLine(buffer, size.getHeight()); String stripped = stripAnsiCodes(s); int lines = countLines(s, cursorPos); int trailing = 0; @@ -288,29 +303,38 @@ public void write(String s) { } else { newCursorPos = trailing; } - + int usedBlankSpace = 0; + gotoLine(buffer, size.getHeight()); if (cursorPos > 1 && lines == 0) { + gotoLine(buffer, size.getHeight() - bottomBlankSpace); buffer.append(s); lastWriteCursorX = newCursorPos; //partial line, just write it - connection.write(buffer.toString()); - return; - } - if (lines == 0) { - lines++; - } - //move the existing content up by the number of lines - int appendLines = Math.max(Math.min(cursorPos > 1 ? lines - 1 : lines, totalStatusLines), 1); - clearStatusMessages(buffer); - buffer.append("\033[").append(size.getHeight() - totalStatusLines).append(";").append(0).append("H"); - buffer.append(s); - buffer.append("\033[").append(size.getHeight()).append(";").append(0).append("H"); - for (int i = 0; i < appendLines; ++i) { - buffer.append("\n"); + writeQueue.add(buffer.toString()); + } else { + if (lines == 0) { + lines++; + } + int originalBlank = bottomBlankSpace; + if (bottomBlankSpace > 0) { + usedBlankSpace = Math.min(bottomBlankSpace, lines); + bottomBlankSpace -= usedBlankSpace; + } + //move the existing content up by the number of lines + int appendLines = Math.max(Math.min(cursorPos > 1 ? lines - 1 : lines, totalStatusLines), 1); + appendLines -= usedBlankSpace; + clearStatusMessages(buffer); + buffer.append("\033[").append(size.getHeight() - totalStatusLines - originalBlank).append(";").append(0) + .append("H"); + buffer.append(s); + buffer.append("\033[").append(size.getHeight()).append(";").append(0).append("H"); + for (int i = 0; i < appendLines; ++i) { + buffer.append("\n"); + } + lastWriteCursorX = newCursorPos; + printStatusAndPrompt(buffer); + writeQueue.add(buffer.toString()); } - lastWriteCursorX = newCursorPos; - printStatusAndPrompt(buffer); - writeQueue.add(buffer.toString()); } } deadlockSafeWrite(); diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestConsoleHandler.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestConsoleHandler.java index 04d1809d19504..99b70431810be 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestConsoleHandler.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestConsoleHandler.java @@ -144,6 +144,11 @@ public void testsDisabled() { promptHandler.setStatus(null); } + @Override + public void testCompileFailed(String message) { + promptHandler.setStatus(message); + } + @Override public void testRunStarted(Consumer listenerConsumer) { diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestListener.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestListener.java index 69ffca4c29ff6..bfac67a31c795 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestListener.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestListener.java @@ -30,4 +30,8 @@ default void setTestOutput(boolean to) { default void setInstrumentationBasedReload(boolean ibr) { } + + default void testCompileFailed(String message) { + + } } diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestRunner.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestRunner.java index f90f116d8ef1e..3a8deabcdb244 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestRunner.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestRunner.java @@ -31,7 +31,7 @@ public class TestRunner { - private static final Logger log = Logger.getLogger(TestRunner.class); + private static final Logger log = Logger.getLogger("io.quarkus.test"); private static final AtomicLong COUNTER = new AtomicLong(); private final TestSupport testSupport; @@ -354,9 +354,14 @@ public void waitTillResumed() { } } - public synchronized void testCompileFailed(Throwable e) { - compileProblem = e; - log.error("Test compile failed", e); + public void testCompileFailed(Throwable e) { + synchronized (this) { + compileProblem = e; + } + + for (TestListener i : testSupport.testListeners) { + i.testCompileFailed(e.getMessage()); + } } public synchronized void testCompileSucceeded() {