Checkstyle and Findbugs for changed files only on

2019-04-08 14:34发布

We work with a lot of legacy code and we think about introducing some metrics for new code. Is it possible to let Findbugs and Checkstyle run on changed files only instead of a complete project?

It would be nice to assure that only file with a minimum of quality is checked in, but the code base itself is not (yet) touched and evaluated not to confuse people by thousands of issues.

2条回答
老娘就宠你
2楼-- · 2019-04-08 14:40

Findbugs has ant tasks that can do diffs against different findbugs results to see just the deltas, so only reporting new bugs, see

http://findbugs.sourceforge.net/manual/datamining.html

查看更多
戒情不戒烟
3楼-- · 2019-04-08 14:45

In theory, it would be possible. You would use a shell script to parse the SVN (or whatever SCM) change logs after a given start date, identify the .java files from these change sets and build two patterns from these:

  • The Findbugs Maven Plugin expects a comma-separated list of class (or package) names for the parameter onlyAnalyze, so you'll have to translate file names to fully qualified class names (this will get tricky when you're dealing with inner classes)
  • The Maven Checkstyle Plugin is even worse, it expects a configuration file for its packageNamesLocation parameter. Unfortunately, only packages are allowed, not individual files. So you'll have to translate file names to packages.

In the above examples I assume that you are using maven. I am pretty sure that similar things can be done with ant, but I wouldn't know.

I myself would probably use a Groovy script instead of a shell script to achieve the above results.

查看更多
登录 后发表回答