From 3afc8cfdf2fa71172b7561883c77b5b11012febf Mon Sep 17 00:00:00 2001 From: Alexander Fedorov Date: Fri, 16 Feb 2024 21:08:27 +0300 Subject: [PATCH] [#26] Start `ISVNManager` implementation * reuse `CallWatch` and others --- .../adapt/jhlsv/NodeActionAdapter.java | 55 +++++++++++++ .../ReposNotifyInformationActionAdapter.java | 69 ++++++++++++++++ .../jhlsv/ReposNotifyInformationAdapter.java | 48 +++++++++++ ...er.java => AdaptClientNotifyCallback.java} | 8 +- .../adapt/svjhl/AdaptReposNotifyCallback.java | 47 +++++++++++ .../svnkit1_10/SvnKit1_10Connector.java | 6 +- .../SvnKit1_10ConnectorFactory.java | 4 +- .../svnkit1_10/SvnKit1_10Manager.java | 79 +++++++++++++++++-- 8 files changed, 302 insertions(+), 14 deletions(-) create mode 100644 bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/jhlsv/NodeActionAdapter.java create mode 100644 bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/jhlsv/ReposNotifyInformationActionAdapter.java create mode 100644 bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/jhlsv/ReposNotifyInformationAdapter.java rename bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/svjhl/{ClientNotifyCallbackAdapter.java => AdaptClientNotifyCallback.java} (82%) create mode 100644 bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/svjhl/AdaptReposNotifyCallback.java diff --git a/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/jhlsv/NodeActionAdapter.java b/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/jhlsv/NodeActionAdapter.java new file mode 100644 index 0000000..0c864fc --- /dev/null +++ b/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/jhlsv/NodeActionAdapter.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2023, 2024 ArSysOp + * + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + */ + +package ru.arsysop.svn.connector.internal.adapt.jhlsv; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.subversion.javahl.ReposNotifyInformation; +import org.eclipse.team.svn.core.connector.SVNRepositoryNotification; +import org.eclipse.team.svn.core.connector.SVNRepositoryNotification.NodeAction; + +import ru.arsysop.svn.connector.internal.adapt.SvnTypeMap; + +public final class NodeActionAdapter +extends SvnTypeMap { + + public NodeActionAdapter(ReposNotifyInformation.NodeAction source) { + super(source); + } + + @Override + protected Map fill() { + Map map = new HashMap<>(); + map.put(ReposNotifyInformation.NodeAction.change, SVNRepositoryNotification.NodeAction.CHANGE); + map.put(ReposNotifyInformation.NodeAction.add, SVNRepositoryNotification.NodeAction.ADD); + map.put(ReposNotifyInformation.NodeAction.deleted, SVNRepositoryNotification.NodeAction.DELETE); + map.put(ReposNotifyInformation.NodeAction.replace, SVNRepositoryNotification.NodeAction.REPLACE); + return map; + } + + @Override + protected SVNRepositoryNotification.NodeAction defaults() { + return NodeAction.UNKNOWN; + } + +} diff --git a/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/jhlsv/ReposNotifyInformationActionAdapter.java b/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/jhlsv/ReposNotifyInformationActionAdapter.java new file mode 100644 index 0000000..9f1b47c --- /dev/null +++ b/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/jhlsv/ReposNotifyInformationActionAdapter.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2023, 2024 ArSysOp + * + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + */ + +package ru.arsysop.svn.connector.internal.adapt.jhlsv; + +import java.util.LinkedHashMap; +import java.util.Map; + +import org.apache.subversion.javahl.ReposNotifyInformation; +import org.apache.subversion.javahl.ReposNotifyInformation.Action; +import org.eclipse.team.svn.core.connector.SVNRepositoryNotification; + +import ru.arsysop.svn.connector.internal.adapt.SvnTypeMap; + +final class ReposNotifyInformationActionAdapter +extends SvnTypeMap { + + ReposNotifyInformationActionAdapter(ReposNotifyInformation.Action source) { + super(source); + } + + @Override + protected Map fill() { + Map map = new LinkedHashMap<>(); + map.put(Action.warning, SVNRepositoryNotification.Action.WARNING); + map.put(Action.dump_rev_end, SVNRepositoryNotification.Action.DUMP_REV_END); + map.put(Action.verify_rev_end, SVNRepositoryNotification.Action.VERIFY_REV_END); + map.put(Action.pack_shard_start, SVNRepositoryNotification.Action.PACK_SHARD_START); + map.put(Action.pack_shard_end, SVNRepositoryNotification.Action.PACK_SHARD_END); + map.put(Action.pack_shard_start_revprop, SVNRepositoryNotification.Action.PACK_SHARD_START_REVPROP); + map.put(Action.pack_shard_end_revprop, SVNRepositoryNotification.Action.PACK_SHARD_END_REVPROP); + map.put(Action.load_txn_start, SVNRepositoryNotification.Action.LOAD_TXN_START); + map.put(Action.load_txn_committed, SVNRepositoryNotification.Action.LOAD_TXN_COMMITTED); + map.put(Action.load_node_start, SVNRepositoryNotification.Action.LOAD_NODE_START); + map.put(Action.load_node_done, SVNRepositoryNotification.Action.LOAD_NODE_END); + map.put(Action.load_copied_node, SVNRepositoryNotification.Action.LOAD_COPIED_NODE); + map.put(Action.load_normalized_mergeinfo, SVNRepositoryNotification.Action.LOAD_NORMALIZED_MERGEINFO); + map.put(Action.mutex_acquired, SVNRepositoryNotification.Action.MUTEX_ACQUIRED); + map.put(Action.recover_start, SVNRepositoryNotification.Action.RECOVER_START); + map.put(Action.upgrade_start, SVNRepositoryNotification.Action.UPGRADE_START); + map.put(Action.load_skipped_rev, SVNRepositoryNotification.Action.LOAD_SKIPPED_REV); + map.put(Action.verify_rev_structure, SVNRepositoryNotification.Action.VERIFY_REV_STRUCTURE); + return map; + } + + @Override + protected SVNRepositoryNotification.Action defaults() { + return SVNRepositoryNotification.Action.UNKNOWN; + } + +} diff --git a/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/jhlsv/ReposNotifyInformationAdapter.java b/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/jhlsv/ReposNotifyInformationAdapter.java new file mode 100644 index 0000000..f2c81e8 --- /dev/null +++ b/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/jhlsv/ReposNotifyInformationAdapter.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023, 2024 ArSysOp + * + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + */ + +package ru.arsysop.svn.connector.internal.adapt.jhlsv; + +import org.apache.subversion.javahl.ReposNotifyInformation; +import org.eclipse.team.svn.core.connector.SVNRepositoryNotification; + +import ru.arsysop.svn.connector.internal.adapt.SvnTypeConstructor; + +public final class ReposNotifyInformationAdapter +extends SvnTypeConstructor { + + public ReposNotifyInformationAdapter(ReposNotifyInformation source) { + super(source); + } + + @Override + public SVNRepositoryNotification adapt() { + return new SVNRepositoryNotification(// + source.getPath(), // + new NodeActionAdapter(source.getNodeAction()).adapt(), + new ReposNotifyInformationActionAdapter(source.getAction()).adapt(), // + source.getRevision(), source.getWarning(), // + source.getShard(), // + source.getNewRevision(), // + source.getOldRevision()); + } + +} \ No newline at end of file diff --git a/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/svjhl/ClientNotifyCallbackAdapter.java b/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/svjhl/AdaptClientNotifyCallback.java similarity index 82% rename from bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/svjhl/ClientNotifyCallbackAdapter.java rename to bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/svjhl/AdaptClientNotifyCallback.java index f893715..46f4826 100644 --- a/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/svjhl/ClientNotifyCallbackAdapter.java +++ b/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/svjhl/AdaptClientNotifyCallback.java @@ -21,16 +21,18 @@ package ru.arsysop.svn.connector.internal.adapt.svjhl; +import java.util.Objects; + import org.eclipse.team.svn.core.connector.ISVNNotificationCallback; import ru.arsysop.svn.connector.internal.adapt.jhlsv.ClientNotifyInformationAdapter; -public final class ClientNotifyCallbackAdapter implements org.apache.subversion.javahl.callback.ClientNotifyCallback { +public final class AdaptClientNotifyCallback implements org.apache.subversion.javahl.callback.ClientNotifyCallback { private final ISVNNotificationCallback callback; - public ClientNotifyCallbackAdapter(ISVNNotificationCallback notify) { - callback = notify; + public AdaptClientNotifyCallback(ISVNNotificationCallback notify) { + callback = Objects.requireNonNull(notify); } public ISVNNotificationCallback callback() { diff --git a/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/svjhl/AdaptReposNotifyCallback.java b/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/svjhl/AdaptReposNotifyCallback.java new file mode 100644 index 0000000..7c11f0c --- /dev/null +++ b/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/svjhl/AdaptReposNotifyCallback.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023, 2024 ArSysOp + * + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + */ + +package ru.arsysop.svn.connector.internal.adapt.svjhl; + +import java.util.Objects; + +import org.apache.subversion.javahl.ReposNotifyInformation; +import org.eclipse.team.svn.core.connector.ISVNRepositoryNotificationCallback; + +import ru.arsysop.svn.connector.internal.adapt.jhlsv.ReposNotifyInformationAdapter; + +public final class AdaptReposNotifyCallback implements org.apache.subversion.javahl.callback.ReposNotifyCallback { + + private final ISVNRepositoryNotificationCallback callback; + + public AdaptReposNotifyCallback(ISVNRepositoryNotificationCallback notify) { + callback = Objects.requireNonNull(notify); + } + + public ISVNRepositoryNotificationCallback callback() { + return callback; + } + + @Override + public void onNotify(ReposNotifyInformation info) { + callback.notify(new ReposNotifyInformationAdapter(info).adapt()); + } +} \ No newline at end of file diff --git a/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/svnkit1_10/SvnKit1_10Connector.java b/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/svnkit1_10/SvnKit1_10Connector.java index ce2ac49..9273ee0 100644 --- a/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/svnkit1_10/SvnKit1_10Connector.java +++ b/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/svnkit1_10/SvnKit1_10Connector.java @@ -66,7 +66,7 @@ import ru.arsysop.svn.connector.internal.adapt.jhlsv.LockNullableAdapter; import ru.arsysop.svn.connector.internal.adapt.jhlsv.NodeKindAdapter; -import ru.arsysop.svn.connector.internal.adapt.svjhl.ClientNotifyCallbackAdapter; +import ru.arsysop.svn.connector.internal.adapt.svjhl.AdaptClientNotifyCallback; import ru.arsysop.svn.connector.internal.adapt.svjhl.DepthAdapter; import ru.arsysop.svn.connector.internal.adapt.svjhl.InfoCallbackAdapter; import ru.arsysop.svn.connector.internal.adapt.svjhl.InheritedCallbackAdapter; @@ -82,13 +82,13 @@ final class SvnKit1_10Connector implements ISVNConnector { //FIXME: AF: not sure why do we need this private final List handlers = new ArrayList<>(); - public SvnKit1_10Connector(String name) { + SvnKit1_10Connector(String name) { SVNFileUtil.setSleepForTimestamp(false);// not time to relax //FIXME: AF: check if we can remove "trilead" from target System.setProperty("svnkit.ssh.client", "apache"); //$NON-NLS-1$ //$NON-NLS-2$ watch = new CallWatch(name); client = SVNClientImpl.newInstance(); - client.notification2(new ClientNotifyCallbackAdapter(watch.notifications)); + client.notification2(new AdaptClientNotifyCallback(watch.notifications)); } @Override diff --git a/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/svnkit1_10/SvnKit1_10ConnectorFactory.java b/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/svnkit1_10/SvnKit1_10ConnectorFactory.java index caab8aa..06c7139 100644 --- a/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/svnkit1_10/SvnKit1_10ConnectorFactory.java +++ b/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/svnkit1_10/SvnKit1_10ConnectorFactory.java @@ -31,11 +31,11 @@ public final class SvnKit1_10ConnectorFactory implements ISVNConnectorFactory { public ISVNConnector createConnector() { - return new SvnKit1_10Connector(getName()); + return new SvnKit1_10Connector(String.format("SVNKit %s Connector", Version.getShortVersionString())); } public ISVNManager createManager() { - return new SvnKit1_10Manager(); + return new SvnKit1_10Manager(String.format("SVNKit %s Manager", Version.getShortVersionString())); } public String getName() { diff --git a/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/svnkit1_10/SvnKit1_10Manager.java b/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/svnkit1_10/SvnKit1_10Manager.java index 980def3..b761aec 100644 --- a/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/svnkit1_10/SvnKit1_10Manager.java +++ b/bundles/ru.arsysop.svn.connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/svnkit1_10/SvnKit1_10Manager.java @@ -21,9 +21,16 @@ package ru.arsysop.svn.connector.internal.svnkit1_10; +import java.io.File; import java.io.InputStream; import java.io.OutputStream; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import org.apache.subversion.javahl.ISVNRepos; +import org.apache.subversion.javahl.SVNRepos; +import org.eclipse.team.svn.core.connector.ISVNCallListener; import org.eclipse.team.svn.core.connector.ISVNManager; import org.eclipse.team.svn.core.connector.ISVNProgressMonitor; import org.eclipse.team.svn.core.connector.ISVNRepositoryFreezeAction; @@ -35,32 +42,87 @@ import org.eclipse.team.svn.core.connector.SVNLock; import org.eclipse.team.svn.core.connector.SVNProperty; import org.eclipse.team.svn.core.connector.SVNRevisionRange; +import org.eclipse.team.svn.core.utility.SVNRepositoryNotificationComposite; + +import ru.arsysop.svn.connector.internal.adapt.svjhl.AdaptReposNotifyCallback; +import ru.arsysop.svn.connector.internal.adapt.svjhl.RevisionAdapter; -//TODO final class SvnKit1_10Manager implements ISVNManager { + private final CallWatch watch; + private final ISVNRepos admin; + private final SVNRepositoryNotificationComposite composite = new SVNRepositoryNotificationComposite(); + + SvnKit1_10Manager(String name) { + watch = new CallWatch(name); + admin = new SVNRepos(); + } + @Override public void create(String repositoryPath, RepositoryKind repositoryType, String configPath, long options, ISVNProgressMonitor monitor) throws SVNConnectorException { - //TODO + Map parameters = new HashMap<>(); + parameters.put("repositoryPath", repositoryPath); //$NON-NLS-1$ + parameters.put("repositoryType", repositoryType); //$NON-NLS-1$ + parameters.put("configPath", configPath); //$NON-NLS-1$ + parameters.put("options", options); //$NON-NLS-1$ + parameters.put("monitor", monitor); //$NON-NLS-1$ + watch.operation(ISVNCallListener.CREATE, parameters, callback(monitor), + p -> admin.create(// + new File(repositoryPath), // + (options & Options.DISABLE_FSYNC_COMMIT) != 0, // + (options & Options.KEEP_LOG) != 0, // + Optional.ofNullable(configPath).map(File::new).orElse(null), + Optional.ofNullable(repositoryType).orElse(ISVNManager.RepositoryKind.FSFS).id)); } @Override public void deltify(String path, SVNRevisionRange range, ISVNProgressMonitor monitor) throws SVNConnectorException { - //TODO + Map parameters = new HashMap<>(); + parameters.put("path", path); //$NON-NLS-1$ + parameters.put("range", range); //$NON-NLS-1$ + parameters.put("monitor", monitor); //$NON-NLS-1$ + watch.operation(ISVNCallListener.DELTIFY, parameters, callback(monitor), p -> admin.deltify(// + new File(path), // + new RevisionAdapter(range.from).adapt(), // + new RevisionAdapter(range.to).adapt())); } @Override public void hotCopy(String path, String targetPath, long options, ISVNProgressMonitor monitor) throws SVNConnectorException { - //TODO + Map parameters = new HashMap<>(); + parameters.put("path", path); //$NON-NLS-1$ + parameters.put("targetPath", targetPath); //$NON-NLS-1$ + parameters.put("options", options); //$NON-NLS-1$ + parameters.put("monitor", monitor); //$NON-NLS-1$ + watch.operation(ISVNCallListener.HOT_COPY, parameters, callback(monitor), + p -> admin.hotcopy(// + new File(path), // + new File(targetPath), // + (options & Options.CLEAN_LOGS) != 0)); } @Override public void dump(String path, OutputStream dataOut, SVNRevisionRange range, ISVNRepositoryNotificationCallback callback, long options, ISVNProgressMonitor monitor) throws SVNConnectorException { - //TODO + Map parameters = new HashMap<>(); + parameters.put("path", path); //$NON-NLS-1$ + parameters.put("dataOut", dataOut); //$NON-NLS-1$ + parameters.put("range", range); //$NON-NLS-1$ + parameters.put("callback", callback); //$NON-NLS-1$ + parameters.put("options", options); //$NON-NLS-1$ + parameters.put("monitor", monitor); //$NON-NLS-1$ + watch.operation(ISVNCallListener.DUMP, parameters, callback(monitor), + p -> admin.dump(// + new File(path), // + dataOut, // + new RevisionAdapter(range.from).adapt(), // + new RevisionAdapter(range.to).adapt(), // + (options & Options.INCREMENTAL) != 0, // + (options & Options.USE_DELTAS) != 0, // + new AdaptReposNotifyCallback(composite))); } @Override @@ -136,9 +198,14 @@ public void pack(String path, ISVNRepositoryNotificationCallback callback, ISVNP //TODO } + private ProgressCallback callback(ISVNProgressMonitor monitor) { + return new ProgressCallback(monitor, admin::cancelOperation); + } + @Override public void dispose() { - //TODO + admin.dispose(); + watch.dispose(); } }