Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#6] Implement basic query and command methods #7

Merged
merged 1 commit into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ Bundle-Version: 0.1.0.qualifier
Bundle-Name: %Bundle-Name
Bundle-Vendor: %Bundle-Vendor
Bundle-RequiredExecutionEnvironment: JavaSE-17
Import-Package: org.apache.subversion.javahl.types;version="1.10.11",
Import-Package: org.apache.subversion.javahl;version="1.10.11",
org.apache.subversion.javahl.callback;version="1.10.11",
org.apache.subversion.javahl.types;version="1.10.11",
org.tmatesoft.sqljet.core;version="1.1.15",
org.tmatesoft.svn.core.internal.wc;version="1.10.11",
org.tmatesoft.svn.core.javahl17;version="1.10.11",
org.tmatesoft.svn.util;version="1.10.11"
Require-Bundle: org.eclipse.core.runtime;bundle-version="3.18.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Copyright (c) ArSysOp 2020-2024
*
* ArSysOp and its affiliates make no warranty of any kind
* with regard to this material.
*
* ArSysOp expressly disclaims all warranties as to the material, express,
* and implied, including but not limited to the implied warranties of
* merchantability, fitness for a particular purpose and non-infringement of third
* party rights.
*
* In no event shall ArSysOp be liable to you or any other person for any damages,
* including, without limitation, any direct, indirect, incidental or consequential
* damages, expenses, lost profits, lost data or other damages arising out of the use,
* misuse or inability to use the material and any derived software, even if ArSysOp,
* its affiliate or an authorized dealer has been advised of the possibility of such damages.
*
*/

package ru.arsysop.svn.connector.internal.svnkit1_10;

import java.util.Map;

import org.apache.subversion.javahl.ClientException;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.team.svn.core.connector.ISVNCallListener;
import org.eclipse.team.svn.core.connector.SVNConnectorAuthenticationException;
import org.eclipse.team.svn.core.connector.SVNConnectorCancelException;
import org.eclipse.team.svn.core.connector.SVNConnectorException;
import org.eclipse.team.svn.core.connector.SVNConnectorUnresolvedConflictException;
import org.eclipse.team.svn.core.connector.SVNErrorCodes;
import org.eclipse.team.svn.core.utility.SVNNotificationComposite;

final class CallWatch {

final SVNNotificationComposite notifications = new SVNNotificationComposite();
private final ListenerList<ISVNCallListener> listeners = new ListenerList<>();

void addListener(ISVNCallListener listener) {
listeners.add(listener);
}

void removeListener(ISVNCallListener listener) {
listeners.remove(listener);
}

<V> V query(String method, Map<String, Object> parameters, Query<V> query) throws SVNConnectorException {
asked(method, parameters);
try {
V value = query.query(parameters);
succeeded(method, parameters, value);
return value;
} catch (ClientException ex) {
SVNConnectorException wrap = wrap(ex);
failed(method, parameters, wrap);
throw wrap;
}
}

<V> V querySafe(String method, Map<String, Object> parameters, QuerySafe<V> query) {
asked(method, parameters);
V value = query.query(parameters);
succeeded(method, parameters, value);
return value;
}

<V> void command(String method, Map<String, Object> parameters, Command command) throws SVNConnectorException {
asked(method, parameters);
try {
command.command(parameters);
succeeded(method, parameters, null);//oh, no! we need to change this interface
} catch (ClientException ex) {
SVNConnectorException wrap = wrap(ex);
failed(method, parameters, wrap);
throw wrap;
}
}

<V> 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);
}
}

private void succeeded(String method, Map<String, Object> parameters, Object value) {
for (ISVNCallListener listener : listeners) {
listener.succeeded(method, parameters, value);
}
}

private void failed(String method, Map<String, Object> parameters, SVNConnectorException exception) {
for (ISVNCallListener listener : listeners) {
listener.failed(method, parameters, exception);
}
}

private SVNConnectorException wrap(ClientException ex) {
if (authenticationFailure(ex)) {
return new SVNConnectorAuthenticationException(ex.getMessage(), ex);
}
if (wasCancelled(ex)) {
return new SVNConnectorCancelException(ex.getMessage(), ex);
}
if (unresolvedConflict(ex)) {
return new SVNConnectorUnresolvedConflictException(ex.getMessage(), ex);
}
return new SVNConnectorException(ex.getMessage(), ex.getAprError(), ex);
}

