aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Sharing filesets between Checkstyle in Ant and Eclipse Plugin? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Sharing filesets between Checkstyle in Ant and Eclipse Plugin?" Watch "Sharing filesets between Checkstyle in Ant and Eclipse Plugin?" New topic
Author

Sharing filesets between Checkstyle in Ant and Eclipse Plugin?

Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

Does anyone know if it is possible to share filesets between the Checkstyle Ant task and the Checkstyle Eclipse plugin?

In the Checkstyle Eclipse plugin you configure filesets for files you want to include using the GUI in Eclipse and the results get stored in the .checkstyle file that is created in the same location as your .project file. An example of the output in the .checkstyle file is:

So this excludes all files from my "tests/java" folder when running Checkstyle from within Eclipse.

This .checkstyle file is obviously specific just to the Eclipse plugin. So when it comes to running Checkstyle as an Ant task in my build I don't think I can use it the settings from this .checkstyle file. I need to specify the filesets to exclude\include in a different way. So for example in my Ant task I have the following:

This will include all my Java files from my source directory and obviously it will not include the files from my test directory. So this works.

Now I have Eclipse and Ant set up to include (or exclude) the correct files for checking with Checkstyle. However I had to configure them both independently. Does anyone know of a way where I can specify which files to check in one location that will be shared between both the Eclipse plugin and the Ant task?


SCJP (1.4 | 5.0), OCJP (6.0), OCMJD
Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

Any ideas folks?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30764
    
156

Sean,
I haven't tried it, but the Ant plugin page provides a config attribute that points to a config file. That config file contains filters. Is it the same format as the .checkstyle file?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

Hi Jeanne. Yep, there's a config setting where you can point at a file that contains the configuration for Checkstyle. I could be wrong, but my understanding is that this configuration file is for specifying what checks will be carried out. I am indeed able to share this file between the Ant task and the Eclipse plugin.

So in my Ant task I have:

where the {dir.settings} is the .settings directory of my Eclipse project.

Then in my .checkstyle file for Eclipse I have the following:

So you can see that both the Ant task and the Eclipse plugin are referencing the same checkstyle.xml file.

However, my problem is that this checkstyle.xml file doesn't seem to allow you specify which files should be included when these checks are run. So I have to specify them separately in both my .checkstyle file and in my Ant target.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Sharing filesets between Checkstyle in Ant and Eclipse Plugin?