Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run all rulesets from a folder using PMD Ant in Eclipse?

I am trying to run PMD from Ant in Eclipse when I build the project.

This is my build.xml file:

<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask"/>

<target name="check_pmd">
    <pmd rulesetfiles="C:\Users\Nikolay\ProjectName\lib\rulesets\java\basic.xml">
        <formatter type="html" toFile="pmd_report.html" toConsole="true"/>
        <fileset dir="C:\Users\Nikolay\ProjectName\src">
            <include name="**/*.java"/>
        </fileset>
    </pmd>
</target>

It works well for basic.xml, but I want to run for all rulesets in java folder (It has around 20 rulesets) So I have tried:

<pmd rulesetfiles="C:\Users\Nikolay\ProjectName\lib\rulesets\java\*.xml">
<pmd rulesetfiles="C:\Users\Nikolay\ProjectName\lib\rulesets\java\*">

But both of them fail when I try to run. Is there a way to specify folder, not a single file without specifying list of files manually?

For future readers to configure Ant PMD under Eclipse:

  • Download pmd-bin.zip from official website
  • Unpack pmd.jar, jaxen.jar and asm.jar
  • Add jars above to Window - Preferences - Ant - Runtime - Ant Home Entries - Add External JARs
  • Unpack rulesets folder
  • Reference location of ruleset from <pmd rulesetfiles=...>
like image 850
Nikolay Kuznetsov Avatar asked Mar 08 '13 11:03

Nikolay Kuznetsov


1 Answers

(expanding answer from coolfan for ant task)

The documentation of PMD rulesetfiles says it is comma separated list of files.

rulesetfiles A comma delimited list of ruleset files ('rulesets/basic.xml,rulesets/design.xml'). If you write your own ruleset files, you can put them on the classpath and plug them in here. Yes, unless the ruleset nested element is used

Ant provides a way to convert fileset into such a format. The task is pathconvert

here is an example from website

<fileset dir="${src.dir}" id="src.files">
      <include name="**/*.java"/>
 </fileset>

 <pathconvert pathsep="," property="javafiles" refid="src.files"/>
like image 81
Jayan Avatar answered Nov 14 '22 20:11

Jayan