Integrations with IDEs

Summary

IDE Package Maintainers
Eclipse pmd-eclipse Tom Burke, Philippe Herlin
Emacs pmd-emacs Nascif Abousalh-Neto
JBuilder pmd-jbuilder Dave Craine
Netbeans/Forte/Sun ONE pmd-netbeans Ole-Martin Mork, Gunnlaugur Thor Briem
JEdit pmd-jedit Jiger Patel
jDeveloper pmd-jdeveloper Tom Copeland
Maven pmd-maven Vincent Massol, Siegfried Goeschl
Gel pmd-gel Tom Copeland
IntelliJ IDEA N/A Tom Copeland
Ant N/A Tom Copeland

Eclipse

Integration into Eclipse is accomplished through the extensive Plugin architecture provided by Eclipse. It is written in Java, and has some nice features to it.

Eclipse Integration will fill the TODO list of the project with each Rule Violation that PMD detects. These violations are marked in the code with the Task icon on the left hand side of the editor.

The Eclipse integration was written with the version 2.0 of Eclipse, so I'm not certain if it will work on earlier versions.

As Eclipse is not my primary IDE, we are looking for people who can make suggestions, and possibly even handle the care and feeding of the Eclipse plugin.

Emacs

Integration with GNU Emacs is performed through an ELisp package, pmd.el. It supports two commands, "pmd-current-buffer" and "pmd-current-dir". The output is captured in a compilation buffer which allows the user to "jump" directly to the source code position associated with the PMD warnings.

Borland JBuilder

To enable this OpenTool in JBuilder, place the PMDOpenTool.jar file AND the pmd-x.x.jar file (where x.x is the version id) into JBuilder's lib/ext directory. Once JBuilder is restart, the PMD OpenTool will be enabled. What you can do:

  • Check a single file by bringing up the context menu from the file tab and selecting PMDCheck
  • Configure the rulesets that the PMD OpenTool will use by selecting Tools->PMD->Configure PMD
  • Check all the files in a project by bringing up the context menu for the project node and selecting PMD Check Project

When running PMD, the results will be displayed in the MessageView under a tab called PMD Results. If you click on a violation message within this view, you will be taken to the line in the source code where the violation was detected.

Things still to do:

  • Enable selection of individual rules within a rule set (maybe)
  • Optional insertion of @todo comments at the point of a violation
  • Possibly provide configurable ability to limit the number of violations per rule per file

JEdit

The way I use the JEdit plugin is:

  • Dock the ErrorList by going to Utilities->Global Options->Docking and putting ErrorList at the bottom of the screen
  • Open the File Browser if it isn't already open
  • Double-click on a source directory
  • Select Plugins->PMD->Check directory recursively

Note that you can select individual rules by going to Utilities->Global Options->Plugin Options->PMD. Also, you can change the plugin to prompt you for a directory to check by going to that same menu and selecting the "Ask for Directory" checkbox.

Maven

Please see the Maven plugins web site for more information.

Gel

Here's how to set up the PMD-Gel plugin:

  • Download the pmd-gel-[version].zip file
  • Close Gel
  • Remove any old plugin versions from your gel\plugins directory
  • Unzip the new zip file into your gel\plugins directory
  • Start Gel
  • Go to Tools->Options->Plugin
  • Select the PMD plugin and click "Remove"
  • Click "Add" and select "net.sourceforge.pmd.gel.PMDPlugin"
  • Restart Gel

That's pretty much it. Now you can open a Java project and click on Plugins->PMD and a configuration panel will pop up. You can pick which ruleset you want to run and you can also pick whether you want to run PMD on the current file or on every source file in your project.

Note that the source code needs to be compilable before PMD can check it.

IDEA

There's not a "real" - i.e., integrated into the same Java VM - plugin for IDEA, but using it as an IDEA External Tool works OK. Here's how to set it up:

  • Open IDEA and go to Tools->IDE Options
  • Select External Tools from the left side menu
  • Click on the Add button
  • Fill in the blocks
    • Name: PMD
    • Description: PMD doth help one clean the code
    • Program: javaw
    • For the next two parameters you'll need to plug in the location of your PMD installation, the rulesets you want to use, and your working directory
    • Parameters: -cp %CLASSPATH%;c:\pmd\lib\pmd-1.2.jar;c:\pmd\lib\jaxen-core-1.0-fcs.jar;c:\pmd\lib\saxpath-1.0-fcs.jar net.sourceforge.pmd.PMD $FilePath$ ideaj rulesets/unusedcode.xml,rulesets/imports.xml $Sourcepath$ $FileClass$.method $FileName$
    • Working directory: c:\

That's pretty much it. Now you can right click on a source directory and select PMD, it'll run recursively on the source files, and the results should be displayed in a window and hyperlinked into the correct file and line of code. I usually right-click on the message window title bar and unselect "autohide" so the window doesn't go away every time I fix something in the code window.

jDeveloper

To install the jDeveloper plugin, download the binary release and unzip it into your jdev/lib/ext directory. Then restart jDeveloper. To use it, open the Tools-&Preferences menu, click on the PMD option, and select a couple of rules to try. To run it, right click on either a Java source file or a .jpr file (i.e., a project file) and select PMD. Any rule violations should show up in a LogWindow at the bottom of the screen.

Ant

Using PMD with Ant is such a standard usage that we hardly think of it as an integration point. But, I guess it is. You can read more about the PMD Ant task here .