The configuration of the PMD Plugin consists of the selection and configuration of the rules you want to use.
The configuration facility lets you select only the rules you want and edit their properties such as the priority or the properties value. You can also modify other rule attributes such as the description, the violation message and a sample code.
The configuration system allows to declare new rules, XPath rules for instance, or import rules definition from external rule sets.
Finally, there's also a feature to export the configured rules in a external rule set.
To sum up, the configuration of the plugin is a complete rule set definition workbench.
To configure the plugin, open the preferences dialog (Window-→Preferences) and select the PMD→Rules Configuration category.
A table containing all the rules currently in use is displayed and show rules name, priority and description. If the description is not entirely visible let the mouse over the cell and a tooltip window will appear with the description text. The bottom table contains the properties of the rule selected in the top table.
When the plugin is first installed, the default rules are those from the basic, design, imports and unused rule sets.
To change the priority, simply direct edit the priority cell and select the desired priority level from the dropdown list. You can select value from "Information" to "Error high" which respectively corresponds to priority from 5 to 1.
Rules properties value is edited the same way. When a rule is selected in the top table, its properties are displayed in the bottom table. You can direct edit the property value cell to change the property value.
Also, pressing the "Add property..." button on the right of the property table lets you add property to the rule. A dialog window appears to ask the new property name. The new property is added to the table with an empty string as value. Then the property value can be changed by direct editing the value cell.
The rule description, violation message and example can also be modified.
Select a rule in the table, then press the "Edit rule..." button. A dialog lets you change these values. The rule name and class although cannot be changed.
There are two way to add rules to the list : either by adding new rules or by importing a rule set file description.
To add a new rule, simply click the "Add rule..." button. A dialog appears to let you enter a name, a implementation class, a message that will be displayed in case of a violation of that rule, a complete description and finally an example.
On validation, the rule priority will be set to 3 (Warning high); then it may be modified by direct editing the priority cell in the rule table.
If the new rule is to be a XPath rule, then check the "XPath rule" checkbox. The implementation class field is automatocally filled with the correct class and the "xpath" priority is automatically added to the rule. After creating the rule, fill the xpath property by direct editing the value cell in the property table.
Instead of creating rules, it may be simpler to import already existing definitions.
Press the "Import rule set..." button. A dialog appears that let you enter the name of a rule set file. The rule set may be a standard rule set. In that case, select it in the drop down list.
The rule set may be an external rule set. Push the "Browse..." button to walkthrough the file system to select the desired rule set.
If a rule is no more wanted, then simply select it and press the "Remove rule" button.
The table can be entirely cleared by selecting the "Clear all" button. This can be used to build a new rule set for example.
If you're satisfied of your new configuration, share it with your team by exporting the rule set.
Press the "Export rule set..." button. A dialog let you spectify the location and file name of the rule set. Normally, the file should have the ".xml" extension.
After specifying the file, a input dialog proposes to enter a description. It is the description of the rule set.
The name of the generated rule set will be the file name without its extension.
As the exported file is a standard PMD rule set, it can be used with other implementation of PMD.