1313import com .intellij .openapi .project .Project ;
1414import com .intellij .openapi .project .ProjectManagerListener ;
1515import com .intellij .openapi .startup .ProjectActivity ;
16- import com .intellij .openapi .util .Computable ;
1716import com .intellij .openapi .vfs .VirtualFile ;
1817import com .intellij .psi .*;
1918import com .intellij .psi .search .searches .AllClassesSearch ;
@@ -81,17 +80,16 @@ public MavenProjectReportGenerator() {
8180 telemetryClient = new TelemetryClient (configuration );
8281 }
8382
84- //@TODO recheck if generated report is idempotent (still the same)
8583 @ Nullable
8684 @ Override
8785 public Object execute (@ Nonnull Project project , @ Nonnull Continuation <? super Unit > continuation ) {
88- ReadAction . nonBlocking (() -> {
89- generateReport ( project );
90- return Unit . INSTANCE ;
91- }). inSmartMode ( project )
92- . expireWhen (project :: isDisposed )
93- . submit ( scheduledExecutor );
94-
86+ scheduledExecutor . schedule (() ->
87+ ReadAction . nonBlocking (() -> {
88+ generateReport ( project ) ;
89+ return Unit . INSTANCE ;
90+ }). inSmartMode (project )
91+ . expireWhen ( project :: isDisposed )
92+ . executeSynchronously (), INITIAL_DELAY_IN_MINUTES , TimeUnit . MINUTES );
9593 return null ;
9694 }
9795
@@ -120,7 +118,7 @@ private void generateReport(@Nonnull Project project) {
120118 sendReportToAppInsights (value );
121119 }
122120 } catch (final Exception e ) {
123- log .error ("Unable to send the Azure SDK report " , e );
121+ log .info ("Unable to send the Azure SDK report " , e );
124122 }
125123 } else {
126124 log .debug ("Azure telemetry is disabled" );
@@ -201,8 +199,9 @@ private void analyzeCode(MavenProjectsManager mavenProjectsManager, MavenProject
201199 final Map <String , Integer > methodCallFrequency = new HashMap <>();
202200 final Map <String , Integer > betaMethodCallFrequency = new HashMap <>();
203201
204- final Module module = ApplicationManager .getApplication ()
205- .runReadAction ((Computable <Module >) () -> mavenProjectsManager .findModule (mavenProject ));
202+ final Module module = ReadAction .nonBlocking (() -> mavenProjectsManager .findModule (mavenProject ))
203+ .expireWhen (mavenProjectsManager .getProject ()::isDisposed )
204+ .executeSynchronously ();
206205 if (module == null ) {
207206 return ;
208207 }
@@ -252,7 +251,7 @@ private void sendReportToAppInsights(MavenProjectReport report) {
252251 telemetryClient .flush ();
253252 log .info ("Successfully sent the report to Application Insights" );
254253 } catch (final Exception ex ) {
255- log .error ("Unable to send report to Application Insights. " + ex .getMessage ());
254+ log .info ("Unable to send report to Application Insights. " + ex .getMessage ());
256255 }
257256 }
258257
@@ -273,24 +272,29 @@ private Map<String, String> getCustomEventProperties(MavenProjectReport report)
273272
274273 private void checkDependencyManagement (MavenProjectsManager mavenProjectsManager , MavenProject mavenProject , MavenProjectReport report ) {
275274 final VirtualFile pomFile = mavenProject .getFile ();
276- final PsiFile psiFile = ApplicationManager .getApplication ()
277- .runReadAction ((Computable <PsiFile >) () -> PsiManager .getInstance (mavenProjectsManager .getProject ()).findFile (pomFile ));
275+ final PsiFile psiFile = ReadAction .nonBlocking (() -> PsiManager .getInstance (mavenProjectsManager .getProject ()).findFile (pomFile ))
276+ .expireWhen (mavenProjectsManager .getProject ()::isDisposed )
277+ .executeSynchronously ();
278278 if (psiFile == null ) {
279279 return ;
280280 }
281281 final FileViewProvider viewProvider = psiFile .getViewProvider ();
282282 final XmlFile xmlFile = (XmlFile ) viewProvider .getPsi (StdLanguages .XML );
283- final XmlTag rootTag = ApplicationManager .getApplication ()
284- .runReadAction ((Computable <XmlTag >) xmlFile ::getRootTag );
283+ final XmlTag rootTag = ReadAction .nonBlocking (() -> xmlFile .getRootTag ())
284+ .expireWhen (mavenProjectsManager .getProject ()::isDisposed )
285+ .executeSynchronously ();
285286 if (rootTag != null && "project" .equals (rootTag .getName ())) {
286- final XmlTag dependencyManagement = ApplicationManager .getApplication ()
287- .runReadAction ((Computable <XmlTag >) () -> rootTag .findFirstSubTag ("dependencyManagement" ));
287+ final XmlTag dependencyManagement = ReadAction .nonBlocking (() -> rootTag .findFirstSubTag ("dependencyManagement" ))
288+ .expireWhen (mavenProjectsManager .getProject ()::isDisposed )
289+ .executeSynchronously ();
288290 if (dependencyManagement != null ) {
289- final XmlTag dependenciesTag = ApplicationManager .getApplication ()
290- .runReadAction ((Computable <XmlTag >) () -> dependencyManagement .findFirstSubTag ("dependencies" ));
291+ final XmlTag dependenciesTag = ReadAction .nonBlocking (() -> dependencyManagement .findFirstSubTag ("dependencies" ))
292+ .expireWhen (mavenProjectsManager .getProject ()::isDisposed )
293+ .executeSynchronously ();
291294 if (dependenciesTag != null ) {
292- final XmlTag [] dependencyTags = ApplicationManager .getApplication ()
293- .runReadAction ((Computable <XmlTag []>) () -> dependenciesTag .findSubTags ("dependency" ));
295+ final XmlTag [] dependencyTags = ReadAction .nonBlocking (() -> dependenciesTag .findSubTags ("dependency" ))
296+ .expireWhen (mavenProjectsManager .getProject ()::isDisposed )
297+ .executeSynchronously ();
294298
295299 for (final XmlTag dependencyTag : dependencyTags ) {
296300 final String groupId = getTextValue (dependencyTag , "groupId" );
0 commit comments