88import com .intellij .openapi .fileEditor .FileEditorManager ;
99import com .intellij .openapi .progress .ProgressIndicator ;
1010import com .intellij .openapi .progress .ProgressManager ;
11+ import com .intellij .openapi .progress .Task ;
1112import com .intellij .openapi .project .Project ;
1213import com .intellij .openapi .roots .ProjectRootManager ;
13- import com .intellij .openapi .vcs .actions .VcsContextFactory ;
1414import com .intellij .openapi .vfs .VfsUtil ;
1515import com .intellij .openapi .vfs .VirtualFile ;
1616import com .intellij .openapi .vfs .VirtualFileFilter ;
1717import com .intellij .openapi .wm .ToolWindow ;
1818import com .intellij .openapi .wm .ToolWindowManager ;
19+ import com .intellij .plugins .bodhi .pmd .core .PMDProgressRenderer ;
1920import com .intellij .plugins .bodhi .pmd .core .PMDResultCollector ;
2021import com .intellij .plugins .bodhi .pmd .tree .*;
22+ import org .jetbrains .annotations .NotNull ;
2123
2224import java .io .File ;
2325import java .util .LinkedList ;
@@ -152,8 +154,9 @@ public void processFiles(Project project, final String ruleSetPaths, final List<
152154 ApplicationManager .getApplication ().saveAll ();
153155
154156 //Run PMD asynchronously
155- Runnable runnable = new Runnable () {
156- public void run () {
157+ ProgressManager .getInstance ().run (new Task .Backgroundable (project , "Running PMD" , true ) {
158+ @ Override
159+ public void run (@ NotNull ProgressIndicator indicator ) {
157160 //Show a progress indicator.
158161 ProgressIndicator progress = ProgressManager .getInstance ().getProgressIndicator ();
159162 String [] ruleSetPathArray = ruleSetPaths .split (RULE_DELIMITER );
@@ -165,15 +168,15 @@ public void run() {
165168 rootNode .setFileCount (files .size ());
166169 rootNode .setRuleSetCount (ruleSetPathArray .length );
167170 rootNode .setRunning (true );
171+ PMDProgressRenderer progressRenderer = new PMDProgressRenderer (progress , files .size () * ruleSetPathArray .length );
168172 for (String ruleSetPath : ruleSetPathArray ) {
169- //TODO: even better progress
170173 progress .setText ("Running : " + ruleSetPath + " on " + files .size () + " file(s)" );
171174
172175 //Create a result collector to get results
173176 PMDResultCollector collector = new PMDResultCollector ();
174177
175178 //Get the tree nodes from result collector
176- List <PMDRuleSetEntryNode > resultRuleNodes = collector .runPMDAndGetResults (files , ruleSetPath , projectComponent );
179+ List <PMDRuleSetEntryNode > resultRuleNodes = collector .runPMDAndGetResults (files , ruleSetPath , projectComponent , progressRenderer );
177180 // sort rules by priority, rule and suppressed nodes are comparable
178181 resultRuleNodes .sort (null );
179182
@@ -189,13 +192,15 @@ public void run() {
189192 rootNode .calculateCounts ();
190193 resultPanel .reloadResultTree ();
191194 }
195+ if (progress .isCanceled ()) {
196+ break ;
197+ }
192198 }
193199 resultPanel .addProcessingErrorsNodeToRootIfHasAny (); // as last node
194200 rootNode .calculateCounts ();
195201 rootNode .setRunning (false );
196202 resultPanel .reloadResultTree ();
197203 }
198- };
199- ProgressManager .getInstance ().runProcessWithProgressSynchronously (runnable , "Running PMD" , true , project );
204+ });
200205 }
201- }
206+ }
0 commit comments