PMD

All

Intro

Learning a bit more about statical validation of JAVA code ~ as a counterpart for Lint my python scripts, then it would be unavoidable to look for issues on my code.

PMD

So as a first statical validation tool, the basic features below:

Running

You can run PMD in Windows and Linux, after installing, ofc. Below the running with basic quickstart rules that comes within the tool:

~~~

  522  ./run.sh pmd -d /c/Users/TechPro/Desktop/lugano -rulesets rulesets/java/quickstart.xml,category/java/codestyle.xml > output1.txt

  523  pmd -d /c/Users/TechPro/Desktop/lugano -f text -R rulesets/java/quickstart.xml> output2.txt

~~~

Creating/Changing Ruleset

After running sometimes you can see that some rules are not necessary, so then you edit the ruleset:

~~~

<rule ref=”rulesets/java/basic.xml/EmptyCatchBlock”

  message=”Must handle exceptions”>

    <priority>2</priority>

</rule>

~~~

Creating new rules 

But then, you need to create some new rules, like this one here, which validates a string that I’m creating.

To create a new rule, basically just run the designer, which comes with bin directory of PMD. As below:

~~~

./run designer

~~~

To create the rule, you will need to create a rule on the XPath Expression, which is done by the AST tree validation, as below:

designer2.JPG

REFs

~

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s