Skip to content

Commit

Permalink
Remove usage of AnsiConsole
Browse files Browse the repository at this point in the history
Init of Ansi system is not needed in Maven plugin.

Additionally, Maven 4 switch to JLine
https://issues.apache.org/jira/browse/MNG-7995
and this class will be not available anymore

Signed-off-by: Slawomir Jaranowski <s.jaranowski@gmail.com>
  • Loading branch information
slawekjaranowski authored and rohanKanojia committed Jun 15, 2024
1 parent 150970d commit c1ff71f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 35 deletions.
9 changes: 1 addition & 8 deletions src/main/java/io/fabric8/maven/docker/util/AnsiLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.apache.maven.plugin.logging.Log;
import org.codehaus.plexus.util.StringUtils;
import org.fusesource.jansi.Ansi;
import org.fusesource.jansi.AnsiConsole;

import static org.fusesource.jansi.Ansi.Color.*;
import static org.fusesource.jansi.Ansi.ansi;
Expand Down Expand Up @@ -244,13 +243,7 @@ private void flush() {

private void initializeColor(boolean useColor) {
this.useAnsi = useColor && !log.isDebugEnabled();
if (useAnsi) {
AnsiConsole.systemInstall();
Ansi.setEnabled(true);
}
else {
Ansi.setEnabled(false);
}
Ansi.setEnabled(useAnsi);
}

private void initializePrintWriter() throws FileNotFoundException {
Expand Down
27 changes: 0 additions & 27 deletions src/test/java/io/fabric8/maven/docker/util/AnsiLoggerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,14 @@
import org.apache.maven.monitor.logging.DefaultLog;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.fusesource.jansi.Ansi;
import org.fusesource.jansi.AnsiConsole;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

/**
* @author roland
* @since 07/10/16
*/
class AnsiLoggerTest {
@BeforeAll
public static void installAnsi() {
AnsiConsole.systemInstall();
}

@BeforeEach
void forceAnsiPassthrough() {
// Because the AnsiConsole keeps a per-VM counter of calls to systemInstall, it is
// difficult to force it to pass through escapes to stdout during test.
// Additionally, running the test in a suite (e.g. with mvn test) means other
// code may have already initialized or manipulated the AnsiConsole.
// Hence we just reset the stdout/stderr references to those captured by AnsiConsole
// during its static initialization and restore them after tests.
System.setOut(AnsiConsole.system_out);
System.setErr(AnsiConsole.system_err);
}

@AfterAll
public static void restoreAnsiPassthrough() {
AnsiConsole.systemUninstall();
System.setOut(AnsiConsole.out);
System.setErr(AnsiConsole.err);
}

@Test
void emphasizeDebug() {
Expand Down

0 comments on commit c1ff71f

Please sign in to comment.