I want to have an opportunity to pass the list of *.java files in commit/changeset to the pre-commit hook which will check those java files for code style.
I've tried to use maven-checkstyle-plugin but it looks like it is not possible to pass to it an arbitrary list of files. Also, running mvn site
builds reports which are not supposed to be used exclusively like a human-readable entity, so it is not trivial to use this report in python scripts (which mercurial hooks basically are).
So the question is: how to check-style an arbitrary list of *.java files in command-line (just like we are checking arbitrary list of python files with pep8, or javascript files with jshint/jslint)?
By style-checking I mean not only printing report to stdout but returning somehow the final result - whether files had or had not passed the guidelines.
if I understand rightly, you want to check not all Java sources in the project, only some specific files?
# this checks all *.java sources
mvn checkstyle:checkstyle -Dcheckstyle.includes=**\/*.java
# this checks only sources matched by Foo*.java
mvn checkstyle:checkstyle -Dcheckstyle.includes=**\/Foo*.java
# this checks only sources matched by Foo*.java and the source Bar.java
mvn checkstyle:checkstyle -Dcheckstyle.includes=**\/Foo*.java,**\/Bar.java
In all cases the result will be
# for your further automatic processing
target/checkstyle-result.xml
# for humans to read
target/site/checkstyle.html
cheers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With