Search in sources :

Example 76 with ProcessCanceledException

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

the class TextFieldWithAutoCompletionListProvider method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull String prefix, @NotNull CompletionResultSet result) {
    Collection<T> items = getItems(prefix, true, parameters);
    addCompletionElements(result, this, items, -10000);
    final ProgressManager progressManager = ProgressManager.getInstance();
    ProgressIndicator mainIndicator = progressManager.getProgressIndicator();
    final ProgressIndicator indicator = mainIndicator != null ? new SensitiveProgressWrapper(mainIndicator) : new EmptyProgressIndicator();
    Future<Collection<T>> future = ApplicationManager.getApplication().executeOnPooledThread(() -> progressManager.runProcess(() -> getItems(prefix, false, parameters), indicator));
    while (true) {
        try {
            Collection<T> tasks = future.get(100, TimeUnit.MILLISECONDS);
            if (tasks != null) {
                addCompletionElements(result, this, tasks, 0);
                return;
            }
        } catch (ProcessCanceledException e) {
            throw e;
        } catch (Exception ignore) {
        }
        ProgressManager.checkCanceled();
    }
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressManager(com.intellij.openapi.progress.ProgressManager) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) SensitiveProgressWrapper(com.intellij.concurrency.SensitiveProgressWrapper) Collection(java.util.Collection) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 77 with ProcessCanceledException

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

the class FileDownloaderImpl method download.

@NotNull
@Override
public List<Pair<File, DownloadableFileDescription>> download(@NotNull final File targetDir) throws IOException {
    List<Pair<File, DownloadableFileDescription>> downloadedFiles = Collections.synchronizedList(new ArrayList<>());
    List<Pair<File, DownloadableFileDescription>> existingFiles = Collections.synchronizedList(new ArrayList<>());
    ProgressIndicator parentIndicator = ProgressManager.getInstance().getProgressIndicator();
    if (parentIndicator == null) {
        parentIndicator = new EmptyProgressIndicator();
    }
    try {
        final ConcurrentTasksProgressManager progressManager = new ConcurrentTasksProgressManager(parentIndicator, myFileDescriptions.size());
        parentIndicator.setText(IdeBundle.message("progress.downloading.0.files.text", myFileDescriptions.size()));
        int maxParallelDownloads = Runtime.getRuntime().availableProcessors();
        LOG.debug("Downloading " + myFileDescriptions.size() + " files using " + maxParallelDownloads + " threads");
        long start = System.currentTimeMillis();
        ExecutorService executor = AppExecutorUtil.createBoundedApplicationPoolExecutor("FileDownloaderImpl pool", maxParallelDownloads);
        List<Future<Void>> results = new ArrayList<>();
        final AtomicLong totalSize = new AtomicLong();
        for (final DownloadableFileDescription description : myFileDescriptions) {
            results.add(executor.submit(() -> {
                SubTaskProgressIndicator indicator = progressManager.createSubTaskIndicator();
                indicator.checkCanceled();
                final File existing = new File(targetDir, description.getDefaultFileName());
                final String url = description.getDownloadUrl();
                if (url.startsWith(LIB_SCHEMA)) {
                    final String path = FileUtil.toSystemDependentName(StringUtil.trimStart(url, LIB_SCHEMA));
                    final File file = PathManager.findFileInLibDirectory(path);
                    existingFiles.add(Pair.create(file, description));
                } else if (url.startsWith(LocalFileSystem.PROTOCOL_PREFIX)) {
                    String path = FileUtil.toSystemDependentName(StringUtil.trimStart(url, LocalFileSystem.PROTOCOL_PREFIX));
                    File file = new File(path);
                    if (file.exists()) {
                        existingFiles.add(Pair.create(file, description));
                    }
                } else {
                    File downloaded;
                    try {
                        downloaded = downloadFile(description, existing, indicator);
                    } catch (IOException e) {
                        throw new IOException(IdeBundle.message("error.file.download.failed", description.getDownloadUrl(), e.getMessage()), e);
                    }
                    if (FileUtil.filesEqual(downloaded, existing)) {
                        existingFiles.add(Pair.create(existing, description));
                    } else {
                        totalSize.addAndGet(downloaded.length());
                        downloadedFiles.add(Pair.create(downloaded, description));
                    }
                }
                indicator.finished();
                return null;
            }));
        }
        for (Future<Void> result : results) {
            try {
                result.get();
            } catch (InterruptedException e) {
                throw new ProcessCanceledException();
            } catch (ExecutionException e) {
                Throwables.propagateIfInstanceOf(e.getCause(), IOException.class);
                Throwables.propagateIfInstanceOf(e.getCause(), ProcessCanceledException.class);
                LOG.error(e);
            }
        }
        long duration = System.currentTimeMillis() - start;
        LOG.debug("Downloaded " + StringUtil.formatFileSize(totalSize.get()) + " in " + StringUtil.formatDuration(duration) + "(" + duration + "ms)");
        List<Pair<File, DownloadableFileDescription>> localFiles = new ArrayList<>();
        localFiles.addAll(moveToDir(downloadedFiles, targetDir));
        localFiles.addAll(existingFiles);
        return localFiles;
    } catch (ProcessCanceledException | IOException e) {
        deleteFiles(downloadedFiles);
        throw e;
    }
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AtomicLong(java.util.concurrent.atomic.AtomicLong) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DownloadableFileDescription(com.intellij.util.download.DownloadableFileDescription) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) File(java.io.File) Pair(com.intellij.openapi.util.Pair) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) NotNull(org.jetbrains.annotations.NotNull)

