Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check style arbitrary list of java files from command line?

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.

like image 560
shabunc Avatar asked Dec 12 '22 05:12

shabunc


1 Answers

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

like image 66
SubOptimal Avatar answered Jan 12 '23 23:01

SubOptimal