forked from phoedos/pmd
added callback thingy to reports
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@629 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -11,12 +11,15 @@ import net.sourceforge.pmd.renderers.XMLRenderer;
|
||||
import net.sourceforge.pmd.RuleViolation;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.Report;
|
||||
import net.sourceforge.pmd.ReportListener;
|
||||
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class ReportTest extends TestCase {
|
||||
public class ReportTest extends TestCase implements ReportListener {
|
||||
|
||||
private boolean semaphore;
|
||||
|
||||
public ReportTest(String name) {
|
||||
super(name);
|
||||
@ -49,23 +52,17 @@ public class ReportTest extends TestCase {
|
||||
assertTrue(result.indexOf("rule2") < result.indexOf("rule1"));
|
||||
}
|
||||
|
||||
/*
|
||||
public void testRenderXML() {
|
||||
Renderer r = new Renderer("xml");
|
||||
r.addRuleViolation(new RuleViolation(new MockRule(), 5, "foo"));
|
||||
String rpt = r.render();
|
||||
assertTrue(rpt.indexOf("foo") != -1);
|
||||
assertTrue(rpt.indexOf("<pmd>") != -1);
|
||||
assertTrue(rpt.indexOf("<file>") != -1);
|
||||
public void testListener() {
|
||||
Report rpt = new Report();
|
||||
rpt.addListener(this);
|
||||
semaphore = false;
|
||||
rpt.addRuleViolation(new RuleViolation(new MockRule(), 5, "file"));
|
||||
assertTrue(semaphore);
|
||||
|
||||
}
|
||||
|
||||
public void testRenderHTML() {
|
||||
Renderer r = new Renderer("html", "format");
|
||||
r.addRuleViolation(new RuleViolation(new MockRule(), 5, "filename"));
|
||||
String rpt = r.render();
|
||||
assertTrue(rpt.indexOf("format") != -1);
|
||||
assertTrue(rpt.indexOf("<table>") != -1);
|
||||
assertTrue(rpt.indexOf("filename") != -1);
|
||||
public void ruleViolationAdded(RuleViolation ruleViolation) {
|
||||
semaphore = true;
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
@ -12,9 +12,18 @@ import java.util.*;
|
||||
public class Report {
|
||||
|
||||
private Set violations = new TreeSet(new RuleViolation.RuleViolationComparator());
|
||||
private List listeners = new ArrayList();
|
||||
|
||||
public void addListener(ReportListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public void addRuleViolation(RuleViolation violation) {
|
||||
violations.add(violation);
|
||||
for (Iterator i = listeners.iterator();i.hasNext();) {
|
||||
ReportListener listener = (ReportListener)i.next();
|
||||
listener.ruleViolationAdded(violation);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
|
10
pmd/src/net/sourceforge/pmd/ReportListener.java
Normal file
10
pmd/src/net/sourceforge/pmd/ReportListener.java
Normal file
@ -0,0 +1,10 @@
|
||||
/*
|
||||
* User: tom
|
||||
* Date: Aug 5, 2002
|
||||
* Time: 11:52:20 AM
|
||||
*/
|
||||
package net.sourceforge.pmd;
|
||||
|
||||
public interface ReportListener {
|
||||
public void ruleViolationAdded(RuleViolation ruleViolation);
|
||||
}
|
Reference in New Issue
Block a user