Implemented solution:
net.sourceforge.pmd.Report
gets two new methods:
Report filterViolations(Predicate<RuleViolation> filter)
: Creates a new report taking all the information from this report, but filtering the violations.Report union(Report other)
: Creates a new report by combining this report with another report. This is similar to "merge", but instead a new report is created.Is your feature request related to a problem? Please describe.
With the latest deprecations (#3692, #3762) Report should not be instantiated anymore. However, in maven-pmd-plugin, there is one use case: The plugin supports an own mechanism to exclude violations (https://maven.apache.org/plugins/maven-pmd-plugin/examples/violation-exclusions.html). These exclusions are applied after PMD is run and the violations are simply deleted from the report.
Currently this is implemented in PMDCollectingRenderer where the violations are collected in a mutable list and at the end a new report is created (see asReport()
).
The exclusion happens here: https://github.com/apache/maven-pmd-plugin/blob/e6fd0db79767b7f15db24cba6b9ce689db0b7f3b/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java#L301 - the returned list from the renderer is modified.
PMDCollectingRenderer could extend from AbstractAccumulatingRenderer, however then the given report
must be used. This returns an unmodifiable List for the violations (
).
maven-pmd-plugin is therefore not able anymore to remove violations after PMD has run and before the report is rendered (into xml, html, ...).
Describe the solution you'd like
Provide a method to remove violations from the report. A simple impl could look like this:
public void excludeViolations(List<RuleViolation> excludedViolations) { violations.removeAll(excludedViolations); }
Describe alternatives you've considered
filterViolations(Predicate)
(note: this is java8...)Additional context
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4