Search in sources :

Example 1 with CoreProgressManager

use of com.intellij.openapi.progress.impl.CoreProgressManager in project intellij-community by JetBrains.

the class AbstractVcsHelperImpl method loadAndShowCommittedChangesDetails.

@Override
public void loadAndShowCommittedChangesDetails(@NotNull final Project project, @NotNull final VcsRevisionNumber revision, @NotNull final VirtualFile virtualFile, @NotNull VcsKey vcsKey, @Nullable final RepositoryLocation location, final boolean isNonLocal) {
    final AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).findVcsByName(vcsKey.getName());
    if (vcs == null)
        return;
    final CommittedChangesProvider provider = vcs.getCommittedChangesProvider();
    if (provider == null)
        return;
    if (isNonLocal && provider.getForNonLocal(virtualFile) == null)
        return;
    final String title = VcsBundle.message("paths.affected.in.revision", revision instanceof ShortVcsRevisionNumber ? ((ShortVcsRevisionNumber) revision).toShortString() : revision.asString());
    final CommittedChangeList[] list = new CommittedChangeList[1];
    final FilePath[] targetPath = new FilePath[1];
    final VcsException[] exc = new VcsException[1];
    final BackgroundableActionLock lock = BackgroundableActionLock.getLock(project, VcsBackgroundableActions.COMMITTED_CHANGES_DETAILS, revision, virtualFile.getPath());
    if (lock.isLocked())
        return;
    lock.lock();
    Task.Backgroundable task = new Task.Backgroundable(project, title, true) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            try {
                if (!isNonLocal) {
                    final Pair<CommittedChangeList, FilePath> pair = provider.getOneList(virtualFile, revision);
                    if (pair != null) {
                        list[0] = pair.getFirst();
                        targetPath[0] = pair.getSecond();
                    }
                } else {
                    if (location != null) {
                        final ChangeBrowserSettings settings = provider.createDefaultSettings();
                        settings.USE_CHANGE_BEFORE_FILTER = true;
                        settings.CHANGE_BEFORE = revision.asString();
                        final List<CommittedChangeList> changes = provider.getCommittedChanges(settings, location, 1);
                        if (changes != null && changes.size() == 1) {
                            list[0] = changes.get(0);
                        }
                    } else {
                        list[0] = getRemoteList(vcs, revision, virtualFile);
                    }
                }
            } catch (VcsException e) {
                exc[0] = e;
            }
        }

        @Override
        public void onCancel() {
            lock.unlock();
        }

        @Override
        public void onSuccess() {
            lock.unlock();
            if (exc[0] != null) {
                showError(exc[0], failedText(virtualFile, revision));
            } else if (list[0] == null) {
                Messages.showErrorDialog(project, failedText(virtualFile, revision), getTitle());
            } else {
                VirtualFile navigateToFile = targetPath[0] != null ? new VcsVirtualFile(targetPath[0].getPath(), null, VcsFileSystem.getInstance()) : virtualFile;
                showChangesListBrowser(list[0], navigateToFile, title);
            }
        }
    };
    // we can's use runProcessWithProgressAsynchronously(task) because then ModalityState.NON_MODAL would be used
    CoreProgressManager progressManager = (CoreProgressManager) ProgressManager.getInstance();
    progressManager.runProcessWithProgressAsynchronously(task, new BackgroundableProcessIndicator(task), null, ModalityState.current());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsVirtualFile(com.intellij.openapi.vcs.vfs.VcsVirtualFile) CoreProgressManager(com.intellij.openapi.progress.impl.CoreProgressManager) Task(com.intellij.openapi.progress.Task) VcsVirtualFile(com.intellij.openapi.vcs.vfs.VcsVirtualFile) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) NotNull(org.jetbrains.annotations.NotNull) ChangeBrowserSettings(com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) BackgroundableProcessIndicator(com.intellij.openapi.progress.impl.BackgroundableProcessIndicator)

Example 2 with CoreProgressManager

use of com.intellij.openapi.progress.impl.CoreProgressManager in project intellij-community by JetBrains.

the class GlobalInspectionContextImpl method startIterateScopeInBackground.

@NotNull
private Future<?> startIterateScopeInBackground(@NotNull final AnalysisScope scope, @Nullable final Collection<VirtualFile> localScopeFiles, final boolean headlessEnvironment, @NotNull final BlockingQueue<PsiFile> outFilesToInspect, @NotNull final ProgressIndicator progressIndicator) {
    Task.Backgroundable task = new Task.Backgroundable(getProject(), "Scanning Files to Inspect") {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            try {
                final FileIndex fileIndex = ProjectRootManager.getInstance(getProject()).getFileIndex();
                scope.accept(file -> {
                    indicator.checkCanceled();
                    if (ProjectUtil.isProjectOrWorkspaceFile(file) || !fileIndex.isInContent(file))
                        return true;
                    PsiFile psiFile = ReadAction.compute(() -> {
                        if (getProject().isDisposed())
                            throw new ProcessCanceledException();
                        PsiFile psi = PsiManager.getInstance(getProject()).findFile(file);
                        Document document = psi == null ? null : shouldProcess(psi, headlessEnvironment, localScopeFiles);
                        if (document != null) {
                            return psi;
                        }
                        return null;
                    });
                    if (psiFile != null) {
                        try {
                            LOG.assertTrue(!ApplicationManager.getApplication().isReadAccessAllowed());
                            outFilesToInspect.put(psiFile);
                        } catch (InterruptedException e) {
                            LOG.error(e);
                        }
                    }
                    indicator.checkCanceled();
                    return true;
                });
            } catch (ProcessCanceledException e) {
            // ignore, but put tombstone
            } finally {
                try {
                    outFilesToInspect.put(TOMBSTONE);
                } catch (InterruptedException e) {
                    LOG.error(e);
                }
            }
        }
    };
    return ((CoreProgressManager) ProgressManager.getInstance()).runProcessWithProgressAsynchronously(task, progressIndicator, null);
}
Also used : CoreProgressManager(com.intellij.openapi.progress.impl.CoreProgressManager) FileIndex(com.intellij.openapi.roots.FileIndex) Document(com.intellij.openapi.editor.Document) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with CoreProgressManager

