After little code change in pmd the integration like described in some blogs from Shay Shmeltzer is now possible.
I use here JDeveloper 11.2.0.4, with other versions this should be very similar. Now let’s start:
-
Create a new folder
-
Download PMD 5.0.4
-
Extract the zip file into the created folder
-
Create a file pmd.xml into the created folder
-
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>
-
Select Tools > External Tools from the JDeveloper menu
-
Press Button New
-
Select Tool Type: Apache Ant
-
Select your created pmd.xml file in Ant Buildfile:
-
Shuttle target pmdAll to SelectedTargets
-
Add Property dir with value ${file.dir}
-
Skip the Options and Process Step to leave the defaults
-
Add the lib directory of pmd as additional classpath entry
-
Enter Caption and Icon as you want
-
Add the tool to the Navigator Context Menu and Main Toolbar and do not forget to set Log Output to Messages Log
-
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.