Is there a way to run Checkstyle only on .java files WITHOUT ANT?

I am trying to get a Checkstyle for any type of file, but ignore anything that is not a .java file. I created a filter, but it doesn't seem to work:

public class DotJavaFilter extends AutomaticBean implements Filter { public DotJavaFilter() throws PatternSyntaxException { } public boolean accept(AuditEvent aEvent) { final String fileName = aEvent.getFileName(); return fileName.endsWith(".java"); } } 

I would like to provide a CS directory of files and handle only .java.

+7
source share
1 answer

You can run it on the command line as follows:

 java -jar checkstyle-5.5-all.jar -c docs/sun_checks.xml -r /path/to/src 

If you use bash, you can enable globstar and then only process java files as follows:

 shopt -s globstar java -jar checkstyle-5.5-all.jar -c docs/sun_checks.xml -r /path/to/src/**/*.java 

Checkstyle command line documentation is here .


Update: Use Suppression Filter

Create a bans file that should ignore all class file checks. You can add regular expressions for other types of files that you are not interested in either.

suppressions.xml:

 <suppressions> <suppress checks="." files=".*\.class"/> </suppressions> 

Add a confirmation filter to the verification file:

my_checks.xml:

 <module name="SuppressionFilter"> <property name="file" value="suppressions.xml"/> </module> 

Run it:

 java -jar checkstyle-5.5-all.jar -c my_checks.xml -r /path/to/src 

Suppression filter documentation can be found here .

+6
source

All Articles