Search in sources :

Example 31 with ProcessCanceledException

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

the class CvsCommittedChangesProvider method getOneList.

@Nullable
@Override
public Pair<CvsChangeList, FilePath> getOneList(VirtualFile file, final VcsRevisionNumber number) throws VcsException {
    final File ioFile = new File(file.getPath());
    final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(ioFile);
    final VirtualFile vcsRoot = ProjectLevelVcsManager.getInstance(myProject).getVcsRootFor(filePath);
    final CvsRepositoryLocation cvsLocation = getLocationFor(filePath);
    if (cvsLocation == null)
        return null;
    final String module = CvsUtil.getModuleName(vcsRoot);
    final CvsEnvironment connectionSettings = cvsLocation.getEnvironment();
    if (connectionSettings.isOffline()) {
        return null;
    }
    final CvsChangeListsBuilder builder = new CvsChangeListsBuilder(module, connectionSettings, myProject, vcsRoot);
    final Ref<CvsChangeList> result = new Ref<>();
    final LoadHistoryOperation operation = new LoadHistoryOperation(connectionSettings, wrapper -> {
        final List<Revision> revisions = wrapper.getRevisions();
        if (revisions.isEmpty())
            return;
        final RevisionWrapper revision = new RevisionWrapper(wrapper.getFile(), revisions.get(0), null);
        result.set(builder.addRevision(revision));
    }, cvsLocation.getModuleName(), number.asString());
    final CvsResult executionResult = operation.run(myProject);
    if (executionResult.isCanceled()) {
        throw new ProcessCanceledException();
    } else if (executionResult.hasErrors()) {
        throw executionResult.composeError();
    }
    if (result.isNull()) {
        return null;
    }
    final Date commitDate = result.get().getCommitDate();
    final CvsEnvironment rootConnectionSettings = CvsEntriesManager.getInstance().getCvsConnectionSettingsFor(vcsRoot);
    final long t = commitDate.getTime();
    final Date dateFrom = new Date(t - CvsChangeList.SUITABLE_DIFF);
    final Date dateTo = new Date(t + CvsChangeList.SUITABLE_DIFF);
    final LoadHistoryOperation operation2 = new LoadHistoryOperation(rootConnectionSettings, module, dateFrom, dateTo, wrapper -> {
        final List<RevisionWrapper> wrappers = builder.revisionWrappersFromLog(wrapper);
        if (wrappers != null) {
            for (RevisionWrapper revisionWrapper : wrappers) {
                if (result.get().containsFileRevision(revisionWrapper)) {
                    continue;
                }
                builder.addRevision(revisionWrapper);
            }
        }
    });
    final CvsResult cvsResult = operation2.run(myProject);
    if (cvsResult.hasErrors()) {
        throw cvsResult.composeError();
    }
    return Pair.create(result.get(), filePath);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CvsResult(com.intellij.openapi.cvsIntegration.CvsResult) Ref(com.intellij.openapi.util.Ref) Revision(org.netbeans.lib.cvsclient.command.log.Revision) CvsEnvironment(com.intellij.cvsSupport2.connections.CvsEnvironment) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Nullable(org.jetbrains.annotations.Nullable)

Example 32 with ProcessCanceledException

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

the class CvsContentRevision method getContentAsBytes.

@Nullable
@Override
public byte[] getContentAsBytes() throws VcsException {
    if (myContent == null) {
        final GetFileContentOperation operation = new GetFileContentOperation(myFile, myEnvironment, myRevision);
        CvsOperationExecutor executor = new CvsOperationExecutor(myProject);
        executor.performActionSync(new CommandCvsHandler(CvsBundle.message("operation.name.load.file"), operation), CvsOperationExecutorCallback.EMPTY);
        CvsResult result = executor.getResult();
        if (result.isCanceled()) {
            throw new ProcessCanceledException();
        }
        if (result.hasErrors()) {
            throw result.composeError();
        }
        if (!operation.isLoaded()) {
            throw new VcsException("Network problem");
        }
        myContent = operation.getFileBytes();
    }
    return myContent;
}
Also used : GetFileContentOperation(com.intellij.cvsSupport2.cvsoperations.cvsContent.GetFileContentOperation) CvsOperationExecutor(com.intellij.cvsSupport2.cvsExecution.CvsOperationExecutor) VcsException(com.intellij.openapi.vcs.VcsException) CommandCvsHandler(com.intellij.cvsSupport2.cvshandlers.CommandCvsHandler) CvsResult(com.intellij.openapi.cvsIntegration.CvsResult) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Nullable(org.jetbrains.annotations.Nullable)

Example 33 with ProcessCanceledException

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

the class CvsRootConfiguration method testConnection.

public void testConnection(Project project) throws AuthenticationException, IOException {
    final IConnection connection = createSettings().createConnection(new ReadWriteStatistics());
    final ErrorMessagesProcessor errorProcessor = new ErrorMessagesProcessor();
    final CvsExecutionEnvironment cvsExecutionEnvironment = new CvsExecutionEnvironment(errorProcessor, CvsExecutionEnvironment.DUMMY_STOPPER, errorProcessor, PostCvsActivity.DEAF, project);
    final CvsResult result = new CvsResultEx();
    try {
        ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
            final GetModulesListOperation operation = new GetModulesListOperation(createSettings());
            final CvsRootProvider cvsRootProvider = operation.getCvsRootProvider();
            try {
                if (connection instanceof SelfTestingConnection) {
                    ((SelfTestingConnection) connection).test(CvsListenerWithProgress.createOnProgress());
                }
                operation.execute(cvsRootProvider, cvsExecutionEnvironment, connection, DummyProgressViewer.INSTANCE);
            } catch (ValidRequestsExpectedException ex) {
                result.addError(new CvsException(ex, cvsRootProvider.getCvsRootAsString()));
            } catch (CommandException ex) {
                result.addError(new CvsException(ex.getUnderlyingException(), cvsRootProvider.getCvsRootAsString()));
            } catch (ProcessCanceledException ex) {
                result.setIsCanceled();
            } catch (BugLog.BugException e) {
                LOG.error(e);
            } catch (Exception e) {
                result.addError(new CvsException(e, cvsRootProvider.getCvsRootAsString()));
            }
        }, CvsBundle.message("operation.name.test.connection"), true, null);
        if (result.isCanceled())
            throw new ProcessCanceledException();
        if (result.hasErrors()) {
            final VcsException vcsException = result.composeError();
            throw new AuthenticationException(vcsException.getLocalizedMessage(), vcsException.getCause());
        }
        final List<VcsException> errors = errorProcessor.getErrors();
        if (!errors.isEmpty()) {
            final VcsException firstError = errors.get(0);
            throw new AuthenticationException(firstError.getLocalizedMessage(), firstError);
        }
    } finally {
        connection.close();
    }
}
Also used : AuthenticationException(org.netbeans.lib.cvsclient.connection.AuthenticationException) CvsException(com.intellij.cvsSupport2.errorHandling.CvsException) IConnection(org.netbeans.lib.cvsclient.connection.IConnection) CommandException(org.netbeans.lib.cvsclient.command.CommandException) ValidRequestsExpectedException(org.netbeans.lib.cvsclient.ValidRequestsExpectedException) ErrorMessagesProcessor(com.intellij.cvsSupport2.cvsoperations.cvsErrors.ErrorMessagesProcessor) CvsResult(com.intellij.openapi.cvsIntegration.CvsResult) ValidRequestsExpectedException(org.netbeans.lib.cvsclient.ValidRequestsExpectedException) CvsException(com.intellij.cvsSupport2.errorHandling.CvsException) AuthenticationException(org.netbeans.lib.cvsclient.connection.AuthenticationException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) VcsException(com.intellij.openapi.vcs.VcsException) CommandException(org.netbeans.lib.cvsclient.command.CommandException) IOException(java.io.IOException) BugLog(org.netbeans.lib.cvsclient.util.BugLog) CvsExecutionEnvironment(com.intellij.cvsSupport2.cvsoperations.common.CvsExecutionEnvironment) GetModulesListOperation(com.intellij.cvsSupport2.cvsoperations.cvsContent.GetModulesListOperation) VcsException(com.intellij.openapi.vcs.VcsException) CvsResultEx(com.intellij.cvsSupport2.CvsResultEx) ReadWriteStatistics(com.intellij.cvsSupport2.javacvsImpl.io.ReadWriteStatistics) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 34 with ProcessCanceledException

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

