Search in sources :

Example 66 with VcsException

use of com.intellij.openapi.vcs.VcsException in project intellij-community by JetBrains.

the class MultipleFileMergeDialog method showMergeDialog.

private void showMergeDialog() {
    DiffRequestFactory requestFactory = DiffRequestFactory.getInstance();
    Collection<VirtualFile> files = myTable.getSelection();
    if (!beforeResolve(files)) {
        return;
    }
    for (final VirtualFile file : files) {
        final MergeData mergeData;
        try {
            mergeData = myProvider.loadRevisions(file);
        } catch (VcsException ex) {
            Messages.showErrorDialog(myRootPanel, "Error loading revisions to merge: " + ex.getMessage());
            break;
        }
        if (mergeData.CURRENT == null || mergeData.LAST == null || mergeData.ORIGINAL == null) {
            Messages.showErrorDialog(myRootPanel, "Error loading revisions to merge");
            break;
        }
        String leftTitle = myMergeDialogCustomizer.getLeftPanelTitle(file);
        String baseTitle = myMergeDialogCustomizer.getCenterPanelTitle(file);
        String rightTitle = myMergeDialogCustomizer.getRightPanelTitle(file, mergeData.LAST_REVISION_NUMBER);
        String title = myMergeDialogCustomizer.getMergeWindowTitle(file);
        final List<byte[]> byteContents = ContainerUtil.list(mergeData.CURRENT, mergeData.ORIGINAL, mergeData.LAST);
        List<String> contentTitles = ContainerUtil.list(leftTitle, baseTitle, rightTitle);
        Consumer<MergeResult> callback = result -> {
            Document document = FileDocumentManager.getInstance().getCachedDocument(file);
            if (document != null)
                FileDocumentManager.getInstance().saveDocument(document);
            checkMarkModifiedProject(file);
            if (result != MergeResult.CANCEL) {
                ApplicationManager.getApplication().runWriteAction(() -> {
                    markFileProcessed(file, getSessionResolution(result));
                });
            }
        };
        MergeRequest request;
        try {
            if (myProvider.isBinary(file)) {
                // respect MIME-types in svn
                request = requestFactory.createBinaryMergeRequest(myProject, file, byteContents, title, contentTitles, callback);
            } else {
                request = requestFactory.createMergeRequest(myProject, file, byteContents, title, contentTitles, callback);
            }
            MergeUtil.putRevisionInfos(request, mergeData);
        } catch (InvalidDiffRequestException e) {
            LOG.error(e);
            Messages.showErrorDialog(myRootPanel, "Can't show merge dialog");
            break;
        }
        DiffManager.getInstance().showMerge(myProject, request);
    }
    updateModelFromFiles();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) UIUtil(com.intellij.util.ui.UIUtil) InvalidDiffRequestException(com.intellij.diff.InvalidDiffRequestException) MergeUtil(com.intellij.diff.merge.MergeUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) DiffManager(com.intellij.diff.DiffManager) ColumnInfo(com.intellij.util.ui.ColumnInfo) TableCellRenderer(javax.swing.table.TableCellRenderer) JBLabel(com.intellij.ui.components.JBLabel) SmartList(com.intellij.util.SmartList) DiffUtil(com.intellij.diff.util.DiffUtil) VcsDirtyScopeManager(com.intellij.openapi.vcs.changes.VcsDirtyScopeManager) SpeedSearchUtil(com.intellij.ui.speedSearch.SpeedSearchUtil) Messages(com.intellij.openapi.ui.Messages) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) VcsException(com.intellij.openapi.vcs.VcsException) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) ListSelectionEvent(javax.swing.event.ListSelectionEvent) VirtualFilePresentation(com.intellij.ide.presentation.VirtualFilePresentation) TableView(com.intellij.ui.table.TableView) MergeRequest(com.intellij.diff.merge.MergeRequest) DoubleClickListener(com.intellij.ui.DoubleClickListener) MergeVersion(com.intellij.openapi.diff.impl.mergeTool.MergeVersion) Nullable(org.jetbrains.annotations.Nullable) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) DiffRequestFactory(com.intellij.diff.DiffRequestFactory) Ref(com.intellij.openapi.util.Ref) Consumer(com.intellij.util.Consumer) java.util(java.util) ActionListener(java.awt.event.ActionListener) ColoredTableCellRenderer(com.intellij.ui.ColoredTableCellRenderer) NonNls(org.jetbrains.annotations.NonNls) ContainerUtil(com.intellij.util.containers.ContainerUtil) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) CommonBundle(com.intellij.CommonBundle) Project(com.intellij.openapi.project.Project) ListTableModel(com.intellij.util.ui.ListTableModel) TableSpeedSearch(com.intellij.ui.TableSpeedSearch) StringUtil(com.intellij.openapi.util.text.StringUtil) ProjectManagerEx(com.intellij.openapi.project.ex.ProjectManagerEx) Convertor(com.intellij.util.containers.Convertor) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) IOException(java.io.IOException) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) VcsBundle(com.intellij.openapi.vcs.VcsBundle) MergeResult(com.intellij.diff.merge.MergeResult) CommandProcessor(com.intellij.openapi.command.CommandProcessor) ListSelectionListener(javax.swing.event.ListSelectionListener) javax.swing(javax.swing) DiffRequestFactory(com.intellij.diff.DiffRequestFactory) InvalidDiffRequestException(com.intellij.diff.InvalidDiffRequestException) MergeResult(com.intellij.diff.merge.MergeResult) Document(com.intellij.openapi.editor.Document) MergeRequest(com.intellij.diff.merge.MergeRequest) VcsException(com.intellij.openapi.vcs.VcsException)

