diff --git a/clwb/src/com/google/idea/blaze/clwb/oclang/run/CidrGoogleTestUtilAdapter.java b/clwb/src/com/google/idea/blaze/clwb/oclang/run/CidrGoogleTestUtilAdapter.java index ec5aa1aeb4f..31ee6982cb9 100644 --- a/clwb/src/com/google/idea/blaze/clwb/oclang/run/CidrGoogleTestUtilAdapter.java +++ b/clwb/src/com/google/idea/blaze/clwb/oclang/run/CidrGoogleTestUtilAdapter.java @@ -17,6 +17,7 @@ import com.google.common.collect.Iterables; import com.google.idea.blaze.clwb.run.GoogleTestUtilAdapter; +import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Couple; import com.intellij.psi.PsiElement; @@ -38,7 +39,6 @@ public class CidrGoogleTestUtilAdapter implements GoogleTestUtilAdapter { @Nullable public static PsiElement findGoogleTestSymbol( Project project, String suiteName, String testName) { - CidrGoogleTestFramework instance = CidrGoogleTestFramework.getInstance(); final String prefixedSuiteName = "suite:" + suiteName; final String prefixedTestName = "test:" + testName; @@ -47,15 +47,8 @@ public static PsiElement findGoogleTestSymbol( (CidrTestScopeElement testElement) -> prefixedSuiteName.equals(testElement.getSuiteName()) && prefixedTestName.equals(testElement.getTestName())); - instance.consumeTestObjects(project, GlobalSearchScope.allScope(project), processor); - if (!processor.isFound()) { - return null; - } - CidrTestScopeElement testElement = processor.getFoundValue(); - if (testElement == null) { - return null; - } - return testElement.getElement(); + + return getTestElement(project, processor); } @Nullable @@ -82,16 +75,7 @@ public static PsiElement findGoogleTestInstantiationSymbol( parameterizedSuiteName.equals(testElement.getSuiteName())); } - CidrGoogleTestFramework instance = CidrGoogleTestFramework.getInstance(); - instance.consumeTestObjects(project, GlobalSearchScope.allScope(project), processor); - if (!processor.isFound()) { - return null; - } - CidrTestScopeElement testElement = processor.getFoundValue(); - if (testElement == null) { - return null; - } - return testElement.getElement(); + return getTestElement(project, (FindFirstWithPredicateProcessor) processor); } /* TODO: Convert to not use CidrGoogleTestUtilObsolete. */ @@ -133,12 +117,15 @@ public PsiElement findGoogleTestSymbol( CidrGoogleTestFramework instance = CidrGoogleTestFramework.getInstance(); FindFirstWithPredicateProcessor processor = new FindFirstWithPredicateProcessor<>(predicate); - instance.consumeTestObjects(project, GlobalSearchScope.allScope(project), processor); - CidrTestScopeElement testScopeElement = processor.getFoundValue(); - if (testScopeElement == null) { - return null; - } - return testScopeElement.getElement(); + + return ReadAction.compute(() -> { + instance.consumeTestObjects(project, GlobalSearchScope.allScope(project), processor); + CidrTestScopeElement testScopeElement = processor.getFoundValue(); + if (testScopeElement == null) { + return null; + } + return testScopeElement.getElement(); + }); } private static Collection findGoogleTestSymbols( @@ -151,8 +138,11 @@ protected boolean accept(CidrTestScopeElement cidrTestScopeElement) { return predicate.test(cidrTestScopeElement); } }; - instance.consumeTestObjects(project, GlobalSearchScope.allScope(project), processor); - return processor.getResults(); + + return ReadAction.compute(() -> { + instance.consumeTestObjects(project, GlobalSearchScope.allScope(project), processor); + return processor.getResults(); + }); } private static class FindFirstWithPredicateProcessor extends FindProcessor { @@ -167,4 +157,19 @@ protected boolean accept(T t) { return !isFound() && predicate.test(t); } } + + private static PsiElement getTestElement(Project project, FindFirstWithPredicateProcessor processor) { + return ReadAction.compute(() -> { + CidrGoogleTestFramework instance = CidrGoogleTestFramework.getInstance(); + instance.consumeTestObjects(project, GlobalSearchScope.allScope(project), processor); + if (!processor.isFound()) { + return null; + } + CidrTestScopeElement testElement = processor.getFoundValue(); + if (testElement == null) { + return null; + } + return testElement.getElement(); + }); + } } diff --git a/clwb/src/com/google/idea/blaze/clwb/run/BlazeCidrLauncher.java b/clwb/src/com/google/idea/blaze/clwb/run/BlazeCidrLauncher.java index 43b0064391c..662c4db0cc5 100644 --- a/clwb/src/com/google/idea/blaze/clwb/run/BlazeCidrLauncher.java +++ b/clwb/src/com/google/idea/blaze/clwb/run/BlazeCidrLauncher.java @@ -59,6 +59,7 @@ import com.intellij.execution.runners.ExecutionEnvironment; import com.intellij.execution.ui.ConsoleView; import com.intellij.ide.util.PropertiesComponent; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.xdebugger.XDebugSession; @@ -135,26 +136,28 @@ private ProcessHandler createProcess(CommandLineState state, List extraB Preconditions.checkNotNull(ProjectViewManager.getInstance(project).getProjectViewSet()); if (shouldDisplayBazelTestFilterWarning()) { - String messageContents = - "The Google Test framework did not apply test filtering correctly before " - + "git commit ba96d0b.
" - + "Please ensure you are past this commit if you are using it.

" - + "More information on the bazel
issue"; - - int selectedOption = - Messages.showDialog( - getProject(), - messageContents, - "Please update 'Google Test' past ba96d0b...", - new String[] {"Close", "Don't show again"}, - 0, // Default to "Close" - Messages.getWarningIcon()); - if (selectedOption == 1) { - PropertiesComponent.getInstance().setValue(DISABLE_BAZEL_GOOGLETEST_FILTER_WARNING, "true"); - } + ApplicationManager.getApplication().invokeAndWait(() -> { + String messageContents = + "The Google Test framework did not apply test filtering correctly before " + + "git commit ba96d0b.
" + + "Please ensure you are past this commit if you are using it.

" + + "More information on the bazel
issue"; + + int selectedOption = + Messages.showDialog( + getProject(), + messageContents, + "Please update 'Google Test' past ba96d0b...", + new String[] {"Close", "Don't show again"}, + 0, // Default to "Close" + Messages.getWarningIcon()); + if (selectedOption == 1) { + PropertiesComponent.getInstance().setValue(DISABLE_BAZEL_GOOGLETEST_FILTER_WARNING, "true"); + } + }); } BlazeCommand.Builder commandBuilder =