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

I am trying to run PMDfrom Antin Eclipsewhile creating a 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>

This works well for basic.xml, but I want to run for all rule sets in a folder java(it has about 20 rule sets). So I 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 a folder rather than a single file without specifying a list of files manually?

For future readers to configure Ant PMD in Eclipse:

  • Download pmd-bin.zipfrom the official site
  • Unpack pmd.jar, jaxen.jarandasm.jar
  • Add Banks Above to Window - Preferences - Ant - Runtime - Ant Home Records - Add External JARs
  • unzip folder rulesets
  • Link to a set of rules from <pmd rulesetfiles=...>
+5
3

( coolfan ant)

PMD , .

rulesetfiles - ( ' /basic.xml, /design.xml'). , . ,

Ant . : pathconvert

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

 <pathconvert pathsep="," property="javafiles" refid="src.files"/>
+3

, , .

, . RuleSetReferenceId.java, 194.

, , "", , , :

"rule1,rule2,rule3,path-to-rule-file4"

, rule-xml -, <pmd>.

, ant, . , , .

:


EDIT:

Jayan <pathconvert>, .

+3

The pmd jq library has an all-java.xml file that includes all rule sets. Try using the following:

<pmd rulesetfiles="rulesets/internal/all-java.xml">
+1
source

All Articles