With Checkstyle it is possible to create own checks and make them available to Checkstyle. This Chapter explains how to configure Checkclipse to use this custom checks and how to build the jars with custom checks, so they perfectly fit to Checkclipse.
There are three different ways to make custom checks known to Checkclipse. They will be explained in the following sections.
On the properties page of the project you can add one or more custom jars in the field "Jar Files with additional checkstyle checks". Just hit the
button and select the jar you want to add. The jar must be located somewhere in the workspace.This is expecially useful, if you created a check that is specific for the current project or if you want to distribute the source of your project.
Advantage
Tied to your project source. If you distribute the source, the custom checks are distributed with it.
Useful for project-specific checks.
Disadvantage
Configuration has to be done for every project.
You can make your custom checks known to checkstyle using a Plug-In Fragment. See here for documentation.
Advantage
Checks globally available to Checkclipse/Checkstyle.
Indepentant of Checkclipse updates.
The plugin directory contains a subdirectory named
"extension-lib". Jar files placed in this directory are
automatically picked up at runtime and the contained checks are
available to Checkstyle. The plugin directory is located at
(with the appropriate version number).Eclipse Install
Directory
/plugin/de.mvmsoft.checkclipse_2.0.0
Advantage
Checks globally available to Checkclipse/Checkstyle.
Disadvantage
Has to be redone after a Checkclipse update.
It is possible to write a custom check that doesn't work if the jar is configured in one of the above ways. This is namly if the check replicates the original package structure of Checkstyle to get access to package local classes or methods. In this cases Checkclipse will report, that an IllegalAccessError has occured during checking. Then the jar with the custom Checks has to be added to the plugins classpath directly.
Stop eclipse
Change to the plugin directory
Eclipse Install
Directory/plugin/de.mvmsoft.checkclipse_2.0.0
.
Place the jar file with your check in the subdirectory
lib
.
Edit the file plugin.xml
to
add your jar to the plug-ins classpath:
<?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.0"?> <plugin id="de.mvmsoft.checkclipse" name="Checkclipse Style Checker" version="2.0.0" provider-name="Marco van Meegen" class="de.mvmsoft.checkclipse.CheckclipsePlugin"> <runtime> <library name="checkclipse.jar"/> <library name="lib/checkstyle-all-Version.jar" /> <library name="lib/checkstyle-optional-Version.jar" /> <library name="lib/myChecks.jar"> </runtime> ...
Restart Eclipse. You might need to use the command line
parameter -clean
, so
that Eclipse is forced to pick up the changed plugin.xml
file.
Advantage
Checks globally available to Checkclipse/Checkstyle.
Disadvantage
Has to be redone after a Checkclipse update.