Example 78 with ProcessCanceledException

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

the class JavaModuleInsight method scanModuleInfoFiles.

private void scanModuleInfoFiles() {
    final List<DetectedSourceRoot> allRoots = super.getSourceRootsToScan();
    final List<JavaModuleSourceRoot> moduleInfoRoots = StreamEx.of(allRoots).select(JavaModuleSourceRoot.class).filter(JavaModuleSourceRoot::isWithModuleInfoFile).filter(root -> !isIgnoredName(root.getDirectory())).toList();
    if (moduleInfoRoots.isEmpty()) {
        return;
    }
    myProgress.setIndeterminate(true);
    myProgress.pushState();
    try {
        Map<String, ModuleInfo> moduleInfos = new HashMap<>();
        for (JavaModuleSourceRoot moduleInfoRoot : moduleInfoRoots) {
            final File sourceRoot = moduleInfoRoot.getDirectory();
            myProgress.setText("Scanning " + sourceRoot.getPath());
            final ModuleInfo moduleInfo = scanModuleInfoFile(sourceRoot);
            if (moduleInfo != null) {
                moduleInfo.descriptor = createModuleDescriptor(moduleInfo.directory, Collections.singletonList(moduleInfoRoot));
                moduleInfos.put(moduleInfo.name, moduleInfo);
                addExportedPackages(sourceRoot, moduleInfo.exportsPackages);
            }
        }
        myProgress.setText("Building modules layout...");
        for (ModuleInfo moduleInfo : moduleInfos.values()) {
            for (String requiresModule : moduleInfo.requiresModules) {
                ModuleInfo requiredModuleInfo = moduleInfos.get(requiresModule);
                if (requiredModuleInfo != null) {
                    moduleInfo.descriptor.addDependencyOn(requiredModuleInfo.descriptor);
                }
            }
        }
        addModules(StreamEx.of(moduleInfos.values()).map(info -> info.descriptor).toList());
    } catch (ProcessCanceledException ignored) {
    } finally {
        myProgress.popState();
    }
}
Also used : DetectedSourceRoot(com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot) java.util(java.util) ContainerUtil(com.intellij.util.containers.ContainerUtil) ReadAction(com.intellij.openapi.application.ReadAction) StringBuilderSpinAllocator(com.intellij.util.StringBuilderSpinAllocator) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ProjectManager(com.intellij.openapi.project.ProjectManager) ZipFile(java.util.zip.ZipFile) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) ZipEntry(java.util.zip.ZipEntry) JavaSourceRootDetectionUtil(com.intellij.ide.util.projectWizard.importSources.JavaSourceRootDetectionUtil) Lexer(com.intellij.lexer.Lexer) LanguageLevel(com.intellij.pom.java.LanguageLevel) StdModuleTypes(com.intellij.openapi.module.StdModuleTypes) JavaModuleSourceRoot(com.intellij.ide.util.projectWizard.importSources.JavaModuleSourceRoot) IncorrectOperationException(com.intellij.util.IncorrectOperationException) StringUtil(com.intellij.openapi.util.text.StringUtil) IOException(java.io.IOException) JavaFileType(com.intellij.ide.highlighter.JavaFileType) DetectedProjectRoot(com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) StreamEx(one.util.streamex.StreamEx) JavaParserDefinition(com.intellij.lang.java.JavaParserDefinition) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) DetectedSourceRoot(com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot) Consumer(com.intellij.util.Consumer) JavaModuleSourceRoot(com.intellij.ide.util.projectWizard.importSources.JavaModuleSourceRoot) ZipFile(java.util.zip.ZipFile) File(java.io.File) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 79 with ProcessCanceledException

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

