2
votes

I am using checkstyle 5.7

I have written a custom FilesFilter as explained in the checkstyle documentation below, http://checkstyle.sourceforge.net/writingfilters.html

As suggested in the documentation, I have written a java file and added an entry for it under "Checker" module in my config xml file. So, this custom filter is supposed to ignore all files containing string "Test" in it's file name.

<module name="com.mycompany.myproject.filters.FilesFilter">
    <property name="files" value="Test" />  
</module>

Due to this entry in the config file, the check style is not loading in eclipse and gives following error,

cannot initialize module FilesFilter - Unable to instantiate FilesFilter

Please help.

1
This post or this other post may help you. - barfuin
Thank you Thomas. This is not exactly a solution, as I suppose, checkstyle should pickup custom filter class from the project class path. Although, I found a work around, which saved hours of work (may be as explained in your posts.) I'll put it as a separate answer below. cheers. - nikhil

1 Answers

0
votes

I think there is no straight solution for this yet. Or may be there is, if you are prepared to invest hours of your time.

Here's what I did as a workaround.

In eclipse, to disable checkstyles for a package (e.g. Test package in my case),

  1. Go to, Project -> Properties -> Checkstyle
  2. On Checkstyle Main tab, there is section "Exclude from checking.." with a set of check boxes.
  3. Select the check box "files from packages:".
  4. Click the "Change.." button in the right hand corner or just double click on "files from packages:"
  5. Select the package you want Checkstyle to ignore. In my case I selected com/myproject/test/ package, and that was it. Checkstyle ignores all files in the test package.

If you are using Checkstyle as an ANT task, you may use excludes option as explained in the following code,

<target name="applyCheckStyle" depends="build" description="--> apply check style to all java files, excluding test package.">
    <checkstyle config="${checkstyle.config}">
        <fileset dir="${src.dir}" includes="**/*.java" excludes="**/test/**" />
        <formatter type="plain" />
        <formatter type="xml" toFile="${build.dir}/checkstyle_errors.xml" />
    </checkstyle>
</target>

This worked for me :)