private boolean authenticationFailure(ClientException t) {
return t.getAprError() == SVNErrorCodes.raNotAuthorized;
}

private boolean wasCancelled(ClientException t) {
return t.getAprError() == SVNErrorCodes.cancelled;
}

private boolean unresolvedConflict(ClientException t) {
return t.getAprError() == SVNErrorCodes.fsConflict || t.getAprError() == SVNErrorCodes.fsTxnOutOfDate;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) ArSysOp 2020-2024
*
* ArSysOp and its affiliates make no warranty of any kind
* with regard to this material.
*
* ArSysOp expressly disclaims all warranties as to the material, express,
* and implied, including but not limited to the implied warranties of
* merchantability, fitness for a particular purpose and non-infringement of third
* party rights.
*
* In no event shall ArSysOp be liable to you or any other person for any damages,
* including, without limitation, any direct, indirect, incidental or consequential
* damages, expenses, lost profits, lost data or other damages arising out of the use,
* misuse or inability to use the material and any derived software, even if ArSysOp,
* its affiliate or an authorized dealer has been advised of the possibility of such damages.
*
*/

package ru.arsysop.svn.connector.internal.svnkit1_10;


@FunctionalInterface
interface Cancel {

void cancel() throws Exception;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) ArSysOp 2020-2024
*
* ArSysOp and its affiliates make no warranty of any kind
* with regard to this material.
*
* ArSysOp expressly disclaims all warranties as to the material, express,
* and implied, including but not limited to the implied warranties of
* merchantability, fitness for a particular purpose and non-infringement of third
* party rights.
*
* In no event shall ArSysOp be liable to you or any other person for any damages,
* including, without limitation, any direct, indirect, incidental or consequential
* damages, expenses, lost profits, lost data or other damages arising out of the use,
* misuse or inability to use the material and any derived software, even if ArSysOp,
* its affiliate or an authorized dealer has been advised of the possibility of such damages.
*
*/

package ru.arsysop.svn.connector.internal.svnkit1_10;

import java.util.Map;

import org.apache.subversion.javahl.ClientException;

@FunctionalInterface
public interface Command {

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) ArSysOp 2020-2024
*
* ArSysOp and its affiliates make no warranty of any kind
* with regard to this material.
*
* ArSysOp expressly disclaims all warranties as to the material, express,
* and implied, including but not limited to the implied warranties of
* merchantability, fitness for a particular purpose and non-infringement of third
* party rights.
*
* In no event shall ArSysOp be liable to you or any other person for any damages,
* including, without limitation, any direct, indirect, incidental or consequential
* damages, expenses, lost profits, lost data or other damages arising out of the use,
* misuse or inability to use the material and any derived software, even if ArSysOp,
* its affiliate or an authorized dealer has been advised of the possibility of such damages.
*
*/

package ru.arsysop.svn.connector.internal.svnkit1_10;

import java.util.Map;

@FunctionalInterface
public interface CommandSafe {

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) ArSysOp 2020-2024
*
* ArSysOp and its affiliates make no warranty of any kind
* with regard to this material.
*
* ArSysOp expressly disclaims all warranties as to the material, express,
* and implied, including but not limited to the implied warranties of
* merchantability, fitness for a particular purpose and non-infringement of third
* party rights.
*
* In no event shall ArSysOp be liable to you or any other person for any damages,
* including, without limitation, any direct, indirect, incidental or consequential
* damages, expenses, lost profits, lost data or other damages arising out of the use,
* misuse or inability to use the material and any derived software, even if ArSysOp,
* its affiliate or an authorized dealer has been advised of the possibility of such damages.
*
*/

package ru.arsysop.svn.connector.internal.svnkit1_10;

import java.util.Map;

import org.apache.subversion.javahl.ClientException;