use of com.intellij.openapi.progress.impl.CoreProgressManager in project kotlin by JetBrains.

the class KtParsingTestCase method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    initApplication();
    ComponentAdapter component = getApplication().getPicoContainer().getComponentAdapter(ProgressManager.class.getName());
    Extensions.registerAreaClass("IDEA_PROJECT", null);
    myProject = new MockProjectEx(getTestRootDisposable());
    myPsiManager = new MockPsiManager(myProject);
    myFileFactory = new PsiFileFactoryImpl(myPsiManager);
    MutablePicoContainer appContainer = getApplication().getPicoContainer();
    registerComponentInstance(appContainer, MessageBus.class, MessageBusFactory.newMessageBus(getApplication()));
    registerComponentInstance(appContainer, SchemesManagerFactory.class, new MockSchemesManagerFactory());
    final MockEditorFactory editorFactory = new MockEditorFactory();
    registerComponentInstance(appContainer, EditorFactory.class, editorFactory);
    registerComponentInstance(appContainer, FileDocumentManager.class, new MockFileDocumentManagerImpl(new Function<CharSequence, Document>() {

        @Override
        public Document fun(CharSequence charSequence) {
            return editorFactory.createDocument(charSequence);
        }
    }, HARD_REF_TO_DOCUMENT_KEY));
    registerComponentInstance(appContainer, PsiDocumentManager.class, new MockPsiDocumentManager());
    registerApplicationService(PsiBuilderFactory.class, new PsiBuilderFactoryImpl());
    registerApplicationService(DefaultASTFactory.class, new CoreASTFactory());
    registerApplicationService(ReferenceProvidersRegistry.class, new ReferenceProvidersRegistryImpl());
    registerApplicationService(ProgressManager.class, new CoreProgressManager());
    myProject.registerService(CachedValuesManager.class, new CachedValuesManagerImpl(myProject, new PsiCachedValuesFactory(myPsiManager)));
    myProject.registerService(PsiManager.class, myPsiManager);
    this.registerExtensionPoint(FileTypeFactory.FILE_TYPE_FACTORY_EP, FileTypeFactory.class);
    for (ParserDefinition definition : myDefinitions) {
        addExplicitExtension(LanguageParserDefinitions.INSTANCE, definition.getFileNodeType().getLanguage(), definition);
    }
    if (myDefinitions.length > 0) {
        configureFromParserDefinition(myDefinitions[0], myFileExt);
    }
    // That's for reparse routines
    final PomModelImpl pomModel = new PomModelImpl(myProject);
    myProject.registerService(PomModel.class, pomModel);
    new TreeAspect(pomModel);
}
Also used : MutablePicoContainer(org.picocontainer.MutablePicoContainer) CoreProgressManager(com.intellij.openapi.progress.impl.CoreProgressManager) MockFileDocumentManagerImpl(com.intellij.mock.MockFileDocumentManagerImpl) TreeAspect(com.intellij.pom.tree.TreeAspect) CachedValuesManagerImpl(com.intellij.util.CachedValuesManagerImpl) CoreASTFactory(com.intellij.core.CoreASTFactory) PsiBuilderFactoryImpl(com.intellij.lang.impl.PsiBuilderFactoryImpl) Function(com.intellij.util.Function) PsiCachedValuesFactory(com.intellij.psi.impl.PsiCachedValuesFactory) ProgressManager(com.intellij.openapi.progress.ProgressManager) CoreProgressManager(com.intellij.openapi.progress.impl.CoreProgressManager) ReferenceProvidersRegistryImpl(com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistryImpl) PsiFileFactoryImpl(com.intellij.psi.impl.PsiFileFactoryImpl) PomModelImpl(com.intellij.pom.core.impl.PomModelImpl) ComponentAdapter(org.picocontainer.ComponentAdapter)

Aggregations

CoreProgressManager (com.intellij.openapi.progress.impl.CoreProgressManager)3 NotNull (org.jetbrains.annotations.NotNull)2 CoreASTFactory (com.intellij.core.CoreASTFactory)1 PsiBuilderFactoryImpl (com.intellij.lang.impl.PsiBuilderFactoryImpl)1 MockFileDocumentManagerImpl (com.intellij.mock.MockFileDocumentManagerImpl)1 Document (com.intellij.openapi.editor.Document)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 Task (com.intellij.openapi.progress.Task)1 BackgroundableProcessIndicator (com.intellij.openapi.progress.impl.BackgroundableProcessIndicator)1 FileIndex (com.intellij.openapi.roots.FileIndex)1 ChangeBrowserSettings (com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings)1 CommittedChangeList (com.intellij.openapi.vcs.versionBrowser.CommittedChangeList)1 VcsVirtualFile (com.intellij.openapi.vcs.vfs.VcsVirtualFile)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PomModelImpl (com.intellij.pom.core.impl.PomModelImpl)1 TreeAspect (com.intellij.pom.tree.TreeAspect)1 PsiCachedValuesFactory (com.intellij.psi.impl.PsiCachedValuesFactory)1 PsiFileFactoryImpl (com.intellij.psi.impl.PsiFileFactoryImpl)1 ReferenceProvidersRegistryImpl (com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistryImpl)1