Repository navigation
[maven-3.9.x] Drop JAnsi, emit ANSI colors directly - #13892
slachiewicz wants to merge 3 commits into
Conversation
Maven 3.9.x counterpart of apache#13888: the distribution ships no native library. maven-embedder provides the four org.fusesource.jansi classes that maven-shared-utils links, so core's own copy and every plugin's bundled copy keep working; color in auto mode follows AnsiTerminal's detection instead of JAnsi's installed stream. Legacy Windows conhost needs --color=always now, which is the accepted trade-off.
60c35d7 to
d3ca05b
Compare
gnodet-bot
left a comment
There was a problem hiding this comment.
The stty size subprocess call has no timeout — if /dev/tty is in a bad state, p.waitFor() blocks indefinitely and Maven startup hangs.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
| .start(); | ||
| try (BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()))) { | ||
| String size = r.readLine(); // "rows cols" | ||
| p.waitFor(); |
There was a problem hiding this comment.
p.waitFor() has no timeout. If stty size stalls (e.g. /dev/tty in a bad state or on a container with a misconfigured pseudo-terminal), Maven startup blocks indefinitely.
Consider using the overload with a timeout and a forced kill:
| p.waitFor(); | |
| if (!p.waitFor(5, java.util.concurrent.TimeUnit.SECONDS)) { | |
| p.destroyForcibly(); | |
| } |
gnodet-bot
left a comment
There was a problem hiding this comment.
The stty size subprocess in detectWidth() calls p.waitFor() without a timeout. If /dev/tty is in a bad state or stty hangs, Maven startup will block indefinitely.
Consider using a timeout:
if (!p.waitFor(2, java.util.concurrent.TimeUnit.SECONDS)) {
p.destroyForcibly();
return -1;
}This review was generated by an AI agent, Hermès on behalf of @gnodet.
| try (BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()))) { | ||
| String size = r.readLine(); // "rows cols" | ||
| p.waitFor(); | ||
| return size == null ? -1 : parseWidth(size.substring(size.indexOf(' ') + 1)); |
There was a problem hiding this comment.
p.waitFor() has no timeout. If stty hangs or /dev/tty is in a bad state, Maven startup will block indefinitely.
Consider adding a bounded wait:
| return size == null ? -1 : parseWidth(size.substring(size.indexOf(' ') + 1)); | |
| if (!p.waitFor(2, java.util.concurrent.TimeUnit.SECONDS)) { | |
| p.destroyForcibly(); | |
| return -1; | |
| } |
Maven 3.9.x counterpart of #13888. Maven only needs colored log output, and JAnsi brought a native library and a
System.out/System.errreplacement for what is a handful of escape codes. With this change the distribution ships no native library.org.fusesource.jansi.Ansi,AnsiConsole,AnsiPrintStreamandAnsiMode(the classes from Drop JLine, emit ANSI colors directly #13888 and Fix #13726: add JAnsi compatibility shim to maven-jline and narrow jansi exports in extension.xml #13727).Ansiwrites the escape sequences itself;AnsiConsole.systemInstall()only counts calls and never replacesSystem.out. Core's own maven-shared-utils and every plugin's bundled copy of it link these four classes and nothing else from JAnsi, so they keep working unchanged. A plugin that bundles JAnsi and uses other classes from it (AnsiRenderer,org.fusesource.jansi.io.*) fails on this build, where 3.9.16 served it core's real JAnsi; 3.10.x took the same trade-off in Fix #13726: add JAnsi compatibility shim to maven-jline and narrow jansi exports in extension.xml #13727.AnsiTerminaldetects whether stdout is an ANSI capable terminal (System.console(),Console.isTerminal()on Java 22+,TERM=dumb).MavenCliturns color on inautomode only when a terminal was detected, so embedded runs stay plain (Embedded MavenCli.doMain ignores --color=yes in 3.10.0 #13357) and--color=alwaysstill forces color there.extension.xmlexports the four classes by name instead oforg.fusesource.jansi.*, and keepsorg.fusesource.jansi:jansiexcluded so a plugin that declares JAnsi gets these classes.jansijar,lib/jansi-nativeand-Dlibrary.jansi.pathinmvnandmvn.cmdare gone.Behavior changes:
autocolors only in consoles known to handle ANSI (Windows Terminal, ConEmu, ANSICON, VS Code, orTERMset). In the old console (conhost), use--color=always; JAnsi's translation of escape codes to console API calls is what the native library did, and it is not replaced.--color=alwaysis given.getTerminalWidth()readsCOLUMNS, thenstty sizeon Unix terminals; otherwise -1.Verified:
mvn verify→ 15 modules green, including themvnpath-conversion script; built distribution: nojansiinlib/,mvn -X validatepiped, with-l, with--color=neverand underTERM=dumbprints no escape codes, under a pseudo-tty (script) and with--color=alwaysit prints them, andmvn --color=always teston a JUnit project colors surefire'sTests run:summary through its own realm's maven-shared-utils 3.4.2 with noNoClassDefFoundError. Not run: Windows, and CI.src/site/resources/images/maven-deps.svgstill shows JAnsi; the image is generated and is left for a separate update. apache/maven-shared-utils#451 drops the JAnsi dependency on the library side as well; this change does not depend on it.