diff options
Diffstat (limited to 'plugins/svn4idea/src/org/jetbrains/idea/svn/api')
11 files changed, 520 insertions, 23 deletions
diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/api/BaseNodeDescription.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/api/BaseNodeDescription.java new file mode 100644 index 000000000000..03e2e07a339c --- /dev/null +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/api/BaseNodeDescription.java @@ -0,0 +1,42 @@ +/* + * 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.api; + +import org.jetbrains.annotations.NotNull; + +/** + * @author Konstantin Kolosovsky. + */ +public abstract class BaseNodeDescription { + + @NotNull protected final NodeKind myKind; + + protected BaseNodeDescription(@NotNull NodeKind kind) { + myKind = kind; + } + + public boolean isFile() { + return myKind.isFile(); + } + + public boolean isDirectory() { + return myKind.isDirectory(); + } + + public boolean isNone() { + return myKind.isNone(); + } +} diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/api/BaseSvnClient.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/api/BaseSvnClient.java index bb8c613c8135..0d58355543ba 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/api/BaseSvnClient.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/api/BaseSvnClient.java @@ -8,10 +8,11 @@ import org.jetbrains.idea.svn.SvnVcs; import org.jetbrains.idea.svn.WorkingCopyFormat; import org.jetbrains.idea.svn.auth.IdeaSvnkitBasedAuthenticationCallback; import org.jetbrains.idea.svn.commandLine.*; +import org.jetbrains.idea.svn.diff.DiffOptions; +import org.tmatesoft.svn.core.SVNCancelException; +import org.tmatesoft.svn.core.SVNDepth; import org.tmatesoft.svn.core.SVNException; -import org.tmatesoft.svn.core.wc.ISVNEventHandler; -import org.tmatesoft.svn.core.wc.SVNEvent; -import org.tmatesoft.svn.core.wc.SVNEventAction; +import org.tmatesoft.svn.core.wc.*; import org.tmatesoft.svn.core.wc2.SvnTarget; import java.io.File; @@ -109,10 +110,10 @@ public abstract class BaseSvnClient implements SvnClient { return runtime.runWithAuthenticationAttempt(command); } - protected static void callHandler(@Nullable ISVNEventHandler handler, @NotNull SVNEvent event) throws VcsException { + protected static void callHandler(@Nullable ProgressTracker handler, @NotNull ProgressEvent event) throws VcsException { if (handler != null) { try { - handler.handleEvent(event, 0); + handler.consume(event); } catch (SVNException e) { throw new SvnBindException(e); @@ -121,7 +122,44 @@ public abstract class BaseSvnClient implements SvnClient { } @NotNull - protected static SVNEvent createEvent(@NotNull File path, @Nullable SVNEventAction action) { - return new SVNEvent(path, null, null, 0, null, null, null, null, action, null, null, null, null, null, null); + protected static ProgressEvent createEvent(@NotNull File path, @Nullable EventAction action) { + return new ProgressEvent(path, 0, null, null, action, null, null); + } + + @Nullable + protected static ISVNEventHandler toEventHandler(@Nullable final ProgressTracker handler) { + ISVNEventHandler result = null; + + if (handler != null) { + result = new ISVNEventHandler() { + @Override + public void handleEvent(SVNEvent event, double progress) throws SVNException { + handler.consume(ProgressEvent.create(event)); + } + + @Override + public void checkCancelled() throws SVNCancelException { + handler.checkCancelled(); + } + }; + } + + return result; + } + + @Nullable + protected static SVNDiffOptions toDiffOptions(@Nullable DiffOptions options) { + return options != null ? new SVNDiffOptions(options.isIgnoreAllWhitespace(), options.isIgnoreAmountOfWhitespace(), + options.isIgnoreEOLStyle()) : null; + } + + @Nullable + protected static SVNDepth toDepth(@Nullable Depth depth) { + return depth != null ? SVNDepth.fromString(depth.getName()) : null; + } + + @NotNull + protected static SVNRevision notNullize(@Nullable SVNRevision revision) { + return revision != null ? revision : SVNRevision.UNDEFINED; } } diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/api/ClientFactory.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/api/ClientFactory.java index 99e00a373d7d..ba3e56de8e63 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/api/ClientFactory.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/api/ClientFactory.java @@ -27,7 +27,6 @@ import org.jetbrains.idea.svn.revert.RevertClient; import org.jetbrains.idea.svn.update.RelocateClient; import org.jetbrains.idea.svn.update.UpdateClient; import org.jetbrains.idea.svn.upgrade.UpgradeClient; -import org.tmatesoft.svn.core.wc.ISVNEventHandler; import org.tmatesoft.svn.core.wc.ISVNStatusFileProvider; /** @@ -102,7 +101,7 @@ public abstract class ClientFactory { } @NotNull - public StatusClient createStatusClient(@Nullable ISVNStatusFileProvider provider, @NotNull ISVNEventHandler handler) { + public StatusClient createStatusClient(@Nullable ISVNStatusFileProvider provider, @NotNull ProgressTracker handler) { return createStatusClient(); } diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/api/Depth.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/api/Depth.java new file mode 100644 index 000000000000..9ccc96e81f67 --- /dev/null +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/api/Depth.java @@ -0,0 +1,93 @@ +/* + * 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.api; + +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.tmatesoft.svn.core.SVNDepth; + +import java.util.Map; + +/** + * @author Konstantin Kolosovsky. + */ +public enum Depth { + + UNKNOWN("unknown"), + INFINITY("infinity"), + IMMEDIATES("immediates"), + FILES("files"), + EMPTY("empty"); + + @NotNull private static final Map<String, Depth> ourAllDepths = ContainerUtil.newHashMap(); + + static { + for (Depth action : Depth.values()) { + register(action); + } + } + + @NotNull private final String myName; + + Depth(@NotNull String name) { + myName = name; + } + + @NotNull + public String getName() { + return myName; + } + + @Override + public String toString() { + return myName; + } + + private static void register(@NotNull Depth depth) { + ourAllDepths.put(depth.myName, depth); + } + + @NotNull + public static Depth from(@NotNull String depthName) { + Depth result = ourAllDepths.get(depthName); + + if (result == null) { + throw new IllegalArgumentException("Unknown depth " + depthName); + } + + return result; + } + + @NotNull + public static Depth from(@Nullable SVNDepth depth) { + return depth != null ? from(depth.getName()) : UNKNOWN; + } + + @NotNull + public static Depth allOrFiles(boolean recursive) { + return recursive ? INFINITY : FILES; + } + + @NotNull + public static Depth allOrEmpty(boolean recursive) { + return recursive ? INFINITY : EMPTY; + } + + public static boolean isRecursive(@Nullable Depth depth) { + return depth == null || depth == INFINITY || depth == UNKNOWN; + } +} diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/api/EventAction.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/api/EventAction.java new file mode 100644 index 000000000000..3a1d3fc80ef1 --- /dev/null +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/api/EventAction.java @@ -0,0 +1,91 @@ +/* + * 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.api; + +import com.intellij.util.ObjectUtils; +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NotNull; +import org.tmatesoft.svn.core.wc.SVNEventAction; + +import java.util.Map; + +/** + * @author Konstantin Kolosovsky. + */ +public enum EventAction { + + // currently used to represent some not used event action from SVNKit + UNKNOWN("unknown"), + + ADD("add"), + DELETE("delete"), + RESTORE("restore"), + REVERT("revert"), + FAILED_REVERT("failed_revert"), + SKIP("skip"), + + UPDATE_DELETE("update_delete"), + UPDATE_ADD("update_add"), + UPDATE_UPDATE("update_update"), + UPDATE_NONE("update_none"), + UPDATE_COMPLETED("update_completed"), + UPDATE_EXTERNAL("update_external"), + UPDATE_SKIP_OBSTRUCTION("update_skip_obstruction"), + UPDATE_STARTED("update_started"), + + COMMIT_MODIFIED("commit_modified"), + COMMIT_ADDED("commit_added"), + COMMIT_DELETED("commit_deleted"), + COMMIT_REPLACED("commit_replaced"), + COMMIT_DELTA_SENT("commit_delta_sent"), + FAILED_OUT_OF_DATE("failed_out_of_date"), + + LOCKED("locked"), + UNLOCKED("unlocked"), + LOCK_FAILED("lock_failed"), + UNLOCK_FAILED("unlock_failed"), + + UPGRADED_PATH("upgraded_path"), + + TREE_CONFLICT("tree_conflict"); + + @NotNull private static final Map<String, EventAction> ourAllActions = ContainerUtil.newHashMap(); + + static { + for (EventAction action : EventAction.values()) { + register(action); + } + } + + private String myKey; + + EventAction(String key) { + myKey = key; + } + + public String toString() { + return myKey; + } + + private static void register(@NotNull EventAction action) { + ourAllActions.put(action.myKey, action); + } + + @NotNull + public static EventAction from(@NotNull SVNEventAction action) { + return ObjectUtils.notNull(ourAllActions.get(action.toString()), UNKNOWN); + } +} diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/api/FileStatusResultParser.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/api/FileStatusResultParser.java index fc202c265a6a..7bc0b32a2e04 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/api/FileStatusResultParser.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/api/FileStatusResultParser.java @@ -6,8 +6,6 @@ import com.intellij.util.containers.Convertor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.tmatesoft.svn.core.SVNException; -import org.tmatesoft.svn.core.wc.ISVNEventHandler; -import org.tmatesoft.svn.core.wc.SVNEvent; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -17,20 +15,18 @@ import java.util.regex.Pattern; */ public class FileStatusResultParser { - private static final double DEFAULT_PROGRESS = 0.0; - @NotNull private Pattern myLinePattern; @Nullable - private ISVNEventHandler handler; + private ProgressTracker handler; @NotNull - private Convertor<Matcher, SVNEvent> myConvertor; + private Convertor<Matcher, ProgressEvent> myConvertor; public FileStatusResultParser(@NotNull Pattern linePattern, - @Nullable ISVNEventHandler handler, - @NotNull Convertor<Matcher, SVNEvent> convertor) { + @Nullable ProgressTracker handler, + @NotNull Convertor<Matcher, ProgressEvent> convertor) { myLinePattern = linePattern; this.handler = handler; myConvertor = convertor; @@ -59,7 +55,7 @@ public class FileStatusResultParser { public void process(@NotNull Matcher matcher) throws VcsException { if (handler != null) { try { - handler.handleEvent(myConvertor.convert(matcher), DEFAULT_PROGRESS); + handler.consume(myConvertor.convert(matcher)); } catch (SVNException e) { throw new VcsException(e); } diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/api/InfoCommandRepositoryProvider.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/api/InfoCommandRepositoryProvider.java index c2be897dc3a1..bfcf37de3a0d 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/api/InfoCommandRepositoryProvider.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/api/InfoCommandRepositoryProvider.java @@ -18,8 +18,7 @@ package org.jetbrains.idea.svn.api; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.idea.svn.SvnVcs; -import org.tmatesoft.svn.core.wc.SVNInfo; -import org.tmatesoft.svn.core.wc.SVNRevision; +import org.jetbrains.idea.svn.info.Info; import org.tmatesoft.svn.core.wc2.SvnTarget; /** @@ -42,7 +41,7 @@ public class InfoCommandRepositoryProvider extends BaseRepositoryProvider { result = new Repository(myTarget.getURL()); } else { - SVNInfo info = myVcs.getInfo(myTarget.getFile()); + Info info = myVcs.getInfo(myTarget.getFile()); result = info != null ? new Repository(info.getRepositoryRootURL()) : null; } diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/api/NodeKind.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/api/NodeKind.java new file mode 100644 index 000000000000..e4820b844c23 --- /dev/null +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/api/NodeKind.java @@ -0,0 +1,94 @@ +/* + * 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.api; + +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NotNull; +import org.tmatesoft.svn.core.SVNNodeKind; + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; +import java.util.Map; + +/** + * @author Konstantin Kolosovsky. + */ +@XmlEnum +public enum NodeKind { + + // see comments in LogEntryPath.Builder for cases when "" kind could appear + @XmlEnumValue("") UNKNOWN("unknown"), + @XmlEnumValue("file") FILE("file"), + @XmlEnumValue("dir") DIR("dir"), + // used in ConflictVersion when node is missing + @XmlEnumValue("none") NONE("none"); + + @NotNull private static final Map<String, NodeKind> ourAllNodeKinds = ContainerUtil.newHashMap(); + + static { + for (NodeKind kind : NodeKind.values()) { + register(kind); + } + } + + @NotNull private final String myKey; + + NodeKind(@NotNull String key) { + myKey = key; + } + + public boolean isFile() { + return FILE.equals(this); + } + + public boolean isDirectory() { + return DIR.equals(this); + } + + public boolean isNone() { + return NONE.equals(this); + } + + @Override + public String toString() { + return myKey; + } + + private static void register(@NotNull NodeKind kind) { + ourAllNodeKinds.put(kind.myKey, kind); + } + + @NotNull + public static NodeKind from(@NotNull String nodeKindName) { + NodeKind result = ourAllNodeKinds.get(nodeKindName); + + if (result == null) { + throw new IllegalArgumentException("Unknown node kind " + nodeKindName); + } + + return result; + } + + @NotNull + public static NodeKind from(@NotNull SVNNodeKind nodeKind) { + return from(nodeKind.toString()); + } + + @NotNull + public static NodeKind from(boolean isDirectory) { + return isDirectory ? DIR : FILE; + } +} diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/api/ProgressEvent.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/api/ProgressEvent.java new file mode 100644 index 000000000000..12bd2e1a91f4 --- /dev/null +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/api/ProgressEvent.java @@ -0,0 +1,118 @@ +/* + * 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.api; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.idea.svn.status.StatusType; +import org.tmatesoft.svn.core.SVNErrorMessage; +import org.tmatesoft.svn.core.SVNURL; +import org.tmatesoft.svn.core.wc.SVNEvent; + +import java.io.File; + +/** + * @author Konstantin Kolosovsky. + */ +public class ProgressEvent { + + private final File myFile; + + private final long myRevision; + private final SVNURL myURL; + + @NotNull private final StatusType myContentsStatus; + @NotNull private final StatusType myPropertiesStatus; + private final SVNErrorMessage myErrorMessage; + private final EventAction myAction; + + @Nullable + public static ProgressEvent create(@Nullable SVNEvent event) { + ProgressEvent result = null; + + if (event != null) { + if (event.getFile() == null && event.getURL() == null) { + result = new ProgressEvent(event.getErrorMessage()); + } + else { + result = + new ProgressEvent(event.getFile(), event.getRevision(), StatusType.from(event.getContentsStatus()), StatusType.from(event.getPropertiesStatus()), + EventAction.from(event.getAction()), event.getErrorMessage(), event.getURL()); + } + } + + return result; + } + + public ProgressEvent(SVNErrorMessage errorMessage) { + this(null, 0, null, null, EventAction.SKIP, errorMessage, null); + } + + public ProgressEvent(File file, + long revision, + @Nullable StatusType contentStatus, + @Nullable StatusType propertiesStatus, + EventAction action, + SVNErrorMessage error, + SVNURL url) { + myFile = file != null ? file.getAbsoluteFile() : null; + myRevision = revision; + myContentsStatus = contentStatus == null ? StatusType.INAPPLICABLE : contentStatus; + myPropertiesStatus = propertiesStatus == null ? StatusType.INAPPLICABLE : propertiesStatus; + myAction = action; + myErrorMessage = error; + myURL = url; + } + + public File getFile() { + return myFile; + } + + public EventAction getAction() { + return myAction; + } + + @NotNull + public StatusType getContentsStatus() { + return myContentsStatus; + } + + public SVNErrorMessage getErrorMessage() { + return myErrorMessage; + } + + @NotNull + public StatusType getPropertiesStatus() { + return myPropertiesStatus; + } + + public long getRevision() { + return myRevision; + } + + public SVNURL getURL() { + return myURL; + } + + @Nullable + public String getPath() { + return myFile != null ? myFile.getName() : myURL != null ? myURL.toString() : null; + } + + public String toString() { + return getAction() + " " + getFile() + " " + getURL(); + } +}
\ No newline at end of file diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/api/ProgressTracker.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/api/ProgressTracker.java new file mode 100644 index 000000000000..303b66a00c62 --- /dev/null +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/api/ProgressTracker.java @@ -0,0 +1,28 @@ +/* + * 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.api; + +import com.intellij.util.ThrowableConsumer; +import org.tmatesoft.svn.core.SVNCancelException; +import org.tmatesoft.svn.core.SVNException; + +/** + * @author Konstantin Kolosovsky. + */ +public interface ProgressTracker extends ThrowableConsumer<ProgressEvent, SVNException> { + + void checkCancelled() throws SVNCancelException; +} diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/api/SvnKitClientFactory.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/api/SvnKitClientFactory.java index 1b834c16585b..f46f5f06ebdb 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/api/SvnKitClientFactory.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/api/SvnKitClientFactory.java @@ -29,7 +29,6 @@ import org.jetbrains.idea.svn.update.SvnKitRelocateClient; import org.jetbrains.idea.svn.update.SvnKitUpdateClient; import org.jetbrains.idea.svn.update.UpdateClient; import org.jetbrains.idea.svn.upgrade.SvnKitUpgradeClient; -import org.tmatesoft.svn.core.wc.ISVNEventHandler; import org.tmatesoft.svn.core.wc.ISVNStatusFileProvider; /** @@ -72,7 +71,7 @@ public class SvnKitClientFactory extends ClientFactory { @NotNull @Override - public StatusClient createStatusClient(@Nullable ISVNStatusFileProvider provider, @NotNull ISVNEventHandler handler) { + public StatusClient createStatusClient(@Nullable ISVNStatusFileProvider provider, @NotNull ProgressTracker handler) { return prepare(new SvnKitStatusClient(provider, handler)); } |