diff options
Diffstat (limited to 'plugins/svn4idea/src/org/jetbrains/idea/svn/info')
9 files changed, 435 insertions, 481 deletions
diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/info/CmdInfoClient.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/info/CmdInfoClient.java index 475dd1a4f77d..91eb7ce42e3e 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/info/CmdInfoClient.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/info/CmdInfoClient.java @@ -20,17 +20,16 @@ import com.intellij.execution.process.ProcessOutputTypes; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vfs.CharsetToolkit; import com.intellij.util.Consumer; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.idea.svn.api.BaseSvnClient; +import org.jetbrains.idea.svn.api.Depth; import org.jetbrains.idea.svn.commandLine.*; -import org.tmatesoft.svn.core.*; -import org.tmatesoft.svn.core.wc.ISVNInfoHandler; -import org.tmatesoft.svn.core.wc.SVNInfo; +import org.tmatesoft.svn.core.SVNException; +import org.tmatesoft.svn.core.SVNURL; import org.tmatesoft.svn.core.wc.SVNRevision; import org.tmatesoft.svn.core.wc2.SvnTarget; import org.xml.sax.SAXException; @@ -41,7 +40,6 @@ import javax.xml.parsers.SAXParserFactory; import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; -import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -55,48 +53,7 @@ public class CmdInfoClient extends BaseSvnClient implements InfoClient { private static final Logger LOG = Logger.getInstance(CmdInfoClient.class); - @Override - public void doInfo(File path, SVNRevision revision, boolean recursive, ISVNInfoHandler handler) throws SVNException { - doInfo(path, SVNRevision.UNDEFINED, revision, recursive ? SVNDepth.INFINITY : SVNDepth.EMPTY, null, handler); - } - - @Override - public void doInfo(File path, SVNRevision pegRevision, SVNRevision revision, boolean recursive, ISVNInfoHandler handler) - throws SVNException { - doInfo(path, pegRevision, revision, recursive ? SVNDepth.INFINITY : SVNDepth.EMPTY, null, handler); - } - - @Override - public void doInfo(File path, - SVNRevision pegRevision, - SVNRevision revision, - SVNDepth depth, - Collection changeLists, - final ISVNInfoHandler handler) throws SVNException { - File base = path.isDirectory() ? path : path.getParentFile(); - base = CommandUtil.correctUpToExistingParent(base); - if (base == null) { - // very unrealistic - throw new SVNException(SVNErrorMessage.create(SVNErrorCode.IO_ERROR, "Can not find existing parent file")); - } - issueCommand(path, pegRevision, revision, depth, changeLists, handler, base); - } - - private void issueCommand(File path, SVNRevision pegRevision, - SVNRevision revision, - SVNDepth depth, - Collection changeLists, - final ISVNInfoHandler handler, File base) throws SVNException { - List<String> parameters = new ArrayList<String>(); - - fillParameters(path.getAbsolutePath(), pegRevision, revision, depth, parameters); - // TODO: Fix this check - update corresponding parameters in InfoClient - CommandUtil.putChangeLists(parameters, changeLists); - - parseResult(handler, base, execute(parameters, path)); - } - - private String execute(@NotNull List<String> parameters, @NotNull File path) throws SVNException { + private String execute(@NotNull List<String> parameters, @NotNull File path) throws SvnBindException { // workaround: separately capture command output - used in exception handling logic to overcome svn 1.8 issue (see below) final ProcessOutput output = new ProcessOutput(); LineCommandListener listener = new LineCommandAdapter() { @@ -113,51 +70,46 @@ public class CmdInfoClient extends BaseSvnClient implements InfoClient { return command.getOutput(); } - catch (VcsException e) { - final String text = e.getMessage(); - final boolean notEmpty = !StringUtil.isEmptyOrSpaces(text); - if (notEmpty && text.contains("W155010")) { + catch (SvnBindException e) { + final String text = StringUtil.notNullize(e.getMessage()); + if (text.contains("W155010")) { // if "svn info" is executed for several files at once, then this warning could be printed only for some files, but info for other // files should be parsed from output return output.getStdout(); } // not a working copy exception // "E155007: '' is not a working copy" - if (notEmpty && text.contains("is not a working copy")) { - if (StringUtil.isNotEmpty(output.getStdout())) { - // TODO: Seems not reproducible in 1.8.4 - // workaround: as in subversion 1.8 "svn info" on a working copy root outputs such error for parent folder, - // if there are files with conflicts. - // but the requested info is still in the output except root closing tag - return output.getStdout() + "</info>"; - } else { - throw new SVNException(SVNErrorMessage.create(SVNErrorCode.WC_NOT_WORKING_COPY, e), e); - } - // svn: E200009: Could not display info for all targets because some targets don't exist - } else if (notEmpty && text.contains("some targets don't exist")) { - throw new SVNException(SVNErrorMessage.create(SVNErrorCode.ILLEGAL_TARGET, e), e); - } else if (notEmpty && text.contains(String.valueOf(SVNErrorCode.WC_UPGRADE_REQUIRED.getCode()))) { - throw new SVNException(SVNErrorMessage.create(SVNErrorCode.WC_UPGRADE_REQUIRED, e), e); - } else if (notEmpty && - (text.contains("upgrade your Subversion client") || - text.contains(String.valueOf(SVNErrorCode.WC_UNSUPPORTED_FORMAT.getCode())))) { - throw new SVNException(SVNErrorMessage.create(SVNErrorCode.WC_UNSUPPORTED_FORMAT, e), e); + if (text.contains("is not a working copy") && StringUtil.isNotEmpty(output.getStdout())) { + // TODO: Seems not reproducible in 1.8.4 + // workaround: as in subversion 1.8 "svn info" on a working copy root outputs such error for parent folder, + // if there are files with conflicts. + // but the requested info is still in the output except root closing tag + return output.getStdout() + "</info>"; } - throw new SVNException(SVNErrorMessage.create(SVNErrorCode.IO_ERROR, e), e); + throw e; } } - private static void parseResult(@NotNull final ISVNInfoHandler handler, @Nullable File base, @Nullable String result) throws SVNException { + @Nullable + private static Info parseResult(@Nullable File base, @Nullable String result) throws SvnBindException { + CollectInfoHandler handler = new CollectInfoHandler(); + + parseResult(handler, base, result); + + return handler.getInfo(); + } + + private static void parseResult(@NotNull final InfoConsumer handler, @Nullable File base, @Nullable String result) + throws SvnBindException { if (StringUtil.isEmptyOrSpaces(result)) { return; } - final SvnInfoHandler[] infoHandler = new SvnInfoHandler[1]; - infoHandler[0] = new SvnInfoHandler(base, new Consumer<SVNInfo>() { + final SvnInfoHandler infoHandler = new SvnInfoHandler(base, new Consumer<Info>() { @Override - public void consume(SVNInfo info) { + public void consume(Info info) { try { - handler.handleInfo(info); + handler.consume(info); } catch (SVNException e) { throw new SvnExceptionWrapper(e); @@ -165,87 +117,68 @@ public class CmdInfoClient extends BaseSvnClient implements InfoClient { } }); + parseResult(result, infoHandler); + } + + private static void parseResult(@NotNull String result, @NotNull SvnInfoHandler handler) throws SvnBindException { try { SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); - parser.parse(new ByteArrayInputStream(result.trim().getBytes(CharsetToolkit.UTF8_CHARSET)), infoHandler[0]); + parser.parse(new ByteArrayInputStream(result.trim().getBytes(CharsetToolkit.UTF8_CHARSET)), handler); } catch (SvnExceptionWrapper e) { LOG.info("info output " + result); - throw (SVNException) e.getCause(); + throw new SvnBindException(e.getCause()); } catch (IOException e) { LOG.info("info output " + result); - throw new SVNException(SVNErrorMessage.create(SVNErrorCode.IO_ERROR, e), e); + throw new SvnBindException(e); } catch (ParserConfigurationException e) { LOG.info("info output " + result); - throw new SVNException(SVNErrorMessage.create(SVNErrorCode.IO_ERROR, e), e); + throw new SvnBindException(e); } catch (SAXException e) { LOG.info("info output " + result); - throw new SVNException(SVNErrorMessage.create(SVNErrorCode.IO_ERROR, e), e); + throw new SvnBindException(e); } } - private static void fillParameters(String path, SVNRevision pegRevision, SVNRevision revision, SVNDepth depth, List<String> parameters) { + @NotNull + private static List<String> buildParameters(@NotNull String path, + @Nullable SVNRevision pegRevision, + @Nullable SVNRevision revision, + @Nullable Depth depth) { + List<String> parameters = ContainerUtil.newArrayList(); + CommandUtil.put(parameters, depth); CommandUtil.put(parameters, revision); CommandUtil.put(parameters, path, pegRevision); parameters.add("--xml"); - } - @Override - public void doInfo(SVNURL url, SVNRevision pegRevision, SVNRevision revision, boolean recursive, ISVNInfoHandler handler) - throws SVNException { - doInfo(url, pegRevision, revision, recursive ? SVNDepth.INFINITY : SVNDepth.EMPTY, handler); + return parameters; } @Override - public void doInfo(SVNURL url, SVNRevision pegRevision, SVNRevision revision, SVNDepth depth, ISVNInfoHandler handler) - throws SVNException { - String path = url.toDecodedString(); - List<String> parameters = new ArrayList<String>(); - - fillParameters(path, pegRevision, revision, depth, parameters); - CommandExecutor command; - try { - command = execute(myVcs, SvnTarget.fromURL(url), SvnCommandName.info, parameters, null); - } - catch (SvnBindException e) { - SVNErrorCode code = e.contains(SVNErrorCode.RA_ILLEGAL_URL) ? SVNErrorCode.RA_ILLEGAL_URL : SVNErrorCode.IO_ERROR; - - throw new SVNException(SVNErrorMessage.create(code, e), e); + public Info doInfo(File path, SVNRevision revision) throws SvnBindException { + File base = path.isDirectory() ? path : path.getParentFile(); + base = CommandUtil.correctUpToExistingParent(base); + if (base == null) { + // very unrealistic + throw new SvnBindException("Can not find existing parent file"); } - parseResult(handler, null, command.getOutput()); + return parseResult(base, execute(buildParameters(path.getAbsolutePath(), SVNRevision.UNDEFINED, revision, Depth.EMPTY), path)); } @Override - public SVNInfo doInfo(File path, SVNRevision revision) throws SVNException { - final SVNInfo[] infoArr = new SVNInfo[1]; - doInfo(path, SVNRevision.UNDEFINED, revision, SVNDepth.EMPTY, null, new ISVNInfoHandler() { - @Override - public void handleInfo(SVNInfo info) throws SVNException { - infoArr[0] = info; - } - }); - return infoArr[0]; - } + public Info doInfo(SVNURL url, SVNRevision pegRevision, SVNRevision revision) throws SvnBindException { + CommandExecutor command = execute(myVcs, SvnTarget.fromURL(url), SvnCommandName.info, buildParameters(url.toDecodedString(), pegRevision, revision, Depth.EMPTY), null); - @Override - public SVNInfo doInfo(SVNURL url, SVNRevision pegRevision, SVNRevision revision) throws SVNException { - final SVNInfo[] infoArr = new SVNInfo[1]; - doInfo(url, pegRevision, revision, SVNDepth.EMPTY, new ISVNInfoHandler() { - @Override - public void handleInfo(SVNInfo info) throws SVNException { - infoArr[0] = info; - } - }); - return infoArr[0]; + return parseResult(null, command.getOutput()); } @Override - public void doInfo(@NotNull Collection<File> paths, @Nullable ISVNInfoHandler handler) throws SVNException { + public void doInfo(@NotNull Collection<File> paths, @Nullable InfoConsumer handler) throws SvnBindException { File base = ContainerUtil.getFirstItem(paths); if (base != null) { @@ -265,4 +198,19 @@ public class CmdInfoClient extends BaseSvnClient implements InfoClient { } } } + + private static class CollectInfoHandler implements InfoConsumer { + + @Nullable private Info myInfo; + + @Override + public void consume(Info info) throws SVNException { + myInfo = info; + } + + @Nullable + public Info getInfo() { + return myInfo; + } + } } diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/info/IdeaSVNInfo.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/info/IdeaSVNInfo.java deleted file mode 100644 index 0e2905e73016..000000000000 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/info/IdeaSVNInfo.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jetbrains.idea.svn.info; - -import org.jetbrains.annotations.Nullable; -import org.tmatesoft.svn.core.SVNDepth; -import org.tmatesoft.svn.core.SVNLock; -import org.tmatesoft.svn.core.SVNNodeKind; -import org.tmatesoft.svn.core.SVNURL; -import org.tmatesoft.svn.core.wc.SVNInfo; -import org.tmatesoft.svn.core.wc.SVNRevision; -import org.tmatesoft.svn.core.wc.SVNTreeConflictDescription; - -import java.io.File; -import java.util.Date; - -/** - * Created by IntelliJ IDEA. - * User: Irina.Chernushina - * Date: 1/23/12 - * Time: 1:02 PM - */ -public class IdeaSVNInfo extends SVNInfo { - private final Date myCorrectCommittedDate; - private final Date myCorrectTextDate; - - public IdeaSVNInfo(@Nullable File file, - SVNURL url, - SVNURL rootURL, - long revision, - SVNNodeKind kind, - String uuid, - long committedRevision, - Date committedDate, - String author, - String schedule, - SVNURL copyFromURL, - long copyFromRevision, - Date textTime, - String propTime, - String checksum, - String conflictOld, - String conflictNew, - String conflictWorking, - String propRejectFile, - SVNLock lock, - SVNDepth depth, - String changelistName, - long wcSize, - SVNTreeConflictDescription treeConflict) { - super(file, url, rootURL, revision, kind, uuid, committedRevision, null, author, schedule, copyFromURL, copyFromRevision, - null, propTime, checksum, conflictOld, conflictNew, conflictWorking, propRejectFile, lock, depth, changelistName, wcSize, - treeConflict); - myCorrectCommittedDate = committedDate; - myCorrectTextDate = textTime; - } - - /** - * Gets the item's last commit date. This is the value of the item's - * {@link org.tmatesoft.svn.core.SVNProperty#COMMITTED_DATE} - * property. - * - * @return the item's last commit date - */ - @Override - public Date getCommittedDate() { - return myCorrectCommittedDate; - } - - /** - * Gets the value of the item's {@link org.tmatesoft.svn.core.SVNProperty#TEXT_TIME} - * property. It corresponds to the last commit time. - * - * @return the value of the item's text-time property - */ - @Override - public Date getTextTime() { - return myCorrectTextDate; - } - - public IdeaSVNInfo(String path, - SVNURL url, - SVNRevision revision, - SVNNodeKind kind, - String uuid, - SVNURL reposRootURL, - long comittedRevision, Date date, String author, SVNLock lock, SVNDepth depth, long size) { - super(path, url, revision, kind, uuid, reposRootURL, comittedRevision, date, author, lock, depth, size); - myCorrectCommittedDate = date; - myCorrectTextDate = null; - } -} diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/info/Info.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/info/Info.java new file mode 100644 index 000000000000..96dbdbbcbc99 --- /dev/null +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/info/Info.java @@ -0,0 +1,267 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.idea.svn.info; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.idea.svn.api.BaseNodeDescription; +import org.jetbrains.idea.svn.api.Depth; +import org.jetbrains.idea.svn.api.NodeKind; +import org.jetbrains.idea.svn.conflict.TreeConflictDescription; +import org.jetbrains.idea.svn.lock.Lock; +import org.tmatesoft.svn.core.SVNURL; +import org.tmatesoft.svn.core.internal.util.SVNDate; +import org.tmatesoft.svn.core.wc.SVNInfo; +import org.tmatesoft.svn.core.wc.SVNRevision; + +import java.io.File; +import java.util.Date; + +/** + * @author Konstantin Kolosovsky. + */ +public class Info extends BaseNodeDescription { + + private final File myFile; + private final String myPath; + private final SVNURL myURL; + private final SVNRevision myRevision; + private final SVNURL myRepositoryRootURL; + private final String myRepositoryUUID; + private final SVNRevision myCommittedRevision; + private final Date myCommittedDate; + private final String myAuthor; + @Nullable private final Lock myLock; + private final boolean myIsRemote; + private final String mySchedule; + private final SVNURL myCopyFromURL; + private final SVNRevision myCopyFromRevision; + private final File myConflictOldFile; + private final File myConflictNewFile; + private final File myConflictWrkFile; + private final File myPropConflictFile; + private final Depth myDepth; + @Nullable private final TreeConflictDescription myTreeConflict; + + @NotNull + public static Info create(@NotNull SVNInfo info) { + Info result; + + if (info.isRemote()) { + result = new Info(info.getPath(), info.getURL(), info.getRevision(), NodeKind.from(info.getKind()), info.getRepositoryUUID(), + info.getRepositoryRootURL(), info.getCommittedRevision().getNumber(), info.getCommittedDate(), info.getAuthor(), + Lock.create(info.getLock()), Depth.from(info.getDepth())); + } + else { + result = + new Info(info.getFile(), info.getURL(), info.getRepositoryRootURL(), info.getRevision().getNumber(), NodeKind.from(info.getKind()), + info.getRepositoryUUID(), info.getCommittedRevision().getNumber(), toString(info.getCommittedDate()), info.getAuthor(), + info.getSchedule(), info.getCopyFromURL(), info.getCopyFromRevision().getNumber(), getPath(info.getConflictOldFile()), + getPath(info.getConflictNewFile()), getPath(info.getConflictWrkFile()), getPath(info.getPropConflictFile()), + Lock.create(info.getLock()), Depth.from(info.getDepth()), TreeConflictDescription.create(info.getTreeConflict())); + } + + return result; + } + + public Info(File file, + SVNURL url, + SVNURL rootURL, + long revision, + @NotNull NodeKind kind, + String uuid, + long committedRevision, + String committedDate, + String author, + String schedule, + SVNURL copyFromURL, + long copyFromRevision, + String conflictOld, + String conflictNew, + String conflictWorking, + String propRejectFile, + @Nullable Lock lock, + Depth depth, + @Nullable TreeConflictDescription treeConflict) { + super(kind); + myFile = file; + myURL = url; + myRevision = SVNRevision.create(revision); + myRepositoryUUID = uuid; + myRepositoryRootURL = rootURL; + + myCommittedRevision = SVNRevision.create(committedRevision); + myCommittedDate = committedDate != null ? SVNDate.parseDate(committedDate) : null; + myAuthor = author; + + mySchedule = schedule; + + myCopyFromURL = copyFromURL; + myCopyFromRevision = SVNRevision.create(copyFromRevision); + + myLock = lock; + myTreeConflict = treeConflict; + + myConflictOldFile = resolveConflictFile(file, conflictOld); + myConflictNewFile = resolveConflictFile(file, conflictNew); + myConflictWrkFile = resolveConflictFile(file, conflictWorking); + myPropConflictFile = resolveConflictFile(file, propRejectFile); + + myIsRemote = false; + myDepth = depth; + + myPath = null; + } + + public Info(String path, + SVNURL url, + SVNRevision revision, + @NotNull NodeKind kind, + String uuid, + SVNURL reposRootURL, + long committedRevision, + Date date, + String author, + @Nullable Lock lock, + Depth depth) { + super(kind); + myIsRemote = true; + myURL = url; + myRevision = revision; + myRepositoryRootURL = reposRootURL; + myRepositoryUUID = uuid; + + myCommittedDate = date; + myCommittedRevision = SVNRevision.create(committedRevision); + myAuthor = author; + + myLock = lock; + myPath = path; + myDepth = depth; + + myFile = null; + mySchedule = null; + myCopyFromURL = null; + myCopyFromRevision = null; + myConflictOldFile = null; + myConflictNewFile = null; + myConflictWrkFile = null; + myPropConflictFile = null; + myTreeConflict = null; + } + + public String getAuthor() { + return myAuthor; + } + + public Date getCommittedDate() { + return myCommittedDate; + } + + public SVNRevision getCommittedRevision() { + return myCommittedRevision; + } + + public File getConflictNewFile() { + return myConflictNewFile; + } + + public File getConflictOldFile() { + return myConflictOldFile; + } + + public File getConflictWrkFile() { + return myConflictWrkFile; + } + + @Nullable + public TreeConflictDescription getTreeConflict() { + return myTreeConflict; + } + + public SVNRevision getCopyFromRevision() { + return myCopyFromRevision; + } + + public SVNURL getCopyFromURL() { + return myCopyFromURL; + } + + public File getFile() { + return myFile; + } + + public boolean isRemote() { + return myIsRemote; + } + + @NotNull + public NodeKind getKind() { + return myKind; + } + + @Nullable + public Lock getLock() { + return myLock; + } + + public String getPath() { + return myPath; + } + + public File getPropConflictFile() { + return myPropConflictFile; + } + + public SVNURL getRepositoryRootURL() { + return myRepositoryRootURL; + } + + public String getRepositoryUUID() { + return myRepositoryUUID; + } + + public SVNRevision getRevision() { + return myRevision; + } + + public String getSchedule() { + return mySchedule; + } + + public SVNURL getURL() { + return myURL; + } + + public Depth getDepth() { + return myDepth; + } + + @Nullable + private static File resolveConflictFile(@Nullable File file, @Nullable String path) { + return file != null && path != null ? new File(file.getParentFile(), path) : null; + } + + @Nullable + private static String getPath(@Nullable File file) { + return file != null ? file.getPath() : null; + } + + @Nullable + private static String toString(@Nullable Date date) { + return date != null ? date.toString() : null; + } +} diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/info/InfoClient.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/info/InfoClient.java index f6582e603eda..56f87a040b17 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/info/InfoClient.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/info/InfoClient.java @@ -18,11 +18,8 @@ package org.jetbrains.idea.svn.info; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.idea.svn.api.SvnClient; -import org.tmatesoft.svn.core.SVNDepth; -import org.tmatesoft.svn.core.SVNException; +import org.jetbrains.idea.svn.commandLine.SvnBindException; import org.tmatesoft.svn.core.SVNURL; -import org.tmatesoft.svn.core.wc.ISVNInfoHandler; -import org.tmatesoft.svn.core.wc.SVNInfo; import org.tmatesoft.svn.core.wc.SVNRevision; import java.io.File; @@ -36,15 +33,9 @@ import java.util.Collection; */ public interface InfoClient extends SvnClient { - void doInfo(File path, SVNRevision revision, boolean recursive, ISVNInfoHandler handler) throws SVNException; - void doInfo(File path, SVNRevision pegRevision, SVNRevision revision, boolean recursive, ISVNInfoHandler handler) throws SVNException; - void doInfo(File path, SVNRevision pegRevision, SVNRevision revision, SVNDepth depth, - Collection changeLists, ISVNInfoHandler handler) throws SVNException; - void doInfo(SVNURL url, SVNRevision pegRevision, SVNRevision revision, boolean recursive, ISVNInfoHandler handler) throws SVNException; - void doInfo(SVNURL url, SVNRevision pegRevision, SVNRevision revision, SVNDepth depth, - ISVNInfoHandler handler) throws SVNException; - SVNInfo doInfo(File path, SVNRevision revision) throws SVNException; - SVNInfo doInfo(SVNURL url, SVNRevision pegRevision, SVNRevision revision) throws SVNException; + Info doInfo(File path, SVNRevision revision) throws SvnBindException; - void doInfo(@NotNull Collection<File> paths, @Nullable ISVNInfoHandler handler) throws SVNException; + Info doInfo(SVNURL url, SVNRevision pegRevision, SVNRevision revision) throws SvnBindException; + + void doInfo(@NotNull Collection<File> paths, @Nullable InfoConsumer handler) throws SvnBindException; } diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/info/InfoConsumer.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/info/InfoConsumer.java new file mode 100644 index 000000000000..317b2b6a5156 --- /dev/null +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/info/InfoConsumer.java @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.idea.svn.info; + +import com.intellij.util.ThrowableConsumer; +import org.jetbrains.idea.svn.info.Info; +import org.tmatesoft.svn.core.SVNException; + +/** + * @author Konstantin Kolosovsky. + */ +public interface InfoConsumer extends ThrowableConsumer<Info, SVNException> { +} diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/info/SVNLockWrapper.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/info/SVNLockWrapper.java deleted file mode 100644 index f5752074da77..000000000000 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/info/SVNLockWrapper.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jetbrains.idea.svn.info; - -import org.tmatesoft.svn.core.SVNLock; - -import java.util.Date; - -/** - * Created with IntelliJ IDEA. - * User: Irina.Chernushina - * Date: 2/21/12 - * Time: 2:33 PM - */ -public class SVNLockWrapper { - private String myPath; - private String myID; - private String myOwner; - private String myComment; - private Date myCreationDate; - private Date myExpirationDate; - - public SVNLockWrapper(String path, String ID, String owner, String comment, Date creationDate, Date expirationDate) { - myPath = path; - myID = ID; - myOwner = owner; - myComment = comment; - myCreationDate = creationDate; - myExpirationDate = expirationDate; - } - - public SVNLockWrapper() { - } - - public SVNLock create() { - return new SVNLock(myPath, myID, myOwner, myComment, myCreationDate, myExpirationDate); - } - - public String getPath() { - return myPath; - } - - public void setPath(String path) { - myPath = path; - } - - public String getID() { - return myID; - } - - public void setID(String ID) { - myID = ID; - } - - public String getOwner() { - return myOwner; - } - - public void setOwner(String owner) { - myOwner = owner; - } - - public String getComment() { - return myComment; - } - - public void setComment(String comment) { - myComment = comment; - } - - public Date getCreationDate() { - return myCreationDate; - } - - public void setCreationDate(Date creationDate) { - myCreationDate = creationDate; - } - - public Date getExpirationDate() { - return myExpirationDate; - } - - public void setExpirationDate(Date expirationDate) { - myExpirationDate = expirationDate; - } -} diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/info/SvnInfoHandler.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/info/SvnInfoHandler.java index e2e5fa910e38..969225eb69e3 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/info/SvnInfoHandler.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/info/SvnInfoHandler.java @@ -21,12 +21,11 @@ import com.intellij.util.Consumer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.idea.svn.SvnUtil; -import org.tmatesoft.svn.core.SVNDepth; +import org.jetbrains.idea.svn.api.NodeKind; +import org.jetbrains.idea.svn.lock.Lock; import org.tmatesoft.svn.core.SVNException; -import org.tmatesoft.svn.core.SVNNodeKind; import org.tmatesoft.svn.core.SVNURL; import org.tmatesoft.svn.core.internal.util.SVNDate; -import org.tmatesoft.svn.core.wc.SVNInfo; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; @@ -42,14 +41,14 @@ import java.util.*; */ public class SvnInfoHandler extends DefaultHandler { @Nullable private final File myBase; - private final Consumer<SVNInfo> myInfoConsumer; - private Map<File, SVNInfo> myResultsMap; + private final Consumer<org.jetbrains.idea.svn.info.Info> myInfoConsumer; + private Map<File, org.jetbrains.idea.svn.info.Info> myResultsMap; private SvnInfoStructure myPending; private final Map<String, Getter<ElementHandlerBase>> myElementsMap; private final List<ElementHandlerBase> myParseStack; private final StringBuilder mySb; - public SvnInfoHandler(@Nullable File base, final Consumer<SVNInfo> infoConsumer) { + public SvnInfoHandler(@Nullable File base, final Consumer<org.jetbrains.idea.svn.info.Info> infoConsumer) { myBase = base; myInfoConsumer = infoConsumer; myPending = createPending(); @@ -57,12 +56,12 @@ public class SvnInfoHandler extends DefaultHandler { fillElements(); myParseStack = new ArrayList<ElementHandlerBase>(); myParseStack.add(new Fake()); - myResultsMap = new HashMap<File, SVNInfo>(); + myResultsMap = new HashMap<File, org.jetbrains.idea.svn.info.Info>(); mySb = new StringBuilder(); } private void switchPending() throws SAXException { - final SVNInfo info; + final org.jetbrains.idea.svn.info.Info info; try { info = myPending.convert(); } @@ -78,7 +77,7 @@ public class SvnInfoHandler extends DefaultHandler { private SvnInfoStructure createPending() { SvnInfoStructure pending = new SvnInfoStructure(); - pending.myDepth = SVNDepth.INFINITY; + pending.myDepth = org.jetbrains.idea.svn.api.Depth.INFINITY; return pending; } @@ -280,7 +279,7 @@ public class SvnInfoHandler extends DefaultHandler { myElementsMap.put("lock", new Getter<ElementHandlerBase>() { @Override public ElementHandlerBase get() { - return new Lock(); + return new LockElement(); } }); myElementsMap.put("token", new Getter<ElementHandlerBase>() { @@ -345,7 +344,7 @@ public class SvnInfoHandler extends DefaultHandler { }); } - public Map<File, SVNInfo> getResultsMap() { + public Map<File, org.jetbrains.idea.svn.info.Info> getResultsMap() { return myResultsMap; } @@ -514,8 +513,7 @@ public class SvnInfoHandler extends DefaultHandler { @Override public void characters(String s, SvnInfoStructure structure) throws SAXException { - final SVNDate date = SVNDate.parseDate(s); - structure.myCommittedDate = date; + structure.myCommittedDate = s; } } @@ -600,8 +598,7 @@ public class SvnInfoHandler extends DefaultHandler { @Override public void characters(String s, SvnInfoStructure structure) throws SAXException { - final SVNDate date = SVNDate.parseDate(s); - structure.myTextTime = date; + structure.myTextTime = s; } } @@ -616,7 +613,7 @@ public class SvnInfoHandler extends DefaultHandler { @Override public void characters(String s, SvnInfoStructure structure) throws SAXException { - structure.myDepth = SVNDepth.fromString(s); + structure.myDepth = org.jetbrains.idea.svn.api.Depth.from(s); } } @@ -796,14 +793,14 @@ public class SvnInfoHandler extends DefaultHandler { } } - private static class Lock extends ElementHandlerBase { - private Lock() { + private static class LockElement extends ElementHandlerBase { + private LockElement() { super(new String[]{"token", "owner", "comment", "created"}, new String[]{}); } @Override protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException { - structure.myLockWrapper = new SVNLockWrapper(); + structure.myLockBuilder = new Lock.Builder(); } @Override @@ -822,7 +819,7 @@ public class SvnInfoHandler extends DefaultHandler { @Override public void characters(String s, SvnInfoStructure structure) throws SAXException { - structure.myLockWrapper.setID(s); + structure.myLockBuilder.setToken(s); } } @@ -837,7 +834,7 @@ public class SvnInfoHandler extends DefaultHandler { @Override public void characters(String s, SvnInfoStructure structure) throws SAXException { - structure.myLockWrapper.setOwner(s); + structure.myLockBuilder.setOwner(s); } } @@ -852,7 +849,7 @@ public class SvnInfoHandler extends DefaultHandler { @Override public void characters(String s, SvnInfoStructure structure) throws SAXException { - structure.myLockWrapper.setComment(s); + structure.myLockBuilder.setComment(s); } } @@ -867,7 +864,7 @@ public class SvnInfoHandler extends DefaultHandler { @Override public void characters(String s, SvnInfoStructure structure) throws SAXException { - structure.myLockWrapper.setCreationDate(SVNDate.parseDate(s)); + structure.myLockBuilder.setCreationDate(SVNDate.parseDate(s)); } } @@ -883,7 +880,7 @@ public class SvnInfoHandler extends DefaultHandler { protected void updateInfo(Attributes attributes, SvnInfoStructure structure) throws SAXException { final String kind = attributes.getValue("kind"); assertSAX(! StringUtil.isEmptyOrSpaces(kind)); - structure.myKind = SVNNodeKind.parseKind(kind); + structure.myKind = NodeKind.from(kind); if (myBase != null) { final String path = attributes.getValue("path"); diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/info/SvnInfoStructure.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/info/SvnInfoStructure.java index 6e1b1db1efa2..42929885f364 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/info/SvnInfoStructure.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/info/SvnInfoStructure.java @@ -15,17 +15,18 @@ */ package org.jetbrains.idea.svn.info; -import com.intellij.util.containers.ContainerUtil; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.idea.svn.api.Depth; +import org.jetbrains.idea.svn.api.NodeKind; +import org.jetbrains.idea.svn.conflict.ConflictAction; +import org.jetbrains.idea.svn.conflict.ConflictOperation; +import org.jetbrains.idea.svn.conflict.ConflictReason; +import org.jetbrains.idea.svn.lock.Lock; import org.tmatesoft.svn.core.*; -import org.tmatesoft.svn.core.internal.wc.SVNConflictVersion; -import org.tmatesoft.svn.core.wc.*; import org.xml.sax.SAXException; import java.io.File; import java.util.Date; -import java.util.Map; /** * Created with IntelliJ IDEA. @@ -35,46 +36,28 @@ import java.util.Map; */ public class SvnInfoStructure { - private static final Map<String, SVNConflictAction> ourConflictActions = ContainerUtil.newHashMap(); - private static final Map<String, SVNConflictReason> ourConflictReasons = ContainerUtil.newHashMap(); - - static { - ourConflictActions.put("add", SVNConflictAction.ADD); - ourConflictActions.put("edit", SVNConflictAction.EDIT); - ourConflictActions.put("delete", SVNConflictAction.DELETE); - ourConflictActions.put("replace", SVNConflictAction.REPLACE); - - ourConflictReasons.put("edit", SVNConflictReason.EDITED); - ourConflictReasons.put("obstruct", SVNConflictReason.OBSTRUCTED); - ourConflictReasons.put("delete", SVNConflictReason.DELETED); - ourConflictReasons.put("miss", SVNConflictReason.MISSING); - ourConflictReasons.put("unversion", SVNConflictReason.UNVERSIONED); - ourConflictReasons.put("add", SVNConflictReason.ADDED); - ourConflictReasons.put("replace", SVNConflictReason.REPLACED); - } - @Nullable public File myFile; public String relativeUrl; public SVNURL myUrl; public SVNURL myRootURL; public long myRevision; - public SVNNodeKind myKind; + public NodeKind myKind; public String myUuid; public long myCommittedRevision; - public Date myCommittedDate; + public String myCommittedDate; public String myAuthor; public String mySchedule; public SVNURL myCopyFromURL; public long myCopyFromRevision; - public Date myTextTime; + public String myTextTime; public String myPropTime; public String myChecksum; public String myConflictOld; public String myConflictNew; public String myConflictWorking; public String myPropRejectFile; - public SVNLockWrapper myLockWrapper; - public SVNDepth myDepth; + public Lock.Builder myLockBuilder; + public Depth myDepth; public String myChangelistName; public long myWcSize; public Date myCorrectCommittedDate; @@ -82,65 +65,37 @@ public class SvnInfoStructure { public TreeConflictDescription myTreeConflict; - public SVNInfo convert() throws SAXException, SVNException { - return new IdeaSVNInfo(myFile, myUrl, myRootURL, myRevision, myKind, myUuid, myCommittedRevision, myCommittedDate, myAuthor, mySchedule, - myCopyFromURL, myCopyFromRevision, myTextTime, myPropTime, myChecksum, myConflictOld, myConflictNew, myConflictWorking, - myPropRejectFile, getLock(), myDepth, myChangelistName, myWcSize, createTreeConflict()); + public Info convert() throws SAXException, SVNException { + return new Info(myFile, myUrl, myRootURL, myRevision, myKind, myUuid, myCommittedRevision, myCommittedDate, myAuthor, mySchedule, + myCopyFromURL, myCopyFromRevision, myConflictOld, myConflictNew, myConflictWorking, + myPropRejectFile, getLock(), myDepth, createTreeConflict()); } - private SVNLock getLock() { - SVNLock lock = null; - - if (myLockWrapper != null) { - myLockWrapper.setPath(relativeUrl); - lock = myLockWrapper.create(); - } - - return lock; + @Nullable + private Lock getLock() { + return myLockBuilder != null ? myLockBuilder.build() : null; } - private SVNTreeConflictDescription createTreeConflict() throws SAXException, SVNException { + private org.jetbrains.idea.svn.conflict.TreeConflictDescription createTreeConflict() throws SAXException, SVNException { if (myTreeConflict == null) { return null; } else { assert myFile != null; - final SVNConflictAction action = parseConflictAction(myTreeConflict.myAction); - final SVNConflictReason reason = parseConflictReason(myTreeConflict.myReason); - SVNOperation operation = SVNOperation.fromString(myTreeConflict.myOperation); - operation = operation == null ? SVNOperation.NONE : operation; - return new SVNTreeConflictDescription(myFile, myKind, action, reason, operation, - createVersion(myTreeConflict.mySourceLeft), - createVersion(myTreeConflict.mySourceRight)); + return new org.jetbrains.idea.svn.conflict.TreeConflictDescription(myFile, myKind, ConflictAction.from(myTreeConflict.myAction), + ConflictReason.from(myTreeConflict.myReason), + ConflictOperation.from(myTreeConflict.myOperation), + createVersion(myTreeConflict.mySourceLeft), + createVersion(myTreeConflict.mySourceRight)); } } - private SVNConflictAction parseConflictAction(@NotNull String actionName) { - SVNConflictAction action = SVNConflictAction.fromString(actionName); - action = action != null ? action : ourConflictActions.get(actionName); - - if (action == null) { - throw new IllegalArgumentException("Unknown conflict action " + actionName); - } - - return action; - } - - private SVNConflictReason parseConflictReason(@NotNull String reasonName) throws SAXException { - SVNConflictReason reason = SVNConflictReason.fromString(reasonName); - reason = reason != null ? reason : ourConflictReasons.get(reasonName); - - if (reason == null) { - throw new SAXException("Can not parse conflict reason: " + reasonName); - } - - return reason; - } - - private SVNConflictVersion createVersion(final ConflictVersion version) throws SVNException, SAXException { - return version == null ? null : new SVNConflictVersion(SVNURL.parseURIEncoded(version.myRepoUrl), version.myPathInRepo, - parseRevision(version.myRevision), SVNNodeKind.parseKind(version.myKind)); + private org.jetbrains.idea.svn.conflict.ConflictVersion createVersion(final ConflictVersion version) throws SVNException, SAXException { + return version == null + ? null + : new org.jetbrains.idea.svn.conflict.ConflictVersion(SVNURL.parseURIEncoded(version.myRepoUrl), version.myPathInRepo, + parseRevision(version.myRevision), NodeKind.from(version.myKind)); } private long parseRevision(final String revision) throws SAXException { diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/info/SvnKitInfoClient.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/info/SvnKitInfoClient.java index 7f50e85cd2d7..3db2c647791a 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/info/SvnKitInfoClient.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/info/SvnKitInfoClient.java @@ -18,12 +18,9 @@ package org.jetbrains.idea.svn.info; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.idea.svn.api.BaseSvnClient; -import org.jetbrains.idea.svn.info.InfoClient; -import org.tmatesoft.svn.core.SVNDepth; +import org.jetbrains.idea.svn.commandLine.SvnBindException; import org.tmatesoft.svn.core.SVNException; import org.tmatesoft.svn.core.SVNURL; -import org.tmatesoft.svn.core.wc.ISVNInfoHandler; -import org.tmatesoft.svn.core.wc.SVNInfo; import org.tmatesoft.svn.core.wc.SVNRevision; import org.tmatesoft.svn.core.wc.SVNWCClient; @@ -43,50 +40,27 @@ public class SvnKitInfoClient extends BaseSvnClient implements InfoClient { } @Override - public void doInfo(File path, SVNRevision revision, boolean recursive, ISVNInfoHandler handler) throws SVNException { - getClient().doInfo(path, revision, recursive, handler); + public Info doInfo(File path, SVNRevision revision) throws SvnBindException { + try { + return Info.create(getClient().doInfo(path, revision)); + } + catch (SVNException e) { + throw new SvnBindException(e); + } } @Override - public void doInfo(File path, SVNRevision pegRevision, SVNRevision revision, boolean recursive, ISVNInfoHandler handler) - throws SVNException { - getClient().doInfo(path, pegRevision, revision, recursive, handler); + public Info doInfo(SVNURL url, SVNRevision pegRevision, SVNRevision revision) throws SvnBindException { + try { + return Info.create(getClient().doInfo(url, pegRevision, revision)); + } + catch (SVNException e) { + throw new SvnBindException(e); + } } @Override - public void doInfo(File path, - SVNRevision pegRevision, - SVNRevision revision, - SVNDepth depth, - Collection changeLists, - ISVNInfoHandler handler) throws SVNException { - getClient().doInfo(path, pegRevision, revision, depth, changeLists, handler); - } - - @Override - public void doInfo(SVNURL url, SVNRevision pegRevision, SVNRevision revision, boolean recursive, ISVNInfoHandler handler) - throws SVNException { - getClient().doInfo(url, pegRevision, revision, recursive, handler); - } - - @Override - public void doInfo(SVNURL url, SVNRevision pegRevision, SVNRevision revision, SVNDepth depth, ISVNInfoHandler handler) - throws SVNException { - getClient().doInfo(url, pegRevision, revision, depth, handler); - } - - @Override - public SVNInfo doInfo(File path, SVNRevision revision) throws SVNException { - return getClient().doInfo(path, revision); - } - - @Override - public SVNInfo doInfo(SVNURL url, SVNRevision pegRevision, SVNRevision revision) throws SVNException { - return getClient().doInfo(url, pegRevision, revision); - } - - @Override - public void doInfo(@NotNull Collection<File> paths, @Nullable ISVNInfoHandler handler) throws SVNException { + public void doInfo(@NotNull Collection<File> paths, @Nullable InfoConsumer handler) throws SvnBindException { throw new UnsupportedOperationException(); } } |