diff options
Diffstat (limited to 'plugins/svn4idea/src/org/jetbrains/idea/svn/status/CmdStatusClient.java')
-rw-r--r-- | plugins/svn4idea/src/org/jetbrains/idea/svn/status/CmdStatusClient.java | 131 |
1 files changed, 46 insertions, 85 deletions
diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/status/CmdStatusClient.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/status/CmdStatusClient.java index 235f5d1ecddc..4030c83005ea 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/status/CmdStatusClient.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/status/CmdStatusClient.java @@ -18,18 +18,18 @@ package org.jetbrains.idea.svn.status; import com.intellij.openapi.util.Getter; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vfs.CharsetToolkit; import com.intellij.util.containers.Convertor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.idea.svn.SvnUtil; import org.jetbrains.idea.svn.api.BaseSvnClient; -import org.jetbrains.idea.svn.commandLine.CommandExecutor; -import org.jetbrains.idea.svn.commandLine.CommandUtil; -import org.jetbrains.idea.svn.commandLine.SvnCommandName; -import org.jetbrains.idea.svn.commandLine.SvnExceptionWrapper; -import org.tmatesoft.svn.core.*; +import org.jetbrains.idea.svn.api.Depth; +import org.jetbrains.idea.svn.commandLine.*; +import org.jetbrains.idea.svn.info.Info; +import org.tmatesoft.svn.core.SVNErrorCode; +import org.tmatesoft.svn.core.SVNException; +import org.tmatesoft.svn.core.SVNURL; import org.tmatesoft.svn.core.internal.util.SVNPathUtil; import org.tmatesoft.svn.core.wc.*; import org.tmatesoft.svn.core.wc2.SvnTarget; @@ -52,75 +52,38 @@ import java.util.*; public class CmdStatusClient extends BaseSvnClient implements StatusClient { @Override - public long doStatus(File path, boolean recursive, boolean remote, boolean reportAll, boolean includeIgnored, ISVNStatusHandler handler) - throws SVNException { - return doStatus(path, recursive, remote, reportAll, includeIgnored, false, handler); - } - - @Override - public long doStatus(File path, - boolean recursive, - boolean remote, - boolean reportAll, - boolean includeIgnored, - boolean collectParentExternals, - ISVNStatusHandler handler) throws SVNException { - return doStatus(path, SVNRevision.UNDEFINED, recursive, remote, reportAll, includeIgnored, collectParentExternals, handler); - } - - @Override - public long doStatus(File path, - SVNRevision revision, - boolean recursive, - boolean remote, - boolean reportAll, - boolean includeIgnored, - boolean collectParentExternals, - ISVNStatusHandler handler) throws SVNException { - return doStatus(path, revision, recursive ? SVNDepth.INFINITY : SVNDepth.EMPTY, remote, reportAll, includeIgnored, - collectParentExternals, handler, null); - } - - @Override public long doStatus(final File path, final SVNRevision revision, - final SVNDepth depth, + final Depth depth, boolean remote, boolean reportAll, boolean includeIgnored, boolean collectParentExternals, - final ISVNStatusHandler handler, - final Collection changeLists) throws SVNException { + final StatusConsumer handler, + final Collection changeLists) throws SvnBindException { File base = path.isDirectory() ? path : path.getParentFile(); base = CommandUtil.correctUpToExistingParent(base); - final SVNInfo infoBase = myFactory.createInfoClient().doInfo(base, revision); + final Info infoBase = myFactory.createInfoClient().doInfo(base, revision); List<String> parameters = new ArrayList<String>(); putParameters(parameters, path, depth, remote, reportAll, includeIgnored, changeLists); - CommandExecutor command; - try { - command = execute(myVcs, SvnTarget.fromFile(path), SvnCommandName.st, parameters, null); - } - catch (VcsException e) { - throw new SVNException(SVNErrorMessage.create(SVNErrorCode.IO_ERROR, e), e); - } + CommandExecutor command = execute(myVcs, SvnTarget.fromFile(path), SvnCommandName.st, parameters, null); parseResult(path, revision, handler, base, infoBase, command); return 0; } private void parseResult(final File path, SVNRevision revision, - ISVNStatusHandler handler, + StatusConsumer handler, File base, - SVNInfo infoBase, - CommandExecutor command) throws SVNException { + Info infoBase, + CommandExecutor command) throws SvnBindException { String result = command.getOutput(); if (StringUtil.isEmptyOrSpaces(result)) { - throw new SVNException(SVNErrorMessage.create(SVNErrorCode.FS_GENERAL, "Status request returned nothing for command: " + - command.getCommandText())); + throw new SvnBindException("Status request returned nothing for command: " + command.getCommandText()); } try { @@ -130,8 +93,7 @@ public class CmdStatusClient extends BaseSvnClient implements StatusClient { parser.parse(new ByteArrayInputStream(result.trim().getBytes(CharsetToolkit.UTF8_CHARSET)), svnHandl[0]); if (!svnHandl[0].isAnythingReported()) { if (!SvnUtil.isSvnVersioned(myVcs, path)) { - throw new SVNException( - SVNErrorMessage.create(SVNErrorCode.WC_NOT_DIRECTORY, "Command - " + command.getCommandText() + ". Result - " + result)); + throw new SvnBindException(SVNErrorCode.WC_NOT_DIRECTORY, "Command - " + command.getCommandText() + ". Result - " + result); } else { // return status indicating "NORMAL" state // typical output would be like @@ -142,38 +104,42 @@ public class CmdStatusClient extends BaseSvnClient implements StatusClient { PortableStatus status = new PortableStatus(); status.setPath(path.getAbsolutePath()); - status.setContentsStatus(SVNStatusType.STATUS_NORMAL); - status.setInfoGetter(new Getter<SVNInfo>() { + status.setContentsStatus(StatusType.STATUS_NORMAL); + status.setInfoGetter(new Getter<Info>() { @Override - public SVNInfo get() { + public Info get() { return createInfoGetter(null).convert(path); } }); - handler.handleStatus(status); + try { + handler.consume(status); + } + catch (SVNException e) { + throw new SvnBindException(e); + } } } } catch (SvnExceptionWrapper e) { - throw (SVNException) e.getCause(); + throw new SvnBindException(e.getCause()); } catch (IOException e) { - throw new SVNException(SVNErrorMessage.create(SVNErrorCode.IO_ERROR, e), e); + throw new SvnBindException(e); } catch (ParserConfigurationException e) { - throw new SVNException(SVNErrorMessage.create(SVNErrorCode.IO_ERROR, e), e); + throw new SvnBindException(e); } catch (SAXException e) { // status parsing errors are logged separately as sometimes there are parsing errors connected to terminal output handling. // these errors primarily occur when status output is rather large. // and status output could be large, for instance, when working copy is locked (seems that each file is listed in status output). command.logCommand(); - - throw new SVNException(SVNErrorMessage.create(SVNErrorCode.IO_ERROR, e), e); + throw new SvnBindException(e); } } private static void putParameters(@NotNull List<String> parameters, @NotNull File path, - @Nullable SVNDepth depth, + @Nullable Depth depth, boolean remote, boolean reportAll, boolean includeIgnored, @@ -189,33 +155,33 @@ public class CmdStatusClient extends BaseSvnClient implements StatusClient { } public SvnStatusHandler createStatusHandler(final SVNRevision revision, - final ISVNStatusHandler handler, + final StatusConsumer handler, final File base, - final SVNInfo infoBase, final SvnStatusHandler[] svnHandl) { + final Info infoBase, final SvnStatusHandler[] svnHandl) { final SvnStatusHandler.ExternalDataCallback callback = createStatusCallback(handler, base, infoBase, svnHandl); return new SvnStatusHandler(callback, base, createInfoGetter(revision)); } - private Convertor<File, SVNInfo> createInfoGetter(final SVNRevision revision) { - return new Convertor<File, SVNInfo>() { + private Convertor<File, Info> createInfoGetter(final SVNRevision revision) { + return new Convertor<File, Info>() { @Override - public SVNInfo convert(File o) { + public Info convert(File o) { try { return myFactory.createInfoClient().doInfo(o, revision); } - catch (SVNException e) { + catch (SvnBindException e) { throw new SvnExceptionWrapper(e); } } }; } - public static SvnStatusHandler.ExternalDataCallback createStatusCallback(final ISVNStatusHandler handler, + public static SvnStatusHandler.ExternalDataCallback createStatusCallback(final StatusConsumer handler, final File base, - final SVNInfo infoBase, + final Info infoBase, final SvnStatusHandler[] svnHandl) { - final Map<File, SVNInfo> externalsMap = new HashMap<File, SVNInfo>(); + final Map<File, Info> externalsMap = new HashMap<File, Info>(); final String[] changelistName = new String[1]; return new SvnStatusHandler.ExternalDataCallback() { @@ -225,7 +191,7 @@ public class CmdStatusClient extends BaseSvnClient implements StatusClient { pending.setChangelistName(changelistName[0]); try { //if (infoBase != null) { - SVNInfo baseInfo = infoBase; + Info baseInfo = infoBase; File baseFile = base; final File pendingFile = new File(pending.getPath()); if (! externalsMap.isEmpty()) { @@ -250,10 +216,10 @@ public class CmdStatusClient extends BaseSvnClient implements StatusClient { } pending.setURL(SVNURL.parseURIEncoded(append)); } - if (SVNStatusType.STATUS_EXTERNAL.equals(pending.getNodeStatus())) { + if (StatusType.STATUS_EXTERNAL.equals(pending.getNodeStatus())) { externalsMap.put(pending.getFile(), pending.getInfo()); } - handler.handleStatus(pending); + handler.consume(pending); } catch (SVNException e) { throw new SvnExceptionWrapper(e); @@ -268,16 +234,11 @@ public class CmdStatusClient extends BaseSvnClient implements StatusClient { } @Override - public SVNStatus doStatus(File path, boolean remote) throws SVNException { - return doStatus(path, remote, false); - } - - @Override - public SVNStatus doStatus(File path, boolean remote, boolean collectParentExternals) throws SVNException { - final SVNStatus[] svnStatus = new SVNStatus[1]; - doStatus(path, SVNRevision.UNDEFINED, SVNDepth.EMPTY, remote, false, false, collectParentExternals, new ISVNStatusHandler() { + public Status doStatus(File path, boolean remote) throws SvnBindException { + final Status[] svnStatus = new Status[1]; + doStatus(path, SVNRevision.UNDEFINED, Depth.EMPTY, remote, false, false, false, new StatusConsumer() { @Override - public void handleStatus(SVNStatus status) throws SVNException { + public void consume(Status status) throws SVNException { svnStatus[0] = status; } }, null); |