Search in sources :

Example 1 with ReadWriteStatistics

use of com.intellij.cvsSupport2.javacvsImpl.io.ReadWriteStatistics in project intellij-community by JetBrains.

the class ExtConnection method check.

@SuppressWarnings({ "IOResourceOpenedButNotSafelyClosed" })
private void check(ICvsCommandStopper stopper, String expectedResult) throws IOException, AuthenticationException {
    InputStreamWrapper streamWrapper = new InputStreamWrapper(myInputStream, stopper, new ReadWriteStatistics());
    try {
        StringBuilder buffer = new StringBuilder();
        while (true) {
            int i = streamWrapper.read();
            if (i == -1 || i == '\n' || i == ' ' || i == '\r')
                break;
            buffer.append((char) i);
        }
        String read = buffer.toString().trim();
        if (!expectedResult.equals(read)) {
            if (StringUtil.startsWithConcatenation(read, myUserName, "@", myHost)) {
                throw new AuthenticationException(CvsBundle.message("exception.text.ext.server.rejected.access"), null);
            } else {
                if (myErrorText.length() > 0) {
                    throw new AuthenticationException(myErrorText.toString(), null);
                } else {
                    throw new AuthenticationException(CvsBundle.message("exception.text.ext.cannot.establish.external.connection"), null);
                }
            }
        }
    } finally {
        streamWrapper.close();
    }
}
Also used : InputStreamWrapper(com.intellij.cvsSupport2.javacvsImpl.io.InputStreamWrapper) AuthenticationException(org.netbeans.lib.cvsclient.connection.AuthenticationException) ReadWriteStatistics(com.intellij.cvsSupport2.javacvsImpl.io.ReadWriteStatistics)

Example 2 with ReadWriteStatistics

use of com.intellij.cvsSupport2.javacvsImpl.io.ReadWriteStatistics 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 3 with ReadWriteStatistics

use of com.intellij.cvsSupport2.javacvsImpl.io.ReadWriteStatistics in project intellij-community by JetBrains.

the class CvsCommandOperation method doExecute.

private void doExecute(final CvsExecutionEnvironment executionEnvironment, boolean underReadAction) throws VcsException {
    final VcsException[] exc = new VcsException[1];
    final Runnable action = () -> {
        try {
            final ReadWriteStatistics statistics = executionEnvironment.getReadWriteStatistics();
            final Collection<CvsRootProvider> allCvsRoots;
            try {
                allCvsRoots = getAllCvsRoots();
            } catch (CannotFindCvsRootException e) {
                throw createVcsExceptionOn(e, null);
            }
            final IProgressViewer progressViewer = new IProgressViewer() {

                @Override
                public void setProgress(double value) {
                    final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
                    if (progressIndicator != null)
                        progressIndicator.setFraction(value);
                }
            };
            int count = 0;
            final double step = 1.0 / allCvsRoots.size();
            for (CvsRootProvider cvsRootProvider : allCvsRoots) {
                try {
                    final double lowerBound = step * count;
                    final RangeProgressViewer partialProgress = new RangeProgressViewer(progressViewer, lowerBound, lowerBound + step);
                    myLastProcessedCvsRoot = cvsRootProvider.getCvsRootAsString();
                    execute(cvsRootProvider, executionEnvironment, statistics, partialProgress);
                    count++;
                } catch (IOCommandException e) {
                    LOG.info(e);
                    throw createVcsExceptionOn(e.getIOException(), cvsRootProvider.getCvsRootAsString());
                } catch (CommandException e) {
                    LOG.info(e);
                    final Exception underlyingException = e.getUnderlyingException();
                    if (underlyingException != null) {
                        LOG.info(underlyingException);
                    }
                    throw createVcsExceptionOn(underlyingException == null ? e : underlyingException, cvsRootProvider.getCvsRootAsString());
                }
            }
        } catch (VcsException e) {
            exc[0] = e;
        }
    };
    if (underReadAction) {
        ApplicationManager.getApplication().runReadAction(action);
    } else {
        action.run();
    }
    if (exc[0] != null)
        throw exc[0];
}
Also used : IProgressViewer(org.netbeans.lib.cvsclient.progress.IProgressViewer) CannotFindCvsRootException(com.intellij.cvsSupport2.errorHandling.CannotFindCvsRootException) CvsException(com.intellij.cvsSupport2.errorHandling.CvsException) AuthenticationException(org.netbeans.lib.cvsclient.connection.AuthenticationException) VcsException(com.intellij.openapi.vcs.VcsException) CannotFindCvsRootException(com.intellij.cvsSupport2.errorHandling.CannotFindCvsRootException) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsException(com.intellij.openapi.vcs.VcsException) RangeProgressViewer(org.netbeans.lib.cvsclient.progress.RangeProgressViewer) Collection(java.util.Collection) CvsRootProvider(com.intellij.cvsSupport2.connections.CvsRootProvider)

