PMD Integration with JDeveloper through Ant External Tools

In the past I read following blogs from Shay Shmeltzer:

Now (after little code change in pmd) this integration is possible. I use here JDeveloper 11.2.0.4, with other versions this should be very similar. Now let’s start:

1. Create a new folder
2. Download PMD 5.0.4
3. Extract the zip file into the created folder
4. Create a file pmd.xml into the created folder
5. Enter following code into the file pmd.xml:

<?xml version="1.0" encoding="windows-1252" ?>
<project xmlns="antlib:org.apache.tools.ant" name="Project1" default="all" basedir=".">
    <path id="classpathForPMD">
        <fileset dir="pmd-bin-5.0.4\lib">
            <include name="**/**.jar"/>
        </fileset>
    </path>
    <taskdef name="pmd" classpathref="classpathForPMD" classname="net.sourceforge.pmd.ant.PMDTask"/>
    <target name="pmdAll">
        <echo message="PMD is running on directory ${dir}" level="info"/>
        <pmd rulesetfiles="rulesets/internal/dogfood.xml" failOnRuleViolation="true" minimumPriority="1">
            <fileset dir="${dir}">
                <include name="**/src/**/*.java"/>
            </fileset>
        </pmd>
    </target>
    <target name="pmd">
        <echo message="PMD is running on file ${dir}\${file}" level="info"/>
        <pmd rulesetfiles="rulesets/internal/dogfood.xml" failOnRuleViolation="true">
            <fileset dir="${dir}">
                <include name="${file}"/>
            </fileset>
        </pmd>
    </target>
</project>

6. Select Tools – Exernal Tools from the JDeveloper menu
7. Press Button New
8. Select Tool Type: Apache Ant
9. Select your created pmd.xml file in Ant Buildfile:

10. Shuttle target pmdAll to SelectedTargets

11. Add Property dir with value ${file.dir}

12. Skip the Options and Process Step to leave the defaults
13. Add the lib directory of pmd as additional classpath entry

14. Enter Caption and Icon as you want

15. Add the tool to the Navigator Context Menu and Main Toolbar and do not forget to set Log Output to Messages Log

16. Press Next and Finish.

Now you can call pmd e.g. from the fusion order demo application

You see the results of the ant process in the message pane and you can click on the link to open the file and jump to the rule violation:

In upcoming blogs I will show you how you can define your own rulesets (replacing the ones in pmd.xml) and how to use it with any kind of xml files, eg. jws, jpr, xcfg etc..

Chrysanth WebStory Published by WebStory
About these ads

, , , ,

  1. Write ADF static code analysis rules with PMD and running these in JDeveloper | develish development

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 43 other followers