When generating reports in the ${project}/reports directory, sometimes reports/pmd-report.html has very useful links that go directly to the web page with the explanation of a rule and why it's a good idea. Sometimes the links don't get generated.
I can't seem to reproduce what sequences of events actually makes the difference between including the links or not.
No links example:
<tr bgcolor="lightgrey">
<td align="center">1</td>
<td width="*%">src/main/java/com/company/utilities/crypto/HmacCalculator.java</td>
<td align="center" width="5%">5</td>
<td width="*">All methods are static. Consider using Singleton instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning.</td>
</tr>
Can't show you an example with links, as I can't reproduce it again. I've generated them multiple times, so I've seen the links do sometimes exist.
Paul
Logged In: YES
user_id=1331887
Originator: NO
I noticed something else. I imported a custom rule set based on ruleset, like this:
<rule ref="rulesets/basic.xml" >
<exclude name="EmptyCatchBlock"/><!-- adding custom property -->
<exclude name="BooleanInstantiation"/><!-- custom lower priority -->
<exclude name="BrokenNullCheck"/><!-- custom lower priority -->
</rule>
<rule ref="rulesets/basic.xml/EmptyCatchBlock" >
<properties>
<property name="allowCommentedBlocks" value="true" />
</properties>
</rule>
<rule ref="rulesets/basic.xml/BooleanInstantiation">
<priority>3</priority>
</rule>
<rule ref="rulesets/basic.xml/BrokenNullCheck">
<priority>3</priority>
</rule>
Yet if I export from eclipse I get something like this:
================== EXPORTED FROM ECLIPSE ===========================================================
<rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid empty 'if' statements" name="EmptyIfStmt">
<description>
Empty If Statement finds instances where a condition is checked but nothing is done about it.
</description>
<example><![CDATA[
public class Foo {
void bar(int x) {
if (x == 0) {
// empty!
}
}
}
]]></example>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//IfStatement/Statement
[EmptyStatement or Block[count(*) = 0]]
]]></value>
</property>
</properties>
</rule>
====================== END EXPORTED FROM ECLIPSE ==================================
However, the same rule from inside the jar, which ALSO INCLUDES the externalInfoUrl="http://pmd.sourceforge.net/rules/basic.html#EmptyIfStmt" which is what I assume the reports need for the links! So I guess the crux of the problem is why is the externalInfoUrl getting lost?
======================== FROM JAR FILE ================================
<rule name="EmptyIfStmt"
message="Avoid empty 'if' statements"
class="net.sourceforge.pmd.rules.XPathRule"
externalInfoUrl="http://pmd.sourceforge.net/rules/basic.html#EmptyIfStmt">
<description>
Empty If Statement finds instances where a condition is checked but nothing is done about it.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//IfStatement/Statement
[EmptyStatement or Block[count(*) = 0]]
]]>
</value>
</property>
</properties>
<example>
<![CDATA[
public class Foo {
void bar(int x) {
if (x == 0) {
// empty!
}
}
}
]]>
</example>
</rule>
======================== END FROM JAR FILE ================================
Logged In: YES
user_id=1331887
Originator: NO
From a cursory/uninformed/quick look at the code, it looks like in net.sourceforge.pmd.runtime.writer.impl.RuleSetWriterImpl method getRuleElement needs a line like:
ruleElement.setAttribute("externalInfoUrl", rule.getExternalInfoUrl());
and maybe there are more places it's needed. I looked and didn't see a place to get a list of all Rule properties in the PMD javadoc, so I guess you have to do it manually like you.
Thanks,
Paul