Search in sources :

Example 1 with ProcessCanceledException

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

the class MavenProjectImporter method importProject.

@Nullable
public List<MavenProjectsProcessorTask> importProject() {
    List<MavenProjectsProcessorTask> postTasks = new ArrayList<>();
    boolean hasChanges;
    // in the case projects are changed during importing we must memorise them
    myAllProjects = new LinkedHashSet<>(myProjectsTree.getProjects());
    // some projects may already have been removed from the tree
    myAllProjects.addAll(myProjectsToImportWithChanges.keySet());
    hasChanges = deleteIncompatibleModules();
    myProjectsToImportWithChanges = collectProjectsToImport(myProjectsToImportWithChanges);
    mapMavenProjectsToModulesAndNames();
    if (myProject.isDisposed())
        return null;
    final boolean projectsHaveChanges = projectsToImportHaveChanges();
    if (projectsHaveChanges) {
        hasChanges = true;
        importModules(postTasks);
        scheduleRefreshResolvedArtifacts(postTasks);
    }
    if (projectsHaveChanges || myImportModuleGroupsRequired) {
        hasChanges = true;
        configModuleGroups();
    }
    if (myProject.isDisposed())
        return null;
    try {
        boolean modulesDeleted = deleteObsoleteModules();
        hasChanges |= modulesDeleted;
        if (hasChanges) {
            removeUnusedProjectLibraries();
        }
    } catch (ProcessCanceledException e) {
        throw e;
    } catch (Exception e) {
        disposeModifiableModels();
        LOG.error(e);
        return null;
    }
    if (hasChanges) {
        MavenUtil.invokeAndWaitWriteAction(myProject, () -> {
            myModelsProvider.commit();
            if (projectsHaveChanges) {
                removeOutdatedCompilerConfigSettings();
                for (MavenProject mavenProject : myAllProjects) {
                    Module module = myMavenProjectToModule.get(mavenProject);
                    if (module != null && module.isDisposed()) {
                        module = null;
                    }
                    for (MavenModuleConfigurer configurer : MavenModuleConfigurer.getConfigurers()) {
                        configurer.configure(mavenProject, myProject, module);
                    }
                }
            }
        });
    } else {
        disposeModifiableModels();
    }
    return postTasks;
}
Also used : Module(com.intellij.openapi.module.Module) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) IOException(java.io.IOException) MavenModuleConfigurer(org.jetbrains.idea.maven.importing.configurers.MavenModuleConfigurer) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ProcessCanceledException

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

the class KotlinBytecodeToolWindow method getBytecodeForFile.

// public for tests
@NotNull
public static String getBytecodeForFile(@NotNull KtFile ktFile, @NotNull CompilerConfiguration configuration) {
    GenerationState state;
    try {
        state = compileSingleFile(ktFile, configuration);
    } catch (ProcessCanceledException e) {
        throw e;
    } catch (Exception e) {
        return printStackTraceToString(e);
    }
    StringBuilder answer = new StringBuilder();
    Collection<Diagnostic> diagnostics = state.getCollectedExtraJvmDiagnostics().all();
    if (!diagnostics.isEmpty()) {
        answer.append("// Backend Errors: \n");
        answer.append("// ================\n");
        for (Diagnostic diagnostic : diagnostics) {
            answer.append("// Error at ").append(diagnostic.getPsiFile().getName()).append(StringsKt.join(diagnostic.getTextRanges(), ",")).append(": ").append(DefaultErrorMessages.render(diagnostic)).append("\n");
        }
        answer.append("// ================\n\n");
    }
    OutputFileCollection outputFiles = state.getFactory();
    for (OutputFile outputFile : outputFiles.asList()) {
        answer.append("// ================");
        answer.append(outputFile.getRelativePath());
        answer.append(" =================\n");
        answer.append(outputFile.asText()).append("\n\n");
    }
    return answer.toString();
}
Also used : OutputFile(org.jetbrains.kotlin.backend.common.output.OutputFile) OutputFileCollection(org.jetbrains.kotlin.backend.common.output.OutputFileCollection) Diagnostic(org.jetbrains.kotlin.diagnostics.Diagnostic) GenerationState(org.jetbrains.kotlin.codegen.state.GenerationState) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ProcessCanceledException

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

