I'm writing a utility which checks Atlassian Stash pull requests for modified files - the goal is to run each Java file through Checkstyle (or Findbugs, or PMD), and then have the plugin comment on each line with problems.
To accomplish this, the plugin must run the contents of each modified Java file in the request through Checkstyle (or other code style enforcement utility). The Atlassian Stash API makes it quite easy to get the contents of modified files, but it doesn't appear possible to run those contents through Checkstyle programmatically - the only way to do it would be to save a temp file on disk and run the Checkstyle jar against it by calling a Runtime.getRuntime().exec(...)
command.
Are there any simplified Checkstyle-like utilities which can be run programmatically using a Java API?
I essentially need something that can do something like this:
String contentsOfJavaFile = ; //stuff
List<Problem> problems = CheckstyleOrSomethingElse.analyze(contentsOfJavaFile);
for(Problem p : problems) {
// p.getLine();
// p.getDescription();
// add comment to Stash
}