the class ModuleInsight method scanModules.

public void scanModules() {
    myProgress.setIndeterminate(true);
    final Map<File, ModuleDescriptor> contentRootToModules = new HashMap<>();
    try {
        myProgress.pushState();
        List<DetectedSourceRoot> processedRoots = new ArrayList<>();
        for (DetectedSourceRoot root : getSourceRootsToScan()) {
            final File sourceRoot = root.getDirectory();
            if (isIgnoredName(sourceRoot)) {
                continue;
            }
            myProgress.setText("Scanning " + sourceRoot.getPath());
            final HashSet<String> usedPackages = new HashSet<>();
            mySourceRootToReferencedPackagesMap.put(sourceRoot, usedPackages);
            final HashSet<String> selfPackages = new HashSet<>();
            addExportedPackages(sourceRoot, selfPackages);
            scanSources(sourceRoot, ProjectFromSourcesBuilderImpl.getPackagePrefix(root), usedPackages, selfPackages);
            usedPackages.removeAll(selfPackages);
            processedRoots.add(root);
        }
        myProgress.popState();
        myProgress.pushState();
        myProgress.setText("Building modules layout...");
        for (DetectedSourceRoot sourceRoot : processedRoots) {
            final File srcRoot = sourceRoot.getDirectory();
            final File moduleContentRoot = isEntryPointRoot(srcRoot) ? srcRoot : srcRoot.getParentFile();
            ModuleDescriptor moduleDescriptor = contentRootToModules.get(moduleContentRoot);
            if (moduleDescriptor != null) {
                moduleDescriptor.addSourceRoot(moduleContentRoot, sourceRoot);
            } else {
                moduleDescriptor = createModuleDescriptor(moduleContentRoot, Collections.singletonList(sourceRoot));
                contentRootToModules.put(moduleContentRoot, moduleDescriptor);
            }
        }
        buildModuleDependencies(contentRootToModules);
        myProgress.popState();
    } catch (ProcessCanceledException ignored) {
    }
    addModules(contentRootToModules.values());
}
Also used : DetectedSourceRoot(com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot) File(java.io.File) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 80 with ProcessCanceledException

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

the class DocumentImpl method changedUpdate.

private void changedUpdate(@NotNull DocumentEvent event, long newModificationStamp, @NotNull CharSequence prevText) {
    try {
        if (LOG.isDebugEnabled())
            LOG.debug(event.toString());
        assert event.getOldFragment().length() == event.getOldLength() : "event.getOldFragment().length() = " + event.getOldFragment().length() + "; event.getOldLength() = " + event.getOldLength();
        assert event.getNewFragment().length() == event.getNewLength() : "event.getNewFragment().length() = " + event.getNewFragment().length() + "; event.getNewLength() = " + event.getNewLength();
        assert prevText.length() + event.getNewLength() - event.getOldLength() == getTextLength() : "prevText.length() = " + prevText.length() + "; event.getNewLength() = " + event.getNewLength() + "; event.getOldLength() = " + event.getOldLength() + "; getTextLength() = " + getTextLength();
        myLineSet = getLineSet().update(prevText, event.getOffset(), event.getOffset() + event.getOldLength(), event.getNewFragment(), event.isWholeTextReplaced());
        assert getTextLength() == myLineSet.getLength() : "getTextLength() = " + getTextLength() + "; myLineSet.getLength() = " + myLineSet.getLength();
        myFrozen = null;
        setModificationStamp(newModificationStamp);
        if (!ShutDownTracker.isShutdownHookRunning()) {
            DocumentListener[] listeners = getListeners();
            for (DocumentListener listener : listeners) {
                try {
                    listener.documentChanged(event);
                } catch (ProcessCanceledException e) {
                    if (!myAssertThreading) {
                        throw e;
                    } else {
                        LOG.error("ProcessCanceledException must not be thrown from document listeners for real document", new Throwable(e));
                    }
                } catch (Throwable e) {
                    LOG.error(e);
                }
            }
        }
    } finally {
        myEventsHandling = false;
    }
}
Also used : DocumentListener(com.intellij.openapi.editor.event.DocumentListener) 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