tags:

views:

26

answers:

1

I'd like to use a custom PMD ruleset file for my build. Basically, I want to use many of the built-in ruleset packages with some rules turned off.

For example, suppose I only wanted the strings and basics rules, I have this ruleset file, called ruleset.xml:

<?xml version="1.0"?>
   <ruleset name="Custom ruleset"
       xmlns="http://pmd.sf.net/ruleset/1.0.0"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
    xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"&gt;
     <description>
     This ruleset checks my code for bad stuff
  </description>
  <rule ref="rulesets/strings.xml"/>
  <rule ref="rulesets/basics.xml"/>

</ruleset>

And then I include a reference to that file in my Ant task, like so:

<target name="pmd"
           description="Analyzes our source code for violations of good Java">
      <pmd shortFilenames="true" failuresPropertyName="failures.count" 
           rulesetfiles="ruleset.xml">

         <formatter type="xml" toFile="${build.home}/pmd.xml" />
         <fileset dir="src">
            <include name="**/*.java" />
         </fileset>
      </pmd>
      <echo message="PMD detected ${failures.count} violations" />
      <xslt in="${build.home}/pmd.xml" 
         style="tools/pmd/etc/xslt/pmd-report.xslt" 
         out="${build.home}/pmd.html" /> 

   </target>

This fails with the following exception:

BUILD FAILED E:\build.xml:120: java.lang.RuntimeException: Couldn't find that class Can't find resource rulesets/basics.xml. Make sure the resource is a valid file or URL or is on the CLASSPATH at net.sourceforge.pmd.RuleSetFactory.parseRuleSetNode(RuleSetFactory.java:229) at net.sourceforge.pmd.RuleSetFactory.createSingleRuleSet(RuleSetFactory.java:135) at net.sourceforge.pmd.RuleSetFactory.createRuleSets(RuleSetFactory.java:85) ...

Basically, the ruleset xml file breaks the classpath for the task. I've tried adding a classpath element to the pmd task, but that doesn't work.

What do I have to add to get my custom ruleset file to work? I'd prefer to add something to the ant file, rather than the ruleset file.

A: 

Doh! Writing this out on SO helped debug my issue. The problem was that there is no basics.xml, it's called basic.xml. Fix the typo and everything runs just fine.

ageektrapped