This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/master by this push:
     new ba9378d62c Fix #11885: Disable ANSI colors when stdout is piped or 
redirected on JDK 22+ (#11887)
ba9378d62c is described below

commit ba9378d62ce48d54d47753e49f1b6289e8ea752c
Author: Guillaume Nodet <[email protected]>
AuthorDate: Tue May 19 17:25:27 2026 +0200

    Fix #11885: Disable ANSI colors when stdout is piped or redirected on JDK 
22+ (#11887)
    
    Change ForcedSysOut to SysOut so that JLine properly checks whether
    stdout is a TTY before creating a system terminal. ForcedSysOut
    bypasses this check, which causes JLine to create a non-dumb terminal
    even when stdout is piped (since stdin is still a TTY), resulting in
    ANSI escape codes appearing in piped output on JDK 22+ where the FFM
    provider successfully creates a terminal from stdin alone.
    
    With SysOut, JLine detects that stdout is not a TTY and falls back to
    a dumb terminal, correctly disabling ANSI colors.
    
    Co-authored-by: Claude Opus 4.6 <[email protected]>
---
 .../main/java/org/apache/maven/cling/invoker/LookupInvoker.java   | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git 
a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java
 
b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java
index 963d8b1706..5ec158321d 100644
--- 
a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java
+++ 
b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java
@@ -342,7 +342,7 @@ protected void doCreateTerminal(C context, TerminalBuilder 
builder) {
             context.coloredOutput = context.coloredOutput != null ? 
context.coloredOutput : false;
             context.closeables.add(out::flush);
         } else {
-            builder.systemOutput(TerminalBuilder.SystemOutput.ForcedSysOut);
+            builder.systemOutput(TerminalBuilder.SystemOutput.SysOut);
         }
         if (context.coloredOutput != null) {
             builder.color(context.coloredOutput);
@@ -354,12 +354,10 @@ protected void doCreateTerminal(C context, 
TerminalBuilder builder) {
      */
     protected final void doConfigureWithTerminal(C context, Terminal terminal) 
{
         context.terminal = terminal;
-        // tricky thing: align what JLine3 detected and Maven thinks:
+        // Align Maven's color setting with JLine's terminal detection:
         // if embedded, we default to context.coloredOutput=false unless 
overridden (see above)
-        // if not embedded, JLine3 may detect redirection and will create dumb 
terminal.
+        // if not embedded, JLine detects redirection via SysOut and will 
create dumb terminal.
         // To align Maven with outcomes, we set here color enabled based on 
these premises.
-        // Note: Maven3 suffers from similar thing: if you do `mvn3 foo > 
log.txt`, the output will
-        // not be not colored (good), but Maven will print out "Message 
scheme: color".
         MessageUtils.setColorEnabled(
                 context.coloredOutput != null ? context.coloredOutput : 
!Terminal.TYPE_DUMB.equals(terminal.getType()));
 

Reply via email to