Skip to content

[MDEP-562] Auto-select dependency tree tokens for capable consoles - #1698

Closed
wilx wants to merge 2 commits into
apache:masterfrom
wilx:issue-997-auto-tree-tokens
Closed

wilx wants to merge 2 commits into
apache:masterfrom
wilx:issue-997-auto-tree-tokens

Conversation

@wilx

@wilx wilx commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

This is a draft because the implementation seems way too involved for choosing tree branch characters. There should be a better way for Maven to give plugins information about its logging output capabilities, particularly the effective encoding and whether logging targets a console or a file. A supported Maven API for this would be preferable to making each plugin inspect logger implementations, stream identity and optional terminal-library versions.

Fixes #997 (MDEP-562).

Behavior

When tokens is omitted, text trees use the existing extended box-drawing tokens if Maven is logging to an interactive terminal whose output encoding can represent all four branch characters. This supports UTF-8 and compatible legacy encodings such as CP437 and CP850. Detection reads Maven's existing JLine or Jansi metadata without installing a terminal, changing console settings or adding runtime dependencies.

Explicit -Dtokens=standard|extended|whitespace settings take precedence and bypass detection. Automatic selection keeps ASCII for outputFile, -l/--log-file, batch mode, redirected output, dumb terminals and unavailable or ambiguous metadata. Forced color does not override those checks. Other output formats are unchanged, and the Java 8 / Maven 3.6.3 minimum remains unchanged.

Why this remains a draft

Maven 3.6.3's Jansi does not expose sufficient public metadata, so automatic selection remains ASCII there. Maven 4 also retains that fallback: both current 4.0.x and 4.1.x/master expose the JLine terminal but do not expose the active logging destination through a plugin-accessible API. A terminal can be present while the logger writes to a -l file. The logger has a package-private logSink and a public setter, but no getter; the CLI selects the actual writer separately. The implementation avoids inspecting private fields.

This limitation is documented in ConsoleSupport and the goal documentation. Explicit extended tokens still work on those Maven versions. The draft is intended to support discussion of a Maven-level capability API and whether this amount of plugin-side detection is appropriate.

Validation

  • Regression tests were written and observed failing before the corresponding implementation changes.
  • mvn clean verify -Prun-its: all 103 integration builds passed.
  • After the final runtime changes, mvn verify -Prun-its '-Dinvoker.test=tree*': 465 unit tests, zero failures/errors, one existing skip; all nine tree integration builds passed.
  • Linux pseudo-terminal and redirected-output checks covered Maven 3.6.3 / Java 8, Maven 3.8.8 / Java 8, Maven 3.9.16 / Java 17 and 21, Maven 3.10.0-rc-1 / Java 21, and Maven 4.0.0-rc-6 / Java 21. Checks included explicit styles, batch mode, -l, forced color, separate stdout/stderr, and ASCII / CP437 / CP850 encodings. The final artifact passed all 20 final runtime checks.
  • Maven 4.0.x and 4.1.x/master were additionally inspected at 9a2aa9b036 and a98d8fa111; the relevant logger implementation is identical. These branch tips were not runtime-tested.
  • mvn spotless:apply spotless:check and git diff --check passed. The subsequent class Javadoc note changes no runtime behavior.
  • Native Windows and macOS console behavior has not been exercised.

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body.
    Note that commits might be squashed by a maintainer on merge.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
    This may not always be possible but is a best-practice.
  • Run mvn verify to make sure basic checks pass.
    A more thorough check will be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its verify).

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

Use existing Jansi and JLine metadata to select extended tokens while preserving explicit overrides and ASCII output for files, pipes, batch mode, and unknown capabilities. Keep Java 8 and Maven 3.6.3 compatibility.

Fixes apache#997.
Explain why the exposed JLine terminal cannot identify the active logger destination when -l redirects output to a file. Document the conservative ASCII fallback and the supported explicit token overrides.

Fixes apache#997.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MDEP-562] Make extended tokens default for displaying trees

1 participant