From 26ebe725e433c47b96121caccbc11ca92d176aa5 Mon Sep 17 00:00:00 2001 From: irengrig Date: Fri, 22 Jan 2010 00:02:25 +0300 Subject: [PATCH] IDEA-50684 (CVS: should not be possible to import to cvs if connection fails) --- .../actions/BrowseCvsRepositoryAction.java | 29 ++++++++++++++++++---- .../cvsoperations/common/LoginPerformer.java | 8 +++++- .../ui/experts/SelectCvsElementStep.java | 27 ++++++++++++++++++++ 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/BrowseCvsRepositoryAction.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/BrowseCvsRepositoryAction.java index 2cec9827f7..eec61112bc 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/BrowseCvsRepositoryAction.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/BrowseCvsRepositoryAction.java @@ -16,24 +16,26 @@ package com.intellij.cvsSupport2.actions; import com.intellij.CvsBundle; -import com.intellij.util.Consumer; import com.intellij.cvsSupport2.actions.cvsContext.CvsContext; import com.intellij.cvsSupport2.actions.cvsContext.CvsContextWrapper; import com.intellij.cvsSupport2.config.CvsRootConfiguration; import com.intellij.cvsSupport2.config.ui.SelectCvsConfigurationDialog; +import com.intellij.cvsSupport2.connections.CvsEnvironment; import com.intellij.cvsSupport2.cvsBrowser.ui.BrowserPanel; import com.intellij.cvsSupport2.cvsExecution.ModalityContext; +import com.intellij.cvsSupport2.cvsExecution.ModalityContextImpl; import com.intellij.cvsSupport2.cvshandlers.AbstractCvsHandler; import com.intellij.cvsSupport2.cvshandlers.CvsHandler; import com.intellij.cvsSupport2.cvshandlers.FileSetToBeUpdated; import com.intellij.cvsSupport2.cvsoperations.common.LoginPerformer; import com.intellij.cvsSupport2.ui.CvsTabbedWindow; -import com.intellij.cvsSupport2.connections.CvsEnvironment; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.Presentation; +import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.project.Project; -import com.intellij.openapi.vcs.actions.VcsContext; import com.intellij.openapi.vcs.VcsException; +import com.intellij.openapi.vcs.actions.VcsContext; +import com.intellij.util.Consumer; import java.util.Collections; @@ -75,6 +77,12 @@ public class BrowseCvsRepositoryAction extends AbstractAction{ CvsTabbedWindow tabbedWindow, boolean successfully, CvsHandler handler) { + if (! loginImpl(context.getProject(), new ModalityContextImpl(ModalityState.NON_MODAL, false), + new Consumer() { + public void consume(VcsException e) { + // + } + })) return; super.onActionPerformed(context, tabbedWindow, successfully, handler); if (successfully){ Project project = context.getProject(); @@ -105,14 +113,25 @@ public class BrowseCvsRepositoryAction extends AbstractAction{ } public boolean login(ModalityContext executor) throws Exception { - final LoginPerformer.MyProjectKnown performer = + return loginImpl(myProject, executor, new Consumer() { + public void consume(VcsException e) { + myErrors.add(e); + } + }); + /*final LoginPerformer.MyProjectKnown performer = new LoginPerformer.MyProjectKnown(myProject, Collections.singletonList(mySelectedConfiguration), new Consumer() { public void consume(VcsException e) { myErrors.add(e); } }); - return performer.loginAll(executor); + return performer.loginAll(executor, false);*/ } } + + public boolean loginImpl(final Project project, final ModalityContext executor, final Consumer exceptionConsumer) { + final LoginPerformer.MyProjectKnown performer = + new LoginPerformer.MyProjectKnown(project, Collections.singletonList(mySelectedConfiguration), exceptionConsumer); + return performer.loginAll(executor, false); + } } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/common/LoginPerformer.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/common/LoginPerformer.java index 451786643f..15d476a768 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/common/LoginPerformer.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/common/LoginPerformer.java @@ -51,6 +51,10 @@ public abstract class LoginPerformer { protected abstract Project getProject(T root); public boolean loginAll(final ModalityContext executor) { + return loginAll(executor, true); + } + + public boolean loginAll(final ModalityContext executor, final boolean goOffline) { for (T root : myRoots) { final Project project = getProject(root); @@ -59,7 +63,9 @@ public abstract class LoginPerformer { final ThreeState checkResult = checkLoginWorker(worker, executor, project, myForceCheck); if (! ThreeState.YES.equals(checkResult)) { if (ThreeState.UNSURE.equals(checkResult)) { - worker.goOffline(); + if (goOffline) { + worker.goOffline(); + } myExceptionConsumer.consume(new CvsException("Authentication canceled", root.getCvsRootAsString())); } return false; diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/SelectCvsElementStep.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/SelectCvsElementStep.java index 6aebdad0d0..b6fc9148af 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/SelectCvsElementStep.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/SelectCvsElementStep.java @@ -16,14 +16,22 @@ package com.intellij.cvsSupport2.ui.experts; import com.intellij.cvsSupport2.config.CvsRootConfiguration; +import com.intellij.cvsSupport2.connections.CvsEnvironment; import com.intellij.cvsSupport2.cvsBrowser.CvsElement; import com.intellij.cvsSupport2.cvsBrowser.CvsTree; import com.intellij.cvsSupport2.cvsBrowser.LoginAbortedException; +import com.intellij.cvsSupport2.cvsExecution.ModalityContextImpl; +import com.intellij.cvsSupport2.cvsoperations.common.LoginPerformer; +import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.Ref; +import com.intellij.openapi.vcs.VcsException; +import com.intellij.util.Consumer; import javax.swing.*; import java.awt.*; +import java.util.Collections; import java.util.Observable; import java.util.Observer; @@ -60,9 +68,28 @@ public class SelectCvsElementStep extends WizardStep { return myCvsTree.getCurrentSelection().length > 0; } + private boolean isLogged(final CvsRootConfiguration selectedConfiguration) { + final Ref errors = new Ref(); + final LoginPerformer.MyProjectKnown performer = new LoginPerformer.MyProjectKnown( + myProject, Collections.singletonList(selectedConfiguration), + new Consumer() { + public void consume(VcsException e) { + errors.set(Boolean.TRUE); + } + }); + final boolean logged = performer.loginAll( + new ModalityContextImpl(ModalityState.stateForComponent(mySelectCVSConfigurationStep.getComponent()), false), false); + if ((! logged) || (! errors.isNull())) { + return false; + } + return true; + } + public boolean setActive() { CvsRootConfiguration selectedConfiguration = mySelectCVSConfigurationStep.getSelectedConfiguration(); + if (! isLogged(selectedConfiguration)) return false; + if (myCvsTree == null || !Comparing.equal(myConfiguration, selectedConfiguration)) { myConfiguration = selectedConfiguration; if (myConfiguration == null) return false; -- 2.11.4.GIT