Search in sources :

Example 1 with AbstractProgressIndicatorBase

use of com.intellij.openapi.progress.util.AbstractProgressIndicatorBase in project intellij-community by JetBrains.

the class SkeletonTestTask method runTestOn.

@Override
public void runTestOn(@NotNull final String sdkHome) throws IOException, InvalidSdkException {
    final Sdk sdk = createTempSdk(sdkHome, SdkCreationType.SDK_PACKAGES_ONLY);
    final File skeletonsPath = new File(PythonSdkType.getSkeletonsPath(PathManager.getSystemPath(), sdk.getHomePath()));
    // File with module skeleton
    File skeletonFileOrDirectory = new File(skeletonsPath, myModuleNameToBeGenerated);
    // Module may be stored in "moduleName.py" or "moduleName/__init__.py"
    if (skeletonFileOrDirectory.isDirectory()) {
        skeletonFileOrDirectory = new File(skeletonFileOrDirectory, PyNames.INIT_DOT_PY);
    } else {
        skeletonFileOrDirectory = new File(skeletonFileOrDirectory.getAbsolutePath() + PyNames.DOT_PY);
    }
    final File skeletonFile = skeletonFileOrDirectory;
    if (skeletonFile.exists()) {
        // To make sure we do not reuse it
        assert skeletonFile.delete() : "Failed to delete file " + skeletonFile;
    }
    ApplicationManager.getApplication().invokeAndWait(() -> {
        // File that uses CLR library
        myFixture.copyFileToProject("dotNet/" + mySourceFileToRunGenerationOn, mySourceFileToRunGenerationOn);
        // Library itself
        myFixture.copyFileToProject("dotNet/PythonLibs.dll", "PythonLibs.dll");
        // Another library
        myFixture.copyFileToProject("dotNet/SingleNameSpace.dll", "SingleNameSpace.dll");
        myFixture.configureByFile(mySourceFileToRunGenerationOn);
    }, ModalityState.NON_MODAL);
    // This inspection should suggest us to generate stubs
    myFixture.enableInspections(PyUnresolvedReferencesInspection.class);
    UIUtil.invokeAndWaitIfNeeded(new Runnable() {

        @Override
        public void run() {
            PsiDocumentManager.getInstance(myFixture.getProject()).commitAllDocuments();
            final String intentionName = PyBundle.message("sdk.gen.stubs.for.binary.modules", myUseQuickFixWithThisModuleOnly);
            final IntentionAction intention = myFixture.findSingleIntention(intentionName);
            Assert.assertNotNull("No intention found to generate skeletons!", intention);
            Assert.assertThat("Intention should be quick fix to run", intention, Matchers.instanceOf(QuickFixWrapper.class));
            final LocalQuickFix quickFix = ((QuickFixWrapper) intention).getFix();
            Assert.assertThat("Quick fix should be 'generate binary skeletons' fix to run", quickFix, Matchers.instanceOf(GenerateBinaryStubsFix.class));
            final Task fixTask = ((GenerateBinaryStubsFix) quickFix).getFixTask(myFixture.getFile());
            fixTask.run(new AbstractProgressIndicatorBase());
        }
    });
    FileUtil.copy(skeletonFile, new File(myFixture.getTempDirPath(), skeletonFile.getName()));
    if (myExpectedSkeletonFile != null) {
        final String actual = StreamUtil.readText(new FileInputStream(skeletonFile), Charset.defaultCharset());
        final String skeletonText = StreamUtil.readText(new FileInputStream(new File(getTestDataPath(), myExpectedSkeletonFile)), Charset.defaultCharset());
        // TODO: Move to separate method ?
        if (!Matchers.equalToIgnoringWhiteSpace(removeGeneratorVersion(skeletonText)).matches(removeGeneratorVersion(actual))) {
            throw new FileComparisonFailure("asd", skeletonText, actual, skeletonFile.getAbsolutePath());
        }
    }
    myFixture.configureByFile(skeletonFile.getName());
}
Also used : Task(com.intellij.openapi.progress.Task) PyExecutionFixtureTestTask(com.jetbrains.env.PyExecutionFixtureTestTask) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) AbstractProgressIndicatorBase(com.intellij.openapi.progress.util.AbstractProgressIndicatorBase) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) Sdk(com.intellij.openapi.projectRoots.Sdk) File(java.io.File) FileInputStream(java.io.FileInputStream) FileComparisonFailure(com.intellij.rt.execution.junit.FileComparisonFailure)

Example 2 with AbstractProgressIndicatorBase

use of com.intellij.openapi.progress.util.AbstractProgressIndicatorBase in project intellij-community by JetBrains.

the class JobUtilTest method checkProgressAndReadAction.

private static void checkProgressAndReadAction(final List<Object> objects, final DaemonProgressIndicator progress, final boolean runInReadAction) throws Throwable {
    final AtomicReference<Throwable> exception = new AtomicReference<>();
    JobLauncher.getInstance().invokeConcurrentlyUnderProgress(objects, progress, runInReadAction, o -> {
        try {
            if (objects.size() <= 1 || JobSchedulerImpl.CORES_COUNT <= JobLauncherImpl.CORES_FORK_THRESHOLD) {
                assertTrue(ApplicationManager.getApplication().isDispatchThread());
            } else {
            }
            ProgressIndicator actualIndicator = ProgressManager.getInstance().getProgressIndicator();
            if (progress == null) {
                assertNotNull(actualIndicator);
                assertTrue(actualIndicator instanceof AbstractProgressIndicatorBase);
            } else {
                assertTrue(actualIndicator instanceof SensitiveProgressWrapper);
                ProgressIndicator original = ((SensitiveProgressWrapper) actualIndicator).getOriginalProgressIndicator();
                assertSame(progress, original);
            }
            assertTrue(!runInReadAction || ApplicationManager.getApplication().isReadAccessAllowed());
        } catch (Throwable e) {
            exception.set(e);
        }
        return true;
    });
    if (exception.get() != null)
        throw exception.get();
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator) AbstractProgressIndicatorBase(com.intellij.openapi.progress.util.AbstractProgressIndicatorBase) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Aggregations

AbstractProgressIndicatorBase (com.intellij.openapi.progress.util.AbstractProgressIndicatorBase)2 DaemonProgressIndicator (com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator)1 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 FileComparisonFailure (com.intellij.rt.execution.junit.FileComparisonFailure)1 PyExecutionFixtureTestTask (com.jetbrains.env.PyExecutionFixtureTestTask)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1