Skip to content

[cli] Print PMD analysis summary - #6823

Merged
UncleOwen merged 4 commits into
pmd:mainfrom
DragonFSKY:fix-cli-summary-counts
Jul 5, 2026
Merged

UncleOwen merged 4 commits into
pmd:mainfrom
DragonFSKY:fix-cli-summary-counts

Conversation

@DragonFSKY

@DragonFSKY DragonFSKY commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #1995.

This adds a final PMD CLI summary after analysis using the existing ReportStats counts, for example:

  • Found no violations.
  • Found 1 violation.
  • Found no violations. There was 1 processing error.

The summary is emitted through the CLI reporter, not stdout, so report output remains unchanged whether reports are rendered to stdout or written with --report-file. Exit-code behavior is unchanged.

Tests

  • ./mvnw -pl pmd-cli -am -DskipTests package
  • ./mvnw -pl pmd-cli -am -Dtest=PmdCliTest -Dsurefire.failIfNoSpecifiedTests=false test

@pmd-actions-helper

pmd-actions-helper Bot commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
There are 0 changed duplications, 0 new duplications and 0 removed duplications.
There are 0 changed CPD errors, 0 new CPD errors and 0 removed CPD errors.

Regression Tester Report

(comment created at 2026-07-05 19:06:05+00:00 for 8a4a1ce)

@UncleOwen UncleOwen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried this.

$ ./pmd check --dir=/data/code/pmd/pmd/main/pmd-java/src/main/java -R rulesets/java/quickstart.xml
[WARN] Progressbar rendering conflicts with reporting to STDOUT. No progressbar will be shown. Try running with argument -r <file> to output the report to a file instead.
[WARN] This analysis could be faster, please consider using Incremental Analysis: https://docs.pmd-code.org/latest/pmd_userdocs_incremental_analysis.html
/data/code/pmd/pmd/main/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTAmbiguousName.java:74:      CompareObjectsWithEquals:       Use equals() to compare object references.
[...]
/data/code/pmd/pmd/main/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/ResolutionFailedException.java:102:   LocalVariableNamingConventions: The final local variable name 'PRETTY_PRINTER_CONFIG' doesn't match '[a-z][a-zA-Z0-9]*'
[INFO] Found 101 violations.
$

Works as expected.

$ ./pmd check --dir=/data/code/pmd/pmd/main/pmd-java/src/main/java -R rulesets/java/quickstart.xml --format=text -r out.txt
[WARN] This analysis could be faster, please consider using Incremental Analysis: https://docs.pmd-code.org/latest/pmd_userdocs_incremental_analysis.html
                                                                                                                                                                                                                  
                                                                                                                                                                                                                  
$

Uh... where is the summary?

@DragonFSKY
DragonFSKY force-pushed the fix-cli-summary-counts branch from 7d1adbb to 1e17172 Compare July 4, 2026 12:59
@DragonFSKY

Copy link
Copy Markdown
Contributor Author

Thanks for checking. I moved the summary logging after PMD finishes closing its listeners, so the progress bar cleanup no longer hides it when --report-file is used. I also applied the wording suggestion and added a regression test for this case.

@DragonFSKY

Copy link
Copy Markdown
Contributor Author

@UncleOwen I updated this PR to match the requested wording and to fix the summary visibility issue: summary logging is now after PMD listener cleanup and I added regression coverage for the progress-bar/report-file path.

I also updated the PR description example from Found no violations. And there was 1 processing error. to Found no violations. There was 1 processing error.. Could you please re-check when you have a chance?

@UncleOwen UncleOwen left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'm not a fan of all those telescoping runCli() calls (those tend to grow and become unmanageable over time), that's why I replaced them with a builder pattern.

@UncleOwen UncleOwen added this to the 7.27.0 milestone Jul 5, 2026
@UncleOwen
UncleOwen merged commit 1562570 into pmd:main Jul 5, 2026
13 checks passed
UncleOwen pushed a commit that referenced this pull request Nov 13, 2026
The progressbar uses JLine to determine the terminal width. Under
Windows in git bash (PWD and MSYSTEM are set), JLine uses the exec
terminal provider, which runs "tty.exe" with the inherited stdin of
the forked surefire JVM. As surefire is reading from stdin (command
channel) at the same time, tty.exe doesn't start until that read
completes. This made PmdCliTest hang (locally) or take about 9.5
minutes (in the Windows CI build).

This happened before and was worked around in d1d10d1 by adding
"--no-progress" to the standard arguments of PmdCliTest. The test
reportsSummaryAfterProgressBarWithReportFile (added with #6823)
needs the progress bar and doesn't use these standard arguments, so
the problem came back.

The tests don't need a real terminal, so disable the exec provider
for all pmd-cli tests instead.

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

[core] PMD should display number of rules violated or errors found

2 participants