Skip to content

Commit

Permalink
[#22] implement getInfo
Browse files Browse the repository at this point in the history
* introduce `Nullable` adapters
* move JavaHL -> Subversive adapters to a dedicated package
* move Subversive -> JavaHL adapters to a dedicated package
  • Loading branch information
ruspl-afed authored and eparovyshnaya committed Feb 15, 2024
1 parent 7da68f1 commit 07811c0
Show file tree
Hide file tree
Showing 22 changed files with 578 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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;

/**
*
* Attention! It accepts <code>null</code> and may return <code>null</code>
*/
public interface SvnNullableAdapter<S, T> extends SvnTypeAdapter<S, T> {

/**
* Attention! It may return <code>null</code>
*/
@Override
T adapt();

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

import java.util.Optional;

/**
*
* They are not kidding, and really transfer <code>null</code>> values here and there
*/
public abstract class SvnNullableConstructor<S, T> implements SvnNullableAdapter<S, T> {

private final Optional<S> optional;

public SvnNullableConstructor(S source) {
optional = Optional.ofNullable(source);
}

@Override
public final T adapt() {
return optional.map(this::adapt).orElse(null);
}

protected abstract T adapt(S source);

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


interface SvnTypeAdapter<S, T> {
public interface SvnTypeAdapter<S, T> {

T adapt();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

import java.util.Objects;

abstract class SvnTypeConstructor<S, T> implements SvnTypeAdapter<S, T> {
public abstract class SvnTypeConstructor<S, T> implements SvnTypeAdapter<S, T> {

protected final S source;

SvnTypeConstructor(S source) {
public SvnTypeConstructor(S source) {
this.source = Objects.requireNonNull(source);
}

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

abstract class SvnTypeMap<S, T> implements SvnTypeAdapter<S, T> {
public abstract class SvnTypeMap<S, T> implements SvnTypeAdapter<S, T> {

private final S source;
private final Map<S, T> map;
Expand All @@ -42,6 +42,6 @@ public final T adapt() {
return Optional.ofNullable(map.get(source)).orElseGet(this::defaults);
}

abstract T defaults();
protected abstract T defaults();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.types.Checksum;
import org.eclipse.team.svn.core.connector.SVNChecksum;
import org.eclipse.team.svn.core.connector.SVNChecksum.Kind;

import ru.arsysop.svn.connector.internal.adapt.SvnNullableConstructor;

public final class ChecksumNullableAdapter extends SvnNullableConstructor<Checksum, SVNChecksum> {

public ChecksumNullableAdapter(Checksum source) {
super(source);
}

@Override
protected SVNChecksum adapt(Checksum checksum) {
return new SVNChecksum(
kind(checksum), //
checksum.getDigest());
}

private Kind kind(Checksum checksum) {
return checksum.getKind() == org.apache.subversion.javahl.types.Checksum.Kind.MD5
? SVNChecksum.Kind.MD5
: SVNChecksum.Kind.SHA1;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* ArSysOp - initial API and implementation
*/

package ru.arsysop.svn.connector.internal.adapt;
package ru.arsysop.svn.connector.internal.adapt.jhlsv;

import java.util.LinkedHashMap;
import java.util.Map;
Expand All @@ -28,6 +28,8 @@
import org.eclipse.team.svn.core.connector.SVNNotification;
import org.eclipse.team.svn.core.connector.SVNNotification.PerformedAction;

import ru.arsysop.svn.connector.internal.adapt.SvnTypeMap;

final class ClientNotifyInformationActionAdapter extends SvnTypeMap<Action, PerformedAction> {

ClientNotifyInformationActionAdapter(Action source) {
Expand Down Expand Up @@ -117,7 +119,7 @@ protected Map<Action, PerformedAction> fill() {
}

@Override
SVNNotification.PerformedAction defaults() {
protected SVNNotification.PerformedAction defaults() {
return SVNNotification.PerformedAction._UNKNOWN_ACTION;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@
* ArSysOp - initial API and implementation
*/

package ru.arsysop.svn.connector.internal.adapt;
package ru.arsysop.svn.connector.internal.adapt.jhlsv;

import org.apache.subversion.javahl.ClientNotifyInformation;
import org.eclipse.team.svn.core.connector.SVNNotification;

final class ClientNotifyInformationAdapter extends SvnTypeConstructor<ClientNotifyInformation, SVNNotification> {
import ru.arsysop.svn.connector.internal.adapt.SvnTypeConstructor;

ClientNotifyInformationAdapter(ClientNotifyInformation source) {
public final class ClientNotifyInformationAdapter extends SvnTypeConstructor<ClientNotifyInformation, SVNNotification> {

public ClientNotifyInformationAdapter(ClientNotifyInformation source) {
super(source);
}

Expand All @@ -37,7 +39,7 @@ public SVNNotification adapt() {
new ClientNotifyInformationActionAdapter(source.getAction()).adapt(), //
new NodeKindAdapter(source.getKind()).adapt(), //
source.getMimeType(), //
new LockAdapter(source.getLock()).adapt(), //
new LockNullableAdapter(source.getLock()).adapt(), //
source.getErrMsg(), //
new ClientNotifyInformationStatusAdapter(source.getContentState()).adapt(), //
new ClientNotifyInformationStatusAdapter(source.getPropState()).adapt(), //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* ArSysOp - initial API and implementation
*/

package ru.arsysop.svn.connector.internal.adapt;
package ru.arsysop.svn.connector.internal.adapt.jhlsv;

import java.util.LinkedHashMap;
import java.util.Map;
Expand All @@ -29,6 +29,8 @@
import org.eclipse.team.svn.core.connector.SVNNotification;
import org.eclipse.team.svn.core.connector.SVNNotification.NodeStatus;

import ru.arsysop.svn.connector.internal.adapt.SvnTypeMap;

final class ClientNotifyInformationStatusAdapter
extends SvnTypeMap<org.apache.subversion.javahl.ClientNotifyInformation.Status, NodeStatus> {

Expand All @@ -51,7 +53,7 @@ protected Map<Status, NodeStatus> fill() {
}

@Override
NodeStatus defaults() {
protected NodeStatus defaults() {
return NodeStatus.UNKNOWN;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* 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 java.util.Optional;

import org.apache.subversion.javahl.ConflictDescriptor;
import org.apache.subversion.javahl.ConflictDescriptor.Operation;
import org.apache.subversion.javahl.ConflictDescriptor.Reason;
import org.eclipse.team.svn.core.connector.SVNConflictDescriptor;

import ru.arsysop.svn.connector.internal.adapt.SvnNullableConstructor;

public final class ConflictDescriptorNullableAdapter
extends SvnNullableConstructor<ConflictDescriptor, SVNConflictDescriptor> {

private Map<ConflictDescriptor.Reason, SVNConflictDescriptor.Reason> reasons;

public ConflictDescriptorNullableAdapter(ConflictDescriptor source) {
super(source);
reasons = new HashMap<>();
reasons.put(org.apache.subversion.javahl.ConflictDescriptor.Reason.edited,
SVNConflictDescriptor.Reason.MODIFIED);
reasons.put(org.apache.subversion.javahl.ConflictDescriptor.Reason.obstructed,
SVNConflictDescriptor.Reason.OBSTRUCTED);
reasons.put(org.apache.subversion.javahl.ConflictDescriptor.Reason.deleted,
SVNConflictDescriptor.Reason.DELETED);
reasons.put(org.apache.subversion.javahl.ConflictDescriptor.Reason.missing,
SVNConflictDescriptor.Reason.MISSING);
reasons.put(org.apache.subversion.javahl.ConflictDescriptor.Reason.unversioned,
SVNConflictDescriptor.Reason.UNVERSIONED);
reasons.put(org.apache.subversion.javahl.ConflictDescriptor.Reason.added, SVNConflictDescriptor.Reason.ADDED);
reasons.put(org.apache.subversion.javahl.ConflictDescriptor.Reason.replaced,
SVNConflictDescriptor.Reason.REPLACED);
reasons.put(org.apache.subversion.javahl.ConflictDescriptor.Reason.moved_away,
SVNConflictDescriptor.Reason.MOVED_AWAY);
reasons.put(org.apache.subversion.javahl.ConflictDescriptor.Reason.moved_here,
SVNConflictDescriptor.Reason.MOVED_HERE);

}

@Override
protected SVNConflictDescriptor adapt(ConflictDescriptor descr) {
return new SVNConflictDescriptor(
descr.getPath(), //
kind(descr.getKind()), //
new NodeKindAdapter(descr.getNodeKind()).adapt(), //
descr.getPropertyName(), //
descr.isBinary(), //
descr.getMIMEType(), //
action(descr.getAction()), //
reason(descr.getReason()), //
operation(descr.getOperation()), //
descr.getBasePath(), //
descr.getTheirPath(), //
descr.getMyPath(), //
descr.getMergedPath(), //
new ConflictVersionNullableAdapter(descr.getSrcLeftVersion()).adapt(),
new ConflictVersionNullableAdapter(descr.getSrcRightVersion()).adapt());
}

private SVNConflictDescriptor.Kind kind(org.apache.subversion.javahl.ConflictDescriptor.Kind kind) {
if (kind == org.apache.subversion.javahl.ConflictDescriptor.Kind.property) {
return SVNConflictDescriptor.Kind.PROPERTIES;
} else if (kind == org.apache.subversion.javahl.ConflictDescriptor.Kind.tree) {
return SVNConflictDescriptor.Kind.TREE;
}
return SVNConflictDescriptor.Kind.CONTENT;
}

private SVNConflictDescriptor.Action action(org.apache.subversion.javahl.ConflictDescriptor.Action tAction) {
SVNConflictDescriptor.Action action = SVNConflictDescriptor.Action.ADD;
if (tAction == org.apache.subversion.javahl.ConflictDescriptor.Action.edit) {
action = SVNConflictDescriptor.Action.MODIFY;
} else if (tAction == org.apache.subversion.javahl.ConflictDescriptor.Action.delete) {
action = SVNConflictDescriptor.Action.DELETE;
} else if (tAction == org.apache.subversion.javahl.ConflictDescriptor.Action.replace) {
action = SVNConflictDescriptor.Action.REPLACE;
}
return action;
}

private SVNConflictDescriptor.Reason reason(Reason reason) {
return Optional.ofNullable(reasons.get(reason)).orElse(SVNConflictDescriptor.Reason.MODIFIED);
}

private SVNConflictDescriptor.Operation operation(Operation operation) {
if (operation == Operation.merge) {
return SVNConflictDescriptor.Operation.MERGE;
} else if (operation == Operation.switched) {
return SVNConflictDescriptor.Operation.SWITCHED;
} else if (operation == Operation.update) {
return SVNConflictDescriptor.Operation.UPDATE;
}
return SVNConflictDescriptor.Operation.NONE;
}

}
Loading

0 comments on commit 07811c0

Please sign in to comment.