问题
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.
回答1:
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.
回答2:
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
来源:https://stackoverflow.com/questions/7243190/checkstyle-and-findbugs-for-changed-files-only-on-jenkins-and-or-hudson