1616import com .intellij .openapi .wm .ToolWindow ;
1717import com .intellij .openapi .wm .ToolWindowManager ;
1818import com .intellij .plugins .bodhi .pmd .core .PMDResultCollector ;
19- import com .intellij .plugins .bodhi .pmd .tree .PMDRuleNode ;
19+ import com .intellij .plugins .bodhi .pmd .tree .PMDBranchNode ;
20+ import com .intellij .plugins .bodhi .pmd .tree .PMDRootNode ;
2021
21- import javax .swing .tree .DefaultMutableTreeNode ;
2222import java .io .File ;
2323import java .util .LinkedList ;
2424import java .util .List ;
2525
26- import static com .intellij .plugins .bodhi .pmd .filter .VirtualFileFilters .and ;
27- import static com .intellij .plugins .bodhi .pmd .filter .VirtualFileFilters .fileHasExtension ;
28- import static com .intellij .plugins .bodhi .pmd .filter .VirtualFileFilters .fileInSources ;
29- import static com .intellij .plugins .bodhi .pmd .filter .VirtualFileFilters .fileInTestSources ;
30- import static com .intellij .plugins .bodhi .pmd .filter .VirtualFileFilters .isDirectory ;
31- import static com .intellij .plugins .bodhi .pmd .filter .VirtualFileFilters .not ;
32- import static com .intellij .plugins .bodhi .pmd .filter .VirtualFileFilters .or ;
26+ import static com .intellij .plugins .bodhi .pmd .filter .VirtualFileFilters .*;
3327
3428/**
3529 * Invokes PMD using the PMDResultCollector and gets results from that. This acts as a
@@ -72,12 +66,12 @@ public static PMDInvoker getInstance() {
7266 * Runs PMD based on the given parameters, and populates result.
7367 *
7468 * @param actionEvent The action event that triggered run
75- * @param rule The rule (s) to run
69+ * @param ruleSetPaths The ruleSetPath (s) for rules to run
7670 * @param isCustomRuleSet Is it a custom ruleset or not.
7771 */
78- public void runPMD (AnActionEvent actionEvent , String rule , boolean isCustomRuleSet ) {
79- //If no rule is selected, nothing to do
80- if (rule == null || rule .length () == 0 ) {
72+ public void runPMD (AnActionEvent actionEvent , String ruleSetPaths , boolean isCustomRuleSet ) {
73+ //If no ruleSetPath is selected, nothing to do
74+ if (ruleSetPaths == null || ruleSetPaths .length () == 0 ) {
8175 return ;
8276 }
8377 //Show the tool window
@@ -86,7 +80,7 @@ public void runPMD(AnActionEvent actionEvent, String rule, boolean isCustomRuleS
8680 Project project = actionEvent .getData (PlatformDataKeys .PROJECT );
8781 PMDProjectComponent projectComponent = project .getComponent (PMDProjectComponent .class );
8882 PMDResultPanel resultPanel = projectComponent .getResultPanel ();
89- PMDRuleNode rootNodeData = (( PMDRuleNode ) resultPanel .getRootNode (). getUserObject () );
83+ PMDRootNode rootNode = resultPanel .getRootNode ();
9084
9185 List <File > files = new LinkedList <File >();
9286 if (actionEvent .getPlace ().equals (ActionPlaces .PROJECT_VIEW_POPUP )
@@ -112,7 +106,7 @@ public void runPMD(AnActionEvent actionEvent, String rule, boolean isCustomRuleS
112106
113107 if (selectedFiles == null || selectedFiles .length == 0 ) {
114108 //toolWindow.displayErrorMessage("Please select a file to process first");
115- rootNodeData .setFileCount (0 );
109+ rootNode .setFileCount (0 );
116110 return ;
117111 }
118112 VirtualFileFilter filter = and (SUPPORTED_EXTENSIONS , fileInSources (project ));
@@ -129,25 +123,25 @@ public void runPMD(AnActionEvent actionEvent, String rule, boolean isCustomRuleS
129123 VirtualFile [] selectedFiles = FileEditorManager .getInstance (project ).getSelectedFiles ();
130124 if (selectedFiles .length == 0 ) {
131125 //toolWindow.displayErrorMessage("Please select a file to process first");
132- rootNodeData .setFileCount (0 );
126+ rootNode .setFileCount (0 );
133127 return ;
134128 }
135129 files .add (new File (selectedFiles [0 ].getPresentableUrl ()));
136130 }
137131
138132 //Got the files, start processing now
139- processFiles (project , rule , files , isCustomRuleSet , projectComponent );
133+ processFiles (project , ruleSetPaths , files , isCustomRuleSet , projectComponent );
140134 }
141135
142136 /**
143137 * Runs PMD on given files.
144138 * @param project the project
145- * @param rule The rule (s) to run
139+ * @param ruleSetPaths The ruleSetPath (s) of rules to run
146140 * @param files The files on which to run
147141 * @param isCustomRuleSet Is it a custom ruleset or not.
148142 * @param projectComponent
149143 */
150- public void processFiles (Project project , final String rule , final List <File > files , final boolean isCustomRuleSet , final PMDProjectComponent projectComponent ) {
144+ public void processFiles (Project project , final String ruleSetPaths , final List <File > files , final boolean isCustomRuleSet , final PMDProjectComponent projectComponent ) {
151145 ToolWindow toolWindow = ToolWindowManager .getInstance (project ).getToolWindow (PMDProjectComponent .TOOL_ID );
152146 toolWindow .activate (null );
153147
@@ -159,43 +153,45 @@ public void processFiles(Project project, final String rule, final List<File> fi
159153 public void run () {
160154 //Show a progress indicator.
161155 ProgressIndicator progress = ProgressManager .getInstance ().getProgressIndicator ();
162- String [] rules = rule .split (RULE_DELIMITER );
156+ String [] ruleSetPathArray = ruleSetPaths .split (RULE_DELIMITER );
163157 PMDResultPanel resultPanel = projectComponent .getResultPanel ();
164158
165- PMDRuleNode rootNodeData = (( PMDRuleNode ) resultPanel .getRootNode (). getUserObject () );
166- PMDResultCollector .report = null ;
167- rootNodeData .setFileCount (files .size ());
168- rootNodeData .setRuleSetCount (rules .length );
169- rootNodeData .setRunning (true );
170- for (int i = 0 ; i < rules . length ; i ++ ) {
159+ PMDRootNode rootNode = resultPanel .getRootNode ();
160+ PMDResultCollector .clearReport () ;
161+ rootNode .setFileCount (files .size ());
162+ rootNode .setRuleSetCount (ruleSetPathArray .length );
163+ rootNode .setRunning (true );
164+ for (String ruleSetPath : ruleSetPathArray ) {
171165 //TODO: even better progress
172- progress .setText ("Running : " + rules [ i ] + " on " + files .size () + " file(s)" );
166+ progress .setText ("Running : " + ruleSetPath + " on " + files .size () + " file(s)" );
173167
174168 //Create a result collector to get results
175169 PMDResultCollector collector = new PMDResultCollector ();
176170
177171 //Get the tree nodes from result collector
178- List <DefaultMutableTreeNode > results = collector .getResults (files , rules [ i ] , projectComponent );
172+ List <PMDBranchNode > resultRuleNodes = collector .runPMDAndGetResults (files , ruleSetPath , projectComponent );
179173
180- if (results .size () != 0 ) {
174+ if (resultRuleNodes .size () != 0 ) {
175+ String ruleSetName ;
181176 if (isCustomRuleSet ) {
182177 //For custom rulesets, using a separate format for rendering
183- rules [ i ] = PMDUtil .getBareFileNameFromPath (rules [ i ] ) + ";" + rules [ i ] ;
178+ ruleSetName = PMDUtil .getBareFileNameFromPath (ruleSetPath ) + ";" + ruleSetPath ;
184179 } else {
185- rules [ i ] = PMDUtil .getBareFileNameFromPath (rules [ i ] );
180+ ruleSetName = PMDUtil .getBareFileNameFromPath (ruleSetPath );
186181 }
187- DefaultMutableTreeNode node = resultPanel .addNode (rules [i ]);
188- //Add all nodes to the tree
189- int childCount = 0 ;
190- for (DefaultMutableTreeNode pmdResult : results ) {
191- resultPanel .addNode (node , pmdResult );
192- childCount += ((PMDRuleNode )pmdResult .getUserObject ()).getViolationCount ();
182+ PMDBranchNode ruleSetNode = resultPanel .addCreateBranchNodeAtRoot (ruleSetName );
183+ //Add all rule nodes to the tree
184+ for (PMDBranchNode resultRuleNode : resultRuleNodes ) {
185+ resultPanel .addNode (ruleSetNode , resultRuleNode );
193186 }
194- (( PMDRuleNode ) node . getUserObject ()). addToViolationCount ( childCount );
195- rootNodeData . addToViolationCount ( childCount );
187+ rootNode . calculateCounts ( );
188+ resultPanel . reloadResultTree ( );
196189 }
197190 }
198- rootNodeData .setRunning (false );
191+ resultPanel .addProcessingErrorsNodeToRootIfHasAny (); // as last node
192+ rootNode .calculateCounts ();
193+ rootNode .setRunning (false );
194+ resultPanel .reloadResultTree ();
199195 }
200196 };
201197 ProgressManager .getInstance ().runProcessWithProgressSynchronously (runnable , "Running PMD" , true , project );
0 commit comments