Ant PMD和规则排除

时间:2011-11-23 20:03:43

标签: pmd

我有一个Ant任务来生成PMD报告:

<pmd rulesetfiles="${commons-home}/src/main/resources/pmd/wai_ruleset.xml">
    <formatter type="xml" toFile="${target.reports.pmd}/pmd-report.xml" linkPrefix="${src.main}/"/>
    <fileset dir="${src.main}">
        <include name="**/*.java"/>
    </fileset>  
</pmd>

wai_ruleset.xml我(尝试)从规则中排除NullAssignment

<?xml version="1.0"?>
    <ruleset name="WAI rule set"
        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">

    <description>
        WAI rules
    </description>

    <!-- imports -->
    <rule ref="rulesets/basic.xml">
        <exclude name="CollapsibleIfStatements"/>
    </rule>
    <rule ref="rulesets/favorites.xml">
        <!-- we redefine it below with a different threshold -->
        <exclude name="CyclomaticComplexity" />
        <!-- empty default constructors are needed by Envers -->
        <exclude name="UnnecessaryConstructor"/>
    </rule>

    <!-- CyclomaticComplexity with a threshold of 12 -->
    <rule ref="rulesets/codesize.xml/CyclomaticComplexity">
        <priority>1</priority>
        <properties>
            <property name="reportLevel" value="12" />
        </properties>
    </rule>

    <rule ref="rulesets/controversial.xml">
        <exclude name="UnnecessaryConstructor"/>
        <exclude name="OnlyOneReturn"/>
        <exclude name="AssignmentInOperand"/>
        <exclude name="BooleanInversion"/>
        <exclude name="NullAssignment"/>
        <exclude name="DataflowAnomalyAnalysis"/>
   </rule>

</ruleset>

如果我不排除NullAssignment,我会将每个分配的两个警告设为null。如果我排除NullAssignment,我仍然会收到每个分配为空的警告。

哪条规则会产生额外的警告?这是一个错误吗?

1 个答案:

答案 0 :(得分:3)

检查favorites.xml是否包含NullAssignment

编辑:实际上,如果它是PMD附带的标准文件,it has NullAssignment included