2748109647 opened a new pull request, #14142:
URL: https://github.com/apache/maven/pull/14142

   Closes #14141
   
   ### Summary
   - Override `render(final String text)` and `render(final String text, 
Object... args)` in `org.fusesource.jansi.Ansi.NoAnsi` 
(`compat/maven-embedder/src/main/java/org/fusesource/jansi/Ansi.java`) so 
`Ansi.ansi().render(...)` strips `@|codes text|@` markup cleanly when ANSI 
color is disabled (`MessageUtils.isColorEnabled() == false`, e.g., `-B`, 
`-Dstyle.color=never`, no terminal installed, or `Ansi.setEnabled(false)`).
   - Validate style codes via `org.jline.jansi.AnsiRenderer.Code.valueOf(...)` 
using a private helper (`renderPlain`) without mutating global 
`org.jline.jansi.Ansi.setEnabled(...)` state or duplicating preceding text on 
trailing unclosed/no-space `@|` tokens.
   - Add unit tests in 
`compat/maven-embedder/src/test/java/org/fusesource/jansi/AnsiTest.java` 
covering disabled color via `MessageUtils.setColorEnabled(false)`, absent 
terminal, `Ansi.setEnabled(false)`, formatted arguments, invalid/edge-case 
markup inputs, and enabled ANSI rendering.
   
   ### Root Cause
   `Ansi.ansi()` returns `NoAnsi` whenever `Ansi.isEnabled()` is `false` 
(`MessageUtils.isColorEnabled() && org.jline.jansi.Ansi.isEnabled()`). While 
`NoAnsi` overrides individual color/attribute/cursor/reset methods as no-ops, 
it previously inherited `Ansi.render(...)`, which delegated to `new 
org.jline.jansi.Ansi().render(text)`. That JLine call uses 
`org.jline.jansi.Ansi.isEnabled()` internally and ignores 
`MessageUtils.isColorEnabled()`, emitting literal ANSI escape codes 
(`\u001b[...m`).
   
   ### Compatibility & Backport
   - Public API and enabled-color output remain unchanged.
   - Targets `master`; maintainers may wish to backport this fix to 
`maven-4.0.x` (`maven-3.10.x` already dropped JLine in #13888).
   
   ### Verification
   - Reproduction before fix: disabled-color cases in `AnsiTest` failed because 
`NoAnsi.render(...)` emitted literal ANSI escape codes (e.g., 
`\u001b[31mError\u001b[m: file.xml (2)`).
   - After fix:
     - `mvn -B -ntp -o -T 1C -pl compat/maven-embedder -am spotless:apply 
checkstyle:check apache-rat:check test` -> `BUILD SUCCESS` across all 41 
reactor modules in scope:
       - `maven-embedder`: `117` tests run, `0` failures, `0` errors, `2` 
preexisting skipped in `MavenCliTest$EmbeddedColor` (`AnsiTest`: `6/6` passed; 
`AnsiConsoleTest`: `5/5` passed)
       - `maven-core`: `ExtensionDescriptorBuilderTest` `4/4` passed
       - `spotless:apply`: `0` files modified; `checkstyle:check`: `0` 
violations; `apache-rat:check`: no issues found
     - `git diff --check`: passed (no whitespace errors)
   - Scope / Limitations:
     - Verified in offline unit-test scope (`-pl compat/maven-embedder -am`); 
modules downstream of `compat/maven-embedder` and `-Prun-its verify` 
integration tests were not executed.
   
   ---
   
   To make clear that you license your contribution under
   the [Apache License Version 2.0, January 
2004](https://www.apache.org/licenses/LICENSE-2.0)
   check one of the following:
   
   - [x] I hereby declare this contribution to be licensed under the [Apache 
License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
   - [ ] I hereby declare that I have filed an [Apache Individual Contributor 
License Agreement](https://www.apache.org/licenses/icla.pdf).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to