Search in sources :

Example 1 with SVNCancelException

use of org.tmatesoft.svn.core.SVNCancelException in project intellij-community by JetBrains.

the class SvnAuthenticationNotifier method validationImpl.

private static boolean validationImpl(final Project project, final SVNURL url, final SvnConfiguration configuration, final SvnAuthenticationManager manager, final boolean checkWrite, final String realm, final String kind, boolean interactive) {
    // we should also NOT show proxy credentials dialog if at least fixed proxy was used, so
    Proxy proxyToRelease = null;
    if (!interactive && configuration.isIsUseDefaultProxy()) {
        final HttpConfigurable instance = HttpConfigurable.getInstance();
        if (instance.USE_HTTP_PROXY && instance.PROXY_AUTHENTICATION && (StringUtil.isEmptyOrSpaces(instance.getProxyLogin()) || StringUtil.isEmptyOrSpaces(instance.getPlainProxyPassword()))) {
            return false;
        }
        if (instance.USE_PROXY_PAC) {
            final List<Proxy> select;
            try {
                select = CommonProxy.getInstance().select(new URI(url.toString()));
            } catch (URISyntaxException e) {
                LOG.info("wrong URL: " + url.toString());
                return false;
            }
            if (select != null && !select.isEmpty()) {
                for (Proxy proxy : select) {
                    if (HttpConfigurable.isRealProxy(proxy) && Proxy.Type.HTTP.equals(proxy.type())) {
                        final InetSocketAddress address = (InetSocketAddress) proxy.address();
                        final PasswordAuthentication password = HttpConfigurable.getInstance().getGenericPassword(address.getHostName(), address.getPort());
                        if (password == null) {
                            CommonProxy.getInstance().noAuthentication("http", address.getHostName(), address.getPort());
                            proxyToRelease = proxy;
                        }
                    }
                }
            }
        }
    }
    SvnInteractiveAuthenticationProvider.clearCallState();
    try {
        // start svnkit authentication cycle
        SvnVcs.getInstance(project).getSvnKitManager().createWCClient(manager).doInfo(url, SVNRevision.UNDEFINED, SVNRevision.HEAD);
    //SvnVcs.getInstance(project).getInfo(url, SVNRevision.HEAD, manager);
    } catch (SVNAuthenticationException | SVNCancelException e) {
        log(e);
        return false;
    } catch (final SVNException e) {
        if (e.getErrorMessage().getErrorCode().isAuthentication()) {
            log(e);
            return false;
        }
        LOG.info("some other exc", e);
        if (interactive) {
            showAuthenticationFailedWithHotFixes(project, configuration, e);
        }
        /// !!!! any exception means user should be notified that authorization failed
        return false;
    } finally {
        if (!interactive && configuration.isIsUseDefaultProxy() && proxyToRelease != null) {
            final InetSocketAddress address = (InetSocketAddress) proxyToRelease.address();
            CommonProxy.getInstance().noAuthentication("http", address.getHostName(), address.getPort());
        }
    }
    if (!checkWrite) {
        return true;
    }
    if (SvnInteractiveAuthenticationProvider.wasCalled() && SvnInteractiveAuthenticationProvider.wasCancelled())
        return false;
    if (SvnInteractiveAuthenticationProvider.wasCalled())
        return true;
    final SvnVcs svnVcs = SvnVcs.getInstance(project);
    final SvnInteractiveAuthenticationProvider provider = new SvnInteractiveAuthenticationProvider(svnVcs, manager);
    final SVNAuthentication svnAuthentication = provider.requestClientAuthentication(kind, url, realm, null, null, true);
    if (svnAuthentication != null) {
        configuration.acknowledge(kind, realm, svnAuthentication);
        try {
            configuration.getAuthenticationManager(svnVcs).acknowledgeAuthentication(true, kind, realm, null, svnAuthentication);
        } catch (SVNException e) {
            LOG.info(e);
        }
        return true;
    }
    return false;
}
Also used : SVNException(org.tmatesoft.svn.core.SVNException) CommonProxy(com.intellij.util.proxy.CommonProxy) HttpConfigurable(com.intellij.util.net.HttpConfigurable) SVNCancelException(org.tmatesoft.svn.core.SVNCancelException) SVNAuthenticationException(org.tmatesoft.svn.core.SVNAuthenticationException) SVNAuthentication(org.tmatesoft.svn.core.auth.SVNAuthentication)

