Skip to content

Commit

Permalink
[#26] Start ISVNManager implementation
Browse files Browse the repository at this point in the history
* add more adapters
* split `Operation` for `CommandLong` and `QueryLong`
  • Loading branch information
ruspl-afed authored and eparovyshnaya committed Feb 17, 2024
1 parent 3afc8cf commit c66b07f
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ public AdaptClientNotifyCallback(ISVNNotificationCallback notify) {
callback = Objects.requireNonNull(notify);
}

public ISVNNotificationCallback callback() {
return callback;
}

@Override
public void onNotify(org.apache.subversion.javahl.ClientNotifyInformation info) {
callback.notify(new ClientNotifyInformationAdapter(info).adapt());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.ISVNRepos.MessageReceiver;
import org.eclipse.team.svn.core.connector.ISVNRepositoryMessageCallback;

public final class AdaptMessageReceiver implements MessageReceiver {

private final ISVNRepositoryMessageCallback callback;

public AdaptMessageReceiver(ISVNRepositoryMessageCallback notify) {
callback = Objects.requireNonNull(notify);
}

@Override
public void receiveMessageLine(String message) {
callback.nextMessage(message);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,25 @@ <V> V queryFast(String method, Map<String, Object> parameters, QueryFast<V> quer
}
}

void commandSafe(String method, Map<String, Object> parameters, CommandSafe command) {
<V> V queryLong(String method, Map<String, Object> parameters, ProgressCallback progress, QueryLong<V> query)
throws SVNConnectorException {
asked(method, parameters);
command.command(parameters);
succeeded(method, parameters, null);//oh, no! we need to change this interface
try {
notifications.add(progress);
progress.start();
watchdog.add(progress);
V value = query.query(parameters);
succeeded(method, parameters, null);//oh, no! we need to change this interface
return value;
} catch (ClientException ex) {
SVNConnectorException wrap = wrap(ex);
failed(method, parameters, wrap);
throw wrap;
} finally {
progress.finish();
watchdog.remove(progress);
notifications.remove(progress);
}
}

void commandFast(String method, Map<String, Object> parameters, CommandFast command) throws SVNConnectorException {
Expand All @@ -90,14 +105,14 @@ void commandFast(String method, Map<String, Object> parameters, CommandFast comm
}
}

void operation(String method, Map<String, Object> parameters, ProgressCallback progress, Operation operation)
void commandLong(String method, Map<String, Object> parameters, ProgressCallback progress, CommandLong command)
throws SVNConnectorException {
asked(method, parameters);
try {
notifications.add(progress);
progress.start();
watchdog.add(progress);
operation.operation(parameters);
command.command(parameters);
succeeded(method, parameters, null);//oh, no! we need to change this interface
} catch (ClientException ex) {
SVNConnectorException wrap = wrap(ex);
Expand All @@ -110,6 +125,12 @@ void operation(String method, Map<String, Object> parameters, ProgressCallback p
}
}

void commandSafe(String method, Map<String, Object> parameters, CommandSafe command) {
asked(method, parameters);
command.command(parameters);
succeeded(method, parameters, null);//oh, no! we need to change this interface
}

private void asked(String method, Map<String, Object> parameters) {
for (ISVNCallListener listener : listeners) {
listener.asked(method, parameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import org.apache.subversion.javahl.ClientException;

@FunctionalInterface
interface Operation {
interface CommandLong {

void operation(Map<String, Object> parameters) throws ClientException;
void command(Map<String, Object> parameters) throws ClientException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.svnkit1_10;

import java.util.Map;

import org.apache.subversion.javahl.ClientException;

@FunctionalInterface
public interface QueryLong<V> {

V query(Map<String, Object> parameters) throws ClientException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public void getInfo(SVNEntryRevisionReference reference, SVNDepth depth, long op
parameters.put("changeLists", changeLists); //$NON-NLS-1$
parameters.put("cb", cb); //$NON-NLS-1$
parameters.put("monitor", monitor); //$NON-NLS-1$
watch.operation(ISVNCallListener.GET_INFO, parameters, callback(monitor),
watch.commandLong(ISVNCallListener.GET_INFO, parameters, callback(monitor),
p -> client.info2(//
reference.path, //
new RevisionAdapter(reference.revision).adapt(), //
Expand Down Expand Up @@ -507,7 +507,7 @@ public void listEntries(SVNEntryRevisionReference reference, SVNDepth depth, int
parameters.put("options", Long.valueOf(options)); //$NON-NLS-1$
parameters.put("cb", cb); //$NON-NLS-1$
parameters.put("monitor", monitor); //$NON-NLS-1$
watch.operation(ISVNCallListener.LIST, parameters, callback(monitor),
watch.commandLong(ISVNCallListener.LIST, parameters, callback(monitor),
p -> listEntries(reference, depth, fields, options, cb));
}

Expand Down Expand Up @@ -552,7 +552,7 @@ public void listProperties(SVNEntryRevisionReference reference, SVNDepth depth,
parameters.put("changeLists", changeLists); //$NON-NLS-1$
parameters.put("callback", callback); //$NON-NLS-1$
parameters.put("monitor", monitor); //$NON-NLS-1$
watch.operation(ISVNCallListener.GET_PROPERTIES, parameters, callback(monitor),
watch.commandLong(ISVNCallListener.GET_PROPERTIES, parameters, callback(monitor),
p -> listProperties(reference, depth, changeLists, options, callback));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Map;
import java.util.Optional;

import org.apache.subversion.javahl.ClientException;
import org.apache.subversion.javahl.ISVNRepos;
import org.apache.subversion.javahl.SVNRepos;
import org.eclipse.team.svn.core.connector.ISVNCallListener;
Expand All @@ -44,6 +45,7 @@
import org.eclipse.team.svn.core.connector.SVNRevisionRange;
import org.eclipse.team.svn.core.utility.SVNRepositoryNotificationComposite;

import ru.arsysop.svn.connector.internal.adapt.svjhl.AdaptMessageReceiver;
import ru.arsysop.svn.connector.internal.adapt.svjhl.AdaptReposNotifyCallback;
import ru.arsysop.svn.connector.internal.adapt.svjhl.RevisionAdapter;

Expand All @@ -67,13 +69,12 @@ public void create(String repositoryPath, RepositoryKind repositoryType, String
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));
watch.commandLong(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
Expand All @@ -82,7 +83,7 @@ public void deltify(String path, SVNRevisionRange range, ISVNProgressMonitor mon
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(//
watch.commandLong(ISVNCallListener.DELTIFY, parameters, callback(monitor), p -> admin.deltify(//
new File(path), //
new RevisionAdapter(range.from).adapt(), //
new RevisionAdapter(range.to).adapt()));
Expand All @@ -96,11 +97,10 @@ public void hotCopy(String path, String targetPath, long options, ISVNProgressMo
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));
watch.commandLong(ISVNCallListener.HOT_COPY, parameters, callback(monitor), p -> admin.hotcopy(//
new File(path), //
new File(targetPath), //
(options & Options.CLEAN_LOGS) != 0));
}

@Override
Expand All @@ -114,41 +114,83 @@ public void dump(String path, OutputStream dataOut, SVNRevisionRange range,
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)));
watch.commandLong(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
public void listDBLogs(String path, ISVNRepositoryMessageCallback receiver, long options,
ISVNProgressMonitor monitor) throws SVNConnectorException {
//TODO
Map<String, Object> parameters = new HashMap<>();
parameters.put("path", path); //$NON-NLS-1$
parameters.put("receiver", receiver); //$NON-NLS-1$
parameters.put("options", options); //$NON-NLS-1$
parameters.put("monitor", monitor); //$NON-NLS-1$
watch.commandLong(ISVNCallListener.LIST_DB_LOGS, parameters, callback(monitor),
p -> listBDLogs(path, receiver, options));
}

private void listBDLogs(String path, ISVNRepositoryMessageCallback receiver, long options) throws ClientException {
if ((options & Options.UNUSED_ONLY) != 0) {
admin.listUnusedDBLogs(new File(path), new AdaptMessageReceiver(receiver));
} else {
admin.listDBLogs(new File(path), new AdaptMessageReceiver(receiver));
}
}

@Override
public void load(String path, InputStream dataInput, SVNRevisionRange range, String relativePath,
ISVNRepositoryNotificationCallback callback, long options, ISVNProgressMonitor monitor)
throws SVNConnectorException {
//TODO
Map<String, Object> parameters = new HashMap<>();
parameters.put("path", path); //$NON-NLS-1$
parameters.put("dataInput", dataInput); //$NON-NLS-1$
parameters.put("range", range); //$NON-NLS-1$
parameters.put("relativePath", relativePath); //$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.commandLong(ISVNCallListener.LOAD, parameters, callback(monitor), p -> admin.load(//
new File(path), //
dataInput, //
new RevisionAdapter(range.from).adapt(), //
new RevisionAdapter(range.to).adapt(), //
(options & Options.IGNORE_UUID) != 0, //
(options & Options.FORCE_UUID) != 0, //
(options & Options.USE_PRECOMMIT_HOOK) != 0, //
(options & Options.USE_POSTCOMMIT_HOOK) != 0, //
relativePath, //
new AdaptReposNotifyCallback(composite)//
));
}

@Override
public void listTransactions(String path, ISVNRepositoryMessageCallback receiver, ISVNProgressMonitor monitor)
throws SVNConnectorException {
//TODO
Map<String, Object> parameters = new HashMap<>();
parameters.put("path", path); //$NON-NLS-1$
parameters.put("receiver", receiver); //$NON-NLS-1$
parameters.put("monitor", monitor); //$NON-NLS-1$
watch.commandLong(ISVNCallListener.LIST_TRANSACTIONS, parameters, callback(monitor),
p -> admin.lstxns(new File(path), new AdaptMessageReceiver(receiver)));
}

@Override
public long recover(String path, ISVNRepositoryNotificationCallback callback, ISVNProgressMonitor monitor)
throws SVNConnectorException {
//TODO
return 0;
Map<String, Object> parameters = new HashMap<>();
parameters.put("path", path); //$NON-NLS-1$
parameters.put("callback", callback); //$NON-NLS-1$
parameters.put("monitor", monitor); //$NON-NLS-1$
return watch.queryLong(ISVNCallListener.RECOVER, parameters, callback(monitor),
p -> admin.recover(new File(path), new AdaptReposNotifyCallback(composite)));
}

@Override
Expand Down

0 comments on commit c66b07f

Please sign in to comment.