PMD Plugin for Idea
What is PMD Plugin?
PMD Plugin integrates PMD static analysis tool in intelliJ. The plugin will support all the pre defined rulesets as well as custom rulesets. The user can run pmd on a single or set of files/folders and see the results in intelliJ. Also all the common functionality in idea like navigating to source etc can be done on the results.
How to invoke?
To run the predefined rulesets on the currently open file, go to Tools -> Run PMD -> PreDefined menu. It will list all the supported rulesets. The user can select the required rules to be run. Also the option 'All' will run all the predefined rulesets.
The user can also right-click any folder/package and run PMD on all the source files in the package/folder.
From version 1.4.7 onwards, the plug-in supports execution of PMD on a Changelist. Right-click on any change list (or changed file) and the PMD menu item will appear.
How to analyze results?
After running PMD (on single or multiple files) the results will be shown in a result panel.
The results are organized according to the rulesets which are done. For example, all the violations related to import issues will be in the imports folder. Also the number of violation in each category and total and listed. Also note the common toolbar actions on the left which are available with most intelliJ tools like ReRun, AutoScroll to source etc. You can expand the nodes and select a particular violation to navigate to source. It will show the location on the source file where the issue was found.
In addition to locating the problem, the rule can be suppressed.
For example, the above rule which is 'Only one return is allowed for a method' may be too restrictive, so it can be suppressed. You can right-click the rule and select 'Suppress' (This will add the pmd special comment - //NOPMD on the problem line on the source file). After this you can rerun the analysis and this violation will be ignored.
Also, by clicking on the 'Details' a detailed explanation of the selected rule will be shown in a browser (which is in PMD website). The Rule and violation nodes also has a tooltip which provides concise notes about the rules.
How to add custom ruleset?
PMD supports custom ruleset file, where the user can group together or add his own rules. This plugin supports such rule sets. Go to settings -> PMD and add the rule set files that are required. Now menu items will appear under Tools -> PMD -> Custom for the rulesets added and they can be run.
Please report to me: amit3dev-at-yahoo.com