Example 2 with SVNCancelException

use of org.tmatesoft.svn.core.SVNCancelException in project intellij-community by JetBrains.

the class ElementWithBranchComparer method run.

public void run() {
    new Task.Modal(myProject, getTitle(), true) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            try {
                beforeCompare();
                myElementUrl = resolveElementUrl();
                if (myElementUrl == null) {
                    reportNotFound();
                } else {
                    compare();
                }
            } catch (SVNCancelException ex) {
                ElementWithBranchComparer.this.onCancel();
            } catch (SVNException ex) {
                reportException(new SvnBindException(ex));
            } catch (SvnBindException ex) {
                reportException(ex);
            } catch (VcsException ex) {
                reportGeneralException(ex);
            }
        }
    }.queue();
    showResult();
}
Also used : Task(com.intellij.openapi.progress.Task) SvnBindException(org.jetbrains.idea.svn.commandLine.SvnBindException) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) SVNCancelException(org.tmatesoft.svn.core.SVNCancelException) VcsException(com.intellij.openapi.vcs.VcsException) SVNException(org.tmatesoft.svn.core.SVNException)

Example 3 with SVNCancelException

use of org.tmatesoft.svn.core.SVNCancelException in project intellij-community by JetBrains.

the class SvnBusyOnAddTest method testRefusedAdd.

@Test
public void testRefusedAdd() throws Exception {
    SVNWCDb db = new SVNWCDb();
    final File ioFile = new File(myWorkingCopyRoot, filename);
    ioFile.getParentFile().mkdirs();
    ioFile.createNewFile();
    try {
        db.open(ISVNWCDb.SVNWCDbOpenMode.ReadWrite, new DefaultSVNOptions(), true, true);
        SVNWCContext context = new SVNWCContext(db, new ISVNEventHandler() {

            @Override
            public void handleEvent(SVNEvent event, double progress) throws SVNException {
            }

            @Override
            public void checkCancelled() throws SVNCancelException {
            }
        });
        File file = context.acquireWriteLock(myWorkingCopyRoot, false, true);
        boolean failed = false;
        try {
            SVNWCClient client = new SVNWCClient((ISVNRepositoryPool) null, new DefaultSVNOptions());
            client.doAdd(ioFile, true, false, false, true);
        } catch (SVNException e) {
            Assert.assertEquals(155004, e.getErrorMessage().getErrorCode().getCode());
            failed = true;
        } finally {
            context.releaseWriteLock(myWorkingCopyRoot);
        }
        Assert.assertTrue(failed);
        SVNStatusClient readClient = new SVNStatusClient((ISVNRepositoryPool) null, new DefaultSVNOptions());
        //readClient.doStatus(ioFile, false);
        readClient.doStatus(myWorkingCopyRoot, false);
    } finally {
        ioFile.delete();
        db.close();
    }
}
Also used : DefaultSVNOptions(org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions) SVNException(org.tmatesoft.svn.core.SVNException) ISVNWCDb(org.tmatesoft.svn.core.internal.wc17.db.ISVNWCDb) SVNWCDb(org.tmatesoft.svn.core.internal.wc17.db.SVNWCDb) SVNWCContext(org.tmatesoft.svn.core.internal.wc17.SVNWCContext) SVNCancelException(org.tmatesoft.svn.core.SVNCancelException) File(java.io.File) Test(org.junit.Test)

Example 4 with SVNCancelException

use of org.tmatesoft.svn.core.SVNCancelException in project intellij-community by JetBrains.

the class SvnCheckoutProvider method checkout.