Example 67 with VcsException

use of com.intellij.openapi.vcs.VcsException in project intellij-community by JetBrains.

the class VcsHandleType method processFiles.

public void processFiles(final Collection<VirtualFile> files, @Nullable final String changelist) {
    try {
        EditFileProvider provider = myVcs.getEditFileProvider();
        assert provider != null;
        provider.editFiles(VfsUtil.toVirtualFileArray(files));
    } catch (VcsException e) {
        Messages.showErrorDialog(VcsBundle.message("message.text.cannot.edit.file", e.getLocalizedMessage()), VcsBundle.message("message.title.edit.files"));
    }
    ApplicationManager.getApplication().runWriteAction(new Runnable() {

        public void run() {
            for (final VirtualFile file : files) {
                file.refresh(false, false);
            }
        }
    });
    if (changelist != null) {
        myChangeListManager.invokeAfterUpdate(new Runnable() {

            @Override
            public void run() {
                LocalChangeList list = myChangeListManager.findChangeList(changelist);
                if (list != null) {
                    List<Change> changes = ContainerUtil.mapNotNull(files, myChangeFunction);
                    myChangeListManager.moveChangesTo(list, changes.toArray(new Change[changes.size()]));
                }
            }
        }, InvokeAfterUpdateMode.SILENT, "", ModalityState.NON_MODAL);
    }
}
Also used : EditFileProvider(com.intellij.openapi.vcs.EditFileProvider) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsException(com.intellij.openapi.vcs.VcsException) LocalChangeList(com.intellij.openapi.vcs.changes.LocalChangeList) LocalChangeList(com.intellij.openapi.vcs.changes.LocalChangeList) List(java.util.List)

Example 68 with VcsException

use of com.intellij.openapi.vcs.VcsException in project intellij-community by JetBrains.

the class VcsLogFilterer method getFilteredDetailsFromTheVcs.