the class TwosideBinaryDiffViewer method performRediff.

@Override
@NotNull
protected Runnable performRediff(@NotNull final ProgressIndicator indicator) {
    try {
        indicator.checkCanceled();
        List<DiffContent> contents = myRequest.getContents();
        if (!(contents.get(0) instanceof FileContent) || !(contents.get(1) instanceof FileContent)) {
            return applyNotification(null);
        }
        final VirtualFile file1 = ((FileContent) contents.get(0)).getFile();
        final VirtualFile file2 = ((FileContent) contents.get(1)).getFile();
        final JComponent notification = ReadAction.compute(() -> {
            if (!file1.isValid() || !file2.isValid()) {
                return DiffNotifications.createError();
            }
            try {
                // we can't use getInputStream() here because we can't restore BOM marker
                // (getBom() can return null for binary files, while getInputStream() strips BOM for all files).
                // It can be made for files from VFS that implements FileSystemInterface though.
                byte[] bytes1 = file1.contentsToByteArray();
                byte[] bytes2 = file2.contentsToByteArray();
                return Arrays.equals(bytes1, bytes2) ? DiffNotifications.createEqualContents() : null;
            } catch (IOException e) {
                LOG.warn(e);
                return null;
            }
        });
        return applyNotification(notification);
    } catch (ProcessCanceledException e) {
        throw e;
    } catch (Throwable e) {
        LOG.error(e);
        return applyNotification(DiffNotifications.createError());
    }
}
Also used : FileContent(com.intellij.diff.contents.FileContent) VirtualFile(com.intellij.openapi.vfs.VirtualFile) IOException(java.io.IOException) DiffContent(com.intellij.diff.contents.DiffContent) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) NotNull(org.jetbrains.annotations.NotNull)

