log.debug()are guarded by some
Adding it to the PMD commandline is relatively easy. Put the class in a jar and put it on the classpath:
snert:/devel/tools/pmd-4.2.3 hrupp$ java -cp \
net.sourceforge.pmd.PMD /source/to/check text \
my.jar contains the classes and ruleset.xml the description for this ruleset
Now with Eclipse, things are a bit more complicated. There is a GUI to basically write
the ruleset.xml in the preferences, but how to add the rule class? I am sure, this can be
done via a Feature Extension, but I didn't find a description quickly.
So here is what I did:
- Shut down eclipse
- Locate the PMD core plugin in eclipse/plugins (e.g.
- Copy the rules jar (my.jar from above) to lib/
- Edit plugin.xml and add an entry for the jar:
- Start eclipse with option
- Now go to the Preferences to the PMD->Rules Configuration section, click 'Add rule...' and add an entry for our new rule:
- Start chasing bogus log.debug() usages :-)
This rule is not yet perfect, as it lacks proper type checking for the 'log' variable. It will probably also fail for Statements like "
if (cond1 && log.isDebugEnabled())".
You can find the code here.
Please let me know when you have solved the type checking or how to better integrate it with Eclipse.