@FunctionalInterface
public interface Query<V> {

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) ArSysOp 2020-2024
*
* ArSysOp and its affiliates make no warranty of any kind
* with regard to this material.
*
* ArSysOp expressly disclaims all warranties as to the material, express,
* and implied, including but not limited to the implied warranties of
* merchantability, fitness for a particular purpose and non-infringement of third
* party rights.
*
* In no event shall ArSysOp be liable to you or any other person for any damages,
* including, without limitation, any direct, indirect, incidental or consequential
* damages, expenses, lost profits, lost data or other damages arising out of the use,
* misuse or inability to use the material and any derived software, even if ArSysOp,
* its affiliate or an authorized dealer has been advised of the possibility of such damages.
*
*/

package ru.arsysop.svn.connector.internal.svnkit1_10;

import java.util.Map;

@FunctionalInterface
public interface QuerySafe<V> {

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
package ru.arsysop.svn.connector.internal.svnkit1_10;

import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -53,50 +55,73 @@
import org.eclipse.team.svn.core.connector.SVNRevision;
import org.eclipse.team.svn.core.connector.SVNRevisionRange;
import org.eclipse.team.svn.core.connector.configuration.ISVNConfigurationEventHandler;
import org.tmatesoft.svn.core.internal.wc.SVNFileUtil;
import org.tmatesoft.svn.core.javahl17.SVNClientImpl;

//TODO
final class SvnKit1_10Connector implements ISVNConnector {

private final CallWatch watch = new CallWatch();
private final SVNClientImpl client;
//FIXME: AF: not sure why do we need this
private final List<ISVNConfigurationEventHandler> handlers = new ArrayList<>();

public SvnKit1_10Connector() {
SVNFileUtil.setSleepForTimestamp(false);// not time to relax
client = SVNClientImpl.newInstance();
//FIXME: AF: not yet
// client.notification2(new ClientNotifyCallbackAdapter(watch.notifications));
}

@Override
public void addCallListener(ISVNCallListener listener) {
//TODO
watch.addListener(listener);
}

@Override
public void removeCallListener(ISVNCallListener listener) {
//TODO
watch.removeListener(listener);
}

@Override
public String getConfigDirectory() throws SVNConnectorException {
//TODO
return null;
return watch.query(ISVNCallListener.GET_CONFIG_DIRECTORY, //
Collections.emptyMap(), //
p -> client.getConfigDirectory());
}

@Override
public void setConfigDirectory(String configDir) throws SVNConnectorException {
//TODO
public void setConfigDirectory(String directory) throws SVNConnectorException {
watch.command(ISVNCallListener.SET_CONFIG_DIRECTORY, //
Map.of("configDir", directory), // //$NON-NLS-1$
p -> client.setConfigDirectory(directory));
}

@Override
public void setConfigurationEventHandler(ISVNConfigurationEventHandler configHandler) throws SVNConnectorException {
//TODO
public void setConfigurationEventHandler(ISVNConfigurationEventHandler handler) throws SVNConnectorException {
handlers.clear();
watch.commandSafe(ISVNCallListener.SET_CONFIGURATION_EVENT_HANDLER, //
Map.of("configHandler", handler), //$NON-NLS-1$
p -> handlers.add(handler));
}

@Override
public ISVNConfigurationEventHandler getConfigurationEventHandler() throws SVNConnectorException {
//TODO
return null;
return watch.querySafe(ISVNCallListener.GET_CONFIGURATION_EVENT_HANDLER, //
Collections.emptyMap(),
p -> handlers.stream().findAny().orElse(null));
}

@Override
public void setUsername(String username) {
//TODO
Map<String, Object> parameters = Map.of("username", username); //$NON-NLS-1$
watch.commandSafe(ISVNCallListener.SET_USERNAME, parameters, p -> client.username(username));
}

@Override
public void setPassword(String password) {
//TODO
Map<String, Object> parameters = Map.of("password", password); //$NON-NLS-1$
watch.commandSafe(ISVNCallListener.SET_PASSWORD, parameters, p -> client.username(password));
}

@Override
Expand Down Expand Up @@ -462,7 +487,7 @@ public void vacuum(String path, long options, ISVNProgressMonitor monitor) throw

@Override
public void dispose() {
//TODO
client.dispose();
}

}
Loading
Loading