Skip to content

[core] Progress reporting #3828

@oowekyala

Description

@oowekyala

Is your feature request related to a problem? Please describe.
It would be nice for the CLI to report progress in real time. Something like a progress bar filling up and a number of violations updated live.

Describe the solution you'd like
I think this can be built into an analysis listener in PMD 7 and performed transparently. Note that implementing this will also require implementing a way to disable it, eg with a --batch-mode flag. CI runs for instance will probably not want to report progress.

Describe alternatives you've considered
Just logging processed file names in real time is good for a log file, but too verbose for an end-user. See #3816

Additional context
IDE integrations would probably want a way to check progress and also cancel the PMD run. Eg in the Intellij API there is this interface IIRC

interface ProgressIndicator {
   boolean isCancelled();
   // other methods to eg set current progress percentage
}

which is checked regularly to abort the current tasks if it was cancelled. I don't think we actually need to include and publish such an API, as it would be easy to implement the same functionality with a listener:

class MyCancelListener implements GlobalAnalysisListener {
    ProgressIndicator indicator;
   
    FileAnalysisListener startFileAnalysis(TextFile file) {
        if (indicator.isCancelled()) throw new AnalysisAbortedError();
        return FileAnalysisListener.noop();
    }

   static class AnalysisAbortedError extends Error { }
}

and catch the error above where you call PMD. Same for live progress reporting, it's very easy to build a listener that will get events when there's a new violation or new file being processed and update a progress bar in an IDE control. For our CLI, we need to avoid interleaving error messages with the progress bar though, so some first-class support in our MessageReporter (#3822) may be necessary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    an:enhancementAn improvement on existing features / rulesin:cliAffects the PMD Command Line Interface

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions