From 957f91ae71e991675b2694b372c263125b773e8d Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Wed, 19 Jun 2024 13:48:43 +0200 Subject: [PATCH 1/2] ClassCastEx in case of some messages Cast is wrong, as message can be of multiple type. Fixes #1036 --- .../mvndaemon/mvnd/common/logging/TerminalOutput.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/org/mvndaemon/mvnd/common/logging/TerminalOutput.java b/common/src/main/java/org/mvndaemon/mvnd/common/logging/TerminalOutput.java index 4dcd9b5a9..befc4856e 100644 --- a/common/src/main/java/org/mvndaemon/mvnd/common/logging/TerminalOutput.java +++ b/common/src/main/java/org/mvndaemon/mvnd/common/logging/TerminalOutput.java @@ -312,9 +312,13 @@ private boolean doAccept(Message entry) { break; } case Message.DISPLAY: { - Message.StringMessage d = (Message.StringMessage) entry; - clearDisplay(); - terminal.writer().printf("%s%n", d.getMessage()); + if (entry instanceof StringMessage) { + Message.StringMessage d = (Message.StringMessage) entry; + terminal.writer().printf("%s%n", d.getMessage()); + } else if (entry instanceof ProjectEvent) { + Message.ProjectEvent d = (Message.ProjectEvent) entry; + terminal.writer().printf("[%s] %s%n", d.getProjectId(), d.getMessage()); + } break; } case Message.PRINT_OUT: { From 390fac962395e46724818175ae3153b6d7cbd12d Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 20 Jun 2024 08:56:19 +0200 Subject: [PATCH 2/2] Implement proper changes --- .../org/mvndaemon/mvnd/client/DefaultClient.java | 2 +- .../main/java/org/mvndaemon/mvnd/common/Message.java | 8 ++------ .../mvndaemon/mvnd/common/logging/TerminalOutput.java | 10 +++------- .../org/mvndaemon/mvnd/assertj/TestClientOutput.java | 2 +- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/client/src/main/java-mvnd/org/mvndaemon/mvnd/client/DefaultClient.java b/client/src/main/java-mvnd/org/mvndaemon/mvnd/client/DefaultClient.java index 24cc49fe2..c76cc9ac1 100644 --- a/client/src/main/java-mvnd/org/mvndaemon/mvnd/client/DefaultClient.java +++ b/client/src/main/java-mvnd/org/mvndaemon/mvnd/client/DefaultClient.java @@ -165,7 +165,7 @@ public static void main(String[] argv) throws Exception { } catch (DaemonException.InterruptedException e) { final AttributedStyle s = new AttributedStyle().bold().foreground(AttributedStyle.RED); String str = new AttributedString(System.lineSeparator() + "Canceled by user", s).toAnsi(); - output.accept(Message.display(str)); + output.accept(Message.err(str)); exitCode = 130; } } diff --git a/common/src/main/java/org/mvndaemon/mvnd/common/Message.java b/common/src/main/java/org/mvndaemon/mvnd/common/Message.java index f274f9402..8b4897bf4 100644 --- a/common/src/main/java/org/mvndaemon/mvnd/common/Message.java +++ b/common/src/main/java/org/mvndaemon/mvnd/common/Message.java @@ -499,6 +499,8 @@ public String toString() { private String mnemonic() { switch (type) { + case DISPLAY: + return "Display"; case PROJECT_LOG_MESSAGE: return "ProjectLogMessage"; default: @@ -730,8 +732,6 @@ private String mnemonic() { return "KeyboardInput"; case BUILD_LOG_MESSAGE: return "BuildLogMessage"; - case DISPLAY: - return "Display"; case PRINT_OUT: return "PrintOut"; case PRINT_ERR: @@ -1112,10 +1112,6 @@ public static StringMessage buildStatus(String payload) { return new StringMessage(BUILD_STATUS, payload); } - public static StringMessage display(String message) { - return new StringMessage(DISPLAY, message); - } - public static RequestInput requestInput(String projectId) { return new RequestInput(projectId); } diff --git a/common/src/main/java/org/mvndaemon/mvnd/common/logging/TerminalOutput.java b/common/src/main/java/org/mvndaemon/mvnd/common/logging/TerminalOutput.java index befc4856e..89708f004 100644 --- a/common/src/main/java/org/mvndaemon/mvnd/common/logging/TerminalOutput.java +++ b/common/src/main/java/org/mvndaemon/mvnd/common/logging/TerminalOutput.java @@ -312,13 +312,9 @@ private boolean doAccept(Message entry) { break; } case Message.DISPLAY: { - if (entry instanceof StringMessage) { - Message.StringMessage d = (Message.StringMessage) entry; - terminal.writer().printf("%s%n", d.getMessage()); - } else if (entry instanceof ProjectEvent) { - Message.ProjectEvent d = (Message.ProjectEvent) entry; - terminal.writer().printf("[%s] %s%n", d.getProjectId(), d.getMessage()); - } + clearDisplay(); + Message.ProjectEvent d = (Message.ProjectEvent) entry; + terminal.writer().printf("[%s] %s%n", d.getProjectId(), d.getMessage()); break; } case Message.PRINT_OUT: { diff --git a/integration-tests/src/test/java/org/mvndaemon/mvnd/assertj/TestClientOutput.java b/integration-tests/src/test/java/org/mvndaemon/mvnd/assertj/TestClientOutput.java index 1daa9c317..524a6ae72 100644 --- a/integration-tests/src/test/java/org/mvndaemon/mvnd/assertj/TestClientOutput.java +++ b/integration-tests/src/test/java/org/mvndaemon/mvnd/assertj/TestClientOutput.java @@ -59,7 +59,7 @@ public void accept(List messages) { @Override public void describeTerminal() { - accept(Message.display("Test terminal")); + accept(Message.display("test", "Test terminal")); } @Override