Checkstyle and CVS

If, like me, you use checkstyle you may have wished from time to time that everyone on your development team used it too.

So, to satisfy that wish I wrote a script that plugs checkstyle into our version control system (CVS).

With this script you can ensure that code in violation of your coding standards never infects your system.

If you do decide to inflict such a thing on your team please do the decent thing and tell them what you are doing and ensure everyone knows what the guidelines are in advance. If everyone needs to put their import statements in alphabetical order (for example) then everyone should know this. It’s no fun having to fix a bunch of code just before check in, especially when you’re up against a deadline.

Other things about this script to note.

  • It’s a bit elaborate but this is mostly due to checking for files in the Attic directory. The aim of the script is to reduce the number of executions of checkstyle to a minimum, as it’s the slowest part of the system.

  • Java and checkstyle need to be installed on your CVS server.

  • It’s a shell script, your CVS server will need to run Unix (I’m sure it could be ported to a Windows batch script as an alternative though).

  • There may be load issues, each commit (not each file though) fires up a Java process, many concurrent commits may kill the server.

  • People will need a way to run checkstyle locally so they can get it all in line before they commit (I use the Ant task myself).

  • You may be hated by your team.

    It’s probably a good idea to try it out on one project at first (it’s configured on a per project basis) and see how it goes from there.

    To add the script to a project edit commitinfo in your local CVSROOT directory then commit that change to CVS.

    Of course, before you do that you’ll need to install the script on your CVS server.

    So, here is the script.

    Good luck!

  • 9 thoughts on “Checkstyle and CVS”

    1. I am looking for some shell script which can do CVS import. I have a zip files which I want to import automatically by running the shell script, which can take a file as a parameter.

    2. Thanks for the script.
      A quick question.
      The checkstyle tries to parse a property file too during checkin and I am looking to avoid this and make it just work on a java source file.
      Is there is a easy way to do it.

    3. Hi, I have now updated the script so it ignores anything that doesn’t have a .java extension.
      I had not noticed this error as I rarely update my properties files, therefore I hadn’t spotted the fact checkstyle was trying to parse them.

    4. Got it Daren,

      I have resolved those problems,

      Your script is working fine.


    5. Hi, ise it up with your script and it works but always runs on those errors: Unable to get class information for KevusException. Unable to get class information for OpenOfficeException.
      I know this has to happen couse Checkstyle cannot find these classes in cvs, but i really cant fugure out which rule causes this check and how to disable it. Can someone help please?

    6. Hi I am too getting this warning “Unable to get class information for <custom exceptions>” and unable to figure out. I also googled it on the net, but was unable to find a solution. tried using checkstyle 3.5 and 4.0 as well.

    7. Is it possible to limit the operation to specific areas of the repositories, I would like to enforce it for team A but not B which work on the same repository but different modules.


    Comments are closed.