the class ExternalDocumentValidator method runJaxpValidation.

private void runJaxpValidation(final XmlElement element, Validator.ValidationHost host) {
    final PsiFile file = element.getContainingFile();
    if (myFile == file && file != null && myModificationStamp == file.getModificationStamp() && !ValidateXmlActionHandler.isValidationDependentFilesOutOfDate((XmlFile) file) && // we have validated before
    SoftReference.dereference(myInfos) != null) {
        addAllInfos(host, myInfos.get());
        return;
    }
    if (myHandler == null)
        myHandler = new ValidateXmlActionHandler(false);
    final Project project = element.getProject();
    final Document document = PsiDocumentManager.getInstance(project).getDocument(file);
    if (document == null)
        return;
    final List<ValidationInfo> results = new LinkedList<>();
    myHost = new Validator.ValidationHost() {

        @Override
        public void addMessage(PsiElement context, String message, int type) {
            addMessage(context, message, type == ERROR ? ErrorType.ERROR : type == WARNING ? ErrorType.WARNING : ErrorType.INFO);
        }

        @Override
        public void addMessage(final PsiElement context, final String message, @NotNull final ErrorType type) {
            final ValidationInfo o = new ValidationInfo(context, message, type);
            results.add(o);
        }
    };
    myHandler.setErrorReporter(new ErrorReporter(myHandler) {

        @Override
        public boolean isStopOnUndeclaredResource() {
            return true;
        }

        @Override
        public void processError(final SAXParseException e, final ValidateXmlActionHandler.ProblemType warning) {
            try {
                ApplicationManager.getApplication().runReadAction(() -> {
                    if (e.getPublicId() != null) {
                        return;
                    }
                    final VirtualFile errorFile = myHandler.getProblemFile(e);
                    if (!Comparing.equal(errorFile, file.getVirtualFile()) && errorFile != null) {
                        // error in attached schema
                        return;
                    }
                    if (document.getLineCount() < e.getLineNumber() || e.getLineNumber() <= 0) {
                        return;
                    }
                    Validator.ValidationHost.ErrorType problemType = getProblemType(warning);
                    int offset = Math.max(0, document.getLineStartOffset(e.getLineNumber() - 1) + e.getColumnNumber() - 2);
                    if (offset >= document.getTextLength())
                        return;
                    PsiElement currentElement = PsiDocumentManager.getInstance(project).getPsiFile(document).findElementAt(offset);
                    PsiElement originalElement = currentElement;
                    final String elementText = currentElement.getText();
                    if (elementText.equals("</")) {
                        currentElement = currentElement.getNextSibling();
                    } else if (elementText.equals(">") || elementText.equals("=")) {
                        currentElement = currentElement.getPrevSibling();
                    }
                    // Cannot find the declaration of element
                    String localizedMessage = e.getLocalizedMessage();
                    // Ideally would be to switch one messageIds
                    int endIndex = localizedMessage.indexOf(':');
                    if (endIndex < localizedMessage.length() - 1 && localizedMessage.charAt(endIndex + 1) == '/') {
                        // ignore : in http://
                        endIndex = -1;
                    }
                    String messageId = endIndex != -1 ? localizedMessage.substring(0, endIndex) : "";
                    localizedMessage = localizedMessage.substring(endIndex + 1).trim();
                    if (localizedMessage.startsWith(CANNOT_FIND_DECLARATION_ERROR_PREFIX) || localizedMessage.startsWith(ELEMENT_ERROR_PREFIX) || localizedMessage.startsWith(ROOT_ELEMENT_ERROR_PREFIX) || localizedMessage.startsWith(CONTENT_OF_ELEMENT_TYPE_ERROR_PREFIX)) {
                        addProblemToTagName(currentElement, originalElement, localizedMessage, warning);
                    //return;
                    } else if (localizedMessage.startsWith(VALUE_ERROR_PREFIX)) {
                        addProblemToTagName(currentElement, originalElement, localizedMessage, warning);
                    } else {
                        if (messageId.startsWith(ATTRIBUTE_MESSAGE_PREFIX)) {
                            @NonNls String prefix = "of attribute ";
                            final int i = localizedMessage.indexOf(prefix);
                            if (i != -1) {
                                int messagePrefixLength = prefix.length() + i;
                                final int nextQuoteIndex = localizedMessage.indexOf(localizedMessage.charAt(messagePrefixLength), messagePrefixLength + 1);
                                String attrName = nextQuoteIndex == -1 ? null : localizedMessage.substring(messagePrefixLength + 1, nextQuoteIndex);
                                XmlTag parent = PsiTreeUtil.getParentOfType(originalElement, XmlTag.class);
                                currentElement = parent.getAttribute(attrName, null);
                                if (currentElement != null) {
                                    currentElement = ((XmlAttribute) currentElement).getValueElement();
                                }
                            }
                            if (currentElement != null) {
                                assertValidElement(currentElement, originalElement, localizedMessage);
                                myHost.addMessage(currentElement, localizedMessage, problemType);
                            } else {
                                addProblemToTagName(originalElement, originalElement, localizedMessage, warning);
                            }
                        } else if (localizedMessage.startsWith(ATTRIBUTE_ERROR_PREFIX)) {
                            final int messagePrefixLength = ATTRIBUTE_ERROR_PREFIX.length();
                            if (localizedMessage.charAt(messagePrefixLength) == '"' || localizedMessage.charAt(messagePrefixLength) == '\'') {
                                // extract the attribute name from message and get it from tag!
                                final int nextQuoteIndex = localizedMessage.indexOf(localizedMessage.charAt(messagePrefixLength), messagePrefixLength + 1);
                                String attrName = nextQuoteIndex == -1 ? null : localizedMessage.substring(messagePrefixLength + 1, nextQuoteIndex);
                                XmlTag parent = PsiTreeUtil.getParentOfType(originalElement, XmlTag.class);
                                currentElement = parent.getAttribute(attrName, null);
                                if (currentElement != null) {
                                    currentElement = SourceTreeToPsiMap.treeElementToPsi(XmlChildRole.ATTRIBUTE_NAME_FINDER.findChild(SourceTreeToPsiMap.psiElementToTree(currentElement)));
                                }
                            } else {
                                currentElement = PsiTreeUtil.getParentOfType(currentElement, XmlTag.class, false);
                            }
                            if (currentElement != null) {
                                assertValidElement(currentElement, originalElement, localizedMessage);
                                myHost.addMessage(currentElement, localizedMessage, problemType);
                            } else {
                                addProblemToTagName(originalElement, originalElement, localizedMessage, warning);
                            }
                        } else if (localizedMessage.startsWith(STRING_ERROR_PREFIX)) {
                            if (currentElement != null) {
                                myHost.addMessage(currentElement, localizedMessage, Validator.ValidationHost.ErrorType.WARNING);
                            }
                        } else {
                            currentElement = getNodeForMessage(currentElement != null ? currentElement : originalElement);
                            assertValidElement(currentElement, originalElement, localizedMessage);
                            if (currentElement != null) {
                                myHost.addMessage(currentElement, localizedMessage, problemType);
                            }
                        }
                    }
                });
            } catch (Exception ex) {
                if (ex instanceof ProcessCanceledException)
                    throw (ProcessCanceledException) ex;
                if (ex instanceof XmlResourceResolver.IgnoredResourceException)
                    throw (XmlResourceResolver.IgnoredResourceException) ex;
                LOG.error(ex);
            }
        }
    });
    myHandler.doValidate((XmlFile) element.getContainingFile());
    myFile = file;
    myModificationStamp = myFile.getModificationStamp();
    myInfos = new WeakReference<>(results);
    addAllInfos(host, results);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) XmlResourceResolver(com.intellij.xml.util.XmlResourceResolver) ErrorReporter(com.intellij.xml.actions.validate.ErrorReporter) SAXParseException(org.xml.sax.SAXParseException) PsiFile(com.intellij.psi.PsiFile) ValidateXmlActionHandler(com.intellij.xml.actions.validate.ValidateXmlActionHandler) PsiElement(com.intellij.psi.PsiElement) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) NonNls(org.jetbrains.annotations.NonNls) LinkedList(java.util.LinkedList) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) SAXParseException(org.xml.sax.SAXParseException) Project(com.intellij.openapi.project.Project) Validator(com.intellij.codeInsight.daemon.Validator)