Example 35 with ProcessCanceledException

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

the class UnifiedDiffViewer method performRediff.

@Override
@NotNull
protected Runnable performRediff(@NotNull final ProgressIndicator indicator) {
    try {
        indicator.checkCanceled();
        final Document document1 = getContent1().getDocument();
        final Document document2 = getContent2().getDocument();
        final CharSequence[] texts = ReadAction.compute(() -> {
            return new CharSequence[] { document1.getImmutableCharSequence(), document2.getImmutableCharSequence() };
        });
        final List<LineFragment> fragments = myTextDiffProvider.compare(texts[0], texts[1], indicator);
        final DocumentContent content1 = getContent1();
        final DocumentContent content2 = getContent2();
        indicator.checkCanceled();
        TwosideDocumentData data = ReadAction.compute(() -> {
            indicator.checkCanceled();
            UnifiedFragmentBuilder builder = new UnifiedFragmentBuilder(fragments, document1, document2, myMasterSide);
            builder.exec();
            indicator.checkCanceled();
            EditorHighlighter highlighter = buildHighlighter(myProject, content1, content2, texts[0], texts[1], builder.getRanges(), builder.getText().length());
            UnifiedEditorRangeHighlighter rangeHighlighter = new UnifiedEditorRangeHighlighter(myProject, document1, document2, builder.getRanges());
            return new TwosideDocumentData(builder, highlighter, rangeHighlighter);
        });
        UnifiedFragmentBuilder builder = data.getBuilder();
        FileType fileType = content2.getContentType() == null ? content1.getContentType() : content2.getContentType();
        LineNumberConvertor convertor1 = builder.getConvertor1();
        LineNumberConvertor convertor2 = builder.getConvertor2();
        List<LineRange> changedLines = builder.getChangedLines();
        boolean isContentsEqual = builder.isEqual();
        CombinedEditorData editorData = new CombinedEditorData(builder.getText(), data.getHighlighter(), data.getRangeHighlighter(), fileType, convertor1.createConvertor(), convertor2.createConvertor());
        return apply(editorData, builder.getBlocks(), convertor1, convertor2, changedLines, isContentsEqual);
    } catch (DiffTooBigException e) {
        return () -> {
            clearDiffPresentation();
            myPanel.setTooBigContent();
        };
    } catch (ProcessCanceledException e) {
        throw e;
    } catch (Throwable e) {
        LOG.error(e);
        return () -> {
            clearDiffPresentation();
            myPanel.setErrorContent();
        };
    }
}
Also used : LineFragment(com.intellij.diff.fragments.LineFragment) FileType(com.intellij.openapi.fileTypes.FileType) DocumentContent(com.intellij.diff.contents.DocumentContent) DiffTooBigException(com.intellij.diff.comparison.DiffTooBigException) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter) 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