Search in sources :

Example 56 with ProcessCanceledException

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

the class IdeStartupScripts method scheduleStartupScriptsExecution.

private static void scheduleStartupScriptsExecution() {
    List<VirtualFile> scripts = getScripts();
    LOG.info(scripts.size() + " startup script(s) found");
    if (scripts.isEmpty())
        return;
    final Future<List<Pair<VirtualFile, IdeScriptEngine>>> scriptsAndEnginesFuture = prepareScriptEnginesAsync(scripts);
    ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerAdapter() {

        final AtomicBoolean myScriptsExecutionStarted = new AtomicBoolean();

        @Override
        public void projectOpened(final Project project) {
            StartupManager.getInstance(project).runWhenProjectIsInitialized(() -> {
                if (project.isDisposed())
                    return;
                if (!myScriptsExecutionStarted.compareAndSet(false, true))
                    return;
                ProjectManager.getInstance().removeProjectManagerListener(this);
                runAllScriptsImpl(project);
            });
        }

        private void runAllScriptsImpl(@NotNull Project project) {
            try {
                for (Pair<VirtualFile, IdeScriptEngine> pair : scriptsAndEnginesFuture.get()) {
                    try {
                        if (pair.second == null) {
                            LOG.warn(pair.first.getPath() + " not supported (no script engine)");
                        } else {
                            runImpl(project, pair.first, pair.second);
                        }
                    } catch (Exception e) {
                        LOG.warn(e);
                    }
                }
            } catch (ProcessCanceledException e) {
                LOG.warn("... cancelled");
            } catch (InterruptedException e) {
                LOG.warn("... interrupted");
            } catch (Exception e) {
                LOG.error(e);
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) IdeScriptException(org.jetbrains.ide.script.IdeScriptException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Project(com.intellij.openapi.project.Project) ProjectManagerAdapter(com.intellij.openapi.project.ProjectManagerAdapter) List(java.util.List) IdeScriptEngine(org.jetbrains.ide.script.IdeScriptEngine) Pair(com.intellij.openapi.util.Pair) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 57 with ProcessCanceledException

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

the class RenameHandlerRegistry method getRenameHandler.

@Nullable
public RenameHandler getRenameHandler(DataContext dataContext) {
    final Map<String, RenameHandler> availableHandlers = new TreeMap<>();
    for (RenameHandler renameHandler : Extensions.getExtensions(RenameHandler.EP_NAME)) {
        if (renameHandler.isRenaming(dataContext)) {
            availableHandlers.put(getHandlerTitle(renameHandler), renameHandler);
        }
    }
    for (RenameHandler renameHandler : myHandlers) {
        if (renameHandler.isRenaming(dataContext)) {
            availableHandlers.put(getHandlerTitle(renameHandler), renameHandler);
        }
    }
    if (availableHandlers.size() == 1)
        return availableHandlers.values().iterator().next();
    for (Iterator<Map.Entry<String, RenameHandler>> iterator = availableHandlers.entrySet().iterator(); iterator.hasNext(); ) {
        Map.Entry<String, RenameHandler> entry = iterator.next();
        if (entry.getValue() instanceof MemberInplaceRenameHandler) {
            iterator.remove();
            break;
        }
    }
    if (availableHandlers.size() == 1)
        return availableHandlers.values().iterator().next();
    if (availableHandlers.size() > 1) {
        if (ApplicationManager.getApplication().isUnitTestMode())
            return availableHandlers.values().iterator().next();
        final String[] strings = ArrayUtil.toStringArray(availableHandlers.keySet());
        final HandlersChooser chooser = new HandlersChooser(CommonDataKeys.PROJECT.getData(dataContext), strings);
        if (chooser.showAndGet()) {
            return availableHandlers.get(chooser.getSelection());
        }
        throw new ProcessCanceledException();
    }
    return myDefaultElementRenameHandler.isRenaming(dataContext) ? myDefaultElementRenameHandler : null;
}
Also used : MemberInplaceRenameHandler(com.intellij.refactoring.rename.inplace.MemberInplaceRenameHandler) MemberInplaceRenameHandler(com.intellij.refactoring.rename.inplace.MemberInplaceRenameHandler) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Nullable(org.jetbrains.annotations.Nullable)

Example 58 with ProcessCanceledException

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

the class SliceManager method runInterruptibly.

void runInterruptibly(@NotNull ProgressIndicator progress, @NotNull Runnable onCancel, @NotNull Runnable runnable) throws ProcessCanceledException {
    Disposable disposable = addPsiListener(progress);
    try {
        progress.checkCanceled();
        ProgressManager.getInstance().executeProcessUnderProgress(runnable, progress);
    } catch (ProcessCanceledException e) {
        progress.cancel();
        //reschedule for later
        onCancel.run();
        throw e;
    } finally {
        Disposer.dispose(disposable);
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 59 with ProcessCanceledException

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

the class AsyncCompletion method startThread.

@Override
public Future<?> startThread(final ProgressIndicator progressIndicator, final Runnable runnable) {
    final Semaphore startSemaphore = new Semaphore();
    startSemaphore.down();
    Future<?> future = ApplicationManager.getApplication().executeOnPooledThread(() -> ProgressManager.getInstance().runProcess(() -> {
        try {
            ApplicationManager.getApplication().runReadAction(() -> {
                startSemaphore.up();
                ProgressManager.checkCanceled();
                runnable.run();
            });
        } catch (ProcessCanceledException ignored) {
        }
    }, progressIndicator));
    startSemaphore.waitFor();
    return future;
}
Also used : Semaphore(com.intellij.util.concurrency.Semaphore) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 60 with ProcessCanceledException

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

the class CompletionThreadingBase method withBatchUpdate.

public static void withBatchUpdate(Runnable runnable) {
    if (ourIsInBatchUpdate.get().booleanValue()) {
        runnable.run();
        return;
    }
    try {
        ourIsInBatchUpdate.set(Boolean.TRUE);
        runnable.run();
        ProgressManager.checkCanceled();
        final CompletionProgressIndicator currentIndicator = CompletionServiceImpl.getCompletionService().getCurrentCompletion();
        if (currentIndicator == null)
            throw new ProcessCanceledException();
        CompletionThreadingBase threading = currentIndicator.getCompletionThreading();
        assert threading != null;
        threading.flushBatchResult(currentIndicator);
    } finally {
        ourIsInBatchUpdate.set(Boolean.FALSE);
    }
}
Also used : ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Aggregations

ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)175 NotNull (org.jetbrains.annotations.NotNull)45 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)41 VirtualFile (com.intellij.openapi.vfs.VirtualFile)38 Project (com.intellij.openapi.project.Project)28 Nullable (org.jetbrains.annotations.Nullable)23 IOException (java.io.IOException)20 Task (com.intellij.openapi.progress.Task)16 File (java.io.File)16 Document (com.intellij.openapi.editor.Document)14 Ref (com.intellij.openapi.util.Ref)13 PsiFile (com.intellij.psi.PsiFile)12 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)11 Logger (com.intellij.openapi.diagnostic.Logger)10 StringUtil (com.intellij.openapi.util.text.StringUtil)9 ContainerUtil (com.intellij.util.containers.ContainerUtil)9 ArrayList (java.util.ArrayList)9 NonNls (org.jetbrains.annotations.NonNls)9 ProgressManager (com.intellij.openapi.progress.ProgressManager)8 java.util (java.util)8