Example 4 with ProcessCanceledException

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

the class TaskManagerImpl method testConnection.

@Override
public boolean testConnection(final TaskRepository repository) {
    TestConnectionTask task = new TestConnectionTask("Test connection") {

        public void run(@NotNull ProgressIndicator indicator) {
            indicator.setText("Connecting to " + repository.getUrl() + "...");
            indicator.setFraction(0);
            indicator.setIndeterminate(true);
            try {
                myConnection = repository.createCancellableConnection();
                if (myConnection != null) {
                    Future<Exception> future = ApplicationManager.getApplication().executeOnPooledThread(myConnection);
                    while (true) {
                        try {
                            myException = future.get(100, TimeUnit.MILLISECONDS);
                            return;
                        } catch (TimeoutException ignore) {
                            try {
                                indicator.checkCanceled();
                            } catch (ProcessCanceledException e) {
                                myException = e;
                                myConnection.cancel();
                                return;
                            }
                        } catch (Exception e) {
                            myException = e;
                            return;
                        }
                    }
                } else {
                    try {
                        repository.testConnection();
                    } catch (Exception e) {
                        LOG.info(e);
                        myException = e;
                    }
                }
            } catch (Exception e) {
                myException = e;
            }
        }
    };
    ProgressManager.getInstance().run(task);
    Exception e = task.myException;
    if (e == null) {
        myBadRepositories.remove(repository);
        Messages.showMessageDialog(myProject, "Connection is successful", "Connection", Messages.getInformationIcon());
    } else if (!(e instanceof ProcessCanceledException)) {
        String message = e.getMessage();
        if (e instanceof UnknownHostException) {
            message = "Unknown host: " + message;
        }
        if (message == null) {
            LOG.error(e);
            message = "Unknown error";
        }
        Messages.showErrorDialog(myProject, StringUtil.capitalize(message), "Error");
    }
    return e == null;
}
Also used : UnknownHostException(java.net.UnknownHostException) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) NotNull(org.jetbrains.annotations.NotNull) TimeoutException(java.util.concurrent.TimeoutException) XmlSerializationException(com.intellij.util.xmlb.XmlSerializationException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) SocketTimeoutException(java.net.SocketTimeoutException) UnknownHostException(java.net.UnknownHostException) TimeoutException(java.util.concurrent.TimeoutException) SocketTimeoutException(java.net.SocketTimeoutException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 5 with ProcessCanceledException

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

the class SvnVcs method upgradeIfNeeded.

private void upgradeIfNeeded(final MessageBus bus) {
    final MessageBusConnection connection = bus.connect();
    connection.subscribe(ChangeListManagerImpl.LISTS_LOADED, lists -> {
        if (lists.isEmpty())
            return;
        try {
            ChangeListManager.getInstance(myProject).setReadOnly(LocalChangeList.DEFAULT_NAME, true);
            if (!myConfiguration.changeListsSynchronized()) {
                processChangeLists(lists);
            }
        } catch (ProcessCanceledException e) {
        } finally {
            myConfiguration.upgrade();
        }
        connection.disconnect();
    });
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Aggregations

ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)186 NotNull (org.jetbrains.annotations.NotNull)47 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)44 VirtualFile (com.intellij.openapi.vfs.VirtualFile)38 Project (com.intellij.openapi.project.Project)31 Nullable (org.jetbrains.annotations.Nullable)27 IOException (java.io.IOException)23 Task (com.intellij.openapi.progress.Task)18 File (java.io.File)17 Document (com.intellij.openapi.editor.Document)14 PsiFile (com.intellij.psi.PsiFile)14 Ref (com.intellij.openapi.util.Ref)13 Logger (com.intellij.openapi.diagnostic.Logger)11 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)11 List (java.util.List)11 VcsException (com.intellij.openapi.vcs.VcsException)10 ArrayList (java.util.ArrayList)10 StringUtil (com.intellij.openapi.util.text.StringUtil)9 ContainerUtil (com.intellij.util.containers.ContainerUtil)9 java.util (java.util)9