Is there a way to call checkstyle from within a Java program?

Andrew :

I have a Java program that creates a list of filepaths I want to run checkstyle on. I was curious if there is a way to directly run checkstyle from within my program or whether I will need to shell out to the CLI.

barfuin :

Yes, that is possible, although it's not so much a documented API, but rather a set of calls that works, and that's kept reasonably stable. In fact, IDE plugins go that way.

For example, the Checkstyle plugin for IntelliJ has some code you can look at to get an idea:
https://github.com/jshiell/checkstyle-idea/tree/5.26.0/src/csaccess/java/org/infernus/idea/checkstyle/service/cmd

It may, however, be easier to just call Checkstyle as a command-line program (via zt-exec, for example) and parse its XML report. That is if you don't need to have the direct feedback provided via in-process AuditListeners.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=94029&siteId=1