From 76a9fc635d0d3e04c6b047e7b10992542991bb72 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 2 Nov 2016 18:04:19 +0100 Subject: [PATCH] invoke BuildTargetScopeProvider in a read action --- .../intellij/compiler/impl/CompileDriver.java | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java index 54b67af6e2f7..3ca27681fdde 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java @@ -26,6 +26,7 @@ import com.intellij.compiler.server.DefaultMessageHandler; import com.intellij.notification.Notification; import com.intellij.notification.NotificationListener; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.compiler.*; import com.intellij.openapi.compiler.ex.CompilerPathsEx; import com.intellij.openapi.deployment.DeploymentUtil; @@ -187,11 +188,9 @@ public class CompileDriver { return Boolean.TRUE.equals(scope.getUserData(COMPILATION_STARTED_AUTOMATICALLY)); } - @Nullable - private TaskFuture compileInExternalProcess(final @NotNull CompileContextImpl compileContext, final boolean onlyCheckUpToDate) - throws Exception { - final CompileScope scope = compileContext.getCompileScope(); - final Collection paths = CompileScopeUtil.fetchFiles(compileContext); + private List getBuildScopes(@NotNull CompileContextImpl compileContext, + CompileScope scope, + Collection paths) { List scopes = new ArrayList<>(); final boolean forceBuild = !compileContext.isMake(); List explicitScopes = CompileScopeUtil.getBaseScopeForExternalBuild(scope); @@ -205,10 +204,29 @@ public class CompileDriver { scopes.addAll(CmdlineProtoUtil.createAllModulesScopes(forceBuild)); } if (paths.isEmpty()) { - for (BuildTargetScopeProvider provider : BuildTargetScopeProvider.EP_NAME.getExtensions()) { - scopes = CompileScopeUtil.mergeScopes(scopes, provider.getBuildTargetScopes(scope, myCompilerFilter, myProject, forceBuild)); - } + scopes = mergeScopesFromProviders(scope, scopes, forceBuild); } + return scopes; + } + + private List mergeScopesFromProviders(CompileScope scope, + List scopes, + boolean forceBuild) { + for (BuildTargetScopeProvider provider : BuildTargetScopeProvider.EP_NAME.getExtensions()) { + List providerScopes = ReadAction.compute( + () -> myProject.isDisposed() ? Collections.emptyList() + : provider.getBuildTargetScopes(scope, myCompilerFilter, myProject, forceBuild)); + scopes = CompileScopeUtil.mergeScopes(scopes, providerScopes); + } + return scopes; + } + + @Nullable + private TaskFuture compileInExternalProcess(final @NotNull CompileContextImpl compileContext, final boolean onlyCheckUpToDate) + throws Exception { + final CompileScope scope = compileContext.getCompileScope(); + final Collection paths = CompileScopeUtil.fetchFiles(compileContext); + List scopes = getBuildScopes(compileContext, scope, paths); // need to pass scope's user data to server final Map builderParams;