forked from phoedos/pmd
Wrapping suppressed violations in a SuppressedViolation object in case folks want info in the reports about how they're suppressing violations. Added same to text and XML reports.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@3899 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -72,9 +72,12 @@
|
||||
<target name="pmd" description="Runs PMD">
|
||||
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask"/>
|
||||
<pmd rulesetfiles="unusedcode" shortFilenames="true">
|
||||
<classpath>
|
||||
<path refid="dependencies.path"/>
|
||||
</classpath>
|
||||
<formatter type="html" toFile="rpt.html" linkPrefix="http://pmd.sf.net/xref/"/>
|
||||
<fileset dir="/home/tom/pmd/pmd/src/">
|
||||
<include name="**/rules/*.java"/>
|
||||
<fileset dir="/home/tom/pmd/pmd/bin/">
|
||||
<include name="Foo.java"/>
|
||||
</fileset>
|
||||
</pmd>
|
||||
</target>
|
||||
|
@ -73,6 +73,18 @@ public class Report {
|
||||
}
|
||||
}
|
||||
|
||||
public static class SuppressedViolation {
|
||||
private RuleViolation rv;
|
||||
private boolean isNOPMD;
|
||||
public SuppressedViolation(RuleViolation rv, boolean isNOPMD) {
|
||||
this.isNOPMD = isNOPMD;
|
||||
this.rv = rv;
|
||||
}
|
||||
public boolean suppressedByNOPMD() { return this.isNOPMD; }
|
||||
public boolean suppressedByAnnotation() { return !this.isNOPMD; }
|
||||
public RuleViolation getRuleViolation() { return this.rv; }
|
||||
}
|
||||
|
||||
/*
|
||||
* The idea is to store the violations in a tree instead of a list, to do
|
||||
* better and faster sort and filter mechanism and to visualize the result
|
||||
@ -145,7 +157,7 @@ public class Report {
|
||||
public void addRuleViolation(RuleViolation violation) {
|
||||
// NOPMD excluder
|
||||
if (linesToExclude.contains(new Integer(violation.getNode().getBeginLine()))) {
|
||||
suppressedRuleViolations.add(violation);
|
||||
suppressedRuleViolations.add(new SuppressedViolation(violation, true));
|
||||
return;
|
||||
}
|
||||
// Annotation excluder
|
||||
@ -157,7 +169,7 @@ public class Report {
|
||||
for (Iterator i = parentTypes.iterator(); i.hasNext();) {
|
||||
ASTTypeDeclaration t = (ASTTypeDeclaration)i.next();
|
||||
if (t.hasSuppressWarningsAnnotationFor(violation.getRule())) {
|
||||
suppressedRuleViolations.add(violation);
|
||||
suppressedRuleViolations.add(new SuppressedViolation(violation, false));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -42,20 +42,9 @@ public class TextRenderer implements Renderer {
|
||||
}
|
||||
|
||||
private void addSuppressed(Report report, StringBuffer buf) {
|
||||
Map suppressed = new HashMap();
|
||||
for (Iterator i = report.getSuppressedRuleViolations().iterator(); i.hasNext();) {
|
||||
RuleViolation excluded = (RuleViolation) i.next();
|
||||
if (!suppressed.containsKey(excluded.getFilename())) {
|
||||
suppressed.put(excluded.getFilename(), new Integer(0));
|
||||
}
|
||||
int newValue = ((Integer)suppressed.get(excluded.getFilename())).intValue();
|
||||
suppressed.put(excluded.getFilename(), new Integer(++newValue));
|
||||
}
|
||||
Set keys = suppressed.keySet();
|
||||
for (Iterator i = keys.iterator(); i.hasNext();){
|
||||
String filename = (String)i.next();
|
||||
int count = ((Integer)suppressed.get(filename)).intValue();
|
||||
buf.append(PMD.EOL + "Suppressed " + count + " rule violation" + (count == 1 ? "" : "s") + " in " + filename);
|
||||
Report.SuppressedViolation excluded = (Report.SuppressedViolation) i.next();
|
||||
buf.append(PMD.EOL + excluded.getRuleViolation().getRule().getName() + " rule violation suppressed by " + (excluded.suppressedByNOPMD() ? "//NOPMD" : "Annotation") + " in " + excluded.getRuleViolation().getFilename());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -69,11 +69,13 @@ public class XMLRenderer implements Renderer {
|
||||
|
||||
// suppressed violations
|
||||
for (Iterator i = report.getSuppressedRuleViolations().iterator(); i.hasNext();) {
|
||||
RuleViolation rv = (RuleViolation) i.next();
|
||||
Report.SuppressedViolation suppressed = (Report.SuppressedViolation) i.next();
|
||||
buf.append("<suppressedviolation ").append("filename=\"");
|
||||
StringUtil.appendXmlEscaped(buf, rv.getFilename());
|
||||
StringUtil.appendXmlEscaped(buf, suppressed.getRuleViolation().getFilename());
|
||||
buf.append("\" suppressiontype=\"");
|
||||
StringUtil.appendXmlEscaped(buf, suppressed.suppressedByNOPMD() ? "nopmd" : "annotation");
|
||||
buf.append("\" msg=\"");
|
||||
StringUtil.appendXmlEscaped(buf, rv.getDescription());
|
||||
StringUtil.appendXmlEscaped(buf, suppressed.getRuleViolation().getDescription());
|
||||
buf.append("\"/>").append(PMD.EOL);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user