Example 4 with ReadWriteStatistics

use of com.intellij.cvsSupport2.javacvsImpl.io.ReadWriteStatistics in project intellij-community by JetBrains.

the class EditOperation method execute.

@Override
protected void execute(CvsRootProvider root, CvsExecutionEnvironment executionEnvironment, ReadWriteStatistics statistics, IProgressViewer progressViewer) throws CommandException, CommandAbortedException, VcsException {
    super.execute(root, executionEnvironment, statistics, progressViewer);
    final VcsException vcsException = new CvsException(FILES_BEING_EDITED_EXCEPTION, root.getCvsRootAsString());
    for (EditedFileInfo info : myEditFileInfos) {
        if (info.isSuitableFor(root))
            return;
        final File file = info.getFile(root);
        final VirtualFile virtualFile = CvsVfsUtil.findFileByIoFile(file);
        if (virtualFile != null)
            vcsException.setVirtualFile(virtualFile);
    }
    if (!myEditFileInfos.isEmpty())
        throw vcsException;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsException(com.intellij.openapi.vcs.VcsException) CvsException(com.intellij.cvsSupport2.errorHandling.CvsException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 5 with ReadWriteStatistics

use of com.intellij.cvsSupport2.javacvsImpl.io.ReadWriteStatistics in project intellij-community by JetBrains.

the class CvsConnectionSettings method createConnection.

public IConnection createConnection(ReadWriteStatistics statistics) {
    CvsListenerWithProgress cvsCommandStopper = CvsListenerWithProgress.createOnProgress();
    IConnection originalConnection = createOriginalConnection(cvsCommandStopper, myCvsRootConfiguration);
    if (originalConnection instanceof SelfTestingConnection) {
        return new SelfTestingConnectionWrapper(originalConnection, statistics, cvsCommandStopper);
    } else {
        return new ConnectionWrapper(originalConnection, statistics, cvsCommandStopper);
    }
}
Also used : CvsListenerWithProgress(com.intellij.cvsSupport2.cvsoperations.cvsMessages.CvsListenerWithProgress) IConnection(org.netbeans.lib.cvsclient.connection.IConnection)

Aggregations

CvsException (com.intellij.cvsSupport2.errorHandling.CvsException)3 VcsException (com.intellij.openapi.vcs.VcsException)3 AuthenticationException (org.netbeans.lib.cvsclient.connection.AuthenticationException)3 ReadWriteStatistics (com.intellij.cvsSupport2.javacvsImpl.io.ReadWriteStatistics)2 IConnection (org.netbeans.lib.cvsclient.connection.IConnection)2 CvsResultEx (com.intellij.cvsSupport2.CvsResultEx)1 CvsRootProvider (com.intellij.cvsSupport2.connections.CvsRootProvider)1 CvsExecutionEnvironment (com.intellij.cvsSupport2.cvsoperations.common.CvsExecutionEnvironment)1 GetModulesListOperation (com.intellij.cvsSupport2.cvsoperations.cvsContent.GetModulesListOperation)1 ErrorMessagesProcessor (com.intellij.cvsSupport2.cvsoperations.cvsErrors.ErrorMessagesProcessor)1 CvsListenerWithProgress (com.intellij.cvsSupport2.cvsoperations.cvsMessages.CvsListenerWithProgress)1 CannotFindCvsRootException (com.intellij.cvsSupport2.errorHandling.CannotFindCvsRootException)1 InputStreamWrapper (com.intellij.cvsSupport2.javacvsImpl.io.InputStreamWrapper)1 CvsResult (com.intellij.openapi.cvsIntegration.CvsResult)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 File (java.io.File)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1