Implemented RFE 743460: The XML report now contains the ruleset name
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@2710 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
????, 2004 - 1.9:
|
||||
Some minor performance optimizations - removed some unnecessary casts from the grammar, simplified some XPath rules.
|
||||
Some minor performance optimizations - removed some unnecessary casts from the grammar, simplified some XPath rules.
|
||||
Implemented RFE 743460: The XML report now contains the ruleset name.
|
||||
|
||||
May 19, 2004 - 1.8:
|
||||
New rules: ExceptionAsFlowControlRule, BadComparisonRule, AvoidThrowingCertainExceptionTypesRule, AvoidCatchingNPERule, OptimizableToArrayCallRule
|
||||
|
@ -27,7 +27,7 @@
|
||||
<li>Short/long variable and method names</li>
|
||||
</ul>
|
||||
<p>PMD has plugins for JDeveloper, JEdit, JBuilder, NetBeans/Sun ONE Studio, IntelliJ IDEA, TextPad, Maven, Ant, Eclipse,
|
||||
Gel, and Emacs. You can <a href="http://sourceforge.net/project/showfiles.php?group_id=56262">download everything from here</a>.</p>
|
||||
Gel, and Emacs. You can <b><a href="http://sourceforge.net/project/showfiles.php?group_id=56262">download everything from here</a></b>.</p>
|
||||
<p>Thanks to the <a href="http://cougaar.org/index.php?referrer=pmd">Cougaar</a> program for sponsoring PMD!</p>
|
||||
]]>
|
||||
</description>
|
||||
|
@ -41,6 +41,7 @@ public class AbstractRuleTest extends TestCase {
|
||||
|
||||
public void testCreateRV() {
|
||||
MyRule r = new MyRule();
|
||||
r.setRuleSetName("foo");
|
||||
RuleContext ctx = new RuleContext();
|
||||
ctx.setSourceCodeFilename("filename");
|
||||
RuleViolation rv = r.createRuleViolation(ctx, 5);
|
||||
@ -48,6 +49,7 @@ public class AbstractRuleTest extends TestCase {
|
||||
assertEquals("Filename mismatch!", "filename", rv.getFilename());
|
||||
assertEquals("Rule object mismatch!", r, rv.getRule());
|
||||
assertEquals("Rule description mismatch!", "myrule", rv.getDescription());
|
||||
assertEquals("RuleSet name mismatch!", "foo", rv.getRule().getRuleSetName());
|
||||
}
|
||||
|
||||
public void testCreateRV2() {
|
||||
|
@ -45,7 +45,7 @@ public class ReportTest extends TestCase implements ReportListener {
|
||||
Report r = new Report();
|
||||
RuleContext ctx = new RuleContext();
|
||||
ctx.setSourceCodeFilename("foo");
|
||||
r.addRuleViolation(new RuleViolation(new MockRule("name", "desc", "msg"), 5, ctx));
|
||||
r.addRuleViolation(new RuleViolation(new MockRule("name", "desc", "msg", "rulesetname"), 5, ctx));
|
||||
assertTrue(!r.isEmpty());
|
||||
}
|
||||
|
||||
@ -81,9 +81,9 @@ public class ReportTest extends TestCase implements ReportListener {
|
||||
Report r = new Report();
|
||||
RuleContext ctx = new RuleContext();
|
||||
ctx.setSourceCodeFilename("foo");
|
||||
r.addRuleViolation(new RuleViolation(new MockRule("name", "desc", "msg"), 10, ctx));
|
||||
r.addRuleViolation(new RuleViolation(new MockRule("name", "desc", "msg", "rulesetname"), 10, ctx));
|
||||
ctx.setSourceCodeFilename("bar");
|
||||
r.addRuleViolation(new RuleViolation(new MockRule("name", "desc", "msg"), 20, ctx));
|
||||
r.addRuleViolation(new RuleViolation(new MockRule("name", "desc", "msg", "rulesetname"), 20, ctx));
|
||||
Renderer rend = new XMLRenderer();
|
||||
String result = rend.render(r);
|
||||
assertTrue("sort order wrong", result.indexOf("bar") < result.indexOf("foo"));
|
||||
@ -93,9 +93,9 @@ public class ReportTest extends TestCase implements ReportListener {
|
||||
Report r = new Report();
|
||||
RuleContext ctx = new RuleContext();
|
||||
ctx.setSourceCodeFilename("foo1");
|
||||
r.addRuleViolation(new RuleViolation(new MockRule("rule2", "rule2", "msg"), 10, ctx));
|
||||
r.addRuleViolation(new RuleViolation(new MockRule("rule2", "rule2", "msg", "rulesetname"), 10, ctx));
|
||||
ctx.setSourceCodeFilename("foo2");
|
||||
r.addRuleViolation(new RuleViolation(new MockRule("rule1", "rule1", "msg"), 20, ctx));
|
||||
r.addRuleViolation(new RuleViolation(new MockRule("rule1", "rule1", "msg", "rulesetname"), 20, ctx));
|
||||
Renderer rend = new XMLRenderer();
|
||||
String result = rend.render(r);
|
||||
assertTrue("sort order wrong", result.indexOf("rule2") < result.indexOf("rule1"));
|
||||
@ -107,7 +107,7 @@ public class ReportTest extends TestCase implements ReportListener {
|
||||
violationSemaphore = false;
|
||||
RuleContext ctx = new RuleContext();
|
||||
ctx.setSourceCodeFilename("file");
|
||||
rpt.addRuleViolation(new RuleViolation(new MockRule("name", "desc", "msg"), 5, ctx));
|
||||
rpt.addRuleViolation(new RuleViolation(new MockRule("name", "desc", "msg", "rulesetname"), 5, ctx));
|
||||
assertTrue(violationSemaphore);
|
||||
|
||||
metricSemaphore = false;
|
||||
@ -128,9 +128,9 @@ public class ReportTest extends TestCase implements ReportListener {
|
||||
Report r = new Report();
|
||||
RuleContext ctx = new RuleContext();
|
||||
ctx.setSourceCodeFilename("foo1");
|
||||
r.addRuleViolation(new RuleViolation(new MockRule("rule2", "rule2", "msg"), 10, ctx));
|
||||
r.addRuleViolation(new RuleViolation(new MockRule("rule2", "rule2", "msg", "rulesetname"), 10, ctx));
|
||||
ctx.setSourceCodeFilename("foo2");
|
||||
Rule mr = new MockRule("rule1", "rule1", "msg");
|
||||
Rule mr = new MockRule("rule1", "rule1", "msg", "rulesetname");
|
||||
r.addRuleViolation(new RuleViolation(mr, 20, ctx));
|
||||
r.addRuleViolation(new RuleViolation(mr, 30, ctx));
|
||||
Map summary = r.getSummary();
|
||||
|
@ -57,7 +57,7 @@ public class RuleSetTest extends TestCase {
|
||||
|
||||
public void testGetRuleByName() {
|
||||
RuleSet rs = new RuleSet();
|
||||
MockRule mock = new MockRule("name", "desc", "msg");
|
||||
MockRule mock = new MockRule("name", "desc", "msg", "rulesetname");
|
||||
rs.addRule(mock);
|
||||
assertEquals("unable to fetch rule by name", mock, rs.getRuleByName("name"));
|
||||
}
|
||||
@ -67,7 +67,7 @@ public class RuleSetTest extends TestCase {
|
||||
|
||||
assertEquals("Size of RuleSet isn't zero.", 0, IUT.size());
|
||||
|
||||
MockRule rule = new MockRule("name", "desc", "msg");
|
||||
MockRule rule = new MockRule("name", "desc", "msg", "rulesetname");
|
||||
IUT.addRule(rule);
|
||||
|
||||
assertEquals("Size of RuleSet isn't one.", 1, IUT.size());
|
||||
@ -82,9 +82,9 @@ public class RuleSetTest extends TestCase {
|
||||
|
||||
public void testAddRuleSet() {
|
||||
RuleSet set1 = new RuleSet();
|
||||
set1.addRule(new MockRule("name", "desc", "msg"));
|
||||
set1.addRule(new MockRule("name", "desc", "msg", "rulesetname"));
|
||||
RuleSet set2 = new RuleSet();
|
||||
set2.addRule(new MockRule("name", "desc", "msg"));
|
||||
set2.addRule(new MockRule("name", "desc", "msg", "rulesetname"));
|
||||
set1.addRuleSet(set2);
|
||||
assertEquals("ruleset size wrong", 2, set1.size());
|
||||
}
|
||||
@ -97,7 +97,7 @@ public class RuleSetTest extends TestCase {
|
||||
public void testApply1Rule() throws Throwable {
|
||||
RuleSet IUT = new RuleSet();
|
||||
|
||||
MockRule rule = new MockRule("name", "desc", "msg");
|
||||
MockRule rule = new MockRule("name", "desc", "msg", "rulesetname");
|
||||
RuleContext ctx = new RuleContext();
|
||||
ctx.setSourceCodeFilename("filename");
|
||||
RuleViolation violation = new RuleViolation(rule, 1, ctx);
|
||||
@ -116,7 +116,7 @@ public class RuleSetTest extends TestCase {
|
||||
Set ruleViolations = new HashSet();
|
||||
|
||||
for (int i = 0; i < numRules; i++) {
|
||||
MockRule rule = new MockRule("name", "desc", "msg");
|
||||
MockRule rule = new MockRule("name", "desc", "msg", "rulesetname");
|
||||
RuleContext ctx = new RuleContext();
|
||||
ctx.setSourceCodeFilename("filename");
|
||||
RuleViolation violation = new RuleViolation(rule, i, ctx);
|
||||
|
@ -31,7 +31,7 @@ import test.net.sourceforge.pmd.testframework.MockRule;
|
||||
public class RuleViolationTest extends TestCase {
|
||||
|
||||
public void testConstructor1() {
|
||||
Rule rule = new MockRule("name", "desc", "msg");
|
||||
Rule rule = new MockRule("name", "desc", "msg", "rulesetname");
|
||||
RuleContext ctx = new RuleContext();
|
||||
ctx.setSourceCodeFilename("filename");
|
||||
RuleViolation r = new RuleViolation(rule, 2, ctx);
|
||||
@ -41,7 +41,7 @@ public class RuleViolationTest extends TestCase {
|
||||
}
|
||||
|
||||
public void testConstructor2() {
|
||||
Rule rule = new MockRule("name", "desc", "msg");
|
||||
Rule rule = new MockRule("name", "desc", "msg", "rulesetname");
|
||||
RuleContext ctx = new RuleContext();
|
||||
ctx.setSourceCodeFilename("filename");
|
||||
RuleViolation r = new RuleViolation(rule, 2, "description", ctx);
|
||||
@ -52,7 +52,7 @@ public class RuleViolationTest extends TestCase {
|
||||
}
|
||||
|
||||
public void testComparatorWithDifferentFilenames() {
|
||||
Rule rule = new MockRule("name", "desc", "msg");
|
||||
Rule rule = new MockRule("name", "desc", "msg", "rulesetname");
|
||||
RuleViolation.RuleViolationComparator comp = new RuleViolation.RuleViolationComparator();
|
||||
RuleContext ctx = new RuleContext();
|
||||
ctx.setSourceCodeFilename("filename1");
|
||||
@ -64,7 +64,7 @@ public class RuleViolationTest extends TestCase {
|
||||
}
|
||||
|
||||
public void testComparatorWithSameFileDifferentLines() {
|
||||
Rule rule = new MockRule("name", "desc", "msg");
|
||||
Rule rule = new MockRule("name", "desc", "msg", "rulesetname");
|
||||
RuleViolation.RuleViolationComparator comp = new RuleViolation.RuleViolationComparator();
|
||||
RuleContext ctx = new RuleContext();
|
||||
ctx.setSourceCodeFilename("filename");
|
||||
@ -75,7 +75,7 @@ public class RuleViolationTest extends TestCase {
|
||||
}
|
||||
|
||||
public void testComparatorWithSameFileSameLines() {
|
||||
Rule rule = new MockRule("name", "desc", "msg");
|
||||
Rule rule = new MockRule("name", "desc", "msg", "rulesetname");
|
||||
RuleViolation.RuleViolationComparator comp = new RuleViolation.RuleViolationComparator();
|
||||
RuleContext ctx = new RuleContext();
|
||||
ctx.setSourceCodeFilename("filename");
|
||||
|
@ -26,7 +26,7 @@ public class TextPadRendererTest extends TestCase {
|
||||
RuleContext ctx = new RuleContext();
|
||||
ctx.setSourceCodeFilename("Foo.java");
|
||||
Report rep = new Report();
|
||||
rep.addRuleViolation(new RuleViolation(new MockRule("DontImportJavaLang", "Avoid importing anything from the package 'java.lang'", "Avoid importing anything from the package 'java.lang'"), 3,ctx));
|
||||
rep.addRuleViolation(new RuleViolation(new MockRule("DontImportJavaLang", "Avoid importing anything from the package 'java.lang'", "Avoid importing anything from the package 'java.lang'", "rulesetname"), 3,ctx));
|
||||
String actual = (new TextPadRenderer()).render(rep);
|
||||
String expected = PMD.EOL + "Foo.java(3, DontImportJavaLang): Avoid importing anything from the package 'java.lang'" ;
|
||||
assertEquals(expected, actual);
|
||||
|
@ -16,8 +16,8 @@ import java.util.List;
|
||||
|
||||
public class XMLRendererTest extends TestCase {
|
||||
|
||||
private MockRule RULE1 = new MockRule("RULE1", "RULE1", "msg");
|
||||
private MockRule RULE2 = new MockRule("RULE2", "RULE2", "msg");
|
||||
private MockRule RULE1 = new MockRule("RULE1", "RULE1", "msg", "rulesetname");
|
||||
private MockRule RULE2 = new MockRule("RULE2", "RULE2", "msg", "rulesetname");
|
||||
private RuleContext ctx = new RuleContext();
|
||||
|
||||
public XMLRendererTest(String name) {
|
||||
@ -57,7 +57,7 @@ public class XMLRendererTest extends TestCase {
|
||||
List expectedStrings = new ArrayList();
|
||||
expectedStrings.add("<pmd>");
|
||||
expectedStrings.add("<file name=\"testSingleReport\">");
|
||||
expectedStrings.add("<violation line=\"1\" rule=\"RULE1\">");
|
||||
expectedStrings.add("<violation line=\"1\" rule=\"RULE1\" ruleset=\"rulesetname\">");
|
||||
expectedStrings.add("Rule1");
|
||||
expectedStrings.add("</violation>");
|
||||
expectedStrings.add("</file>");
|
||||
@ -88,10 +88,10 @@ public class XMLRendererTest extends TestCase {
|
||||
List expectedStrings = new ArrayList();
|
||||
expectedStrings.add("<pmd>");
|
||||
expectedStrings.add("<file name=\"testDoubleReport\">");
|
||||
expectedStrings.add("<violation line=\"1\" rule=\"RULE1\">");
|
||||
expectedStrings.add("<violation line=\"1\" rule=\"RULE1\" ruleset=\"rulesetname\">");
|
||||
expectedStrings.add("Rule1");
|
||||
expectedStrings.add("</violation>");
|
||||
expectedStrings.add("<violation line=\"2\" rule=\"RULE2\">");
|
||||
expectedStrings.add("<violation line=\"2\" rule=\"RULE2\" ruleset=\"rulesetname\">");
|
||||
expectedStrings.add("Rule2");
|
||||
expectedStrings.add("</violation>");
|
||||
expectedStrings.add("</file>");
|
||||
@ -126,12 +126,12 @@ public class XMLRendererTest extends TestCase {
|
||||
List expectedStrings = new ArrayList();
|
||||
expectedStrings.add("<pmd>");
|
||||
expectedStrings.add("<file name=\"testTwoFiles_0\">");
|
||||
expectedStrings.add("<violation line=\"1\" rule=\"RULE1\">");
|
||||
expectedStrings.add("<violation line=\"1\" rule=\"RULE1\" ruleset=\"rulesetname\">");
|
||||
expectedStrings.add("Rule1");
|
||||
expectedStrings.add("</violation>");
|
||||
expectedStrings.add("</file>");
|
||||
expectedStrings.add("<file name=\"testTwoFiles_1\">");
|
||||
expectedStrings.add("<violation line=\"1\" rule=\"RULE1\">");
|
||||
expectedStrings.add("<violation line=\"1\" rule=\"RULE1\" ruleset=\"rulesetname\">");
|
||||
expectedStrings.add("Rule1");
|
||||
expectedStrings.add("</violation>");
|
||||
expectedStrings.add("</file>");
|
||||
@ -169,15 +169,15 @@ public class XMLRendererTest extends TestCase {
|
||||
List expectedStrings = new ArrayList();
|
||||
expectedStrings.add("<pmd>");
|
||||
expectedStrings.add("<file name=\"testTwoFiles_0\">");
|
||||
expectedStrings.add("<violation line=\"1\" rule=\"RULE1\">");
|
||||
expectedStrings.add("<violation line=\"1\" rule=\"RULE1\" ruleset=\"rulesetname\">");
|
||||
expectedStrings.add("Rule1");
|
||||
expectedStrings.add("</violation>");
|
||||
expectedStrings.add("<violation line=\"2\" rule=\"RULE2\">");
|
||||
expectedStrings.add("<violation line=\"2\" rule=\"RULE2\" ruleset=\"rulesetname\">");
|
||||
expectedStrings.add("Rule2");
|
||||
expectedStrings.add("</violation>");
|
||||
expectedStrings.add("</file>");
|
||||
expectedStrings.add("<file name=\"testTwoFiles_1\">");
|
||||
expectedStrings.add("<violation line=\"1\" rule=\"RULE1\">");
|
||||
expectedStrings.add("<violation line=\"1\" rule=\"RULE1\" ruleset=\"rulesetname\">");
|
||||
expectedStrings.add("Rule1");
|
||||
expectedStrings.add("</violation>");
|
||||
expectedStrings.add("</file>");
|
||||
@ -217,7 +217,7 @@ public class XMLRendererTest extends TestCase {
|
||||
expectedStrings.add(" 'e' acute: ");
|
||||
expectedStrings.add("é");
|
||||
expectedStrings.add("\">");
|
||||
expectedStrings.add("<violation line=\"1\" rule=\"RULE1\">");
|
||||
expectedStrings.add("<violation line=\"1\" rule=\"RULE1\" ruleset=\"rulesetname\">");
|
||||
expectedStrings.add("[RULE] Less than: ");
|
||||
expectedStrings.add("<");
|
||||
expectedStrings.add(" Greater than: ");
|
||||
|
@ -17,6 +17,7 @@ import java.util.Set;
|
||||
public class MockRule implements Rule {
|
||||
|
||||
private String name;
|
||||
private String ruleSetName;
|
||||
private String description;
|
||||
private String message;
|
||||
private Set violations = new HashSet();
|
||||
@ -24,6 +25,14 @@ public class MockRule implements Rule {
|
||||
private String example;
|
||||
private int priority;
|
||||
|
||||
public String getRuleSetName() {
|
||||
return ruleSetName;
|
||||
}
|
||||
|
||||
public void setRuleSetName(String ruleSetName) {
|
||||
this.ruleSetName = ruleSetName;
|
||||
}
|
||||
|
||||
public String getExample() {
|
||||
return example;
|
||||
}
|
||||
@ -109,10 +118,11 @@ public class MockRule implements Rule {
|
||||
public MockRule() {
|
||||
}
|
||||
|
||||
public MockRule(String name, String description, String message) {
|
||||
public MockRule(String name, String description, String message, String ruleSetName) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.message = message;
|
||||
this.ruleSetName = ruleSetName;
|
||||
}
|
||||
|
||||
|
||||
|
@ -17,9 +17,18 @@ public abstract class AbstractRule extends JavaParserVisitorAdapter implements R
|
||||
private String message;
|
||||
private String description;
|
||||
private String example;
|
||||
private String ruleSetName;
|
||||
private boolean m_include;
|
||||
private int m_priority = LOWEST_PRIORITY;
|
||||
|
||||
public String getRuleSetName() {
|
||||
return ruleSetName;
|
||||
}
|
||||
|
||||
public void setRuleSetName(String ruleSetName) {
|
||||
this.ruleSetName = ruleSetName;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
public interface Rule {
|
||||
|
||||
public static final int LOWEST_PRIORITY = 5;
|
||||
public static final String[] PRIORITIES = {"High", "Medium High", "Medium", "Medium Low", "Low"};
|
||||
|
||||
@ -20,6 +21,10 @@ public interface Rule {
|
||||
|
||||
void setName(String name);
|
||||
|
||||
String getRuleSetName();
|
||||
|
||||
void setRuleSetName(String name);
|
||||
|
||||
void setMessage(String message);
|
||||
|
||||
void setDescription(String description);
|
||||
|
@ -147,7 +147,6 @@ public class RuleSetFactory {
|
||||
if (in == null) {
|
||||
throw new RuleSetNotFoundException("Can't find resource " + name + ". Make sure the resource is a valid file or URL or is on the CLASSPATH. Here's the current classpath: " + System.getProperty("java.class.path"));
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
@ -199,7 +198,8 @@ public class RuleSetFactory {
|
||||
Rule rule = (Rule) getClassLoader().loadClass(className).newInstance();
|
||||
rule.setName(name);
|
||||
rule.setMessage(message);
|
||||
|
||||
rule.setRuleSetName(ruleSet.getName());
|
||||
|
||||
NodeList nodeList = ruleElement.getChildNodes();
|
||||
for (int i = 0; i < nodeList.getLength(); i++) {
|
||||
Node node = nodeList.item(i);
|
||||
|
@ -29,12 +29,14 @@ public class XMLRenderer implements Renderer {
|
||||
.append(PMD.EOL);
|
||||
}
|
||||
|
||||
buf.append("<violation line=\"")
|
||||
.append(rv.getLine()) // int
|
||||
.append("\" rule=\"");
|
||||
buf.append("<violation line=\"").append(rv.getLine()).append("\"");
|
||||
buf.append(" rule=\"");
|
||||
StringUtil.appendXmlEscaped(buf, rv.getRule().getName());
|
||||
buf.append("\">")
|
||||
.append(PMD.EOL);
|
||||
buf.append("\"");
|
||||
buf.append(" ruleset=\"");
|
||||
StringUtil.appendXmlEscaped(buf, rv.getRule().getRuleSetName());
|
||||
buf.append("\">");
|
||||
buf.append(PMD.EOL);
|
||||
StringUtil.appendXmlEscaped(buf, rv.getDescription());
|
||||
|
||||
buf.append(PMD.EOL);
|
||||
|
Reference in New Issue
Block a user