Tuesday, 27 March 2018

Working with PMD in Eclipse

In this post, you are going to learn.
a.   What is PMD?
b.   Languages supported by PMD
c.   What can I do with PMD?
d.   What are the features of PMD?
e.   Install PMD Eclipse plugin
f.    Configure PMD in Eclipse
g.   Find the bugs using PMD
h.   How to generate reports using PMD?

What is PMD?
PMD stands for 'Programming Mistake Detector', it is an open source static source code analyzer.

Languages supported by PMD
At the time of writing this article, PMD supports below languages.

a.   Java
b.   JSP
c.   JavaScript
d.   Salesforce.com Apex and Visualforce
e.   PLSQL
f.    Apache Velocity
g.   XML and Maven POM
h.   XSL

What can I do with PMD?
By using PMD, you can identify the common programming flaws done by the developers.

For example, you can identify,

a.   Unused variables
b.   empty try/catch/finally/switch blocks
c.   unnecessary object creations
d.   duplicated code
e.   dead code (unused local variables, private methods, parameters) etc.,

What are the features of PMD?
a.   Supporting 8 languages (Java, JSP, JavaScript, Salesforce.com Apex and Visualforce, PLSQL, Apache Velocity, XML and Maven POM, XSL).
b.   Many ready-to-use built-in rules.
c.   Custom rules can be written in Java
d.   Custom rules can be written using XPath expression that query the AST of the sources
e.   Many output formats
f.    Many integrations into IDEs, build tools

Install PMD Eclipse plugin
Open Eclipse.

Help -> Install New Software.


Work with below url.


Select ‘PMD for Eclipse 4’ and press Next. Follow the next steps in the GUI.

Once installation is successful, restart the eclipse.

Configure PMD in Eclipse
Window -> preferences -> PMD

It opens window like below.
Find the bugs using PMD
Right click on the project -> PMD -> Check Code.
Now, you can able to see all the violations in ‘Violations overview’ Section.
By any chance 'Violations Overview' is not opened, then you can open by going through below path.
Window->Show View->Other->PMD->Violations Overview

How to generate reports using PMD?
Right click on the project -> PMD -> Generate Reports

Now you can see the generated reports in 'reports' folder inside the project folder.

You can always selects the reports format by changing the report format.
Window -> Preferences -> PMD -> Reports.
Reference

You may like


Previous                                                    Next                                                    Home

No comments:

Post a Comment