diff --git a/files-sftp-jadaptive-fs/build.gradle b/files-jadaptive-sftp/build.gradle similarity index 67% rename from files-sftp-jadaptive-fs/build.gradle rename to files-jadaptive-sftp/build.gradle index 3fa236c..53dc5a8 100644 --- a/files-sftp-jadaptive-fs/build.gradle +++ b/files-jadaptive-sftp/build.gradle @@ -1,5 +1,4 @@ dependencies { api project(':files-api') api libs.maverick.synergy.client - testImplementation libs.net.security } diff --git a/files-jadaptive-sftp/src/main/java/module-info.java b/files-jadaptive-sftp/src/main/java/module-info.java new file mode 100644 index 0000000..41710b2 --- /dev/null +++ b/files-jadaptive-sftp/src/main/java/module-info.java @@ -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; +} diff --git a/files-jadaptive-sftp/src/main/java/org/xbib/files/jadaptive/sftp/SftpContext.java b/files-jadaptive-sftp/src/main/java/org/xbib/files/jadaptive/sftp/SftpContext.java new file mode 100644 index 0000000..7cdd9f2 --- /dev/null +++ b/files-jadaptive-sftp/src/main/java/org/xbib/files/jadaptive/sftp/SftpContext.java @@ -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 env) throws IOException { + } + + @Override + public void close() throws IOException { + } +} diff --git a/files-sftp-jadaptive-fs/src/main/java/org/xbib/files/sftp/jadaptive/fs/spi/SFTPFileService.java b/files-jadaptive-sftp/src/main/java/org/xbib/files/jadaptive/sftp/SftpFileService.java similarity index 96% rename from files-sftp-jadaptive-fs/src/main/java/org/xbib/files/sftp/jadaptive/fs/spi/SFTPFileService.java rename to files-jadaptive-sftp/src/main/java/org/xbib/files/jadaptive/sftp/SftpFileService.java index cb24e03..8547cf5 100644 --- a/files-sftp-jadaptive-fs/src/main/java/org/xbib/files/sftp/jadaptive/fs/spi/SFTPFileService.java +++ b/files-jadaptive-sftp/src/main/java/org/xbib/files/jadaptive/sftp/SftpFileService.java @@ -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 env; - public SFTPFileService(URI uri, Map env) { + public SftpFileService(URI uri, Map env) { this.uri = uri; this.env = env; } @@ -303,31 +303,31 @@ public class SFTPFileService implements FileService { @Override public DirectoryStream 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 stream(String path, DirectoryStream.Filter 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 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 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 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 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 performWithContext(WithContext 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; diff --git a/files-sftp-jadaptive-fs/src/main/java/org/xbib/files/sftp/jadaptive/fs/spi/SFTPFileServiceProvider.java b/files-jadaptive-sftp/src/main/java/org/xbib/files/jadaptive/sftp/SftpFileServiceProvider.java similarity index 64% rename from files-sftp-jadaptive-fs/src/main/java/org/xbib/files/sftp/jadaptive/fs/spi/SFTPFileServiceProvider.java rename to files-jadaptive-sftp/src/main/java/org/xbib/files/jadaptive/sftp/SftpFileServiceProvider.java index 4f4bb78..5429d7e 100644 --- a/files-sftp-jadaptive-fs/src/main/java/org/xbib/files/sftp/jadaptive/fs/spi/SFTPFileServiceProvider.java +++ b/files-jadaptive-sftp/src/main/java/org/xbib/files/jadaptive/sftp/SftpFileServiceProvider.java @@ -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 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; } } diff --git a/files-jadaptive-sftp/src/main/java/org/xbib/files/jadaptive/sftp/SftpFileSystem.java b/files-jadaptive-sftp/src/main/java/org/xbib/files/jadaptive/sftp/SftpFileSystem.java new file mode 100644 index 0000000..271193f --- /dev/null +++ b/files-jadaptive-sftp/src/main/java/org/xbib/files/jadaptive/sftp/SftpFileSystem.java @@ -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); + } +} diff --git a/files-jadaptive-sftp/src/main/java/org/xbib/files/jadaptive/sftp/SftpFileSystemProvider.java b/files-jadaptive-sftp/src/main/java/org/xbib/files/jadaptive/sftp/SftpFileSystemProvider.java new file mode 100644 index 0000000..dad131a --- /dev/null +++ b/files-jadaptive-sftp/src/main/java/org/xbib/files/jadaptive/sftp/SftpFileSystemProvider.java @@ -0,0 +1,6 @@ +package org.xbib.files.jadaptive.sftp; + +import com.sshtools.common.files.nio.AbstractFileNIOProvider; + +public class SftpFileSystemProvider extends AbstractFileNIOProvider { +} diff --git a/files-jadaptive-sftp/src/main/java/org/xbib/files/jadaptive/sftp/WithContext.java b/files-jadaptive-sftp/src/main/java/org/xbib/files/jadaptive/sftp/WithContext.java new file mode 100644 index 0000000..f8c4fff --- /dev/null +++ b/files-jadaptive-sftp/src/main/java/org/xbib/files/jadaptive/sftp/WithContext.java @@ -0,0 +1,8 @@ +package org.xbib.files.jadaptive.sftp; + +import java.io.IOException; + +@FunctionalInterface +interface WithContext { + T perform(SftpContext ctx) throws IOException; +} diff --git a/files-jadaptive-sftp/src/main/resources/META-INF/services/java.nio.file.spi.FileSystemProvider b/files-jadaptive-sftp/src/main/resources/META-INF/services/java.nio.file.spi.FileSystemProvider new file mode 100644 index 0000000..f492ab7 --- /dev/null +++ b/files-jadaptive-sftp/src/main/resources/META-INF/services/java.nio.file.spi.FileSystemProvider @@ -0,0 +1 @@ +org.xbib.files.jadaptive.sftp.SftpFileSystemProvider \ No newline at end of file diff --git a/files-jadaptive-sftp/src/test/java/module-info.java b/files-jadaptive-sftp/src/test/java/module-info.java new file mode 100644 index 0000000..f3ebf0f --- /dev/null +++ b/files-jadaptive-sftp/src/test/java/module-info.java @@ -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; +} diff --git a/files-jadaptive-sftp/src/test/java/org/xbib/files/jadaptive/sftp/test/SftpFileSystemTest.java b/files-jadaptive-sftp/src/test/java/org/xbib/files/jadaptive/sftp/test/SftpFileSystemTest.java new file mode 100644 index 0000000..67598c7 --- /dev/null +++ b/files-jadaptive-sftp/src/test/java/org/xbib/files/jadaptive/sftp/test/SftpFileSystemTest.java @@ -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 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); + } + } + } +} diff --git a/files-jadaptive-sftp/src/test/resources/logging.properties b/files-jadaptive-sftp/src/test/resources/logging.properties new file mode 100644 index 0000000..c22095e --- /dev/null +++ b/files-jadaptive-sftp/src/test/resources/logging.properties @@ -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 diff --git a/files-sftp-fs/src/test/resources/logging.properties b/files-sftp-fs/src/test/resources/logging.properties index b1f9e8e..c22095e 100644 --- a/files-sftp-fs/src/test/resources/logging.properties +++ b/files-sftp-fs/src/test/resources/logging.properties @@ -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 diff --git a/files-sftp-jadaptive-fs/src/main/java/module-info.java b/files-sftp-jadaptive-fs/src/main/java/module-info.java deleted file mode 100644 index 70abebd..0000000 --- a/files-sftp-jadaptive-fs/src/main/java/module-info.java +++ /dev/null @@ -1,3 +0,0 @@ -module org.xbib.files.sftp.jadaptive.fs { - requires org.xbib.files; -} \ No newline at end of file diff --git a/files-sftp-jadaptive-fs/src/main/java/org/xbib/files/sftp/jadaptive/fs/SftpFileSystem.java b/files-sftp-jadaptive-fs/src/main/java/org/xbib/files/sftp/jadaptive/fs/SftpFileSystem.java deleted file mode 100644 index fd8b5a1..0000000 --- a/files-sftp-jadaptive-fs/src/main/java/org/xbib/files/sftp/jadaptive/fs/SftpFileSystem.java +++ /dev/null @@ -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 getRootDirectories() { - return null; - } - - @Override - public Iterable getFileStores() { - return null; - } - - @Override - public Set 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; - } -} diff --git a/files-sftp-jadaptive-fs/src/main/java/org/xbib/files/sftp/jadaptive/fs/SftpFileSystemProvider.java b/files-sftp-jadaptive-fs/src/main/java/org/xbib/files/sftp/jadaptive/fs/SftpFileSystemProvider.java deleted file mode 100644 index 6b05074..0000000 --- a/files-sftp-jadaptive-fs/src/main/java/org/xbib/files/sftp/jadaptive/fs/SftpFileSystemProvider.java +++ /dev/null @@ -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 options) { - return null; - } - -} diff --git a/files-sftp-jadaptive-fs/src/main/java/org/xbib/files/sftp/jadaptive/fs/spi/SFTPContext.java b/files-sftp-jadaptive-fs/src/main/java/org/xbib/files/sftp/jadaptive/fs/spi/SFTPContext.java deleted file mode 100644 index ff0c866..0000000 --- a/files-sftp-jadaptive-fs/src/main/java/org/xbib/files/sftp/jadaptive/fs/spi/SFTPContext.java +++ /dev/null @@ -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 env) throws IOException { - } - - @Override - public void close() throws IOException { - } -} diff --git a/files-sftp-jadaptive-fs/src/main/java/org/xbib/files/sftp/jadaptive/fs/spi/WithContext.java b/files-sftp-jadaptive-fs/src/main/java/org/xbib/files/sftp/jadaptive/fs/spi/WithContext.java deleted file mode 100644 index 26efd15..0000000 --- a/files-sftp-jadaptive-fs/src/main/java/org/xbib/files/sftp/jadaptive/fs/spi/WithContext.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.xbib.files.sftp.jadaptive.fs.spi; - -import java.io.IOException; - -interface WithContext { - T perform(SFTPContext ctx) throws IOException; -} diff --git a/settings.gradle b/settings.gradle index 1ef6ac5..9c25d81 100644 --- a/settings.gradle +++ b/settings.gradle @@ -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'