我想为我的构建使用自定义 PMD 规则集文件。基本上,我想使用许多关闭了一些规则的内置规则集包。
例如,假设我只想要字符串和基本规则,我有这个规则集文件,名为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">
<description>
This ruleset checks my code for bad stuff
</description>
<rule ref="rulesets/strings.xml"/>
<rule ref="rulesets/basics.xml"/>
</ruleset>
然后我在我的 Ant 任务中包含对该文件的引用,如下所示:
<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>
这失败了,但有以下例外:
构建失败 E:\build.xml:120: java.lang.RuntimeException: 找不到该类 找不到资源规则集/basics.xml。确保资源是有效的文件或 URL,或者位于 net.sourceforge.pmd.RuleSetFactory.parseRuleSetNode(RuleSetFactory.java:229) 的 CLASSPATH 上 net.sourceforge.pmd.RuleSetFactory.createSingleRuleSet(RuleSetFactory.java:135) net.sourceforge.pmd.RuleSetFactory.createRuleSets(RuleSetFactory.java:85) ...
基本上,规则集 xml 文件会破坏任务的类路径。我尝试将类路径元素添加到 pmd 任务,但这不起作用。
我必须添加什么才能让我的自定义规则集文件正常工作?我更愿意在 ant 文件中添加一些内容,而不是在规则集文件中添加内容。