From ba33768825ddc269285deec4bbdbfc682342b954 Mon Sep 17 00:00:00 2001 From: Alexander Milster Date: Thu, 11 Jul 2024 12:07:07 +0200 Subject: [PATCH 1/6] Avoid overlap of log with progress bars --- .../de/jplag/cli/logger/CollectedLogger.java | 14 +++-- .../java/de/jplag/cli/logger/IdleBar.java | 6 +- .../cli/logger/LogDelayingProgressBar.java | 17 +++++ .../de/jplag/cli/logger/TerminalPrinter.java | 63 +++++++++++++++++++ .../jplag/cli/logger/TongfeiProgressBar.java | 6 +- 5 files changed, 96 insertions(+), 10 deletions(-) create mode 100644 cli/src/main/java/de/jplag/cli/logger/LogDelayingProgressBar.java create mode 100644 cli/src/main/java/de/jplag/cli/logger/TerminalPrinter.java diff --git a/cli/src/main/java/de/jplag/cli/logger/CollectedLogger.java b/cli/src/main/java/de/jplag/cli/logger/CollectedLogger.java index b93e8cacf7..fbcf4929e1 100644 --- a/cli/src/main/java/de/jplag/cli/logger/CollectedLogger.java +++ b/cli/src/main/java/de/jplag/cli/logger/CollectedLogger.java @@ -1,5 +1,6 @@ package de.jplag.cli.logger; +import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -19,7 +20,6 @@ public class CollectedLogger extends AbstractLogger { private static final String JPLAG_LOGGER_PREFIX = "de.jplag."; private static final Level LOG_LEVEL_FOR_EXTERNAL_LIBRARIES = Level.ERROR; private static final int MAXIMUM_MESSAGE_LENGTH = 32; - private static final PrintStream TARGET_STREAM = System.out; private static Level currentLogLevel = Level.INFO; private final transient SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-hh:mm:ss_SSS"); @@ -148,11 +148,10 @@ private StringBuilder prepareLogOutput(LogEntry entry) { private void printLogEntry(LogEntry entry) { StringBuilder output = prepareLogOutput(entry); - TARGET_STREAM.println(output); + TerminalPrinter.getInstance().println(output.toString()); if (entry.cause() != null) { - entry.cause().printStackTrace(TARGET_STREAM); + this.printStackTrace(entry.cause()); } - TARGET_STREAM.flush(); } public static Level getLogLevel() { @@ -162,4 +161,11 @@ public static Level getLogLevel() { public static void setLogLevel(Level logLevel) { currentLogLevel = logLevel; } + + private void printStackTrace(Throwable error) { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + error.printStackTrace(new PrintStream(outputStream)); + String stackTrace = outputStream.toString(); + TerminalPrinter.getInstance().println(stackTrace); + } } diff --git a/cli/src/main/java/de/jplag/cli/logger/IdleBar.java b/cli/src/main/java/de/jplag/cli/logger/IdleBar.java index e5b7f0d3da..acce8fc138 100644 --- a/cli/src/main/java/de/jplag/cli/logger/IdleBar.java +++ b/cli/src/main/java/de/jplag/cli/logger/IdleBar.java @@ -7,12 +7,10 @@ import org.jline.terminal.Terminal; import org.jline.terminal.TerminalBuilder; -import de.jplag.logging.ProgressBar; - /** * Prints an idle progress bar, that does not count upwards. */ -public class IdleBar implements ProgressBar { +public class IdleBar extends LogDelayingProgressBar { private final PrintStream output; private final Thread runner; @@ -27,6 +25,7 @@ public class IdleBar implements ProgressBar { private boolean running = false; public IdleBar(String text) { + super(); this.output = System.out; this.runner = new Thread(this::run); this.length = 50; @@ -53,6 +52,7 @@ public void start() { @Override public void dispose() { + super.dispose(); this.running = false; try { this.runner.join(); diff --git a/cli/src/main/java/de/jplag/cli/logger/LogDelayingProgressBar.java b/cli/src/main/java/de/jplag/cli/logger/LogDelayingProgressBar.java new file mode 100644 index 0000000000..dfa4cbb79e --- /dev/null +++ b/cli/src/main/java/de/jplag/cli/logger/LogDelayingProgressBar.java @@ -0,0 +1,17 @@ +package de.jplag.cli.logger; + +import de.jplag.logging.ProgressBar; + +/** + * Superclass for progress bars, that delay the log output until the bar is done + */ +public abstract class LogDelayingProgressBar implements ProgressBar { + public LogDelayingProgressBar() { + TerminalPrinter.getInstance().delay(); + } + + @Override + public void dispose() { + TerminalPrinter.getInstance().unDelay(); + } +} diff --git a/cli/src/main/java/de/jplag/cli/logger/TerminalPrinter.java b/cli/src/main/java/de/jplag/cli/logger/TerminalPrinter.java new file mode 100644 index 0000000000..52e8ddc936 --- /dev/null +++ b/cli/src/main/java/de/jplag/cli/logger/TerminalPrinter.java @@ -0,0 +1,63 @@ +package de.jplag.cli.logger; + +import java.io.PrintStream; +import java.util.PriorityQueue; +import java.util.Queue; + +public class TerminalPrinter { + private static TerminalPrinter instance; + + public static TerminalPrinter getInstance() { + synchronized (TerminalPrinter.class) { + if (instance == null) { + synchronized (TerminalPrinter.class) { + instance = new TerminalPrinter(); + } + } + } + + return instance; + } + + private final Queue outputQueue; + private final PrintStream targetStream; + + private boolean isDelayed; + + private TerminalPrinter() { + this.outputQueue = new PriorityQueue<>(); + this.targetStream = System.out; + this.isDelayed = false; + } + + public void println(String output) { + synchronized (TerminalPrinter.class) { + this.outputQueue.offer(output); + this.printQueue(); + } + } + + public void delay() { + synchronized (TerminalPrinter.class) { + this.isDelayed = true; + } + } + + public void unDelay() { + synchronized (TerminalPrinter.class) { + this.isDelayed = false; + this.printQueue(); + } + } + + private void printQueue() { + synchronized (TerminalPrinter.class) { + if (!this.isDelayed) { + while (!this.outputQueue.isEmpty()) { + this.targetStream.println(this.outputQueue.poll()); + } + this.targetStream.flush(); + } + } + } +} diff --git a/cli/src/main/java/de/jplag/cli/logger/TongfeiProgressBar.java b/cli/src/main/java/de/jplag/cli/logger/TongfeiProgressBar.java index 4305a497e0..067cd160c3 100644 --- a/cli/src/main/java/de/jplag/cli/logger/TongfeiProgressBar.java +++ b/cli/src/main/java/de/jplag/cli/logger/TongfeiProgressBar.java @@ -1,14 +1,13 @@ package de.jplag.cli.logger; -import de.jplag.logging.ProgressBar; - /** * A ProgressBar, that used the tongfei progress bar library underneath, to show progress bars on the cli. */ -public class TongfeiProgressBar implements ProgressBar { +public class TongfeiProgressBar extends LogDelayingProgressBar { private final me.tongfei.progressbar.ProgressBar progressBar; public TongfeiProgressBar(me.tongfei.progressbar.ProgressBar progressBar) { + super(); this.progressBar = progressBar; } @@ -19,6 +18,7 @@ public void step(int number) { @Override public void dispose() { + super.dispose(); this.progressBar.close(); } } From e494612919643d2e1e7354bfdc087e4655af51a5 Mon Sep 17 00:00:00 2001 From: Alexander Milster Date: Thu, 11 Jul 2024 12:25:13 +0200 Subject: [PATCH 2/6] Javadoc for TerminalPrinter.java --- .../cli/logger/LogDelayingProgressBar.java | 2 +- .../de/jplag/cli/logger/TerminalPrinter.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cli/src/main/java/de/jplag/cli/logger/LogDelayingProgressBar.java b/cli/src/main/java/de/jplag/cli/logger/LogDelayingProgressBar.java index dfa4cbb79e..95e0507155 100644 --- a/cli/src/main/java/de/jplag/cli/logger/LogDelayingProgressBar.java +++ b/cli/src/main/java/de/jplag/cli/logger/LogDelayingProgressBar.java @@ -6,7 +6,7 @@ * Superclass for progress bars, that delay the log output until the bar is done */ public abstract class LogDelayingProgressBar implements ProgressBar { - public LogDelayingProgressBar() { + protected LogDelayingProgressBar() { TerminalPrinter.getInstance().delay(); } diff --git a/cli/src/main/java/de/jplag/cli/logger/TerminalPrinter.java b/cli/src/main/java/de/jplag/cli/logger/TerminalPrinter.java index 52e8ddc936..01a8462b15 100644 --- a/cli/src/main/java/de/jplag/cli/logger/TerminalPrinter.java +++ b/cli/src/main/java/de/jplag/cli/logger/TerminalPrinter.java @@ -4,9 +4,16 @@ import java.util.PriorityQueue; import java.util.Queue; +/** + * Prints strings to stdout. Provides the option to delay the actual printing. + */ public class TerminalPrinter { private static TerminalPrinter instance; + /** + * Threadsafe singleton getter + * @return The singleton instance + */ public static TerminalPrinter getInstance() { synchronized (TerminalPrinter.class) { if (instance == null) { @@ -30,6 +37,10 @@ private TerminalPrinter() { this.isDelayed = false; } + /** + * Prints the given string to the terminal appending a line-break + * @param output The string to print + */ public void println(String output) { synchronized (TerminalPrinter.class) { this.outputQueue.offer(output); @@ -37,12 +48,18 @@ public void println(String output) { } } + /** + * Stops printing to the terminal until {@link #unDelay()} is called + */ public void delay() { synchronized (TerminalPrinter.class) { this.isDelayed = true; } } + /** + * Resumes printing if {@link #delay()} was called + */ public void unDelay() { synchronized (TerminalPrinter.class) { this.isDelayed = false; From c2ac19507d173391da9bbeb77bfb1d5bb17871f6 Mon Sep 17 00:00:00 2001 From: Alexander Milster Date: Thu, 11 Jul 2024 12:33:36 +0200 Subject: [PATCH 3/6] Implemented simple test for TerminalPrinter --- .../de/jplag/cli/logger/TerminalPrinter.java | 9 +++- .../jplag/cli/logger/TerminalPrinterTest.java | 51 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 cli/src/test/java/de/jplag/cli/logger/TerminalPrinterTest.java diff --git a/cli/src/main/java/de/jplag/cli/logger/TerminalPrinter.java b/cli/src/main/java/de/jplag/cli/logger/TerminalPrinter.java index 01a8462b15..fe33d8baf1 100644 --- a/cli/src/main/java/de/jplag/cli/logger/TerminalPrinter.java +++ b/cli/src/main/java/de/jplag/cli/logger/TerminalPrinter.java @@ -27,7 +27,7 @@ public static TerminalPrinter getInstance() { } private final Queue outputQueue; - private final PrintStream targetStream; + private PrintStream targetStream; private boolean isDelayed; @@ -67,6 +67,13 @@ public void unDelay() { } } + /** + * Changes the output stream messages are written to + */ + public void setOutputStream(PrintStream printStream) { + this.targetStream = printStream; + } + private void printQueue() { synchronized (TerminalPrinter.class) { if (!this.isDelayed) { diff --git a/cli/src/test/java/de/jplag/cli/logger/TerminalPrinterTest.java b/cli/src/test/java/de/jplag/cli/logger/TerminalPrinterTest.java new file mode 100644 index 0000000000..7430bc0f29 --- /dev/null +++ b/cli/src/test/java/de/jplag/cli/logger/TerminalPrinterTest.java @@ -0,0 +1,51 @@ +package de.jplag.cli.logger; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +class TerminalPrinterTest { + private final static String TEST_MESSAGE = "Hello World"; + + private static ByteArrayOutputStream outputStream; + + @BeforeAll + static void setUp() { + outputStream = new ByteArrayOutputStream(); + TerminalPrinter.getInstance().setOutputStream(new PrintStream(outputStream)); + } + + @AfterAll + static void tearDown() { + TerminalPrinter.getInstance().setOutputStream(System.out); + } + + @AfterEach + void cleanUpAfterTest() { + TerminalPrinter.getInstance().unDelay(); + outputStream.reset(); + } + + @Test + void testDelay() { + TerminalPrinter.getInstance().delay(); + TerminalPrinter.getInstance().println(TEST_MESSAGE); + + Assertions.assertEquals("", outputStream.toString()); + + TerminalPrinter.getInstance().unDelay(); + + Assertions.assertEquals(TEST_MESSAGE + System.lineSeparator(), outputStream.toString()); + } + + @Test + void testDirectPrinting() { + TerminalPrinter.getInstance().println(TEST_MESSAGE); + Assertions.assertEquals(TEST_MESSAGE + System.lineSeparator(), outputStream.toString()); + } +} From 9f2a946ee0f0207fcabbfc63f89dd62e1ee363cf Mon Sep 17 00:00:00 2001 From: Alexander Milster Date: Fri, 19 Jul 2024 13:23:59 +0200 Subject: [PATCH 4/6] Improved code style --- .../de/jplag/cli/logger/CollectedLogger.java | 4 +- .../de/jplag/cli/logger/DelayablePrinter.java | 73 ++++++++++++++++ .../cli/logger/LogDelayingProgressBar.java | 4 +- .../de/jplag/cli/logger/TerminalPrinter.java | 87 ------------------- ...terTest.java => DelayablePrinterTest.java} | 16 ++-- 5 files changed, 85 insertions(+), 99 deletions(-) create mode 100644 cli/src/main/java/de/jplag/cli/logger/DelayablePrinter.java delete mode 100644 cli/src/main/java/de/jplag/cli/logger/TerminalPrinter.java rename cli/src/test/java/de/jplag/cli/logger/{TerminalPrinterTest.java => DelayablePrinterTest.java} (68%) diff --git a/cli/src/main/java/de/jplag/cli/logger/CollectedLogger.java b/cli/src/main/java/de/jplag/cli/logger/CollectedLogger.java index fbcf4929e1..54fdb9d304 100644 --- a/cli/src/main/java/de/jplag/cli/logger/CollectedLogger.java +++ b/cli/src/main/java/de/jplag/cli/logger/CollectedLogger.java @@ -148,7 +148,7 @@ private StringBuilder prepareLogOutput(LogEntry entry) { private void printLogEntry(LogEntry entry) { StringBuilder output = prepareLogOutput(entry); - TerminalPrinter.getInstance().println(output.toString()); + DelayablePrinter.getInstance().println(output.toString()); if (entry.cause() != null) { this.printStackTrace(entry.cause()); } @@ -166,6 +166,6 @@ private void printStackTrace(Throwable error) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); error.printStackTrace(new PrintStream(outputStream)); String stackTrace = outputStream.toString(); - TerminalPrinter.getInstance().println(stackTrace); + DelayablePrinter.getInstance().println(stackTrace); } } diff --git a/cli/src/main/java/de/jplag/cli/logger/DelayablePrinter.java b/cli/src/main/java/de/jplag/cli/logger/DelayablePrinter.java new file mode 100644 index 0000000000..eb00c87e00 --- /dev/null +++ b/cli/src/main/java/de/jplag/cli/logger/DelayablePrinter.java @@ -0,0 +1,73 @@ +package de.jplag.cli.logger; + +import java.io.PrintStream; +import java.util.PriorityQueue; +import java.util.Queue; + +/** + * Prints strings to stdout. Provides the option to delay the actual printing. + */ +public class DelayablePrinter { + private final Queue outputQueue; + private PrintStream targetStream; + + private boolean isDelayed; + + private static final class InstanceHolder { + private static final DelayablePrinter instance = new DelayablePrinter(); + } + + /** + * Threadsafe singleton getter + * @return The singleton instance + */ + public static DelayablePrinter getInstance() { + return InstanceHolder.instance; + } + + private DelayablePrinter() { + this.outputQueue = new PriorityQueue<>(); + this.targetStream = System.out; + this.isDelayed = false; + } + + /** + * Prints the given string to the terminal appending a line-break + * @param output The string to print + */ + synchronized public void println(String output) { + this.outputQueue.offer(output); + this.printQueue(); + } + + /** + * Stops printing to the terminal until {@link #resume()} is called + */ + synchronized public void delay() { + this.isDelayed = true; + } + + /** + * Resumes printing if {@link #delay()} was called + */ + synchronized public void resume() { + this.isDelayed = false; + this.printQueue(); + } + + /** + * Changes the output stream messages are written to + */ + public void setOutputStream(PrintStream printStream) { + this.targetStream = printStream; + } + + synchronized private void printQueue() { + if (!this.isDelayed) { + while (!this.outputQueue.isEmpty()) { + this.targetStream.println(this.outputQueue.poll()); + } + this.targetStream.flush(); + } + } +} diff --git a/cli/src/main/java/de/jplag/cli/logger/LogDelayingProgressBar.java b/cli/src/main/java/de/jplag/cli/logger/LogDelayingProgressBar.java index 95e0507155..b572086f86 100644 --- a/cli/src/main/java/de/jplag/cli/logger/LogDelayingProgressBar.java +++ b/cli/src/main/java/de/jplag/cli/logger/LogDelayingProgressBar.java @@ -7,11 +7,11 @@ */ public abstract class LogDelayingProgressBar implements ProgressBar { protected LogDelayingProgressBar() { - TerminalPrinter.getInstance().delay(); + DelayablePrinter.getInstance().delay(); } @Override public void dispose() { - TerminalPrinter.getInstance().unDelay(); + DelayablePrinter.getInstance().resume(); } } diff --git a/cli/src/main/java/de/jplag/cli/logger/TerminalPrinter.java b/cli/src/main/java/de/jplag/cli/logger/TerminalPrinter.java deleted file mode 100644 index fe33d8baf1..0000000000 --- a/cli/src/main/java/de/jplag/cli/logger/TerminalPrinter.java +++ /dev/null @@ -1,87 +0,0 @@ -package de.jplag.cli.logger; - -import java.io.PrintStream; -import java.util.PriorityQueue; -import java.util.Queue; - -/** - * Prints strings to stdout. Provides the option to delay the actual printing. - */ -public class TerminalPrinter { - private static TerminalPrinter instance; - - /** - * Threadsafe singleton getter - * @return The singleton instance - */ - public static TerminalPrinter getInstance() { - synchronized (TerminalPrinter.class) { - if (instance == null) { - synchronized (TerminalPrinter.class) { - instance = new TerminalPrinter(); - } - } - } - - return instance; - } - - private final Queue outputQueue; - private PrintStream targetStream; - - private boolean isDelayed; - - private TerminalPrinter() { - this.outputQueue = new PriorityQueue<>(); - this.targetStream = System.out; - this.isDelayed = false; - } - - /** - * Prints the given string to the terminal appending a line-break - * @param output The string to print - */ - public void println(String output) { - synchronized (TerminalPrinter.class) { - this.outputQueue.offer(output); - this.printQueue(); - } - } - - /** - * Stops printing to the terminal until {@link #unDelay()} is called - */ - public void delay() { - synchronized (TerminalPrinter.class) { - this.isDelayed = true; - } - } - - /** - * Resumes printing if {@link #delay()} was called - */ - public void unDelay() { - synchronized (TerminalPrinter.class) { - this.isDelayed = false; - this.printQueue(); - } - } - - /** - * Changes the output stream messages are written to - */ - public void setOutputStream(PrintStream printStream) { - this.targetStream = printStream; - } - - private void printQueue() { - synchronized (TerminalPrinter.class) { - if (!this.isDelayed) { - while (!this.outputQueue.isEmpty()) { - this.targetStream.println(this.outputQueue.poll()); - } - this.targetStream.flush(); - } - } - } -} diff --git a/cli/src/test/java/de/jplag/cli/logger/TerminalPrinterTest.java b/cli/src/test/java/de/jplag/cli/logger/DelayablePrinterTest.java similarity index 68% rename from cli/src/test/java/de/jplag/cli/logger/TerminalPrinterTest.java rename to cli/src/test/java/de/jplag/cli/logger/DelayablePrinterTest.java index 7430bc0f29..51063b465c 100644 --- a/cli/src/test/java/de/jplag/cli/logger/TerminalPrinterTest.java +++ b/cli/src/test/java/de/jplag/cli/logger/DelayablePrinterTest.java @@ -9,7 +9,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -class TerminalPrinterTest { +class DelayablePrinterTest { private final static String TEST_MESSAGE = "Hello World"; private static ByteArrayOutputStream outputStream; @@ -17,35 +17,35 @@ class TerminalPrinterTest { @BeforeAll static void setUp() { outputStream = new ByteArrayOutputStream(); - TerminalPrinter.getInstance().setOutputStream(new PrintStream(outputStream)); + DelayablePrinter.getInstance().setOutputStream(new PrintStream(outputStream)); } @AfterAll static void tearDown() { - TerminalPrinter.getInstance().setOutputStream(System.out); + DelayablePrinter.getInstance().setOutputStream(System.out); } @AfterEach void cleanUpAfterTest() { - TerminalPrinter.getInstance().unDelay(); + DelayablePrinter.getInstance().resume(); outputStream.reset(); } @Test void testDelay() { - TerminalPrinter.getInstance().delay(); - TerminalPrinter.getInstance().println(TEST_MESSAGE); + DelayablePrinter.getInstance().delay(); + DelayablePrinter.getInstance().println(TEST_MESSAGE); Assertions.assertEquals("", outputStream.toString()); - TerminalPrinter.getInstance().unDelay(); + DelayablePrinter.getInstance().resume(); Assertions.assertEquals(TEST_MESSAGE + System.lineSeparator(), outputStream.toString()); } @Test void testDirectPrinting() { - TerminalPrinter.getInstance().println(TEST_MESSAGE); + DelayablePrinter.getInstance().println(TEST_MESSAGE); Assertions.assertEquals(TEST_MESSAGE + System.lineSeparator(), outputStream.toString()); } } From 5e89cd726aa926c6aa2c17fd413c987aa3361918 Mon Sep 17 00:00:00 2001 From: Alexander Milster Date: Fri, 19 Jul 2024 13:47:08 +0200 Subject: [PATCH 5/6] Sonarcloud --- .../main/java/de/jplag/cli/logger/DelayablePrinter.java | 8 ++++---- .../java/de/jplag/cli/logger/DelayablePrinterTest.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cli/src/main/java/de/jplag/cli/logger/DelayablePrinter.java b/cli/src/main/java/de/jplag/cli/logger/DelayablePrinter.java index eb00c87e00..f8b1d5fcee 100644 --- a/cli/src/main/java/de/jplag/cli/logger/DelayablePrinter.java +++ b/cli/src/main/java/de/jplag/cli/logger/DelayablePrinter.java @@ -35,7 +35,7 @@ private DelayablePrinter() { * Prints the given string to the terminal appending a line-break * @param output The string to print */ - synchronized public void println(String output) { + public synchronized void println(String output) { this.outputQueue.offer(output); this.printQueue(); } @@ -43,14 +43,14 @@ synchronized public void println(String output) { /** * Stops printing to the terminal until {@link #resume()} is called */ - synchronized public void delay() { + public synchronized void delay() { this.isDelayed = true; } /** * Resumes printing if {@link #delay()} was called */ - synchronized public void resume() { + public synchronized void resume() { this.isDelayed = false; this.printQueue(); } @@ -62,7 +62,7 @@ public void setOutputStream(PrintStream printStream) { this.targetStream = printStream; } - synchronized private void printQueue() { + private synchronized void printQueue() { if (!this.isDelayed) { while (!this.outputQueue.isEmpty()) { this.targetStream.println(this.outputQueue.poll()); diff --git a/cli/src/test/java/de/jplag/cli/logger/DelayablePrinterTest.java b/cli/src/test/java/de/jplag/cli/logger/DelayablePrinterTest.java index 51063b465c..540f9ca083 100644 --- a/cli/src/test/java/de/jplag/cli/logger/DelayablePrinterTest.java +++ b/cli/src/test/java/de/jplag/cli/logger/DelayablePrinterTest.java @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test; class DelayablePrinterTest { - private final static String TEST_MESSAGE = "Hello World"; + private static final String TEST_MESSAGE = "Hello World"; private static ByteArrayOutputStream outputStream; From e8e1368cbe3df878342d183b7b4b9ec8a8a3c73e Mon Sep 17 00:00:00 2001 From: Alexander Milster Date: Fri, 26 Jul 2024 13:45:46 +0200 Subject: [PATCH 6/6] Fixed wrong order of progress bar dispose. --- cli/src/main/java/de/jplag/cli/logger/IdleBar.java | 2 +- cli/src/main/java/de/jplag/cli/logger/TongfeiProgressBar.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/src/main/java/de/jplag/cli/logger/IdleBar.java b/cli/src/main/java/de/jplag/cli/logger/IdleBar.java index acce8fc138..c9aee2da8c 100644 --- a/cli/src/main/java/de/jplag/cli/logger/IdleBar.java +++ b/cli/src/main/java/de/jplag/cli/logger/IdleBar.java @@ -52,7 +52,6 @@ public void start() { @Override public void dispose() { - super.dispose(); this.running = false; try { this.runner.join(); @@ -61,6 +60,7 @@ public void dispose() { } this.output.print('\r'); this.output.println(this.text + ": complete"); + super.dispose(); } private void run() { diff --git a/cli/src/main/java/de/jplag/cli/logger/TongfeiProgressBar.java b/cli/src/main/java/de/jplag/cli/logger/TongfeiProgressBar.java index 067cd160c3..d50ed1f181 100644 --- a/cli/src/main/java/de/jplag/cli/logger/TongfeiProgressBar.java +++ b/cli/src/main/java/de/jplag/cli/logger/TongfeiProgressBar.java @@ -18,7 +18,7 @@ public void step(int number) { @Override public void dispose() { - super.dispose(); this.progressBar.close(); + super.dispose(); } }