I have a quite strange behavior.
I create a XPath rule for PMD 4.2.6 in a file named pmd-extensions.xml :
...
<rule name="AvoidPrintStackTrace-XPath"
message="Avoid to use printStackTrace - XPath"
class="net.sourceforge.pmd.rules.XPathRule">
<description>Avoid to use printStackTrace - XPath</description>
<properties>
<property name="xpath">
<value>
<![CDATA[
//Name[contains (@Image, "printStackTrace")]
]]>
</value>
</property>
</properties>
<example>
<![CDATA[
// don't do this!
myException.printStackTrace()
]]>
</example>
</rule>
...
I have an unit test validating this rule and working fine:
...
@Before
public void setUp() {
addRule("rulesets/pmd-extensions.xml", "AvoidPrintStackTrace-XPath");
}
...
But when I embed this rule in Sonar, the rule doesn't fire any violation while I expected one:
...
<rule key="AvoidPrintStackStrace-XPath" >
<name>AvoidPrintStackStrace-XPath</name>
<configKey>rulesets/pmd-extensions.xml/AvoidPrintStackTrace-XPath</configKey>
<category name="Usability"/>
<description>Avoid to use printStackTrace - XPath</description>
</rule>
...
And if I declare this rule directly in Sonar (with same XPath expression), the rule fire a violation as expected:
...
<rule key="AvoidPrintStackStrace-XPath-Sonar" priority="MAJOR">
<name><![CDATA[AvoidPrintStackStrace-XPath-Sonar]]></name>
<configKey><![CDATA[net.sourceforge.pmd.rules.XPathRule]]></configKey>
<category name="Maintainability"/>
<description>Avoid to use printStackTrace - XPath-Sonar</description>
<param key="xpath" type="s">
<description><![CDATA[XPath expressions.]]></description>
<defaultValue>//Name[contains (@Image, "printStackTrace")]</defaultValue>
</param>
<param key="message" type="s">
<description><![CDATA[Message to display when a violation occurs.]]></description>
<defaultValue>Prevent use of printStackTrace</defaultValue>
</param>
</rule>
...
What's wrong ?
Thanks.