A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/4340 below:

[core] Allow to filter found matches in CPDReport · Issue #4340 · pmd/pmd · GitHub

Is your feature request related to a problem? Please describe.
The maven-pmd-plugin supports filtering of duplication results via property excludeFromFailureFile.

When upgrading to pmd7 (for #4235) I noticed, that with the new report class CPDReport it is not possible anymore, to filter anything. The CPDReport can only be created by PMD itself (the constructor is package private).

The maven-pmd-plugin takes the found list of matches and filters them before feeding them into one of PMD's CPD renderers.

Describe the solution you'd like
I'd like to add a filter method similar to #3792:

    @Experimental
    public CPDReport filterMatches(Predicate<Match> filter) {
        List<Match> filtered = new ArrayList<>();
        for (Match match : this.getMatches()) {
            if (filter.test(match)) {
                filtered.add(match);
            }
        }

        return new CPDReport(filtered, this.getNumberOfTokensPerFile());
    }

Describe alternatives you've considered
Not tested, but should be possible: In maven-pmd-plugin, we could create a CPDReportFriend in the same package, that can create a new instance of CPDReport. But I don't like this idea, because that's just a workaround.

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