@NotNull
private static Collection<CommitId> getFilteredDetailsFromTheVcs(@NotNull Map<VirtualFile, VcsLogProvider> providers, @NotNull VcsLogFilterCollection filterCollection, int maxCount) throws VcsException {
    Set<VirtualFile> visibleRoots = VcsLogUtil.getAllVisibleRoots(providers.keySet(), filterCollection.getRootFilter(), filterCollection.getStructureFilter());
    Collection<CommitId> commits = ContainerUtil.newArrayList();
    for (Map.Entry<VirtualFile, VcsLogProvider> entry : providers.entrySet()) {
        final VirtualFile root = entry.getKey();
        if (!visibleRoots.contains(root) || (filterCollection.getUserFilter() != null && filterCollection.getUserFilter().getUsers(root).isEmpty())) {
            // there is a structure or user filter, but it doesn't match this root
            continue;
        }
        VcsLogFilterCollection rootSpecificCollection = filterCollection;
        if (rootSpecificCollection.getStructureFilter() != null) {
            rootSpecificCollection = new VcsLogFilterCollectionBuilder(filterCollection).with(new VcsLogStructureFilterImpl(ContainerUtil.newHashSet(VcsLogUtil.getFilteredFilesForRoot(root, filterCollection)))).build();
        }
        List<TimedVcsCommit> matchingCommits = entry.getValue().getCommitsMatchingFilter(root, rootSpecificCollection, maxCount);
        commits.addAll(ContainerUtil.map(matchingCommits, commit -> new CommitId(commit.getId(), root)));
    }
    return commits;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) com.intellij.vcs.log.data(com.intellij.vcs.log.data) VcsLogUtil(com.intellij.vcs.log.impl.VcsLogUtil) UIUtil(com.intellij.util.ui.UIUtil) java.util(java.util) GraphCommit(com.intellij.vcs.log.graph.GraphCommit) VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashSet(com.intellij.util.containers.HashSet) VcsLogIndex(com.intellij.vcs.log.data.index.VcsLogIndex) Computable(com.intellij.openapi.util.Computable) com.intellij.vcs.log(com.intellij.vcs.log) ContainerUtil(com.intellij.util.containers.ContainerUtil) VcsLogFilterCollectionBuilder(com.intellij.vcs.log.impl.VcsLogFilterCollectionImpl.VcsLogFilterCollectionBuilder) Nullable(org.jetbrains.annotations.Nullable) VisibleGraph(com.intellij.vcs.log.graph.VisibleGraph) StopWatch(com.intellij.vcs.log.util.StopWatch) Pair(com.intellij.openapi.util.Pair) PermanentGraph(com.intellij.vcs.log.graph.PermanentGraph) Logger(com.intellij.openapi.diagnostic.Logger) VcsException(com.intellij.openapi.vcs.VcsException) NotNull(org.jetbrains.annotations.NotNull) VcsLogHashFilterImpl(com.intellij.vcs.log.impl.VcsLogHashFilterImpl) VcsLogFilterCollectionBuilder(com.intellij.vcs.log.impl.VcsLogFilterCollectionImpl.VcsLogFilterCollectionBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 69 with VcsException

use of com.intellij.openapi.vcs.VcsException 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 70 with VcsException

use of com.intellij.openapi.vcs.VcsException 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)

Aggregations

VcsException (com.intellij.openapi.vcs.VcsException)200 VirtualFile (com.intellij.openapi.vfs.VirtualFile)89 File (java.io.File)48 NotNull (org.jetbrains.annotations.NotNull)42 FilePath (com.intellij.openapi.vcs.FilePath)35 Change (com.intellij.openapi.vcs.changes.Change)33 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)26 ArrayList (java.util.ArrayList)24 Nullable (org.jetbrains.annotations.Nullable)23 IOException (java.io.IOException)20 SVNException (org.tmatesoft.svn.core.SVNException)19 Project (com.intellij.openapi.project.Project)17 Ref (com.intellij.openapi.util.Ref)16 Test (org.junit.Test)14 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)13 GitRepository (git4idea.repo.GitRepository)12 Task (com.intellij.openapi.progress.Task)11 List (java.util.List)11 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)10 ContentRevision (com.intellij.openapi.vcs.changes.ContentRevision)10