There are two ways to use the PMD plugin :
PMD violations are reported as markers. To show them, look in the "Tasks" view. They appear as traditional problem markers at the rule corresponding level. PMD rules have 5 levels and Eclipse markers have 3 levels. There is the correspondance :
Finally, rules can be selected on a per project basis. The PMD preferences enable a full configuration of rules to be used. Then only a subset of these rules can be selected on each project.
This is the simplest way to use PMD. On a project properties dialog, switch to the PMD page. Click on the "Enable PMD" check box to activate PMD for this project.
When the dialog is closed, PMD is executed against all the files in the project. Then, when a file is modified or added, PMD will be executed only on this file.
If you choose not to use PMD as an incremental builder, you can execute PMD once when you want against a project, a folder or a file.
First, select projects, folders or files, then choose "Check Code With PMD" on the context menu. A progress indicator informs about the execution of PMD.
To select only a subset of the configured rules, just open the project properties. Select the PMD category. A table shows all configured rules, with their priority and description. Simply check or uncheck the check box at the left of each rule to select or unselect it.
This feature is available what ever the utilization of PMD, either as an incremental builder or manually.
Basically, violations are reported as "problem markers" so that they can be viewed in the task view and in the impacted source file. This is the natural way in Eclipse to report problems, errors or warning. If violations are not wanted in the task view, the plugin comes with a specific view that shows only PMD violations. To open that view, select "PMD violations" in the "PMD" category when selecting Window->Show view->Other...
To hide PMD violations in the task view, open its filter dialog and deselect the "PMD Marker" and "PMD Task Marker".
The PMD violation view works like the tasks view. It shows all violations whith their main data :
By default, violations are ordered by their priority (1, 2...). To change the ordering, click on the desired column. The ordering columns are Priority, Rule, Class, Package and Project.
It is possible to filter violations, either by their prority level or by the resource type. To filter
violations by their prority level, use the
,
,
,
and
buttons to select the corresponding priority level. If the button is pressed, the corresponding violations are shown ;
if the button is released, the corresponding violations are hidden. The same effect is achieved by selecting
the desired filters in the view context menu "Filter by priority".
The violations can also be filtered by resource type. If the
button is selected, then only the violations for the current project are shown. If the
button is pressed, then only the violations for the selected file are shown. The same effect is achieved by selecting
the desired filter in the context menu "Filter by resource". The "Project" and "File" filters are mutually
exclusive.
For any violations, it is possible to delete them. Simply select the desired violations, then either press
the "Del" key, or select the "Remove violation" from the context menu or press the
,
in the view task bar.
Finally, it's possible to review the rule description and sample. Select a violation and choose "View rule" in the context menu. Also, by double-clicking a violation, an editor on the targeted source file is open with the cursor placed on the line pointed by the violation.