experimenting with maverick synergy

This commit is contained in:
Jörg Prante 2024-05-24 17:59:07 +02:00
parent 1f52dedf13
commit 5c18f0704f
19 changed files with 125 additions and 144 deletions

View file

@ -1,5 +1,4 @@
dependencies {
api project(':files-api')
api libs.maverick.synergy.client
testImplementation libs.net.security
}

View file

@ -0,0 +1,12 @@
import org.xbib.files.jadaptive.sftp.SftpFileSystemProvider;
import java.nio.file.spi.FileSystemProvider;
module org.xbib.files.jadaptive.sftp {
requires java.logging;
requires org.xbib.files;
requires com.sshtools.maverick.base;
requires com.sshtools.synergy.common;
requires com.sshtools.synergy.client;
provides FileSystemProvider with SftpFileSystemProvider;
}

View file

@ -0,0 +1,20 @@
package org.xbib.files.jadaptive.sftp;
import java.io.Closeable;
import java.io.IOException;
import java.net.URI;
import java.util.Map;
public class SftpContext implements Closeable {
SftpFileSystemProvider provider;
SftpFileSystem fileSystem;
public SftpContext(URI uri, Map<String, ?> env) throws IOException {
}
@Override
public void close() throws IOException {
}
}

View file

@ -1,4 +1,4 @@
package org.xbib.files.sftp.jadaptive.fs.spi;
package org.xbib.files.jadaptive.sftp;
import org.xbib.files.FileService;
import org.xbib.files.FileWalker;
@ -33,7 +33,7 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;
public class SFTPFileService implements FileService {
public class SftpFileService implements FileService {
private static final int BUFFER_SIZE = 128 * 1024;
@ -47,7 +47,7 @@ public class SFTPFileService implements FileService {
private final Map<String, ?> env;
public SFTPFileService(URI uri, Map<String, ?> env) {
public SftpFileService(URI uri, Map<String, ?> env) {
this.uri = uri;
this.env = env;
}
@ -303,31 +303,31 @@ public class SFTPFileService implements FileService {
@Override
public DirectoryStream<Path> stream(String path, String glob) throws IOException {
SFTPContext ctx = new SFTPContext(uri, env);
SftpContext ctx = new SftpContext(uri, env);
return new WrappedDirectoryStream<>(ctx, Files.newDirectoryStream(ctx.fileSystem.getPath(path), glob));
}
@Override
public DirectoryStream<Path> stream(String path, DirectoryStream.Filter<Path> filter) throws IOException {
SFTPContext ctx = new SFTPContext(uri, env);
SftpContext ctx = new SftpContext(uri, env);
return new WrappedDirectoryStream<>(ctx, Files.newDirectoryStream(ctx.fileSystem.getPath(path), filter));
}
@Override
public Stream<Path> list(String path) throws IOException {
SFTPContext ctx = new SFTPContext(uri, env);
SftpContext ctx = new SftpContext(uri, env);
return FileWalker.list(new WrappedDirectoryStream<>(ctx, Files.newDirectoryStream(ctx.fileSystem.getPath(path))));
}
@Override
public Stream<Path> walk(String path, FileVisitOption... options) throws IOException {
SFTPContext ctx = new SFTPContext(uri, env);
SftpContext ctx = new SftpContext(uri, env);
return FileWalker.walk(ctx, ctx.fileSystem.getPath(path), Integer.MAX_VALUE, options);
}
@Override
public Stream<Path> walk(String path, int maxdepth, FileVisitOption... options) throws IOException {
SFTPContext ctx = new SFTPContext(uri, env);
SftpContext ctx = new SftpContext(uri, env);
return FileWalker.walk(ctx, ctx.fileSystem.getPath(path), maxdepth, options);
}
@ -357,7 +357,7 @@ public class SFTPFileService implements FileService {
});
}
private void doUpload(SFTPContext ctx,
private void doUpload(SftpContext ctx,
ReadableByteChannel source,
Path target,
Set<PosixFilePermission> dirPerms,
@ -367,19 +367,19 @@ public class SFTPFileService implements FileService {
transfer(source, ctx.provider.newByteChannel(target, prepareWriteOptions(copyOptions)));
}
private void download(SFTPContext ctx,
private void download(SftpContext ctx,
Path source,
OutputStream outputStream) throws IOException {
download(ctx, source, Channels.newChannel(outputStream));
}
private void download(SFTPContext ctx,
private void download(SftpContext ctx,
Path source,
WritableByteChannel writableByteChannel) throws IOException {
transfer(ctx.provider.newByteChannel(source, prepareReadOptions()), writableByteChannel);
}
private void download(SFTPContext ctx,
private void download(SftpContext ctx,
Path source,
Path target,
CopyOption... copyOptions) throws IOException {
@ -459,10 +459,10 @@ public class SFTPFileService implements FileService {
}
private <T> T performWithContext(WithContext<T> action) throws IOException {
SFTPContext ctx = null;
SftpContext ctx = null;
try {
if (uri != null) {
ctx = new SFTPContext(uri, env);
ctx = new SftpContext(uri, env);
return action.perform(ctx);
} else {
return null;

View file

@ -1,4 +1,4 @@
package org.xbib.files.sftp.jadaptive.fs.spi;
package org.xbib.files.jadaptive.sftp;
import org.xbib.files.FileService;
import org.xbib.files.FileServiceProvider;
@ -6,10 +6,10 @@ import org.xbib.files.FileServiceProvider;
import java.net.URI;
import java.util.Map;
public class SFTPFileServiceProvider implements FileServiceProvider {
public class SftpFileServiceProvider implements FileServiceProvider {
@Override
public FileService provide(URI uri, Map<String, ?> env) {
return uri.isAbsolute() && uri.getScheme().equals("sftp") ? new SFTPFileService(uri, env) : null;
return uri.isAbsolute() && uri.getScheme().equals("sftp") ? new SftpFileService(uri, env) : null;
}
}

View file

@ -0,0 +1,16 @@
package org.xbib.files.jadaptive.sftp;
import com.sshtools.common.files.nio.AbstractFileNIOFileSystem;
import com.sshtools.common.files.nio.AbstractFileNIOProvider;
import com.sshtools.common.ssh.SshConnection;
import java.net.URI;
public class SftpFileSystem extends AbstractFileNIOFileSystem {
public SftpFileSystem(SshConnection con,
URI uri,
AbstractFileNIOProvider provider) {
super(con, uri, provider);
}
}

View file

@ -0,0 +1,6 @@
package org.xbib.files.jadaptive.sftp;
import com.sshtools.common.files.nio.AbstractFileNIOProvider;
public class SftpFileSystemProvider extends AbstractFileNIOProvider {
}

View file

@ -0,0 +1,8 @@
package org.xbib.files.jadaptive.sftp;
import java.io.IOException;
@FunctionalInterface
interface WithContext<T> {
T perform(SftpContext ctx) throws IOException;
}

View file

@ -0,0 +1 @@
org.xbib.files.jadaptive.sftp.SftpFileSystemProvider

View file

@ -0,0 +1,8 @@
module org.xbib.files.jadaptive.sftp.test {
requires java.logging;
requires transitive org.junit.jupiter.api;
requires org.xbib.files;
requires org.xbib.files.jadaptive.sftp;
exports org.xbib.files.jadaptive.sftp.test;
opens org.xbib.files.jadaptive.sftp.test to org.junit.platform.commons;
}

View file

@ -0,0 +1,30 @@
package org.xbib.files.jadaptive.sftp.test;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
public class SftpFileSystemTest {
private static final Logger logger = Logger.getLogger(SftpFileSystemTest.class.getName());
public SftpFileSystemTest() {
}
@Test
public void testFileSystem() throws IOException {
Map<String, ?> env = Map.of("username", "joerg");
try (FileSystem fileSystem = FileSystems.newFileSystem(URI.create("abfs://alkmene:22"), env)) {
for (Path path : fileSystem.getRootDirectories()) {
logger.log(Level.INFO, "root dir = " + path);
}
}
}
}

View file

@ -0,0 +1,5 @@
handlers=java.util.logging.ConsoleHandler
.level=ALL
java.util.logging.SimpleFormatter.format=%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL %4$-7s [%3$s] %5$s %6$s%n
java.util.logging.ConsoleHandler.level=ALL
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter

View file

@ -1,8 +1,5 @@
handlers=java.util.logging.ConsoleHandler,java.util.logging.FileHandler
handlers=java.util.logging.ConsoleHandler
.level=ALL
java.util.logging.SimpleFormatter.format=%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL %4$-7s [%3$s] %5$s %6$s%n
java.util.logging.ConsoleHandler.level=ALL
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.FileHandler.level=INFO
java.util.logging.FileHandler.pattern=build/test.log
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter

View file

@ -1,3 +0,0 @@
module org.xbib.files.sftp.jadaptive.fs {
requires org.xbib.files;
}

View file

@ -1,74 +0,0 @@
package org.xbib.files.sftp.jadaptive.fs;
import java.io.IOException;
import java.nio.file.FileStore;
import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.WatchService;
import java.nio.file.attribute.UserPrincipalLookupService;
import java.nio.file.spi.FileSystemProvider;
import java.util.Set;
public class SftpFileSystem extends FileSystem {
@Override
public FileSystemProvider provider() {
return null;
}
@Override
public void close() throws IOException {
}
@Override
public boolean isOpen() {
return false;
}
@Override
public boolean isReadOnly() {
return false;
}
@Override
public String getSeparator() {
return "";
}
@Override
public Iterable<Path> getRootDirectories() {
return null;
}
@Override
public Iterable<FileStore> getFileStores() {
return null;
}
@Override
public Set<String> supportedFileAttributeViews() {
return Set.of();
}
@Override
public Path getPath(String s, String... strings) {
return null;
}
@Override
public PathMatcher getPathMatcher(String s) {
return null;
}
@Override
public UserPrincipalLookupService getUserPrincipalLookupService() {
return null;
}
@Override
public WatchService newWatchService() throws IOException {
return null;
}
}

View file

@ -1,14 +0,0 @@
package org.xbib.files.sftp.jadaptive.fs;
import java.nio.channels.ByteChannel;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.util.Set;
public class SftpFileSystemProvider {
public ByteChannel newByteChannel(Path path, Set<? extends OpenOption> options) {
return null;
}
}

View file

@ -1,23 +0,0 @@
package org.xbib.files.sftp.jadaptive.fs.spi;
import org.xbib.files.sftp.jadaptive.fs.SftpFileSystem;
import org.xbib.files.sftp.jadaptive.fs.SftpFileSystemProvider;
import java.io.Closeable;
import java.io.IOException;
import java.net.URI;
import java.util.Map;
public class SFTPContext implements Closeable {
SftpFileSystemProvider provider;
SftpFileSystem fileSystem;
public SFTPContext(URI uri, Map<String, ?> env) throws IOException {
}
@Override
public void close() throws IOException {
}
}

View file

@ -1,7 +0,0 @@
package org.xbib.files.sftp.jadaptive.fs.spi;
import java.io.IOException;
interface WithContext<T> {
T perform(SFTPContext ctx) throws IOException;
}

View file

@ -42,6 +42,6 @@ include 'files-ftp-fs'
include 'files-ftp-mock'
include 'files-sftp'
include 'files-sftp-fs'
include 'files-sftp-jadaptive-fs'
include 'files-jadaptive-sftp'
include 'files-webdav'
include 'files-webdav-fs'