public static void checkout(final Project project, final File target, final String url, final SVNRevision revision, final Depth depth, final boolean ignoreExternals, final Listener listener, final WorkingCopyFormat selectedFormat) {
    final Ref<Boolean> checkoutSuccessful = new Ref<>();
    final Exception[] exception = new Exception[1];
    final Task.Backgroundable checkoutBackgroundTask = new Task.Backgroundable(project, message("message.title.check.out"), true, VcsConfiguration.getInstance(project).getCheckoutOption()) {

        public void run(@NotNull final ProgressIndicator indicator) {
            final WorkingCopyFormat format = selectedFormat == null ? UNKNOWN : selectedFormat;
            SvnWorkingCopyFormatHolder.setPresetFormat(format);
            SvnVcs vcs = SvnVcs.getInstance(project);
            ProgressTracker handler = new CheckoutEventHandler(vcs, false, ProgressManager.getInstance().getProgressIndicator());
            ProgressManager.progress(message("progress.text.checking.out", target.getAbsolutePath()));
            try {
                getFactory(vcs, format).createCheckoutClient().checkout(SvnTarget.fromURL(SVNURL.parseURIEncoded(url)), target, revision, depth, ignoreExternals, true, format, handler);
                ProgressManager.checkCanceled();
                checkoutSuccessful.set(Boolean.TRUE);
            } catch (SVNCancelException ignore) {
            } catch (SVNException | VcsException e) {
                exception[0] = e;
            } finally {
                SvnWorkingCopyFormatHolder.setPresetFormat(null);
            }
        }

        public void onCancel() {
            onSuccess();
        }

        public void onSuccess() {
            if (exception[0] != null) {
                showErrorDialog(message("message.text.cannot.checkout", exception[0].getMessage()), message("message.title.check.out"));
            }
            VirtualFile vf = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(target);
            if (vf != null) {
                vf.refresh(true, true, () -> getApplication().invokeLater(() -> notifyListener()));
            } else {
                notifyListener();
            }
        }

        private void notifyListener() {
            notifyRootManagerIfUnderProject(project, target);
            if (listener != null) {
                if (!checkoutSuccessful.isNull()) {
                    listener.directoryCheckedOut(target, SvnVcs.getKey());
                }
                listener.checkoutCompleted();
            }
        }
    };
    ProgressManager.getInstance().run(checkoutBackgroundTask);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Task(com.intellij.openapi.progress.Task) WorkingCopyFormat(org.jetbrains.idea.svn.WorkingCopyFormat) ProgressTracker(org.jetbrains.idea.svn.api.ProgressTracker) SVNException(org.tmatesoft.svn.core.SVNException) NotNull(org.jetbrains.annotations.NotNull) VcsException(com.intellij.openapi.vcs.VcsException) SVNCancelException(org.tmatesoft.svn.core.SVNCancelException) SVNException(org.tmatesoft.svn.core.SVNException) SvnVcs(org.jetbrains.idea.svn.SvnVcs) Ref(com.intellij.openapi.util.Ref) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) SVNCancelException(org.tmatesoft.svn.core.SVNCancelException) VcsException(com.intellij.openapi.vcs.VcsException)

Aggregations

SVNCancelException (org.tmatesoft.svn.core.SVNCancelException)4 SVNException (org.tmatesoft.svn.core.SVNException)4 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Task (com.intellij.openapi.progress.Task)2 VcsException (com.intellij.openapi.vcs.VcsException)2 Ref (com.intellij.openapi.util.Ref)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 HttpConfigurable (com.intellij.util.net.HttpConfigurable)1 CommonProxy (com.intellij.util.proxy.CommonProxy)1 File (java.io.File)1 NotNull (org.jetbrains.annotations.NotNull)1 SvnVcs (org.jetbrains.idea.svn.SvnVcs)1 WorkingCopyFormat (org.jetbrains.idea.svn.WorkingCopyFormat)1 ProgressTracker (org.jetbrains.idea.svn.api.ProgressTracker)1 SvnBindException (org.jetbrains.idea.svn.commandLine.SvnBindException)1 Test (org.junit.Test)1 SVNAuthenticationException (org.tmatesoft.svn.core.SVNAuthenticationException)1 SVNAuthentication (org.tmatesoft.svn.core.auth.SVNAuthentication)1 DefaultSVNOptions (org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions)1 SVNWCContext (org.tmatesoft.svn.core.internal.wc17.SVNWCContext)1