2121import java .util .*;
2222
2323/**
24- * Responsible for running PMD and collecting the results which can be represeted in
24+ * Responsible for running PMD and collecting the results which can be represented in
2525 * tree format.
2626 *
2727 * @author bodhi
2828 * @version 1.3
2929 */
3030public class PMDResultCollector {
3131
32- private Map <String , PMDBranchNode > ruleNameToNodeMap ;
33- public static Report report ;
32+ private final Map <String , PMDBranchNode > ruleNameToNodeMap ;
33+ private static Report report = new Report () ;
3434
3535 /**
3636 * Creates an instance of PMDResultCollector.
@@ -39,6 +39,20 @@ public PMDResultCollector() {
3939 ruleNameToNodeMap = new LinkedHashMap <>();
4040 } // linked to keep insertion order
4141
42+ /**
43+ * Clears the pmd results Report by assigning a new one
44+ */
45+ public static void clearReport () {
46+ report = new Report ();
47+ }
48+
49+ /**
50+ * Returns the report with pmd results
51+ * @return the report with pmd results
52+ */
53+ public static Report getReport () {
54+ return report ;
55+ }
4256 /**
4357 * Runs the given ruleSet(s) on given set of files and returns the result.
4458 *
@@ -122,7 +136,7 @@ private String shortMessage(String message)
122136 }
123137
124138 /**
125- * Verifies whether the rule set specified at the path is a valid PMD ruleset .
139+ * Verifies whether the rule set specified at the path is a valid PMD rule set .
126140 *
127141 * @param path path of the rule set
128142 * @return true if valid rule set, false otherwise.
@@ -171,7 +185,7 @@ private class PMDResultRenderer extends AbstractIncrementingRenderer {
171185
172186 private final List <PMDBranchNode > pmdRuleResultNodes ;
173187 private final PMDBranchNode processingErrorsNode ;
174- private Set <String > filesWithError = new HashSet ();
188+ private final Set <String > filesWithError = new HashSet <> ();
175189
176190 public PMDResultRenderer (List <PMDBranchNode > pmdRuleSetResults , PMDBranchNode errorsNode ) {
177191 super ("pmdplugin" , "PMD plugin renderer" );
@@ -182,9 +196,6 @@ public PMDResultRenderer(List<PMDBranchNode> pmdRuleSetResults, PMDBranchNode er
182196 @ Override
183197 public void renderFileViolations (Iterator <RuleViolation > violations ) throws IOException {
184198 PMDTreeNodeFactory nodeFactory = PMDTreeNodeFactory .getInstance ();
185- if (PMDResultCollector .report == null ) {
186- PMDResultCollector .report = new Report ();
187- }
188199 while (violations .hasNext ()) {
189200 RuleViolation iRuleViolation = violations .next ();
190201 PMDResultCollector .report .addRuleViolation (iRuleViolation );
0 commit comments