-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* introduce `Nullable` adapters * move JavaHL -> Subversive adapters to a dedicated package * move Subversive -> JavaHL adapters to a dedicated package
- Loading branch information
1 parent
7da68f1
commit 7b268c6
Showing
22 changed files
with
578 additions
and
42 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
....connector.svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/SvnNullableAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
...nector.svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/SvnNullableConstructor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...svnkit1_10/src/ru/arsysop/svn/connector/internal/adapt/jhlsv/ChecksumNullableAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
.../src/ru/arsysop/svn/connector/internal/adapt/jhlsv/ConflictDescriptorNullableAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
Oops, something went wrong.