Skip to content

Commit

Permalink
Improve compile error message
Browse files Browse the repository at this point in the history
This makes it appear in the status message.

Also fixes console bugs if the status message is large, or
the console is small.
  • Loading branch information
stuartwdouglas committed Jun 10, 2021
1 parent d7ad0a1 commit 86aa972
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ public void compile(Set<File> 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<? extends JavaFileObject> i : diagnostics.getDiagnostics()) {
sb.append("\n");
sb.append(i.toString());
}
sb.append("\u001b[0m");
throw new RuntimeException(sb.toString());
}

logDiagnostics(diagnostics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <p>
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ public void testsDisabled() {
promptHandler.setStatus(null);
}

@Override
public void testCompileFailed(String message) {
promptHandler.setStatus(message);
}

@Override
public void testRunStarted(Consumer<TestRunListener> listenerConsumer) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ default void setTestOutput(boolean to) {
default void setInstrumentationBasedReload(boolean ibr) {

}

default void testCompileFailed(String message) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 86aa972

Please sign in to comment.