From d8bd95376292601d35a7815d5a541c6a1c45921a Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Tue, 27 Feb 2024 19:04:54 +0900 Subject: [PATCH 1/5] [fuse] separate vavi-net-fuse sub module into new independent module vavi-nio-file-fuse --- README.md | 1 + pom.xml | 17 +- vavi-net-fuse/local.properties.sample | 1 - vavi-net-fuse/pom.xml | 153 ------- vavi-net-fuse/readme.md | 26 -- .../ru/serce/jnrfuse/utils/MountUtils.java | 33 -- .../src/main/java/vavi/net/fuse/Fuse.java | 51 --- .../main/java/vavi/net/fuse/FuseProvider.java | 21 - .../vavi/net/fuse/fusejna/FuseJnaFuse.java | 120 ----- .../net/fuse/fusejna/FuseJnaFuseProvider.java | 27 -- .../vavi/net/fuse/fusejna/JavaNioFileFS.java | 424 ------------------ .../fusejna/SingleThreadJavaNioFileFS.java | 188 -------- .../java/vavi/net/fuse/javafs/JavaFSFuse.java | 85 ---- .../net/fuse/javafs/JavaFSFuseProvider.java | 27 -- .../vavi/net/fuse/jnrfuse/JavaNioFileFS.java | 415 ----------------- .../vavi/net/fuse/jnrfuse/JnrFuseFuse.java | 118 ----- .../net/fuse/jnrfuse/JnrFuseFuseProvider.java | 27 -- .../jnrfuse/SingleThreadJavaNioFileFS.java | 190 -------- .../services/vavi.net.fuse.FuseProvider | 3 - vavi-net-fuse/src/test/java/Main2.java | 84 ---- vavi-net-fuse/src/test/java/Main4.java | 112 ----- .../src/test/java/vavi/net/fuse/Base.java | 206 --------- .../src/test/resources/logging.properties | 13 - vavi-nio-file-amazondrive/pom.xml | 4 +- vavi-nio-file-archive/pom.xml | 8 +- vavi-nio-file-flickr/pom.xml | 4 +- vavi-nio-file-gathered/pom.xml | 8 +- vavi-nio-file-googledrive/pom.xml | 8 +- vavi-nio-file-hfs/pom.xml | 8 +- vavi-nio-file-onedrive/pom.xml | 8 +- vavi-nio-file-onedrive3/pom.xml | 8 +- vavi-nio-file-onedrive4/pom.xml | 8 +- vavi-nio-file-vfs/pom.xml | 8 +- 33 files changed, 50 insertions(+), 2364 deletions(-) delete mode 100644 vavi-net-fuse/local.properties.sample delete mode 100644 vavi-net-fuse/pom.xml delete mode 100644 vavi-net-fuse/readme.md delete mode 100644 vavi-net-fuse/src/main/java/ru/serce/jnrfuse/utils/MountUtils.java delete mode 100644 vavi-net-fuse/src/main/java/vavi/net/fuse/Fuse.java delete mode 100644 vavi-net-fuse/src/main/java/vavi/net/fuse/FuseProvider.java delete mode 100644 vavi-net-fuse/src/main/java/vavi/net/fuse/fusejna/FuseJnaFuse.java delete mode 100644 vavi-net-fuse/src/main/java/vavi/net/fuse/fusejna/FuseJnaFuseProvider.java delete mode 100644 vavi-net-fuse/src/main/java/vavi/net/fuse/fusejna/JavaNioFileFS.java delete mode 100644 vavi-net-fuse/src/main/java/vavi/net/fuse/fusejna/SingleThreadJavaNioFileFS.java delete mode 100644 vavi-net-fuse/src/main/java/vavi/net/fuse/javafs/JavaFSFuse.java delete mode 100644 vavi-net-fuse/src/main/java/vavi/net/fuse/javafs/JavaFSFuseProvider.java delete mode 100644 vavi-net-fuse/src/main/java/vavi/net/fuse/jnrfuse/JavaNioFileFS.java delete mode 100644 vavi-net-fuse/src/main/java/vavi/net/fuse/jnrfuse/JnrFuseFuse.java delete mode 100644 vavi-net-fuse/src/main/java/vavi/net/fuse/jnrfuse/JnrFuseFuseProvider.java delete mode 100644 vavi-net-fuse/src/main/java/vavi/net/fuse/jnrfuse/SingleThreadJavaNioFileFS.java delete mode 100644 vavi-net-fuse/src/main/resources/META-INF/services/vavi.net.fuse.FuseProvider delete mode 100644 vavi-net-fuse/src/test/java/Main2.java delete mode 100644 vavi-net-fuse/src/test/java/Main4.java delete mode 100644 vavi-net-fuse/src/test/java/vavi/net/fuse/Base.java delete mode 100644 vavi-net-fuse/src/test/resources/logging.properties diff --git a/README.md b/README.md index 52319265..78871ded 100644 --- a/README.md +++ b/README.md @@ -97,3 +97,4 @@ * https://github.com/mucommander/mucommander * trash,recent * ~~separate vavi-nio-file-commons and merge into vavi-nio-file-base~~ + * separate fuse part (use obsoleted vavi-nio-file -> vavi-nio-file-fuse) diff --git a/pom.xml b/pom.xml index 69e86884..8d1c00a0 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,6 @@ vavi-nio-file-onedrive4 vavi-nio-file-vfs vavi-nio-file-sandbox - vavi-net-fuse @@ -28,6 +27,9 @@ com.github.umjammer 0.0.14v + + com.github.umjammer + 0.0.16 vavi-apps-fuse @@ -115,9 +117,16 @@ - vavi - vavi-net-fuse - 0.1.9 + ${vavi-nio-file-fuse.groupId} + vavi-nio-file-fuse + ${vavi-nio-file-fuse.version} + test + + + + ${vavi-nio-file-fuse.groupId} + vavi-nio-file-fuse + ${vavi-nio-file-fuse.version} test-jar test diff --git a/vavi-net-fuse/local.properties.sample b/vavi-net-fuse/local.properties.sample deleted file mode 100644 index 500a6b7c..00000000 --- a/vavi-net-fuse/local.properties.sample +++ /dev/null @@ -1 +0,0 @@ -fuse.mountPoint=/Users/you/mnt/fuse \ No newline at end of file diff --git a/vavi-net-fuse/pom.xml b/vavi-net-fuse/pom.xml deleted file mode 100644 index 1eec2b1f..00000000 --- a/vavi-net-fuse/pom.xml +++ /dev/null @@ -1,153 +0,0 @@ - - - - 4.0.0 - - - vavi - vavi-apps-fuse - 0.1.9 - - - vavi-net-fuse - - vavi-net-fuse - https://github.com/umjammer/vavi-net-fuse - - https://github.com/umjammer/vavi-net-fuse - - - https://github.com/umjammer/vavi-net-fuse/issues - - - - - local (not on CI) - - - ${basedir}/local.properties - - - env.JITPACK - !true - - - - - - org.codehaus.mojo - properties-maven-plugin - 1.1.0 - - - initialize - - read-project-properties - - - - ${basedir}/local.properties - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.2.2 - - - **/Main4 - - - ${fuse.mountPoint} - - - -Djava.util.logging.config.file=${project.build.testOutputDirectory}/logging.properties - -Djna.library.path=/usr/local/lib - - - - - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 3.3.0 - - - - test-jar - - - - - - - - - - - com.github.umjammer - javafs - 0.1.7v - - - - com.github.umjammer - fuse-jna - 1.0.5v - - - com.github.serceman - jnr-fuse - 0.5.7 - - - - com.github.umjammer - vavi-commons - 1.1.10 - - - - ${vavi-nio-file-base.groupId} - vavi-nio-file-base - - - - org.junit.jupiter - junit-jupiter-api - test - - - org.junit.jupiter - junit-jupiter-engine - test - - - org.junit.platform - junit-platform-commons - test - - - org.junit.jupiter - junit-jupiter-params - test - - - - com.google.jimfs - jimfs - 1.3.0 - test - - - diff --git a/vavi-net-fuse/readme.md b/vavi-net-fuse/readme.md deleted file mode 100644 index c51f7d06..00000000 --- a/vavi-net-fuse/readme.md +++ /dev/null @@ -1,26 +0,0 @@ -# vavi-net-fuse - -integrated fuse filesystem mounter. - -this is the api, implementation is provided as SPI. - -## Providers - -| fs | list | upload | download | copy | move | rm | mkdir | cache | watch | library | -|--------------------|------|--------|----------|------|------|----|-------|-------|-------|---------| -| javafs | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | - | | [javafs](https://github.com/umjammer/javafs) | -| fuse-jna | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | - | | [fuse-jna](https://github.com/EtiennePerot/fuse-jna) | -| jnr-fuse | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | - | | [jnr-fuse](https://github.com/SerCeMan/jnr-fuse) | - -## Workaround - - * if the test goes wrong, update macfuse and reboot the mac - -## TODO - - * ~~https://github.com/cryptomator/fuse-nio-adapter~~ - * spotlight - * https://stackoverflow.com/a/2335565 - * https://wiki.samba.org/index.php/Spotlight_with_Elasticsearch_Backend - * https://gitlab.com/samba-team/samba/-/blob/master/source3/rpcclient/cmd_spotlight.c - * `Path#toFile()` UnsupportedOperationException ... mount fs as fuse then `toFile` \ No newline at end of file diff --git a/vavi-net-fuse/src/main/java/ru/serce/jnrfuse/utils/MountUtils.java b/vavi-net-fuse/src/main/java/ru/serce/jnrfuse/utils/MountUtils.java deleted file mode 100644 index 13c9f34e..00000000 --- a/vavi-net-fuse/src/main/java/ru/serce/jnrfuse/utils/MountUtils.java +++ /dev/null @@ -1,33 +0,0 @@ -package ru.serce.jnrfuse.utils; - -import java.io.IOException; -import java.nio.file.Path; - -import ru.serce.jnrfuse.FuseException; - - -/** - * ad-hoc replacement - */ -public class MountUtils { - - /** - * Perform/force an umount at the provided Path - */ - public static void umount(Path mountPoint) { - String mountPath = mountPoint.toAbsolutePath().toString(); - try { - new ProcessBuilder("fusermount", "-u", "-z", mountPath).start(); - } catch (IOException e) { - try { - new ProcessBuilder("umount", "-f", mountPath).start().waitFor(); - } catch (InterruptedException ie) { - Thread.currentThread().interrupt(); - throw new FuseException("Unable to umount FS", e); - } catch (IOException ioe) { - ioe.addSuppressed(e); - throw new FuseException("Unable to umount FS", ioe); - } - } - } -} diff --git a/vavi-net-fuse/src/main/java/vavi/net/fuse/Fuse.java b/vavi-net-fuse/src/main/java/vavi/net/fuse/Fuse.java deleted file mode 100644 index 6a9aa519..00000000 --- a/vavi-net-fuse/src/main/java/vavi/net/fuse/Fuse.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2020 by Naohide Sano, All rights reserved. - * - * Programmed by Naohide Sano - */ - -package vavi.net.fuse; - -import java.io.Closeable; -import java.io.IOException; -import java.nio.file.FileSystem; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.ServiceLoader; - - -/** - * Fuse. - * - * @author Naohide Sano (umjammer) - * @version 0.00 2020/05/29 umjammer initial version
- */ -public interface Fuse extends Closeable { - - /** */ - String ENV_SINGLE_THREAD = "single_thread"; - - /** should be non-blocking */ - void mount(FileSystem fs, String mountPoint, Map env) throws IOException; - - /** */ - ServiceLoader serviceLoader = ServiceLoader.load(FuseProvider.class); - - /** */ - static Fuse getFuse() { - String className = System.getProperty("vavi.net.fuse.FuseProvider.class", "vavi.net.fuse.fusejna.FuseJnaFuseProvider"); - for (FuseProvider provider : serviceLoader) { - if (provider.getClass().getName().equals(className)) { - return provider.getFuse(); - } - } - throw new NoSuchElementException(className); - } - - /** TODO location */ - static boolean isEnabled(String key, Map map) { - return map.containsKey(key) && (map.get(key) == null || (boolean) map.get(key)); - } -} - -/* */ diff --git a/vavi-net-fuse/src/main/java/vavi/net/fuse/FuseProvider.java b/vavi-net-fuse/src/main/java/vavi/net/fuse/FuseProvider.java deleted file mode 100644 index 3c517248..00000000 --- a/vavi-net-fuse/src/main/java/vavi/net/fuse/FuseProvider.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2020 by Naohide Sano, All rights reserved. - * - * Programmed by Naohide Sano - */ - -package vavi.net.fuse; - - -/** - * Factory. - * - * @author Naohide Sano (umjammer) - * @version 0.00 2020/06/03 umjammer initial version
- */ -public interface FuseProvider { - - Fuse getFuse(); -} - -/* */ diff --git a/vavi-net-fuse/src/main/java/vavi/net/fuse/fusejna/FuseJnaFuse.java b/vavi-net-fuse/src/main/java/vavi/net/fuse/fusejna/FuseJnaFuse.java deleted file mode 100644 index 4e72e018..00000000 --- a/vavi-net-fuse/src/main/java/vavi/net/fuse/fusejna/FuseJnaFuse.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2020 by Naohide Sano, All rights reserved. - * - * Programmed by Naohide Sano - */ - -package vavi.net.fuse.fusejna; - -import java.io.IOException; -import java.nio.file.FileSystem; -import java.nio.file.Paths; -import java.nio.file.attribute.PosixFilePermission; -import java.util.EnumSet; -import java.util.Map; -import java.util.Set; -import java.util.logging.Level; - -import vavi.net.fuse.Fuse; -import vavi.util.Debug; - -import co.paralleluniverse.fuse.TypeMode; -import net.fusejna.FuseException; -import net.fusejna.FuseFilesystem; - - -/** - * JnaFuseFuse. (jna-fuse engine) - * - * @author Naohide Sano (umjammer) - * @version 0.00 2020/05/29 umjammer initial version
- */ -public class FuseJnaFuse implements Fuse { - - /** key for env, no need to specify value */ - public static final String ENV_IGNORE_APPLE_DOUBLE = JavaNioFileFS.ENV_IGNORE_APPLE_DOUBLE; - - /** TODO utility delegate */ - static boolean isEnabled(String key, Map map) { - return Fuse.isEnabled(key, map); - } - - /** */ - private FuseFilesystem fuse; - - @Override - public void mount(FileSystem fs, String mountPoint, Map env) throws IOException { - try { - if (env.containsKey(ENV_SINGLE_THREAD) && (Boolean) env.get(ENV_SINGLE_THREAD)) { - fuse = new SingleThreadJavaNioFileFS(fs, env); -Debug.println("use single thread"); - } else { - fuse = new JavaNioFileFS(fs, env); - } - fuse.mount(Paths.get(mountPoint).toFile(), false); - Runtime.getRuntime().addShutdownHook(new Thread(() -> { try { close(); } catch (Exception e) { e.printStackTrace(); }})); - } catch (FuseException e) { - throw new IOException(e); - } - } - - @Override - public void close() throws IOException { - try { - if (fuse != null) { -Debug.println("unmount..."); - fuse.unmount(); - fuse = null; -Debug.println("unmount done"); - } - } catch (FuseException e) { -Debug.println(Level.WARNING, "unmount: " + e); - throw new IOException(e); - } - } - - /** */ - static boolean[] permissionsToMode(Set permissions) { - boolean[] mode = new boolean[9]; - for (PosixFilePermission px : permissions) { - switch (px) { - case OWNER_READ: mode[0] = true; break; - case OWNER_WRITE: mode[1] = true; break; - case OWNER_EXECUTE: mode[2] = true; break; - case GROUP_READ: mode[3] = true; break; - case GROUP_WRITE: mode[4] = true; break; - case GROUP_EXECUTE: mode[5] = true; break; - case OTHERS_READ: mode[6] = true; break; - case OTHERS_WRITE: mode[7] = true; break; - case OTHERS_EXECUTE: mode[8] = true; break; - } - } - return mode; - } - - /** */ - static Set modeToPermissions(long mode) { - final EnumSet permissions = EnumSet.noneOf(PosixFilePermission.class); - if ((mode & TypeMode.S_IRUSR) != 0) - permissions.add(PosixFilePermission.OWNER_READ); - if ((mode & TypeMode.S_IWUSR) != 0) - permissions.add(PosixFilePermission.OWNER_WRITE); - if ((mode & TypeMode.S_IXUSR) != 0) - permissions.add(PosixFilePermission.OWNER_EXECUTE); - if ((mode & TypeMode.S_IRGRP) != 0) - permissions.add(PosixFilePermission.GROUP_READ); - if ((mode & TypeMode.S_IWGRP) != 0) - permissions.add(PosixFilePermission.GROUP_WRITE); - if ((mode & TypeMode.S_IXGRP) != 0) - permissions.add(PosixFilePermission.GROUP_EXECUTE); - if ((mode & TypeMode.S_IROTH) != 0) - permissions.add(PosixFilePermission.OTHERS_READ); - if ((mode & TypeMode.S_IWOTH) != 0) - permissions.add(PosixFilePermission.OTHERS_WRITE); - if ((mode & TypeMode.S_IXOTH) != 0) - permissions.add(PosixFilePermission.OTHERS_EXECUTE); - return permissions; - } -} - -/* */ diff --git a/vavi-net-fuse/src/main/java/vavi/net/fuse/fusejna/FuseJnaFuseProvider.java b/vavi-net-fuse/src/main/java/vavi/net/fuse/fusejna/FuseJnaFuseProvider.java deleted file mode 100644 index 648c6acb..00000000 --- a/vavi-net-fuse/src/main/java/vavi/net/fuse/fusejna/FuseJnaFuseProvider.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2020 by Naohide Sano, All rights reserved. - * - * Programmed by Naohide Sano - */ - -package vavi.net.fuse.fusejna; - -import vavi.net.fuse.Fuse; -import vavi.net.fuse.FuseProvider; - - -/** - * FuseJnaFuseProvider. - * - * @author Naohide Sano (umjammer) - * @version 0.00 2020/06/03 umjammer initial version
- */ -public class FuseJnaFuseProvider implements FuseProvider { - - @Override - public Fuse getFuse() { - return new FuseJnaFuse(); - } -} - -/* */ diff --git a/vavi-net-fuse/src/main/java/vavi/net/fuse/fusejna/JavaNioFileFS.java b/vavi-net-fuse/src/main/java/vavi/net/fuse/fusejna/JavaNioFileFS.java deleted file mode 100644 index 0feef461..00000000 --- a/vavi-net-fuse/src/main/java/vavi/net/fuse/fusejna/JavaNioFileFS.java +++ /dev/null @@ -1,424 +0,0 @@ -/* - * Copyright (c) 2016 by Naohide Sano, All rights reserved. - * - * Programmed by Naohide Sano - */ - -package vavi.net.fuse.fusejna; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.channels.Channel; -import java.nio.channels.NonWritableChannelException; -import java.nio.channels.SeekableByteChannel; -import java.nio.file.AccessDeniedException; -import java.nio.file.FileStore; -import java.nio.file.FileSystem; -import java.nio.file.LinkOption; -import java.nio.file.NoSuchFileException; -import java.nio.file.OpenOption; -import java.nio.file.StandardOpenOption; -import java.nio.file.attribute.BasicFileAttributes; -import java.nio.file.attribute.PosixFileAttributeView; -import java.nio.file.attribute.PosixFileAttributes; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicLong; -import java.util.logging.Level; - -import vavi.net.fuse.Fuse; -import vavi.nio.file.Util; -import vavi.util.Debug; - -import jnr.constants.platform.Errno; -import net.fusejna.DirectoryFiller; -import net.fusejna.ErrorCodes; -import net.fusejna.StructFuseFileInfo.FileInfoWrapper; -import net.fusejna.StructStat.StatWrapper; -import net.fusejna.StructStatvfs.StatvfsWrapper; -import net.fusejna.types.TypeMode.ModeWrapper; -import net.fusejna.types.TypeMode.NodeType; -import net.fusejna.util.FuseFilesystemAdapterAssumeImplemented; - - -/** - * JavaNioFileFS. (fuse-jna) - * - * @author Naohide Sano (umjammer) - * @version 0.00 2016/02/29 umjammer initial version
- */ -class JavaNioFileFS extends FuseFilesystemAdapterAssumeImplemented { - - /** */ - protected transient FileSystem fileSystem; - - /** key for env, no need to specify value */ - static final String ENV_IGNORE_APPLE_DOUBLE = "noappledouble"; - - /** */ - private final AtomicLong fileHandle = new AtomicLong(0); - - /** */ - private final ConcurrentMap fileHandles = new ConcurrentHashMap<>(); - - protected boolean ignoreAppleDouble; - - /** - * @param fileSystem a file system to wrap by fuse - */ - public JavaNioFileFS(FileSystem fileSystem, Map env) { - this.fileSystem = fileSystem; - ignoreAppleDouble = FuseJnaFuse.isEnabled(ENV_IGNORE_APPLE_DOUBLE, env); -Debug.println(Level.FINE, "ENV_IGNORE_APPLE_DOUBLE: " + ignoreAppleDouble); - } - - @Override - public int access(final String path, final int access) { -Debug.println(Level.FINER, "access: " + path); - try { - // TODO access - fileSystem.provider().checkAccess(fileSystem.getPath(path)); - return 0; - } catch (NoSuchFileException e) { - return -ErrorCodes.ENOENT(); - } catch (AccessDeniedException e) { -Debug.println(e); - return -ErrorCodes.EACCES(); - } catch (IOException e) { -Debug.printStackTrace(e); - return -ErrorCodes.EACCES(); - } - } - - @Override - public int create(final String path, final ModeWrapper mode, final FileInfoWrapper info) { -Debug.println(Level.FINE, "create: " + path); - try { - Set options = new HashSet<>(); - options.add(StandardOpenOption.WRITE); - options.add(StandardOpenOption.CREATE_NEW); - SeekableByteChannel channel = fileSystem.provider().newByteChannel(fileSystem.getPath(path), options); - long fh = fileHandle.incrementAndGet(); - fileHandles.put(fh, channel); - info.fh(fh); - - return 0; - } catch (IOException e) { -Debug.printStackTrace(e); - return -ErrorCodes.EIO(); - } - } - - @Override - public int getattr(final String path, final StatWrapper stat) { -Debug.println(Level.FINER, "getattr: " + path); - try { - BasicFileAttributes attributes = - fileSystem.provider().readAttributes(fileSystem.getPath(path), BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS); - - if (attributes instanceof PosixFileAttributes) { - boolean[] m = FuseJnaFuse.permissionsToMode(((PosixFileAttributes) attributes).permissions()); - if (attributes.isDirectory()) { - stat.setMode(NodeType.DIRECTORY, m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8]) - .setAllTimesSec(attributes.lastModifiedTime().to(TimeUnit.SECONDS)); - } else { - stat.setMode(NodeType.FILE, m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8]) - .setAllTimesSec(attributes.lastModifiedTime().to(TimeUnit.SECONDS)) - .size(attributes.size()); - } - } else { - if (attributes.isDirectory()) { - stat.setMode(NodeType.DIRECTORY, true, true, true, true, false, true, true, false, true) - .setAllTimesSec(attributes.lastModifiedTime().to(TimeUnit.SECONDS)); - } else { - stat.setMode(NodeType.FILE, true, true, false, true, false, false, true, false, false) - .setAllTimesSec(attributes.lastModifiedTime().to(TimeUnit.SECONDS)) - .size(attributes.size()); - } - } - return 0; - } catch (NoSuchFileException e) { - if (e.getMessage().startsWith("ignore apple double file:")) { -Debug.println(Level.FINE, e.getMessage()); - return 0; - } else { - if (ignoreAppleDouble) { - if (Util.isAppleDouble(path)) { -Debug.println(Level.FINER, e.getMessage()); - } else { -Debug.println(Level.FINE, e); - } - } - return -ErrorCodes.ENOENT(); - } - } catch (IOException e) { -Debug.printStackTrace(e); - return -ErrorCodes.EIO(); - } - } - - @Override - public int fgetattr(final String path, final StatWrapper stat, final FileInfoWrapper info) - { -Debug.println(Level.FINE, "fgetattr: " + path); - return getattr(path, stat); - } - - @Override - public int mkdir(final String path, final ModeWrapper mode) { -Debug.println(Level.FINE, "mkdir: " + path); - try { - fileSystem.provider().createDirectory(fileSystem.getPath(path)); - return 0; - } catch (IOException e) { -Debug.printStackTrace(e); - return -ErrorCodes.EIO(); - } - } - - @Override - public int open(final String path, final FileInfoWrapper info) { -Debug.println(Level.FINE, "open: " + path); - try { - Set options = new HashSet<>(); - options.add(StandardOpenOption.READ); - SeekableByteChannel channel = fileSystem.provider().newByteChannel(fileSystem.getPath(path), options); - long fh = fileHandle.incrementAndGet(); - fileHandles.put(fh, channel); - info.fh(fh); - - return 0; - } catch (IOException e) { -Debug.printStackTrace(e); - return -ErrorCodes.EIO(); - } - } - - /** why not defined? */ - private static final int O_NONBLOCK = 04000; - - @Override - public int read(final String path, final ByteBuffer buffer, final long size, final long offset, final FileInfoWrapper info) { -Debug.println(Level.FINE, "read: " + path + ", " + offset + ", " + size + ", " + info.fh()); - try { - if (fileHandles.containsKey(info.fh())) { - SeekableByteChannel channel = fileHandles.get(info.fh()); - if (info.nonseekable()) { - assert offset == channel.position(); - } else { - channel.position(offset); - } - int n = channel.read(buffer); - if (n > 0) { - if ((info.flags() & O_NONBLOCK) != 0) { - assert n <= 0 || n == size; - } else { - int c; - while (n < size) { - if ((c = channel.read(buffer)) <= 0) - break; - n += c; - } - } -Debug.println(Level.FINE, "read: " + n); - return n; - } else { -Debug.println(Level.FINE, "read: 0"); - return 0; // we did not read any bytes - } - } else { - return -ErrorCodes.EEXIST(); - } - } catch (IOException e) { -Debug.printStackTrace(e); - return -ErrorCodes.EIO(); - } - } - - @Override - public int readdir(final String path, final DirectoryFiller filler) { -Debug.println(Level.FINE, "readdir: " + path); - try { - fileSystem.provider().newDirectoryStream(fileSystem.getPath(path), p -> true) - .forEach(p -> { - try { - filler.add(Util.toFilenameString(p)); - } catch (IOException e) { - throw new IllegalStateException(e); - } - }); - return 0; - } catch (IOException e) { -Debug.printStackTrace(e); - return -ErrorCodes.EIO(); - } - } - - @Override - public int rename(final String path, final String newName) { -Debug.println(Level.FINE, "rename: " + path); - try { - fileSystem.provider().move(fileSystem.getPath(path), fileSystem.getPath(newName)); - return 0; - } catch (IOException e) { -Debug.printStackTrace(e); - return -ErrorCodes.EIO(); - } - } - - @Override - public int rmdir(final String path) { -Debug.println(Level.FINE, "rmdir: " + path); - try { - fileSystem.provider().delete(fileSystem.getPath(path)); - return 0; - } catch (IOException e) { -Debug.printStackTrace(e); - return -ErrorCodes.EIO(); - } - } - - @Override - public int truncate(final String path, final long offset) { -Debug.println(Level.FINE, "truncate: " + path); - // TODO - return -ErrorCodes.ENOSYS(); - } - - @Override - public int unlink(final String path) { -Debug.println(Level.FINE, "unlink: " + path); - try { - fileSystem.provider().delete(fileSystem.getPath(path)); - return 0; - } catch (IOException e) { -Debug.printStackTrace(e); - return -ErrorCodes.EIO(); - } - } - - @Override - public int write(final String path, - final ByteBuffer buf, - final long size, - final long offset, - final FileInfoWrapper info) { -Debug.println(Level.FINE, "write: " + path + ", " + offset + ", " + size + ", " + info.fh()); - try { - if (fileHandles.containsKey(info.fh())) { - SeekableByteChannel channel = fileHandles.get(info.fh()); - if (!info.append() && !info.nonseekable()) { - try { // TODO ad-hoc - channel.position(offset); - } catch (IOException e) { - if (e.getMessage().contains("@vavi")) { - long o = Long.parseLong(e.getMessage().substring(9, e.getMessage().length() - 1)); - if (offset > o) { - Debug.println(Level.SEVERE, "write: skip bad position: " + offset); - throw new IOException("cannot skip last bytes send", e); - } else { - Debug.println(Level.WARNING, "write: correct bad position: " + offset + " -> " + o); - return Math.min((int) (o - offset), (int) size); - } - } else { - throw e; - } - } - } - int n = channel.write(buf); - if (n > 0) { - if ((info.flags() & O_NONBLOCK) != 0) { - assert n <= 0 || n == size; - } else { - int c; - while (n < size) { - if ((c = channel.write(buf)) <= 0) { - break; - } - n += c; - } - } - } - return n; - } else { - return -ErrorCodes.EEXIST(); - } - } catch (NonWritableChannelException e) { -Debug.println(Level.FINER, "NonWritableChannelException: unmounting?"); - return -ErrorCodes.EIO(); - } catch (IOException e) { -Debug.printStackTrace(e); - return -ErrorCodes.EIO(); - } - } - - @Override - public int statfs(final String path, final StatvfsWrapper stat) { -Debug.println(Level.FINER, "statfs: " + path); - try { - FileStore fileStore = fileSystem.getFileStores().iterator().next(); -//Debug.println("total: " + fileStore.getTotalSpace()); -//Debug.println("free: " + fileStore.getUsableSpace()); - - long blockSize = 512; - - long total = fileStore.getTotalSpace() / blockSize; - long free = fileStore.getUsableSpace() / blockSize; - long used = total - free; - - stat.bavail(used); - stat.bfree(free); - stat.blocks(total); - stat.bsize(blockSize); - stat.favail(-1); - stat.ffree(-1); - stat.files(-1); - stat.frsize(1); - - return 0; - } catch (IOException e) { -Debug.printStackTrace(e); - return -ErrorCodes.EIO(); - } - } - - @Override - public int release(final String path, final FileInfoWrapper info) { -Debug.println(Level.FINE, "release: " + path); - try { - if (fileHandles.containsKey(info.fh())) { - Channel channel = fileHandles.get(info.fh()); - channel.close(); - return 0; - } else { - return -ErrorCodes.EEXIST(); - } - } catch (IOException e) { -Debug.println(e); - return -ErrorCodes.EIO(); - } finally { - fileHandles.remove(info.fh()); - } - } - - @Override - public int chmod(String path, ModeWrapper mode) { -Debug.println(Level.FINE, "chmod: " + path); - try { - if (fileSystem.provider().getFileStore(fileSystem.getPath(path)).supportsFileAttributeView(PosixFileAttributeView.class)) { - PosixFileAttributeView attrs = fileSystem.provider().getFileAttributeView(fileSystem.getPath(path), PosixFileAttributeView.class); - attrs.setPermissions(FuseJnaFuse.modeToPermissions(mode.mode())); - return 0; - } else { - return -Errno.EAFNOSUPPORT.ordinal(); - } - } catch (Exception e) { -Debug.printStackTrace(e); - return -ErrorCodes.EIO(); - } - } -} diff --git a/vavi-net-fuse/src/main/java/vavi/net/fuse/fusejna/SingleThreadJavaNioFileFS.java b/vavi-net-fuse/src/main/java/vavi/net/fuse/fusejna/SingleThreadJavaNioFileFS.java deleted file mode 100644 index 32ba7ecc..00000000 --- a/vavi-net-fuse/src/main/java/vavi/net/fuse/fusejna/SingleThreadJavaNioFileFS.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright (c) 2016 by Naohide Sano, All rights reserved. - * - * Programmed by Naohide Sano - */ - -package vavi.net.fuse.fusejna; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.file.FileSystem; -import java.util.Map; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; - -import net.fusejna.DirectoryFiller; -import net.fusejna.StructFuseFileInfo.FileInfoWrapper; -import net.fusejna.StructStat.StatWrapper; -import net.fusejna.types.TypeMode.ModeWrapper; - - -/** - * SingleThreadJavaNioFileFS. (fuse-jna) - * - * @author Naohide Sano (umjammer) - * @version 0.00 2016/02/29 umjammer initial version
- */ -class SingleThreadJavaNioFileFS extends JavaNioFileFS { - - /** */ - private ExecutorService singleService = Executors.newSingleThreadExecutor(); - - /** */ - private ExecutorService multiService = Executors.newCachedThreadPool(); - - /** - * @param fileSystem - */ - public SingleThreadJavaNioFileFS(FileSystem fileSystem, Map env) throws IOException { - super(fileSystem, env); - } - - @Override - public int access(String path, int access) { - Future f = multiService.submit(() -> super.access(path, access)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int getattr(final String path, final StatWrapper stat) { - Future f = multiService.submit(() -> super.getattr(path, stat)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int create(final String path, final ModeWrapper mode, final FileInfoWrapper info) { - Future f = singleService.submit(() -> super.create(path, mode, info)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int open(final String path, final FileInfoWrapper info) { - Future f = singleService.submit(() -> super.open(path, info)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int read(final String path, final ByteBuffer buf, final long size, final long offset, final FileInfoWrapper info) { - Future f = singleService.submit(() -> super.read(path, buf, size, offset, info)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int write(final String path, - final ByteBuffer buf, - final long size, - final long offset, - final FileInfoWrapper info) { - Future f = singleService.submit(() -> super.write(path, buf, size, offset, info)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int release(final String path, final FileInfoWrapper info) { - Future f = singleService.submit(() -> super.release(path, info)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int chmod(String path, ModeWrapper mode) { - Future f = singleService.submit(() -> super.chmod(path, mode)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int mkdir(final String path, final ModeWrapper mode) { - Future f = singleService.submit(() -> super.mkdir(path, mode)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int rmdir(final String path) { - Future f = singleService.submit(() -> super.rmdir(path)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int readdir(final String path, final DirectoryFiller filler) { - Future f = singleService.submit(() -> super.readdir(path, filler)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int rename(final String path, final String newName) { - Future f = singleService.submit(() -> super.rename(path, newName)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int truncate(final String path, final long offset) { - Future f = singleService.submit(() -> super.truncate(path, offset)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int unlink(final String path) { - Future f = singleService.submit(() -> super.unlink(path)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } -} diff --git a/vavi-net-fuse/src/main/java/vavi/net/fuse/javafs/JavaFSFuse.java b/vavi-net-fuse/src/main/java/vavi/net/fuse/javafs/JavaFSFuse.java deleted file mode 100644 index 1d9d923b..00000000 --- a/vavi-net-fuse/src/main/java/vavi/net/fuse/javafs/JavaFSFuse.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2020 by Naohide Sano, All rights reserved. - * - * Programmed by Naohide Sano - */ - -package vavi.net.fuse.javafs; - -import java.io.IOException; -import java.nio.file.FileSystem; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Level; - -import vavi.net.fuse.Fuse; -import vavi.util.Debug; - -import co.paralleluniverse.javafs.JavaFS; - - -/** - * JavaFSFuse. (javafs engine) - * - * @author Naohide Sano (umjammer) - * @version 0.00 2020/05/29 umjammer initial version
- */ -public class JavaFSFuse implements Fuse { - - public static final String ENV_READ_ONLY = "readOnly"; - - public static final String ENV_DEBUG = "debug"; - - /** */ - private String mountPoint; - - @Override - public void mount(FileSystem fs, String mountPoint, Map env) throws IOException { - this.mountPoint = mountPoint; - boolean readOnly = false; - boolean debug = false; - Map env_ = null; - if (env != null) { - if (env.containsKey(ENV_READ_ONLY)) { - readOnly = Boolean.parseBoolean(String.valueOf(env.get(ENV_READ_ONLY))); - env.remove(ENV_READ_ONLY); - } - if (env.containsKey(ENV_DEBUG)) { - debug = Boolean.parseBoolean(String.valueOf(env.get(ENV_DEBUG))); - env.remove(ENV_DEBUG); - } - env_ = new HashMap<>(); - for (Map.Entry e : env.entrySet()) { - env_.put(e.getKey(), e.getValue() == null ? null : String.valueOf(e.getValue())); - } - } -//Debug.println("debug: " + debug); -//Debug.println("readonly: " + debug); - JavaFS.mount(fs, Paths.get(mountPoint), readOnly, debug, env_); - Runtime.getRuntime().addShutdownHook(new Thread(() -> { try { close(); } catch (IOException e) { e.printStackTrace(); }})); - } - - @Override - public void close() throws IOException { - try { - if (mountPoint != null) { -Debug.println("umount..."); - JavaFS.unmount(Paths.get(mountPoint)); - mountPoint = null; -Debug.println("umount done"); - } - } catch (IllegalStateException e) { - if (e.getMessage().contains("Tried to unmount a filesystem which is not mounted")) { -Debug.println("already umount"); - } else { - throw e; - } - } catch (IOException e) { -Debug.println(Level.WARNING, "umount: " + e); - throw e; - } - } -} - -/* */ diff --git a/vavi-net-fuse/src/main/java/vavi/net/fuse/javafs/JavaFSFuseProvider.java b/vavi-net-fuse/src/main/java/vavi/net/fuse/javafs/JavaFSFuseProvider.java deleted file mode 100644 index ea712cbe..00000000 --- a/vavi-net-fuse/src/main/java/vavi/net/fuse/javafs/JavaFSFuseProvider.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2020 by Naohide Sano, All rights reserved. - * - * Programmed by Naohide Sano - */ - -package vavi.net.fuse.javafs; - -import vavi.net.fuse.Fuse; -import vavi.net.fuse.FuseProvider; - - -/** - * JavaFSFuseProvider. - * - * @author Naohide Sano (umjammer) - * @version 0.00 2020/06/03 umjammer initial version
- */ -public class JavaFSFuseProvider implements FuseProvider { - - @Override - public Fuse getFuse() { - return new JavaFSFuse(); - } -} - -/* */ diff --git a/vavi-net-fuse/src/main/java/vavi/net/fuse/jnrfuse/JavaNioFileFS.java b/vavi-net-fuse/src/main/java/vavi/net/fuse/jnrfuse/JavaNioFileFS.java deleted file mode 100644 index 5e0d0ea6..00000000 --- a/vavi-net-fuse/src/main/java/vavi/net/fuse/jnrfuse/JavaNioFileFS.java +++ /dev/null @@ -1,415 +0,0 @@ -/* - * Copyright (c) 2016 by Naohide Sano, All rights reserved. - * - * Programmed by Naohide Sano - */ - -package vavi.net.fuse.jnrfuse; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.channels.SeekableByteChannel; -import java.nio.file.FileStore; -import java.nio.file.FileSystem; -import java.nio.file.LinkOption; -import java.nio.file.NoSuchFileException; -import java.nio.file.OpenOption; -import java.nio.file.StandardOpenOption; -import java.nio.file.attribute.BasicFileAttributes; -import java.nio.file.attribute.PosixFileAttributeView; -import java.nio.file.attribute.PosixFileAttributes; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicLong; -import java.util.logging.Level; - -import jnr.constants.platform.Errno; -import jnr.ffi.Pointer; -import jnr.ffi.types.mode_t; -import jnr.ffi.types.off_t; -import jnr.ffi.types.size_t; -import ru.serce.jnrfuse.ErrorCodes; -import ru.serce.jnrfuse.FuseFillDir; -import ru.serce.jnrfuse.FuseStubFS; -import ru.serce.jnrfuse.struct.FileStat; -import ru.serce.jnrfuse.struct.Flock; -import ru.serce.jnrfuse.struct.FuseFileInfo; -import ru.serce.jnrfuse.struct.Statvfs; -import vavi.nio.file.Util; -import vavi.util.Debug; - - -/** - * JavaNioFileFS. (jnr-fuse) - * - * @author Naohide Sano (umjammer) - * @version 0.00 2016/02/29 umjammer initial version
- */ -class JavaNioFileFS extends FuseStubFS { - - private static final int BUFFER_SIZE = 0x10000; - - /** */ - private transient FileSystem fileSystem; - - /** key for env, no need to specify value */ - static final String ENV_IGNORE_APPLE_DOUBLE = "noappledouble"; - - /** */ - private final AtomicLong fileHandle = new AtomicLong(0); - - /** */ - private static final ConcurrentMap fileHandles = new ConcurrentHashMap<>(); - - protected boolean ignoreAppleDouble; - - /** - * @param fileSystem a file system to wrap by fuse - */ - public JavaNioFileFS(FileSystem fileSystem, Map env) { - this.fileSystem = fileSystem; - ignoreAppleDouble = JnrFuseFuse.isEnabled(ENV_IGNORE_APPLE_DOUBLE, env); -Debug.println(Level.FINE, "ENV_IGNORE_APPLE_DOUBLE: " + ignoreAppleDouble); - } - - @Override - public int access(String path, int access) { -Debug.println(Level.FINEST, "access: " + path); - try { - // TODO access - fileSystem.provider().checkAccess(fileSystem.getPath(path)); - return 0; - } catch (NoSuchFileException e) { -Debug.println(e); - return -ErrorCodes.ENOENT(); - } catch (IOException e) { -Debug.println(e); - return -ErrorCodes.EACCES(); - } - } - - @Override - public int create(String path, @mode_t long mode, FuseFileInfo info) { -Debug.println(Level.FINE, "create: " + path); - try { - Set options = new HashSet<>(); - options.add(StandardOpenOption.WRITE); - options.add(StandardOpenOption.CREATE_NEW); - SeekableByteChannel channel = fileSystem.provider().newByteChannel(fileSystem.getPath(path), options); - long fh = fileHandle.incrementAndGet(); - fileHandles.put(fh, channel); - info.fh.set(fh); - - return 0; - } catch (IOException e) { -Debug.printStackTrace(e); - return -ErrorCodes.EIO(); - } - } - - @Override - public int getattr(String path, FileStat stat) { -Debug.println(Level.FINEST, "getattr: " + path); - try { - BasicFileAttributes attributes = - fileSystem.provider().readAttributes(fileSystem.getPath(path), BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS); - - if (attributes instanceof PosixFileAttributes) { - long mode = JnrFuseFuse.permissionsToMode(((PosixFileAttributes) attributes).permissions()); - if (attributes.isDirectory()) { - stat.st_mode.set(FileStat.S_IFDIR | mode); - stat.st_mtim.tv_sec.set(attributes.lastModifiedTime().to(TimeUnit.SECONDS)); - stat.st_ctim.tv_sec.set(attributes.creationTime().to(TimeUnit.SECONDS)); - } else { - stat.st_mode.set(FileStat.S_IFREG | mode); - stat.st_mtim.tv_sec.set(attributes.lastModifiedTime().to(TimeUnit.SECONDS)); - stat.st_ctim.tv_sec.set(attributes.creationTime().to(TimeUnit.SECONDS)); - stat.st_size.set(attributes.size()); - } - } else { - if (attributes.isDirectory()) { - stat.st_mode.set(FileStat.S_IFDIR | 0755); - stat.st_mtim.tv_sec.set(attributes.lastModifiedTime().to(TimeUnit.SECONDS)); - stat.st_ctim.tv_sec.set(attributes.creationTime().to(TimeUnit.SECONDS)); - } else { - stat.st_mode.set(FileStat.S_IFREG | 0644); - stat.st_mtim.tv_sec.set(attributes.lastModifiedTime().to(TimeUnit.SECONDS)); - stat.st_ctim.tv_sec.set(attributes.creationTime().to(TimeUnit.SECONDS)); - stat.st_size.set(attributes.size()); - } - } - return 0; - } catch (NoSuchFileException e) { - if (e.getMessage().startsWith("ignore apple double file:")) { -Debug.println(Level.FINEST, e.getMessage()); - return 0; - } else { - if (ignoreAppleDouble) { - if (Util.isAppleDouble(path)) { -Debug.println(Level.FINEST, e.getMessage()); - } else { -Debug.println(Level.FINE, e); - } - } - return -ErrorCodes.ENOENT(); - } - } catch (IOException e) { -Debug.printStackTrace(e); - return -ErrorCodes.EIO(); - } - } - - @Override - public int fgetattr(String path, FileStat stat, FuseFileInfo info) - { -Debug.println(Level.FINE, "fgetattr: " + path); - return getattr(path, stat); - } - - @Override - public int mkdir(String path, @mode_t long mode) { -Debug.println(Level.FINE, "mkdir: " + path); - try { - fileSystem.provider().createDirectory(fileSystem.getPath(path)); - return 0; - } catch (IOException e) { -Debug.printStackTrace(e); - return -ErrorCodes.EIO(); - } - } - - @Override - public int open(String path, FuseFileInfo info) { - try { - Set options = new HashSet<>(); - options.add(StandardOpenOption.READ); - SeekableByteChannel channel = fileSystem.provider().newByteChannel(fileSystem.getPath(path), options); - long fh = fileHandle.incrementAndGet(); - fileHandles.put(fh, channel); - info.fh.set(fh); -Debug.println(Level.FINE, "open: " + path + ", fh: " + fh); - - return 0; - } catch (IOException e) { -Debug.printStackTrace(e); - return -ErrorCodes.EIO(); - } - } - - @Override - public int read(String path, Pointer buf, long size, long offset, FuseFileInfo info) { -Debug.println(Level.FINE, "read: " + path + ", " + offset + ", " + size + ", fh: " + info.fh.get()); - try { - if (fileHandles.containsKey(info.fh.get())) { - SeekableByteChannel channel = fileHandles.get(info.fh.get()); - channel.position(offset); - ByteBuffer bb = ByteBuffer.allocate(BUFFER_SIZE); - long pos = 0; -Debug.printf(Level.FINER, "Attempting to read %d-%d:", offset, offset + size); - do { - bb.clear(); - bb.limit((int) Math.min(bb.capacity(), size - pos)); - int read = channel.read(bb); - if (read == -1) { -Debug.println(Level.FINER, "Reached EOF"); - return (int) pos; // reached EOF TODO: wtf cast - } else { -Debug.printf(Level.FINER, "Reading %d-%d", offset + pos, offset + pos + read); - buf.put(pos, bb.array(), 0, read); - pos += read; - } - } while (pos < size); - return (int) pos; - } else { -Debug.println(Level.FINE, "read: no fh: " + path); - return -ErrorCodes.EEXIST(); - } - } catch (IOException e) { -Debug.printStackTrace(e); - return -ErrorCodes.EIO(); - } - } - - @Override - public int readdir(String path, Pointer buf, FuseFillDir filler, @off_t long offset, FuseFileInfo info) { -Debug.println(Level.FINER, "readdir: " + path); - try { - fileSystem.provider().newDirectoryStream(fileSystem.getPath(path), p -> true) - .forEach(p -> { -Debug.println(Level.FINER, "p: " + p); - try { - filler.apply(buf, Util.toFilenameString(p), null, 0); - } catch (IOException e) { - throw new IllegalStateException(e); - } - }); - return 0; - } catch (IOException e) { -Debug.printStackTrace(e); - return -ErrorCodes.EIO(); - } - } - - @Override - public int rename(String path, String newName) { -Debug.println(Level.FINE, "rename: " + path); - try { - fileSystem.provider().move(fileSystem.getPath(path), fileSystem.getPath(newName)); - return 0; - } catch (IOException e) { -Debug.printStackTrace(e); - return -ErrorCodes.EIO(); - } - } - - @Override - public int rmdir(String path) { -Debug.println(Level.FINE, "rmdir: " + path); - try { - fileSystem.provider().delete(fileSystem.getPath(path)); - return 0; - } catch (IOException e) { -Debug.printStackTrace(e); - return -ErrorCodes.EIO(); - } - } - - @Override - public int truncate(String path, long offset) { -Debug.println(Level.FINE, "truncate: " + path); - // TODO - return -ErrorCodes.ENOSYS(); - } - - @Override - public int unlink(String path) { -Debug.println(Level.FINE, "unlink: " + path); - try { - fileSystem.provider().delete(fileSystem.getPath(path)); - return 0; - } catch (IOException e) { -Debug.printStackTrace(e); - return -ErrorCodes.EIO(); - } - } - - @Override - public int write(String path, Pointer buf, @size_t long size, @off_t long offset, FuseFileInfo info) { -Debug.println(Level.FINE, "write: " + path + ", " + offset + ", " + size + ", fh: " + info.fh.get()); - try { - if (fileHandles.containsKey(info.fh.get())) { - ByteBuffer bb = ByteBuffer.allocate(BUFFER_SIZE); - long written = 0; - SeekableByteChannel channel = fileHandles.get(info.fh.get()); -try { // TODO ad-hoc - channel.position(offset); -} catch (IOException e) { - if (e.getMessage().contains("@vavi")) { - long o = Long.parseLong(e.getMessage().substring(9, e.getMessage().length() - 1)); - if (offset > o) { - Debug.println(Level.SEVERE, "write: skip bad position: " + offset); - throw new IOException("cannot skip last bytes send", e); - } else { - Debug.println(Level.WARNING, "write: correct bad position: " + offset + " -> " + o); - return Math.min((int) (o - offset), (int) size); - } - } else { - throw e; - } -} - do { - long remaining = size - written; - bb.clear(); - int len = (int) Math.min(remaining, bb.capacity()); - buf.get(written, bb.array(), 0, len); - bb.limit(len); - int r = channel.write(bb); - written += r; - } while (written < size); - return (int) written; - } else { - return -ErrorCodes.EEXIST(); - } - } catch (IOException e) { -Debug.printStackTrace(e); - return -ErrorCodes.EIO(); - } - } - - @Override - public int statfs(String path, Statvfs stbuf) { -Debug.println(Level.FINEST, "statfs: " + path); - try { - FileStore fileStore = fileSystem.getFileStores().iterator().next(); -//Debug.println("total: " + fileStore.getTotalSpace()); -//Debug.println("free: " + fileStore.getUsableSpace()); - - long blockSize = 512; - - long total = fileStore.getTotalSpace() / blockSize; - long free = fileStore.getUsableSpace() / blockSize; - long used = total - free; - - stbuf.f_bavail.set(used); - stbuf.f_bfree.set(free); - stbuf.f_blocks.set(total); - stbuf.f_bsize.set(blockSize); - stbuf.f_favail.set(-1); - stbuf.f_ffree.set(-1); - stbuf.f_files.set(-1); - stbuf.f_frsize.set(1); - - return 0; - } catch (IOException e) { -Debug.printStackTrace(e); - return -ErrorCodes.EIO(); - } - } - - @Override - public int chmod(String path, @mode_t long mode) { -Debug.println(Level.FINE, "chmod: " + path); - try { - if (fileSystem.provider().getFileStore(fileSystem.getPath(path)).supportsFileAttributeView(PosixFileAttributeView.class)) { - PosixFileAttributeView attrs = fileSystem.provider().getFileAttributeView(fileSystem.getPath(path), PosixFileAttributeView.class); - attrs.setPermissions(JnrFuseFuse.modeToPermissions(mode)); - return 0; - } else { - return -Errno.EAFNOSUPPORT.ordinal(); - } - } catch (Exception e) { -Debug.printStackTrace(e); - return -ErrorCodes.EIO(); - } - } - - @Override - public int release(String path, FuseFileInfo info) { -Debug.println(Level.FINE, "release: " + path + ", fh: " + info.fh.get()); - try { - if (fileHandles.containsKey(info.fh.get())) { - SeekableByteChannel channel = fileHandles.get(info.fh.get()); - channel.close(); - return 0; - } else { -Debug.println(Level.FINE, "release: no fh: " + path); - return -ErrorCodes.EEXIST(); - } - } catch (IOException e) { -Debug.printStackTrace(e); - return -ErrorCodes.EIO(); - } finally { - fileHandles.remove(info.fh.get()); - } - } - - @Override - public int lock(String path, FuseFileInfo info, int cmd, Flock flock) { -Debug.println(Level.FINE, "lock: " + path + ", fh: " + info.fh.get()); - return 0; - } -} diff --git a/vavi-net-fuse/src/main/java/vavi/net/fuse/jnrfuse/JnrFuseFuse.java b/vavi-net-fuse/src/main/java/vavi/net/fuse/jnrfuse/JnrFuseFuse.java deleted file mode 100644 index 403e3d31..00000000 --- a/vavi-net-fuse/src/main/java/vavi/net/fuse/jnrfuse/JnrFuseFuse.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2020 by Naohide Sano, All rights reserved. - * - * Programmed by Naohide Sano - */ - -package vavi.net.fuse.jnrfuse; - -import java.io.IOException; -import java.nio.file.FileSystem; -import java.nio.file.Paths; -import java.nio.file.attribute.PosixFilePermission; -import java.util.EnumSet; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import co.paralleluniverse.fuse.TypeMode; -import ru.serce.jnrfuse.FuseStubFS; -import vavi.net.fuse.Fuse; -import vavi.util.Debug; - - -/** - * JnrFuseFuse. (jnr-fuse engine) - * - * @author Naohide Sano (umjammer) - * @version 0.00 2020/05/29 umjammer initial version
- */ -public class JnrFuseFuse implements Fuse { - - /** key for env, no need to specify value */ - public static final String ENV_IGNORE_APPLE_DOUBLE = JavaNioFileFS.ENV_IGNORE_APPLE_DOUBLE; - - /** TODO utility delegate */ - static boolean isEnabled(String key, Map map) { - return Fuse.isEnabled(key, map); - } - - /** */ - private FuseStubFS fuse; - - /** non-daemon thread */ - private ExecutorService es = Executors.newSingleThreadExecutor(); - - @Override - public void mount(FileSystem fs, String mountPoint, Map env) throws IOException { - if (env.containsKey(ENV_SINGLE_THREAD) && (Boolean) env.get(ENV_SINGLE_THREAD)) { - fuse = new SingleThreadJavaNioFileFS(fs, env); -Debug.println("use single thread"); - } else { - fuse = new JavaNioFileFS(fs, env); - } - es.submit(() -> { - // jnrfuse non-blocking thread is daemon - // so make mount blocking and make own non-daemon thread - fuse.mount(Paths.get(mountPoint), true); - }); - Runtime.getRuntime().addShutdownHook(new Thread(() -> { try { close(); } catch (IOException e) { e.printStackTrace(); }})); - } - - @Override - public void close() throws IOException { - if (fuse != null) { -Debug.println("unmount..."); - fuse.umount(); - fuse = null; - es.shutdown(); -Debug.println("unmount done"); - } - } - - /** */ - static long permissionsToMode(Set permissions) { - long mode = 0; - for (PosixFilePermission px : permissions) { - switch (px) { - case OWNER_READ: mode |= TypeMode.S_IRUSR; break; - case OWNER_WRITE: mode |= TypeMode.S_IWUSR; break; - case OWNER_EXECUTE: mode |= TypeMode.S_IXUSR; break; - case GROUP_READ: mode |= TypeMode.S_IRGRP; break; - case GROUP_WRITE: mode |= TypeMode.S_IWGRP; break; - case GROUP_EXECUTE: mode |= TypeMode.S_IXGRP; break; - case OTHERS_READ: mode |= TypeMode.S_IROTH; break; - case OTHERS_WRITE: mode |= TypeMode.S_IWOTH; break; - case OTHERS_EXECUTE: mode |= TypeMode.S_IXOTH; break; - } - } - return mode; - } - - /** */ - static Set modeToPermissions(long mode) { - EnumSet permissions = EnumSet.noneOf(PosixFilePermission.class); - if ((mode & TypeMode.S_IRUSR) != 0) - permissions.add(PosixFilePermission.OWNER_READ); - if ((mode & TypeMode.S_IWUSR) != 0) - permissions.add(PosixFilePermission.OWNER_WRITE); - if ((mode & TypeMode.S_IXUSR) != 0) - permissions.add(PosixFilePermission.OWNER_EXECUTE); - if ((mode & TypeMode.S_IRGRP) != 0) - permissions.add(PosixFilePermission.GROUP_READ); - if ((mode & TypeMode.S_IWGRP) != 0) - permissions.add(PosixFilePermission.GROUP_WRITE); - if ((mode & TypeMode.S_IXGRP) != 0) - permissions.add(PosixFilePermission.GROUP_EXECUTE); - if ((mode & TypeMode.S_IROTH) != 0) - permissions.add(PosixFilePermission.OTHERS_READ); - if ((mode & TypeMode.S_IWOTH) != 0) - permissions.add(PosixFilePermission.OTHERS_WRITE); - if ((mode & TypeMode.S_IXOTH) != 0) - permissions.add(PosixFilePermission.OTHERS_EXECUTE); - return permissions; - } -} - -/* */ diff --git a/vavi-net-fuse/src/main/java/vavi/net/fuse/jnrfuse/JnrFuseFuseProvider.java b/vavi-net-fuse/src/main/java/vavi/net/fuse/jnrfuse/JnrFuseFuseProvider.java deleted file mode 100644 index 094a85dd..00000000 --- a/vavi-net-fuse/src/main/java/vavi/net/fuse/jnrfuse/JnrFuseFuseProvider.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2020 by Naohide Sano, All rights reserved. - * - * Programmed by Naohide Sano - */ - -package vavi.net.fuse.jnrfuse; - -import vavi.net.fuse.Fuse; -import vavi.net.fuse.FuseProvider; - - -/** - * JnrFuseFuseProvider. - * - * @author Naohide Sano (umjammer) - * @version 0.00 2020/06/03 umjammer initial version
- */ -public class JnrFuseFuseProvider implements FuseProvider { - - @Override - public Fuse getFuse() { - return new JnrFuseFuse(); - } -} - -/* */ diff --git a/vavi-net-fuse/src/main/java/vavi/net/fuse/jnrfuse/SingleThreadJavaNioFileFS.java b/vavi-net-fuse/src/main/java/vavi/net/fuse/jnrfuse/SingleThreadJavaNioFileFS.java deleted file mode 100644 index d4d32e15..00000000 --- a/vavi-net-fuse/src/main/java/vavi/net/fuse/jnrfuse/SingleThreadJavaNioFileFS.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright (c) 2016 by Naohide Sano, All rights reserved. - * - * Programmed by Naohide Sano - */ - -package vavi.net.fuse.jnrfuse; - -import java.io.IOException; -import java.nio.file.FileSystem; -import java.util.Map; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; - -import jnr.ffi.Pointer; -import jnr.ffi.types.off_t; -import ru.serce.jnrfuse.FuseFillDir; -import ru.serce.jnrfuse.struct.FileStat; -import ru.serce.jnrfuse.struct.FuseFileInfo; - - -/** - * SingleThreadJavaNioFileFS. (jnr-fuse) - * - * @author Naohide Sano (umjammer) - * @version 0.00 2016/02/29 umjammer initial version
- */ -class SingleThreadJavaNioFileFS extends JavaNioFileFS { - - /** */ - private ExecutorService singleService = Executors.newSingleThreadExecutor(); - - /** */ - private ExecutorService multiService = Executors.newCachedThreadPool(); - - /** - * @param fileSystem - */ - public SingleThreadJavaNioFileFS(FileSystem fileSystem, Map env) throws IOException { - super(fileSystem, env); - } - - @Override - public int access(String path, int access) { - Future f = multiService.submit(() -> { - return super.access(path, access); - }); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int getattr(final String path, final FileStat stat) { - Future f = multiService.submit(() -> super.getattr(path, stat)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int create(final String path, final long mode, final FuseFileInfo info) { - Future f = singleService.submit(() -> super.create(path, mode, info)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int open(final String path, final FuseFileInfo info) { - Future f = singleService.submit(() -> super.open(path, info)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int read(final String path, final Pointer buf, final long size, final long offset, final FuseFileInfo info) { - Future f = singleService.submit(() -> super.read(path, buf, size, offset, info)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int write(final String path, - final Pointer buf, - final long size, - final long offset, - final FuseFileInfo info) { - Future f = singleService.submit(() -> super.write(path, buf, size, offset, info)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int release(final String path, final FuseFileInfo info) { - Future f = singleService.submit(() -> super.release(path, info)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int chmod(String path, long mode) { - Future f = singleService.submit(() -> super.chmod(path, mode)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int mkdir(final String path, final long mode) { - Future f = singleService.submit(() -> super.mkdir(path, mode)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int rmdir(final String path) { - Future f = singleService.submit(() -> super.rmdir(path)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int readdir(final String path, Pointer buf, final FuseFillDir filler, @off_t long offset, FuseFileInfo info) { - Future f = singleService.submit(() -> super.readdir(path, buf, filler, offset, info)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int rename(final String path, final String newName) { - Future f = singleService.submit(() -> super.rename(path, newName)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int truncate(final String path, final long offset) { - Future f = singleService.submit(() -> super.truncate(path, offset)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - - @Override - public int unlink(final String path) { - Future f = singleService.submit(() -> super.unlink(path)); - try { - return f.get(); - } catch (InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } -} diff --git a/vavi-net-fuse/src/main/resources/META-INF/services/vavi.net.fuse.FuseProvider b/vavi-net-fuse/src/main/resources/META-INF/services/vavi.net.fuse.FuseProvider deleted file mode 100644 index 3873a6f0..00000000 --- a/vavi-net-fuse/src/main/resources/META-INF/services/vavi.net.fuse.FuseProvider +++ /dev/null @@ -1,3 +0,0 @@ -vavi.net.fuse.fusejna.FuseJnaFuseProvider -vavi.net.fuse.javafs.JavaFSFuseProvider -vavi.net.fuse.jnrfuse.JnrFuseFuseProvider \ No newline at end of file diff --git a/vavi-net-fuse/src/test/java/Main2.java b/vavi-net-fuse/src/test/java/Main2.java deleted file mode 100644 index d1856211..00000000 --- a/vavi-net-fuse/src/test/java/Main2.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2017 by Naohide Sano, All rights reserved. - * - * Programmed by Naohide Sano - */ - -import java.nio.file.FileSystem; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import com.google.common.jimfs.Configuration; -import com.google.common.jimfs.Jimfs; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; -import vavi.net.fuse.Base; -import vavi.net.fuse.Fuse; -import vavi.util.Debug; - - -/** - * Test2. (jimfs, fuse) - *

- * - * @author Naohide Sano (umjammer) - * @version 0.00 2017/03/19 umjammer initial version
- */ -public class Main2 { - - static { - System.setProperty("vavi.util.logging.VaviFormatter.extraClassMethod", - "co\\.paralleluniverse\\.fuse\\.LoggedFuseFilesystem#log"); - } - - FileSystem fs; - String mountPoint; - Map options; - - @BeforeEach - public void before() throws Exception { - - mountPoint = System.getenv("FUSE_MOUNT_POINT"); -Debug.println("mountPoint: " + mountPoint); - - fs = Jimfs.newFileSystem(Configuration.unix()); - - options = new HashMap<>(); - options.put("fsname", "jimfs_fs" + "@" + System.currentTimeMillis()); - options.put("noappledouble", null); - //options.put("noapplexattr", null); - options.put(vavi.net.fuse.javafs.JavaFSFuse.ENV_DEBUG, false); - options.put(vavi.net.fuse.javafs.JavaFSFuse.ENV_READ_ONLY, false); - } - - @ParameterizedTest - @EnabledIfEnvironmentVariable(named = "FUSE_MOUNT_POINT", matches = ".+") - @ValueSource(strings = { - "vavi.net.fuse.javafs.JavaFSFuseProvider", - "vavi.net.fuse.jnrfuse.JnrFuseFuseProvider", - "vavi.net.fuse.fusejna.FuseJnaFuseProvider", - }) - public void test01(String providerClassName) throws Exception { - System.setProperty("vavi.net.fuse.FuseProvider.class", providerClassName); -System.err.println("--------------------------- " + providerClassName + " ---------------------------"); - - Base.testLargeFile(fs, mountPoint, options); - - fs.close(); - } - - /** - * @param args none - */ - public static void main(String[] args) throws Exception { - Main2 app = new Main2(); - app.before(); - - Fuse.getFuse().mount(app.fs, app.mountPoint, app.options); - } -} - -/* */ diff --git a/vavi-net-fuse/src/test/java/Main4.java b/vavi-net-fuse/src/test/java/Main4.java deleted file mode 100644 index 6132b321..00000000 --- a/vavi-net-fuse/src/test/java/Main4.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2017 by Naohide Sano, All rights reserved. - * - * Programmed by Naohide Sano - */ - -import java.nio.file.FileSystem; -import java.util.HashMap; -import java.util.Map; - -import com.google.common.jimfs.Configuration; -import com.google.common.jimfs.Jimfs; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; -import vavi.net.fuse.Base; -import vavi.net.fuse.Fuse; -import vavi.util.Debug; - - -/** - * Test4. (jimfs, fuse) - *

- * upload - *

    - *
  • create - *
  • write - *
  • chmod - *
  • chmod - *
  • chmod - *
  • flush - *
  • lock - *
  • release - *
- * download - *
    - *
  • open - *
  • read - *
  • flush - *
  • lock - *
  • release - *
- * - * TODO read is not called because of cache??? - * - * @author Naohide Sano (umjammer) - * @version 0.00 2017/03/19 umjammer initial version
- */ -public class Main4 { - - static { - System.setProperty("vavi.util.logging.VaviFormatter.extraClassMethod", - "co\\.paralleluniverse\\.fuse\\.LoggedFuseFilesystem#log"); - } - - FileSystem fs; - String mountPoint; - Map options; - - @BeforeEach - public void before() throws Exception { - - mountPoint = System.getenv("FUSE_MOUNT_POINT"); -Debug.println("mountPoint: " + mountPoint); - - fs = Jimfs.newFileSystem(Configuration.unix()); - - options = new HashMap<>(); - options.put("fsname", "jimfs_fs" + "@" + System.currentTimeMillis()); - options.put("noappledouble", null); - //options.put("noapplexattr", null); - options.put(vavi.net.fuse.javafs.JavaFSFuse.ENV_DEBUG, false); - options.put(vavi.net.fuse.javafs.JavaFSFuse.ENV_READ_ONLY, false); - } - - @ParameterizedTest - @EnabledIfEnvironmentVariable(named = "FUSE_MOUNT_POINT", matches = ".+") - @ValueSource(strings = { - "vavi.net.fuse.javafs.JavaFSFuseProvider", - "vavi.net.fuse.jnrfuse.JnrFuseFuseProvider", - "vavi.net.fuse.fusejna.FuseJnaFuseProvider", - }) - public void test01(String providerClassName) throws Exception { - System.setProperty("vavi.net.fuse.FuseProvider.class", providerClassName); -System.err.println("--------------------------- " + providerClassName + " ---------------------------"); - - Base.testFuse(fs, mountPoint, options); - - fs.close(); - - Thread.sleep(333); - } - - /** - * @param args none - */ - public static void main(String[] args) throws Exception { - Main4 app = new Main4(); - app.before(); - - System.setProperty("vavi.net.fuse.FuseProvider.class", "vavi.net.fuse.javafs.JavaFSFuseProvider"); -// System.setProperty("vavi.net.fuse.FuseProvider.class", "vavi.net.fuse.fusejna.FuseJnaFuseProvider"); -// System.setProperty("vavi.net.fuse.FuseProvider.class", "vavi.net.fuse.jnrfuse.JnrFuseFuseProvider"); - - app.options.put("allow_other", null); - - Fuse.getFuse().mount(app.fs, app.mountPoint, app.options); - } -} - -/* */ diff --git a/vavi-net-fuse/src/test/java/vavi/net/fuse/Base.java b/vavi-net-fuse/src/test/java/vavi/net/fuse/Base.java deleted file mode 100644 index d32ef4eb..00000000 --- a/vavi-net-fuse/src/test/java/vavi/net/fuse/Base.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (c) 2020 by Naohide Sano, All rights reserved. - * - * Programmed by Naohide Sano - */ - -package vavi.net.fuse; - -import java.nio.file.FileSystem; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.List; -import java.util.Map; -import java.util.Random; - -import vavi.util.Debug; -import vavix.util.Checksum; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - - -/** - * Base. - * - * @author Naohide Sano (umjammer) - * @version 0.00 2020/06/05 umjammer initial version
- */ -public abstract class Base { - - /** */ - private static int exec(String... commandLine) throws Exception { - ProcessBuilder processBuilder = new ProcessBuilder(commandLine); - processBuilder.inheritIO(); - System.out.println("$ " + String.join(" ", commandLine)); - Process process = processBuilder.start(); - process.waitFor(); - return process.exitValue(); - } - - /** */ - public static void testFuse(FileSystem fs, String mountPoint, Map options) throws Exception { - Path local = null; - Path localTmp = null; - try (Fuse fuse = Fuse.getFuse()) { - fuse.mount(fs, mountPoint, options); - - Path localTmpDir = Paths.get("tmp"); - if (!Files.exists(localTmpDir)) { -Debug.println("[_mkdir] " + localTmpDir); - Files.createDirectories(localTmpDir); - } - - // local -> remote - local = Files.createTempFile(localTmpDir, "vavifuse-1-", ".tmp"); - byte[] bytes = new byte[5 * 1024 * 1024 + 12345]; - Random random = new Random(System.currentTimeMillis()); - random.nextBytes(bytes); - Files.write(local, bytes); - - Path remoteDir = Paths.get(mountPoint, "VAVI_FUSE_TEST4"); - if (!Files.exists(remoteDir)) { -Debug.println("[mkdir] " + remoteDir); - assertEquals(0, exec("/bin/mkdir", remoteDir.toString())); - } -Debug.println("[_rm] " + remoteDir + "/*"); - Files.list(remoteDir).forEach(p -> { -Debug.println("{_rm} " + p); - try { - assertEquals(0, exec("/bin/rm", p.toString())); - } catch (Exception e) { - throw new IllegalStateException(e); - } - }); - Path remote = remoteDir.resolve(local.getFileName()); - if (Files.exists(remote)) { -Debug.println("[rm] " + remote); - assertEquals(0, exec("/bin/rm", remote.toString())); - } - -Debug.println("[cp] " + local + " " + remote); - // TODO cp returns 1 but copying is succeed - assertTrue(List.of(0, 1).contains(exec("/bin/cp", local.toString(), remote.toString()))); - assertEquals(0, exec("/bin/ls", "-l", remote.toString())); - assertEquals(0, exec("/bin/ls", "-l", local.toString())); - assertTrue(Files.exists(remote)); - assertEquals(Files.size(local), Files.size(remote)); - assertEquals(Checksum.getChecksum(local), Checksum.getChecksum(remote)); - - // remote -> local - localTmp = Files.createTempFile(localTmpDir, "vavifuse-2-", ".tmp"); - if (Files.exists(localTmp)) { -Debug.println("[_rm] " + localTmp); - assertEquals(0, exec("/bin/rm", localTmp.toString())); - } - -Debug.println("[cp] " + remote + " " + localTmp); - assertEquals(0, exec("/bin/cp", remote.toString(), localTmp.toString())); - assertEquals(0, exec("/bin/ls", "-l", remoteDir.toString())); - assertEquals(0, exec("/bin/ls", "-l", localTmp.toString())); - assertTrue(Files.exists(localTmp)); - assertEquals(Files.size(remote), Files.size(localTmp)); - assertEquals(Checksum.getChecksum(remote), Checksum.getChecksum(localTmp)); - - // clean up -Debug.println("[rm] " + remote); - assertEquals(0, exec("/bin/rm", remote.toString())); -Debug.println("[_rm] " + remoteDir + "/*"); - Files.list(remoteDir).forEach(p -> { - try { -Debug.println("{_rm} " + p); - assertEquals(0, exec("/bin/rm", p.toString())); - } catch (Exception e) { - throw new IllegalStateException(e); - } - }); -Debug.println("[rmdir] " + remoteDir); - assertEquals(0, exec("/bin/rmdir", remoteDir.toString())); - assertFalse(Files.exists(remote)); - assertFalse(Files.exists(remoteDir)); - } finally { - if (localTmp != null && Files.exists(localTmp)) { - try { -Debug.println("[_rm] " + localTmp); - assertEquals(0, exec("/bin/rm", localTmp.toString())); - } catch (Exception e) { - e.printStackTrace(); - } - } - if (local != null && Files.exists(local)) { -Debug.println("[_rm] " + local); - assertEquals(0, exec("/bin/rm", local.toString())); - } - } - } - - /** */ - public static void testLargeFile(FileSystem fs, String mountPoint, Map options) throws Exception { - try (Fuse fuse = Fuse.getFuse()) { - fuse.mount(fs, mountPoint, options); - - Path tmpDir = Paths.get("tmp"); - if (!Files.exists(tmpDir)) { -System.out.println("[mkdir -p] " + tmpDir); - Files.createDirectories(tmpDir); - } - Path source = Files.createTempFile(tmpDir, "vavifuse-1-", ".tmp"); - byte[] bytes = new byte[50 * 1024 * 1024 + 12345]; - Random random = new Random(System.currentTimeMillis()); - random.nextBytes(bytes); -System.out.println("[create random file] " + bytes.length); - Files.write(source, bytes); - - Path dir = Paths.get(mountPoint,"VAVIFUSE_FS_TEST_L"); - Path target = dir.resolve(source.getFileName()); - if (Files.exists(dir)) { -System.out.println("[rm -rf] " + dir); - assertEquals(0, exec("/bin/rm", "-rf", dir.toString())); - } - -System.out.println("[mkdir] " + dir); - assertEquals(0, exec("/bin/mkdir", dir.toString())); - -System.out.println("[cp(1)] " + source + " " + target); - assertEquals(0, exec("/bin/cp", source.toString(), target.toString())); - assertTrue(Files.exists(target)); - assertEquals(Files.size(source), Files.size(target)); - assertEquals(Checksum.getChecksum(source), Checksum.getChecksum(target)); - - Path source2 = source.getParent().resolve(source.getFileName().toString().replace("vavifuse-1-", "vavifuse-2-")); - -System.out.println("[cp(2)] " + target + " " + source2); - assertEquals(0, exec("/bin/cp", target.toString(), source2.toString())); - assertTrue(Files.exists(target)); - assertEquals(Files.size(source2), Files.size(target)); - assertEquals(Checksum.getChecksum(source2), Checksum.getChecksum(target)); - - Path target2 = target.getParent().resolve(target.getFileName().toString().replace("vavifuse-1-", "vavifuse-2-")); - -System.out.println("[cp(3)] " + target + " " + target2); - assertEquals(0, exec("/bin/cp", target.toString(), target2.toString())); - assertTrue(Files.exists(target)); - assertEquals(Files.size(target), Files.size(target2)); - assertEquals(Checksum.getChecksum(target), Checksum.getChecksum(target2)); - -System.out.println("[rm] " + source2); - assertEquals(0, exec("/bin/rm", source2.toString())); -System.out.println("[rm] " + target); - assertEquals(0, exec("/bin/rm", target.toString())); -System.out.println("[rm] " + target2); - assertEquals(0, exec("/bin/rm", target2.toString())); - -System.out.println("[rm -rf] " + dir); - assertEquals(0, exec("/bin/rm", "-rf", dir.toString())); - - if (Files.exists(source)) { -System.out.println("[rm] " + source); - Files.delete(source); - } - } - } -} - -/* */ diff --git a/vavi-net-fuse/src/test/resources/logging.properties b/vavi-net-fuse/src/test/resources/logging.properties deleted file mode 100644 index febeccec..00000000 --- a/vavi-net-fuse/src/test/resources/logging.properties +++ /dev/null @@ -1,13 +0,0 @@ -handlers=java.util.logging.ConsoleHandler -.level=INFO -java.util.logging.ConsoleHandler.level=ALL -java.util.logging.ConsoleHandler.formatter=vavi.util.logging.VaviFormatter - -# -#vavi.util.level=FINER -# javafs -#co.paralleluniverse.fuse.FuseFilesystem.level=FINER -# jnrfuse -# no controllable logger? -# fusejna -#net.fusejna.level=FINER \ No newline at end of file diff --git a/vavi-nio-file-amazondrive/pom.xml b/vavi-nio-file-amazondrive/pom.xml index f297fd53..0427b4b6 100644 --- a/vavi-nio-file-amazondrive/pom.xml +++ b/vavi-nio-file-amazondrive/pom.xml @@ -56,8 +56,8 @@ - vavi - vavi-net-fuse + ${vavi-nio-file-fuse.groupId} + vavi-nio-file-fuse test diff --git a/vavi-nio-file-archive/pom.xml b/vavi-nio-file-archive/pom.xml index 2b065d71..33a9ac8b 100644 --- a/vavi-nio-file-archive/pom.xml +++ b/vavi-nio-file-archive/pom.xml @@ -78,13 +78,13 @@ - vavi - vavi-net-fuse + ${vavi-nio-file-fuse.groupId} + vavi-nio-file-fuse test - vavi - vavi-net-fuse + ${vavi-nio-file-fuse.groupId} + vavi-nio-file-fuse test-jar test diff --git a/vavi-nio-file-flickr/pom.xml b/vavi-nio-file-flickr/pom.xml index e5eb9ec6..8f2f9be1 100644 --- a/vavi-nio-file-flickr/pom.xml +++ b/vavi-nio-file-flickr/pom.xml @@ -49,8 +49,8 @@ - vavi - vavi-net-fuse + ${vavi-nio-file-fuse.groupId} + vavi-nio-file-fuse test diff --git a/vavi-nio-file-gathered/pom.xml b/vavi-nio-file-gathered/pom.xml index 5e606512..3511dfd3 100644 --- a/vavi-nio-file-gathered/pom.xml +++ b/vavi-nio-file-gathered/pom.xml @@ -76,13 +76,13 @@ test - vavi - vavi-net-fuse + ${vavi-nio-file-fuse.groupId} + vavi-nio-file-fuse test - vavi - vavi-net-fuse + ${vavi-nio-file-fuse.groupId} + vavi-nio-file-fuse test-jar test diff --git a/vavi-nio-file-googledrive/pom.xml b/vavi-nio-file-googledrive/pom.xml index 49da27a7..2a77b89b 100644 --- a/vavi-nio-file-googledrive/pom.xml +++ b/vavi-nio-file-googledrive/pom.xml @@ -120,13 +120,13 @@ test - vavi - vavi-net-fuse + ${vavi-nio-file-fuse.groupId} + vavi-nio-file-fuse test - vavi - vavi-net-fuse + ${vavi-nio-file-fuse.groupId} + vavi-nio-file-fuse test-jar test diff --git a/vavi-nio-file-hfs/pom.xml b/vavi-nio-file-hfs/pom.xml index f3b5a249..c5e6a2e7 100644 --- a/vavi-nio-file-hfs/pom.xml +++ b/vavi-nio-file-hfs/pom.xml @@ -66,13 +66,13 @@ - vavi - vavi-net-fuse + ${vavi-nio-file-fuse.groupId} + vavi-nio-file-fuse test - vavi - vavi-net-fuse + ${vavi-nio-file-fuse.groupId} + vavi-nio-file-fuse test-jar test diff --git a/vavi-nio-file-onedrive/pom.xml b/vavi-nio-file-onedrive/pom.xml index 0b568387..d7e043ac 100644 --- a/vavi-nio-file-onedrive/pom.xml +++ b/vavi-nio-file-onedrive/pom.xml @@ -79,13 +79,13 @@ test - vavi - vavi-net-fuse + ${vavi-nio-file-fuse.groupId} + vavi-nio-file-fuse test - vavi - vavi-net-fuse + ${vavi-nio-file-fuse.groupId} + vavi-nio-file-fuse test-jar test diff --git a/vavi-nio-file-onedrive3/pom.xml b/vavi-nio-file-onedrive3/pom.xml index 838b3231..45630212 100644 --- a/vavi-nio-file-onedrive3/pom.xml +++ b/vavi-nio-file-onedrive3/pom.xml @@ -78,13 +78,13 @@ test - vavi - vavi-net-fuse + ${vavi-nio-file-fuse.groupId} + vavi-nio-file-fuse test - vavi - vavi-net-fuse + ${vavi-nio-file-fuse.groupId} + vavi-nio-file-fuse test-jar test diff --git a/vavi-nio-file-onedrive4/pom.xml b/vavi-nio-file-onedrive4/pom.xml index c7a10e3b..dc823ef9 100644 --- a/vavi-nio-file-onedrive4/pom.xml +++ b/vavi-nio-file-onedrive4/pom.xml @@ -108,13 +108,13 @@ test - vavi - vavi-net-fuse + ${vavi-nio-file-fuse.groupId} + vavi-nio-file-fuse test - vavi - vavi-net-fuse + ${vavi-nio-file-fuse.groupId} + vavi-nio-file-fuse test-jar test diff --git a/vavi-nio-file-vfs/pom.xml b/vavi-nio-file-vfs/pom.xml index d5f41574..125135a2 100644 --- a/vavi-nio-file-vfs/pom.xml +++ b/vavi-nio-file-vfs/pom.xml @@ -187,13 +187,13 @@ - vavi - vavi-net-fuse + ${vavi-nio-file-fuse.groupId} + vavi-nio-file-fuse test - vavi - vavi-net-fuse + ${vavi-nio-file-fuse.groupId} + vavi-nio-file-fuse test-jar test From c0deeb031062b31e786ac12889d0ec6f97e34c19 Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Tue, 27 Feb 2024 20:13:22 +0900 Subject: [PATCH 2/5] [gathered] move box, dropbox fuse tests into each own dependencies --- vavi-nio-file-gathered/pom.xml | 4 +- .../test/java/vavi/nio/file/box/BoxFS.java | 56 ---------- .../src/test/java/vavi/nio/file/box/Main.java | 29 ----- .../test/java/vavi/nio/file/box/Main2.java | 37 ------ .../test/java/vavi/nio/file/box/Main3.java | 32 ------ .../test/java/vavi/nio/file/box/Main4.java | 105 ------------------ .../java/vavi/nio/file/dropbox/DropBoxFS.java | 56 ---------- .../test/java/vavi/nio/file/dropbox/Main.java | 35 ------ .../java/vavi/nio/file/dropbox/Main2.java | 37 ------ .../java/vavi/nio/file/dropbox/Main3.java | 35 ------ .../java/vavi/nio/file/dropbox/Main4.java | 103 ----------------- 11 files changed, 2 insertions(+), 527 deletions(-) delete mode 100644 vavi-nio-file-gathered/src/test/java/vavi/nio/file/box/BoxFS.java delete mode 100644 vavi-nio-file-gathered/src/test/java/vavi/nio/file/box/Main.java delete mode 100644 vavi-nio-file-gathered/src/test/java/vavi/nio/file/box/Main2.java delete mode 100644 vavi-nio-file-gathered/src/test/java/vavi/nio/file/box/Main3.java delete mode 100644 vavi-nio-file-gathered/src/test/java/vavi/nio/file/box/Main4.java delete mode 100644 vavi-nio-file-gathered/src/test/java/vavi/nio/file/dropbox/DropBoxFS.java delete mode 100644 vavi-nio-file-gathered/src/test/java/vavi/nio/file/dropbox/Main.java delete mode 100644 vavi-nio-file-gathered/src/test/java/vavi/nio/file/dropbox/Main2.java delete mode 100644 vavi-nio-file-gathered/src/test/java/vavi/nio/file/dropbox/Main3.java delete mode 100644 vavi-nio-file-gathered/src/test/java/vavi/nio/file/dropbox/Main4.java diff --git a/vavi-nio-file-gathered/pom.xml b/vavi-nio-file-gathered/pom.xml index 3511dfd3..4c2f7276 100644 --- a/vavi-nio-file-gathered/pom.xml +++ b/vavi-nio-file-gathered/pom.xml @@ -102,13 +102,13 @@ com.github.umjammer vavi-nio-file-dropbox - 0.0.20v + 0.0.21 test com.github.umjammer vavi-nio-file-box - 0.1.15v + 0.1.16 test diff --git a/vavi-nio-file-gathered/src/test/java/vavi/nio/file/box/BoxFS.java b/vavi-nio-file-gathered/src/test/java/vavi/nio/file/box/BoxFS.java deleted file mode 100644 index b687d905..00000000 --- a/vavi-nio-file-gathered/src/test/java/vavi/nio/file/box/BoxFS.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2016 by Naohide Sano, All rights reserved. - * - * Programmed by Naohide Sano - */ - -package vavi.nio.file.box; - -import java.net.URI; -import java.nio.file.FileSystem; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import com.github.fge.filesystem.box.BoxFileSystemProvider; - -import vavi.net.auth.oauth2.OAuth2AppCredential; -import vavi.net.auth.oauth2.box.BoxLocalAppCredential; -import vavi.net.fuse.Fuse; - - -/** - * BoxFS. - * - * @author Naohide Sano (umjammer) - * @version 0.00 2016/02/29 umjammer initial version
- */ -public class BoxFS { - - /** - * @param args 0: mount point, 1: email - */ - public static void main(String[] args) throws Exception { - if (args.length != 2) { - System.err.println("Usage: BoxFS "); - System.exit(1); - } - - String email = args[1]; - - URI uri = URI.create("box:///?id=" + email); - - OAuth2AppCredential appCredential = new BoxLocalAppCredential(); - -// System.setProperty("vavi.net.fuse.FuseProvider.class", "vavi.net.fuse.javafs.JavaFSFuseProvider"); -// System.setProperty("vavi.net.fuse.FuseProvider.class", "vavi.net.fuse.jnrfuse.JnrFuseFuseProvider"); - - Map env = new HashMap<>(); - env.put(BoxFileSystemProvider.ENV_APP_CREDENTIAL, appCredential); - env.put("ignoreAppleDouble", true); - - FileSystem fs = new BoxFileSystemProvider().newFileSystem(uri, env); - - Fuse.getFuse().mount(fs, args[0], Collections.EMPTY_MAP); - } -} diff --git a/vavi-nio-file-gathered/src/test/java/vavi/nio/file/box/Main.java b/vavi-nio-file-gathered/src/test/java/vavi/nio/file/box/Main.java deleted file mode 100644 index ebfd6f97..00000000 --- a/vavi-nio-file-gathered/src/test/java/vavi/nio/file/box/Main.java +++ /dev/null @@ -1,29 +0,0 @@ -package vavi.nio.file.box; - -import java.net.URI; -import java.util.Collections; - -import org.junit.jupiter.api.Test; - -import com.github.fge.filesystem.box.BoxFileSystemProvider; - -import static vavi.nio.file.Base.testAll; - - -/** - * Main. (box) - * - * @author Naohide Sano (umjammer) - * @version 0.00 2019/07/11 umjammer initial version
- */ -public class Main { - - @Test - void test01() throws Exception { - String email = System.getenv("BOX_TEST_ACCOUNT"); - - URI uri = URI.create("box:///?id=" + email); - - testAll(new BoxFileSystemProvider().newFileSystem(uri, Collections.EMPTY_MAP)); - } -} \ No newline at end of file diff --git a/vavi-nio-file-gathered/src/test/java/vavi/nio/file/box/Main2.java b/vavi-nio-file-gathered/src/test/java/vavi/nio/file/box/Main2.java deleted file mode 100644 index c0dc6d9f..00000000 --- a/vavi-nio-file-gathered/src/test/java/vavi/nio/file/box/Main2.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2016 by Naohide Sano, All rights reserved. - * - * Programmed by Naohide Sano - */ - -package vavi.nio.file.box; - -import java.net.URI; -import java.nio.file.FileSystem; -import java.util.Collections; - -import org.junit.jupiter.api.Test; - -import com.github.fge.filesystem.box.BoxFileSystemProvider; - -import static vavi.nio.file.Base.testLargeFile; - - -/** - * Box. (v2) - * - * @author Naohide Sano (umjammer) - * @version 0.00 2016/03/xx umjammer initial version
- */ -public class Main2 { - - @Test - void test01() throws Exception { - String email = System.getenv("BOX_TEST_ACCOUNT"); - - URI uri = URI.create("box:///?id=" + email); - FileSystem fs = new BoxFileSystemProvider().newFileSystem(uri, Collections.EMPTY_MAP); - - testLargeFile(fs, null); - } -} \ No newline at end of file diff --git a/vavi-nio-file-gathered/src/test/java/vavi/nio/file/box/Main3.java b/vavi-nio-file-gathered/src/test/java/vavi/nio/file/box/Main3.java deleted file mode 100644 index 98035252..00000000 --- a/vavi-nio-file-gathered/src/test/java/vavi/nio/file/box/Main3.java +++ /dev/null @@ -1,32 +0,0 @@ - -package vavi.nio.file.box; - -import java.net.URI; -import java.nio.file.FileSystem; -import java.util.Collections; - -import org.junit.jupiter.api.Test; - -import com.github.fge.filesystem.box.BoxFileSystemProvider; - -import static vavi.nio.file.Base.testMoveFolder; - - -/** - * box move folder - * - * @author Naohide Sano (umjammer) - * @version 0.00 2019/07/11 umjammer initial version
- */ -public final class Main3 { - - @Test - void test01() throws Exception { - String email = System.getenv("BOX_TEST_ACCOUNT"); - - URI uri = URI.create("box:///?id=" + email); - FileSystem fs = new BoxFileSystemProvider().newFileSystem(uri, Collections.EMPTY_MAP); - - testMoveFolder(fs); - } -} diff --git a/vavi-nio-file-gathered/src/test/java/vavi/nio/file/box/Main4.java b/vavi-nio-file-gathered/src/test/java/vavi/nio/file/box/Main4.java deleted file mode 100644 index b0da7f76..00000000 --- a/vavi-nio-file-gathered/src/test/java/vavi/nio/file/box/Main4.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2017 by Naohide Sano, All rights reserved. - * - * Programmed by Naohide Sano - */ - -package vavi.nio.file.box; - -import java.io.IOException; -import java.net.URI; -import java.nio.file.FileSystem; -import java.nio.file.FileSystems; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; - -import com.github.fge.filesystem.box.BoxFileSystemProvider; - -import vavi.net.fuse.Base; - -import co.paralleluniverse.javafs.JavaFS; - - -/** - * Main4. (fuse) - * - * @author Naohide Sano (umjammer) - * @version 0.00 2017/03/19 umjammer initial version
- */ -@DisabledIfEnvironmentVariable(named = "GITHUB_WORKFLOW", matches = ".*") -public class Main4 { - - String mountPoint; - FileSystem fs; - Map options; - - @BeforeEach - public void before() throws Exception { - System.setProperty("vavi.util.logging.VaviFormatter.extraClassMethod", "co\\.paralleluniverse\\.fuse\\.LoggedFuseFilesystem#log"); - - String email = System.getenv("TEST4_ACCOUNT"); - mountPoint = System.getenv("TEST4_MOUNT_POINT"); - - URI uri = URI.create("box:///?id=" + email); - - Map env = new HashMap<>(); - env.put("ignoreAppleDouble", true); - - fs = FileSystems.newFileSystem(uri, env); - - options = new HashMap<>(); - options.put("fsname", "box_fs" + "@" + System.currentTimeMillis()); - options.put("noappledouble", null); - //options.put("noapplexattr", null); - options.put(vavi.net.fuse.javafs.JavaFSFuse.ENV_DEBUG, false); - options.put(vavi.net.fuse.javafs.JavaFSFuse.ENV_READ_ONLY, false); - } - - @ParameterizedTest - @ValueSource(strings = { - "vavi.net.fuse.javafs.JavaFSFuseProvider", - "vavi.net.fuse.jnrfuse.JnrFuseFuseProvider", - "vavi.net.fuse.fusejna.FuseJnaFuseProvider", - }) - public void test01(String providerClassName) throws Exception { - System.setProperty("vavi.net.fuse.FuseProvider.class", providerClassName); - - try { - Base.testFuse(fs, mountPoint, options); - } finally { - fs.close(); - } - } - - // - - /** - * @param args 0: mount point, 1: email - */ - public static void main(final String... args) throws IOException { - String email = args[1]; - - final Map env = new HashMap<>(); - env.put("ignoreAppleDouble", true); - - URI uri = URI.create("box:///?id=" + email); - - final FileSystem fs = new BoxFileSystemProvider().newFileSystem(uri, env); - -// System.setProperty("vavi.net.fuse.FuseProvider.class", "vavi.net.fuse.javafs.JavaFSFuseProvider"); -// System.setProperty("vavi.net.fuse.FuseProvider.class", "vavi.net.fuse.jnrfuse.JnrFuseFuseProvider"); - - Map options = new HashMap<>(); - options.put("fsname", "box_fs" + "@" + System.currentTimeMillis()); - - JavaFS.mount(fs, Paths.get(args[0]), true, true, options); - } -} - -/* */ diff --git a/vavi-nio-file-gathered/src/test/java/vavi/nio/file/dropbox/DropBoxFS.java b/vavi-nio-file-gathered/src/test/java/vavi/nio/file/dropbox/DropBoxFS.java deleted file mode 100644 index 71ed7645..00000000 --- a/vavi-nio-file-gathered/src/test/java/vavi/nio/file/dropbox/DropBoxFS.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2016 by Naohide Sano, All rights reserved. - * - * Programmed by Naohide Sano - */ - -package vavi.nio.file.dropbox; - -import java.net.URI; -import java.nio.file.FileSystem; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import com.github.fge.fs.dropbox.DropBoxFileSystemProvider; - -import vavi.net.auth.oauth2.OAuth2AppCredential; -import vavi.net.auth.oauth2.dropbox.DropBoxLocalAppCredential; -import vavi.net.fuse.Fuse; - - -/** - * DropBoxFS. (fuse-jna) - * - * @author Naohide Sano (umjammer) - * @version 0.00 2016/03/02 umjammer initial version
- */ -public class DropBoxFS { - - /** - * @param args 0: mount point, 1: email - */ - public static void main(String[] args) throws Exception { - if (args.length != 2) { - System.err.println("Usage: DropBoxFS "); - System.exit(1); - } - - String email = args[1]; - - URI uri = URI.create("dropbox:///?id=" + email); - - OAuth2AppCredential appCredential = new DropBoxLocalAppCredential(); - -// System.setProperty("vavi.net.fuse.FuseProvider.class", "vavi.net.fuse.javafs.JavaFSFuseProvider"); -// System.setProperty("vavi.net.fuse.FuseProvider.class", "vavi.net.fuse.jnrfuse.JnrFuseFuseProvider"); - - Map env = new HashMap<>(); - env.put(DropBoxFileSystemProvider.ENV_APP_CREDENTIAL, appCredential); - env.put("ignoreAppleDouble", true); - - FileSystem fs = new DropBoxFileSystemProvider().newFileSystem(uri, env); - - Fuse.getFuse().mount(fs, args[0], Collections.EMPTY_MAP); - } -} diff --git a/vavi-nio-file-gathered/src/test/java/vavi/nio/file/dropbox/Main.java b/vavi-nio-file-gathered/src/test/java/vavi/nio/file/dropbox/Main.java deleted file mode 100644 index 26ac3d0c..00000000 --- a/vavi-nio-file-gathered/src/test/java/vavi/nio/file/dropbox/Main.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2016 by Naohide Sano, All rights reserved. - * - * Programmed by Naohide Sano - */ - -package vavi.nio.file.dropbox; - -import java.net.URI; -import java.util.Collections; - -import org.junit.jupiter.api.Test; - -import com.github.fge.fs.dropbox.DropBoxFileSystemProvider; - -import static vavi.nio.file.Base.testAll; - - -/** - * Main. (java fs, dropbox) - * - * @author Naohide Sano (umjammer) - * @version 0.00 2019/07/11 umjammer initial version
- */ -public class Main { - - @Test - void test01() throws Exception { - String email = System.getenv("DROPBOX_TEST_ACCOUNT"); - - URI uri = URI.create("dropbox:///?id=" + email); - - testAll(new DropBoxFileSystemProvider().newFileSystem(uri, Collections.EMPTY_MAP)); - } -} \ No newline at end of file diff --git a/vavi-nio-file-gathered/src/test/java/vavi/nio/file/dropbox/Main2.java b/vavi-nio-file-gathered/src/test/java/vavi/nio/file/dropbox/Main2.java deleted file mode 100644 index 9f719b96..00000000 --- a/vavi-nio-file-gathered/src/test/java/vavi/nio/file/dropbox/Main2.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2016 by Naohide Sano, All rights reserved. - * - * Programmed by Naohide Sano - */ - -package vavi.nio.file.dropbox; - -import java.net.URI; -import java.nio.file.FileSystem; -import java.util.Collections; - -import org.junit.jupiter.api.Test; - -import com.github.fge.fs.dropbox.DropBoxFileSystemProvider; - -import static vavi.nio.file.Base.testLargeFile; - - -/** - * DropBox. (v2) - * - * @author Naohide Sano (umjammer) - * @version 0.00 2016/03/xx umjammer initial version
- */ -public class Main2 { - - @Test - void test01() throws Exception { - String email = System.getenv("DROPBOX_TEST_ACCOUNT"); - - URI uri = URI.create("dropbox:///?id=" + email); - FileSystem fs = new DropBoxFileSystemProvider().newFileSystem(uri, Collections.EMPTY_MAP); - - testLargeFile(fs, null); - } -} \ No newline at end of file diff --git a/vavi-nio-file-gathered/src/test/java/vavi/nio/file/dropbox/Main3.java b/vavi-nio-file-gathered/src/test/java/vavi/nio/file/dropbox/Main3.java deleted file mode 100644 index 082f560f..00000000 --- a/vavi-nio-file-gathered/src/test/java/vavi/nio/file/dropbox/Main3.java +++ /dev/null @@ -1,35 +0,0 @@ - -package vavi.nio.file.dropbox; - -import java.net.URI; -import java.nio.file.FileSystem; -import java.util.Collections; - -import org.junit.jupiter.api.Test; - -import com.github.fge.fs.dropbox.DropBoxFileSystemProvider; - -import vavi.util.properties.annotation.PropsEntity; - -import static vavi.nio.file.Base.testMoveFolder; - - -/** - * dropbox move folder. - * - * @author Naohide Sano (umjammer) - * @version 0.00 2016/03/21 umjammer initial version
- */ -@PropsEntity(url = "file://${HOME}/.vavifuse/dropbox/{0}") -public final class Main3 { - - @Test - void test01() throws Exception { - String email = System.getenv("DROPBOX_TEST_ACCOUNT"); - - URI uri = URI.create("dropbox:///?id=" + email); - FileSystem fs = new DropBoxFileSystemProvider().newFileSystem(uri, Collections.EMPTY_MAP); - - testMoveFolder(fs); - } -} diff --git a/vavi-nio-file-gathered/src/test/java/vavi/nio/file/dropbox/Main4.java b/vavi-nio-file-gathered/src/test/java/vavi/nio/file/dropbox/Main4.java deleted file mode 100644 index aab5ddd7..00000000 --- a/vavi-nio-file-gathered/src/test/java/vavi/nio/file/dropbox/Main4.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2017 by Naohide Sano, All rights reserved. - * - * Programmed by Naohide Sano - */ - -package vavi.nio.file.dropbox; - -import java.io.IOException; -import java.net.URI; -import java.nio.file.FileSystem; -import java.nio.file.FileSystems; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; - -import com.github.fge.fs.dropbox.DropBoxFileSystemProvider; - -import vavi.net.fuse.Base; - -import co.paralleluniverse.javafs.JavaFS; - - -/** - * fuse test. (dropbox) - * - * @author Naohide Sano (umjammer) - * @version 0.00 2017/03/19 umjammer initial version
- */ -@DisabledIfEnvironmentVariable(named = "GITHUB_WORKFLOW", matches = ".*") -public class Main4 { - - String mountPoint; - FileSystem fs; - Map options; - - @BeforeEach - public void before() throws Exception { - System.setProperty("vavi.util.logging.VaviFormatter.extraClassMethod", "co\\.paralleluniverse\\.fuse\\.LoggedFuseFilesystem#log"); - - String email = System.getenv("TEST4_ACCOUNT"); - mountPoint = System.getenv("TEST4_MOUNT_POINT"); - - URI uri = URI.create("dropbox:///?id=" + email); - - Map env = new HashMap<>(); - env.put("ignoreAppleDouble", true); - - fs = FileSystems.newFileSystem(uri, env); - - options = new HashMap<>(); - options.put("fsname", "dropbox_fs" + "@" + System.currentTimeMillis()); - options.put("noappledouble", null); - //options.put("noapplexattr", null); - options.put(vavi.net.fuse.javafs.JavaFSFuse.ENV_DEBUG, false); - options.put(vavi.net.fuse.javafs.JavaFSFuse.ENV_READ_ONLY, false); - } - - @ParameterizedTest - @ValueSource(strings = { - "vavi.net.fuse.javafs.JavaFSFuseProvider", - "vavi.net.fuse.jnrfuse.JnrFuseFuseProvider", - "vavi.net.fuse.fusejna.FuseJnaFuseProvider", - }) - public void test01(String providerClassName) throws Exception { - System.setProperty("vavi.net.fuse.FuseProvider.class", providerClassName); - - Base.testFuse(fs, mountPoint, options); - - fs.close(); - } - - // - - /** - * @param args 0: mount point, 1: email - */ - public static void main(final String... args) throws IOException { - String email = args[1]; - - Map env = new HashMap<>(); - env.put("ignoreAppleDouble", true); - - URI uri = URI.create("dropbox:///?id=" + email); - - FileSystem fs = new DropBoxFileSystemProvider().newFileSystem(uri, env); - -// System.setProperty("vavi.net.fuse.FuseProvider.class", "vavi.net.fuse.javafs.JavaFSFuseProvider"); -// System.setProperty("vavi.net.fuse.FuseProvider.class", "vavi.net.fuse.jnrfuse.JnrFuseFuseProvider"); - - Map options = new HashMap<>(); - options.put("fsname", "dropbox_fs" + "@" + System.currentTimeMillis()); - - JavaFS.mount(fs, Paths.get(args[0]), false, true, options); - } -} - -/* */ From 78b744361843cb27643a4099636ac07a1ac9f127 Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Wed, 28 Feb 2024 00:40:02 +0900 Subject: [PATCH 3/5] follow ide advices --- .../acd/AcdBasicFileAttributesProvider.java | 2 +- .../java/vavi/nio/file/acd/AcdFileStore.java | 2 +- .../nio/file/acd/AcdFileSystemDriver.java | 4 +- .../nio/file/acd/AcdFileSystemRepository.java | 4 +- .../vavi/nio/file/acd/AcdOutputStream.java | 2 +- .../ArchiveBasicFileAttributesProvider.java | 2 +- .../nio/file/archive/ArchiveFileStore.java | 2 +- .../file/archive/ArchiveFileSystemDriver.java | 5 +- .../vavi/nio/file/flickr/FlickrFileStore.java | 6 +- .../flickr/FlickrFileSystemRepository.java | 4 +- .../nio/file/flickr/FlickrInputStream.java | 5 +- .../nio/file/flickr/FlickrOutputStream.java | 4 +- .../GatheredBasicFileAttributesProvider.java | 30 +- .../nio/file/gathered/GatheredFileStore.java | 7 +- .../gathered/GatheredFileSystemDriver.java | 4 +- .../GatheredFileSystemRepository.java | 3 +- .../java/vavi/nio/file/gathered/NameMap.java | 7 +- .../GatheredFileSystemProviderTest.java | 8 +- .../googledrive/GoogleDriveCopyOption.java | 4 +- .../googledrive/GoogleDriveOpenOption.java | 4 +- ...riveUserDefinedFileAttributesProvider.java | 12 +- .../googledrive/GoogleDriveWatchService.java | 2 +- .../GoogleWebSocketNotification.java | 2 +- .../nio/file/googledrive/SearcherTest.java | 3 +- .../file/googledrive/WatchDirectoryTest.java | 4 +- .../file/googledrive/WatchServiceTest.java | 14 +- .../nio/file/googledrive/WebHookTest.java | 5 +- .../nio/file/googledrive/WebHookTest3.java | 14 +- .../hfs/HfsBasicFileAttributesProvider.java | 6 +- .../java/vavi/nio/file/hfs/HfsFileStore.java | 1 - .../nio/file/hfs/HfsFileSystemRepository.java | 42 +-- .../file/hfs/HfsFileSystemProviderTest.java | 1 - .../onedrive/OneDriveFileSystemDriver.java | 6 +- .../OneDriveFileSystemRepository.java | 6 +- .../file/onedrive/OneDriveUploadOption.java | 9 +- .../OneDriveWebSocketNotification.java | 2 +- .../test/java/vavi/nio/file/onedrive/App.java | 10 +- .../java/vavi/nio/file/onedrive/Rename.java | 2 +- .../onedrive3/OneDriveFileSystemDriver.java | 17 +- .../OneDriveFileSystemRepository.java | 2 +- .../file/onedrive3/OneDriveUploadOption.java | 2 + .../MicrosoftWebSocketNotification.java | 2 +- .../nio/file/onedrive3/WebHookApiTest.java | 2 +- .../nio/file/onedrive4/OneDriveFileStore.java | 3 +- .../onedrive4/OneDriveFileSystemDriver.java | 75 ++-- .../OneDriveFileSystemRepository.java | 1 - .../file/onedrive4/OneDriveUploadOption.java | 9 +- ...riveUserDefinedFileAttributesProvider.java | 4 +- .../onedrive4/graph/LraMonitorProvider.java | 4 +- .../onedrive4/graph/LraMonitorRequest.java | 12 +- .../file/onedrive4/graph/MonitorObject.java | 2 +- .../graph/ThumbnailUploadProvider.java | 24 +- .../MicrosoftWebSocketNotification.java | 2 +- .../nio/file/onedrive4/OneDriveEasyFS.java | 4 +- .../vavi/nio/file/onedrive4/TestGraph.java | 74 ++-- .../nio/file/onedrive4/WebHookApiTest.java | 8 +- .../src/test/java/Classification2.java | 4 +- .../src/test/java/Classification3.java | 2 +- .../src/test/java/CloserFinder.java | 30 +- .../src/test/java/Descriptor.java | 29 +- .../test/java/GoogleDriveDeletedChecker.java | 8 +- .../src/test/java/GoogleDriveFilename.java | 1 - .../src/test/java/GoogleDriveThumbnail.java | 2 +- .../src/test/java/GoogleDriveUploader.java | 2 +- .../src/test/java/OneDriveThumbnail.java | 8 +- .../src/test/java/ShowEmptyFolder.java | 2 +- .../src/test/java/Synchronizer.java | 2 +- .../src/test/java/Test1.java | 4 +- .../src/test/java/TestAozora.java | 2 +- .../vavi/nio/file/watch/WatchServiceTest.java | 320 +++++++----------- .../proprietary/vfs/SftpVfsAuthenticator.java | 2 +- .../proprietary/vfs/SmbVfsAuthenticator.java | 2 +- .../proprietary/vfs/VfsAuthenticator.java | 13 +- .../auth/proprietary/vfs/VfsCredential.java | 43 ++- .../src/test/java/vavi/nio/file/vfs/Main.java | 9 +- .../test/java/vavi/nio/file/vfs/Main2.java | 3 +- .../test/java/vavi/nio/file/vfs/Main3.java | 3 +- .../test/java/vavi/nio/file/vfs/Main4.java | 7 +- .../java/vavi/nio/file/vfs/TestVfsWebdav.java | 3 +- 79 files changed, 443 insertions(+), 555 deletions(-) diff --git a/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdBasicFileAttributesProvider.java b/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdBasicFileAttributesProvider.java index 04566d5a..21322810 100644 --- a/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdBasicFileAttributesProvider.java +++ b/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdBasicFileAttributesProvider.java @@ -86,7 +86,7 @@ public boolean isDirectory() { */ @Override public long size() { - return FileInfo.class.isInstance(entry) ? FileInfo.class.cast(entry).getContentProperties().getSize() : 0; + return entry instanceof FileInfo ? ((FileInfo) entry).getContentProperties().getSize() : 0; } /* @see java.nio.file.attribute.PosixFileAttributes#owner() */ diff --git a/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdFileStore.java b/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdFileStore.java index fcb2958d..e21ca509 100644 --- a/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdFileStore.java +++ b/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdFileStore.java @@ -20,7 +20,7 @@ * A simple Amazon Cloud Drive {@link FileStore} * *

- * This makes use of information available in {@link StorageQuota}. + * This makes use of information available in {@link AccountQuota}. * Information is computed in "real time". *

*/ diff --git a/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdFileSystemDriver.java b/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdFileSystemDriver.java index a0868c6f..bbe7a791 100644 --- a/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdFileSystemDriver.java +++ b/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdFileSystemDriver.java @@ -83,7 +83,7 @@ protected InputStream downloadEntryImpl(NodeInfo entry, Path path, Set options) throws IOException { File temp = File.createTempFile("vavi-apps-fuse-", ".upload"); - return new AcdOutputStream(drive, temp, toFilenameString(path), FolderInfo.class.cast(parentEntry), file -> { + return new AcdOutputStream(drive, temp, toFilenameString(path), (FolderInfo) parentEntry, file -> { System.out.println("file: " + file.getName() + ", " + file.getCreationDate() + ", " + file.getContentProperties().getSize()); updateEntry(path, file); }); @@ -102,7 +102,7 @@ protected NodeInfo createDirectoryEntry(NodeInfo parentEntry, Path dir) throws I @Override protected boolean hasChildren(NodeInfo dirEntry, Path dir) throws IOException { - return drive.getList(dirEntry.getId()).size() > 0; + return !drive.getList(dirEntry.getId()).isEmpty(); } @Override diff --git a/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdFileSystemRepository.java b/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdFileSystemRepository.java index 718e010a..7289289f 100644 --- a/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdFileSystemRepository.java +++ b/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdFileSystemRepository.java @@ -47,7 +47,7 @@ public FileSystemDriver createDriver(final URI uri, final Map env) th UserCredential userCredential = null; if (env.containsKey(AcdFileSystemProvider.ENV_USER_CREDENTIAL)) { - userCredential = UserCredential.class.cast(env.get(AcdFileSystemProvider.ENV_USER_CREDENTIAL)); + userCredential = (UserCredential) env.get(AcdFileSystemProvider.ENV_USER_CREDENTIAL); } Map params = getParamsMap(uri); @@ -65,7 +65,7 @@ public FileSystemDriver createDriver(final URI uri, final Map env) th OAuth2AppCredential appCredential = null; if (env.containsKey(AcdFileSystemProvider.ENV_APP_CREDENTIAL)) { - appCredential = OAuth2AppCredential.class.cast(env.get(AcdFileSystemProvider.ENV_APP_CREDENTIAL)); + appCredential = (OAuth2AppCredential) env.get(AcdFileSystemProvider.ENV_APP_CREDENTIAL); } if (appCredential == null) { diff --git a/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdOutputStream.java b/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdOutputStream.java index b59f7e07..39a5f90a 100644 --- a/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdOutputStream.java +++ b/vavi-nio-file-amazondrive/src/main/java/vavi/nio/file/acd/AcdOutputStream.java @@ -35,7 +35,7 @@ * throw an exception; which means it may throw none, or it may throw an * unchecked exception. As such, the {@link #close()} method of this * class captures all {@link RuntimeException}s which {@link - * java.io.File#close()} may throw and wrap it into a {@link + * java.io.OutputStream#close()} may throw and wrap it into a {@link * IOException}. If the underlying output stream did throw an * exception, however, then such an exception is {@link * Throwable#addSuppressed(Throwable) suppressed}. diff --git a/vavi-nio-file-archive/src/main/java/vavi/nio/file/archive/ArchiveBasicFileAttributesProvider.java b/vavi-nio-file-archive/src/main/java/vavi/nio/file/archive/ArchiveBasicFileAttributesProvider.java index 6cde844d..f8e15a00 100644 --- a/vavi-nio-file-archive/src/main/java/vavi/nio/file/archive/ArchiveBasicFileAttributesProvider.java +++ b/vavi-nio-file-archive/src/main/java/vavi/nio/file/archive/ArchiveBasicFileAttributesProvider.java @@ -34,7 +34,7 @@ public final class ArchiveBasicFileAttributesProvider extends BasicFileAttributesProvider implements PosixFileAttributes { /** null means root */ - private Entry entry; + private final Entry entry; public ArchiveBasicFileAttributesProvider(final Entry entry) throws IOException { this.entry = entry; diff --git a/vavi-nio-file-archive/src/main/java/vavi/nio/file/archive/ArchiveFileStore.java b/vavi-nio-file-archive/src/main/java/vavi/nio/file/archive/ArchiveFileStore.java index a605fa0e..97dc13b7 100644 --- a/vavi-nio-file-archive/src/main/java/vavi/nio/file/archive/ArchiveFileStore.java +++ b/vavi-nio-file-archive/src/main/java/vavi/nio/file/archive/ArchiveFileStore.java @@ -17,7 +17,7 @@ * A simple archive {@link FileStore} * *

- * This makes use of information available in {@link StorageQuota}. + * This makes use of information available in {@link vavi.util.archive.Archive}. * Information is computed in "real time". *

*/ diff --git a/vavi-nio-file-archive/src/main/java/vavi/nio/file/archive/ArchiveFileSystemDriver.java b/vavi-nio-file-archive/src/main/java/vavi/nio/file/archive/ArchiveFileSystemDriver.java index dcee6625..b94a886f 100644 --- a/vavi-nio-file-archive/src/main/java/vavi/nio/file/archive/ArchiveFileSystemDriver.java +++ b/vavi-nio-file-archive/src/main/java/vavi/nio/file/archive/ArchiveFileSystemDriver.java @@ -14,7 +14,6 @@ import java.nio.file.CopyOption; import java.nio.file.DirectoryStream; import java.nio.file.FileStore; -import java.nio.file.Files; import java.nio.file.NoSuchFileException; import java.nio.file.OpenOption; import java.nio.file.Path; @@ -66,7 +65,7 @@ static String toArchiveString(Path path) { } /** for the case archive#entries() does not return dirs */ - private Map> directories = new HashMap<>(); + private final Map> directories = new HashMap<>(); /** */ private Entry getEntry(Path path) throws FileNotFoundException{ @@ -170,7 +169,7 @@ private List getDirectoryEntries(final Path dir) throws IOException { if (entry.getName().startsWith(dirString)) { String entryName = entry.getName().substring(dirString.length()); String[] names = entryName.split("/"); - if (names[0].length() > 0) { // exclude self? + if (!names[0].isEmpty()) { // exclude self? Path childPath = dir.resolve(names[0]); if (!list.contains(childPath)) list.add(childPath); diff --git a/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrFileStore.java b/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrFileStore.java index 24ef9d39..f6c52122 100644 --- a/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrFileStore.java +++ b/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrFileStore.java @@ -20,7 +20,7 @@ * A simple Flickr {@link FileStore} * *

- * This makes use of information available in {@link StorageQuota}. + * This makes use of information available in {@link User}. * Information is computed in "real time". *

*/ @@ -33,9 +33,9 @@ public final class FlickrFileStore extends FileStoreBase { * * @param flickr the (valid) Flickr flickr to use */ - public FlickrFileStore(final Flickr drive, final FileAttributesFactory factory) { + public FlickrFileStore(final Flickr flickr, final FileAttributesFactory factory) { super("flickr", factory, false); - this.flickr = drive; + this.flickr = flickr; } /** diff --git a/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrFileSystemRepository.java b/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrFileSystemRepository.java index ab5b41a9..4e1f6ea2 100644 --- a/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrFileSystemRepository.java +++ b/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrFileSystemRepository.java @@ -45,7 +45,7 @@ public FileSystemDriver createDriver(final URI uri, final Map env) th UserCredential userCredential = null; if (env.containsKey(FlickrFileSystemProvider.ENV_USER_CREDENTIAL)) { - userCredential = UserCredential.class.cast(env.get(FlickrFileSystemProvider.ENV_USER_CREDENTIAL)); + userCredential = (UserCredential) env.get(FlickrFileSystemProvider.ENV_USER_CREDENTIAL); } Map params = getParamsMap(uri); @@ -63,7 +63,7 @@ public FileSystemDriver createDriver(final URI uri, final Map env) th OAuth2AppCredential appCredential = null; if (env.containsKey(FlickrFileSystemProvider.ENV_APP_CREDENTIAL)) { - appCredential = OAuth2AppCredential.class.cast(env.get(FlickrFileSystemProvider.ENV_APP_CREDENTIAL)); + appCredential = (OAuth2AppCredential) env.get(FlickrFileSystemProvider.ENV_APP_CREDENTIAL); } if (appCredential == null) { diff --git a/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrInputStream.java b/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrInputStream.java index 0c52932e..75508c70 100644 --- a/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrInputStream.java +++ b/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrInputStream.java @@ -19,7 +19,6 @@ import com.flickr4java.flickr.Flickr; import com.flickr4java.flickr.FlickrException; import com.flickr4java.flickr.photos.Photo; -import com.github.fge.filesystem.driver.FileSystemDriver; /** @@ -39,12 +38,12 @@ * unchecked exception. As such, the {@link #close()} method of this * class captures all {@link RuntimeException}s which {@link * #close()} may throw and wrap it into a {@link - * FlickrIOException}. If the underlying input stream did throw an + * IOException}. If the underlying input stream did throw an * exception, however, then such an exception is {@link * Throwable#addSuppressed(Throwable) suppressed}. *

* - * @see FileSystemDriver#newInputStream(Path, OpenOption...) + * @see java.nio.file.Files#newInputStream(Path, OpenOption...) */ @ParametersAreNonnullByDefault public final class FlickrInputStream extends InputStream { diff --git a/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrOutputStream.java b/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrOutputStream.java index e0dbb14b..0e5e6e16 100644 --- a/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrOutputStream.java +++ b/vavi-nio-file-flickr/src/main/java/vavi/nio/file/flickr/FlickrOutputStream.java @@ -38,8 +38,8 @@ * throw an exception; which means it may throw none, or it may throw an * unchecked exception. As such, the {@link #close()} method of this * class captures all {@link RuntimeException}s which {@link - * java.io.File#close()} may throw and wrap it into a {@link - * FlickrIOException}. If the underlying output stream did throw an + * java.io.OutputStream#close()} may throw and wrap it into a {@link + * IOException}. If the underlying output stream did throw an * exception, however, then such an exception is {@link * Throwable#addSuppressed(Throwable) suppressed}. *

diff --git a/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/GatheredBasicFileAttributesProvider.java b/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/GatheredBasicFileAttributesProvider.java index 2464a4cd..5461ae43 100644 --- a/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/GatheredBasicFileAttributesProvider.java +++ b/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/GatheredBasicFileAttributesProvider.java @@ -32,7 +32,7 @@ */ public final class GatheredBasicFileAttributesProvider extends BasicFileAttributesProvider implements PosixFileAttributes { - private Object entry; + private final Object entry; public GatheredBasicFileAttributesProvider(@Nonnull final Object entry) throws IOException { this.entry = entry; @@ -52,16 +52,14 @@ public GatheredBasicFileAttributesProvider(@Nonnull final Object entry) throws I @Override public FileTime lastModifiedTime() { try { - if (FileSystem.class.isInstance(entry)) { - FileSystem fs = FileSystem.class.cast(entry); - if (GatheredFileSystemProvider.class.isInstance(fs.provider())) { + if (entry instanceof FileSystem fs) { + if (fs.provider() instanceof GatheredFileSystemProvider) { return FileTime.fromMillis(System.currentTimeMillis()); } else { return Files.getLastModifiedTime(fs.getRootDirectories().iterator().next()); } - } else if (Path.class.isInstance(entry)) { - Path path = Path.class.cast(entry); -//System.err.println("@@@: " + entry + ", " + path.getFileSystem().provider()); + } else if (entry instanceof Path path) { + //System.err.println("@@@: " + entry + ", " + path.getFileSystem().provider()); return Files.getLastModifiedTime(path); } else { throw new IllegalStateException("unsupported type: " + entry.getClass().getName()); @@ -82,10 +80,9 @@ public FileTime lastModifiedTime() { */ @Override public boolean isRegularFile() { - if (FileSystem.class.isInstance(entry)) { + if (entry instanceof FileSystem) { return false; - } else if (Path.class.isInstance(entry)) { - Path path = Path.class.cast(entry); + } else if (entry instanceof Path path) { return Files.isRegularFile(path); } else { throw new IllegalStateException("unsupported type: " + entry.getClass().getName()); @@ -97,10 +94,9 @@ public boolean isRegularFile() { */ @Override public boolean isDirectory() { - if (FileSystem.class.isInstance(entry)) { + if (entry instanceof FileSystem) { return true; - } else if (Path.class.isInstance(entry)) { - Path path = Path.class.cast(entry); + } else if (entry instanceof Path path) { return Files.isDirectory(path); } else { throw new IllegalStateException("unsupported type: " + entry.getClass().getName()); @@ -119,10 +115,10 @@ public boolean isDirectory() { @Override public long size() { try { - if (FileSystem.class.isInstance(entry)) { - return FileSystem.class.cast(entry).getFileStores().iterator().next().getTotalSpace(); - } else if (Path.class.isInstance(entry)) { - return Files.size(Path.class.cast(entry)); + if (entry instanceof FileSystem) { + return ((FileSystem) entry).getFileStores().iterator().next().getTotalSpace(); + } else if (entry instanceof Path) { + return Files.size((Path) entry); } else { throw new IllegalStateException("unsupported type: " + entry.getClass().getName()); } diff --git a/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/GatheredFileStore.java b/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/GatheredFileStore.java index 80ce4c68..41793116 100644 --- a/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/GatheredFileStore.java +++ b/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/GatheredFileStore.java @@ -14,12 +14,7 @@ /** - * A simple Commons VFS2 {@link FileStore} - * - *

- * This makes use of information available in {@link StorageQuota}. - * Information is computed in "real time". - *

+ * A simple Commons VFS2 {@link FileStore}. */ public final class GatheredFileStore extends FileStoreBase { diff --git a/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/GatheredFileSystemDriver.java b/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/GatheredFileSystemDriver.java index e60013f4..be40f6e3 100644 --- a/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/GatheredFileSystemDriver.java +++ b/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/GatheredFileSystemDriver.java @@ -57,7 +57,7 @@ public GatheredFileSystemDriver(final FileStore fileStore, super(fileStore, provider); this.fileSystems = fileSystems; if (env.containsKey(GatheredFileSystemProvider.ENV_NAME_MAP)) { - this.nameMap = NameMap.class.cast(env.get(GatheredFileSystemProvider.ENV_NAME_MAP)); + this.nameMap = (NameMap) env.get(GatheredFileSystemProvider.ENV_NAME_MAP); } } @@ -70,7 +70,7 @@ public InputStream newInputStream(final Path path, final Set env) throws IOException { if (!env.containsKey(GatheredFileSystemProvider.ENV_FILESYSTEMS)) { throw new NoSuchElementException(GatheredFileSystemProvider.ENV_FILESYSTEMS); } - Map fileSystems = Map.class.cast(env.get(GatheredFileSystemProvider.ENV_FILESYSTEMS)); + Map fileSystems = (Map) env.get(GatheredFileSystemProvider.ENV_FILESYSTEMS); GatheredFileStore fileStore = new GatheredFileStore(factoryProvider.getAttributesFactory()); return new GatheredFileSystemDriver(fileStore, factoryProvider, fileSystems, env); diff --git a/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/NameMap.java b/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/NameMap.java index 9e40650d..d9202c46 100644 --- a/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/NameMap.java +++ b/vavi-nio-file-gathered/src/main/java/vavi/nio/file/gathered/NameMap.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.net.URLDecoder; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.Map; import com.google.common.collect.BiMap; @@ -23,14 +24,14 @@ */ public class NameMap { - private BiMap nameMap = HashBiMap.create(); + private final BiMap nameMap = HashBiMap.create(); /** id -> display name */ public String encodeFsName(String id) throws IOException { if (!nameMap.isEmpty()) { return nameMap.get(id); } else { - return URLEncoder.encode(id, "utf-8"); + return URLEncoder.encode(id, StandardCharsets.UTF_8); } } @@ -39,7 +40,7 @@ public String decodeFsName(String path) throws IOException { if (!nameMap.isEmpty()) { return nameMap.inverse().get(path); } else { - return URLDecoder.decode(path, "utf-8"); + return URLDecoder.decode(path, StandardCharsets.UTF_8); } } diff --git a/vavi-nio-file-gathered/src/test/java/vavi/nio/file/gathered/GatheredFileSystemProviderTest.java b/vavi-nio-file-gathered/src/test/java/vavi/nio/file/gathered/GatheredFileSystemProviderTest.java index 23b39652..2925bc02 100644 --- a/vavi-nio-file-gathered/src/test/java/vavi/nio/file/gathered/GatheredFileSystemProviderTest.java +++ b/vavi-nio-file-gathered/src/test/java/vavi/nio/file/gathered/GatheredFileSystemProviderTest.java @@ -84,13 +84,13 @@ public static void main(String[] args) throws Exception { } /** */ - private OAuth2AppCredential microsoftAppCredential = new MicrosoftGraphLocalAppCredential(); + private final OAuth2AppCredential microsoftAppCredential = new MicrosoftGraphLocalAppCredential(); /** */ - private OAuth2AppCredential googleAppCredential = new GoogleLocalOAuth2AppCredential("googledrive"); + private final OAuth2AppCredential googleAppCredential = new GoogleLocalOAuth2AppCredential("googledrive"); /** */ - private OAuth2AppCredential boxAppCredential = new BoxLocalAppCredential(); + private final OAuth2AppCredential boxAppCredential = new BoxLocalAppCredential(); /** */ - private OAuth2AppCredential dropboxAppCredential = new DropBoxLocalAppCredential(); + private final OAuth2AppCredential dropboxAppCredential = new DropBoxLocalAppCredential(); private FileSystem getFileSystem(String id) throws IOException { String[] part1s = id.split(":"); diff --git a/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveCopyOption.java b/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveCopyOption.java index ea41bbe2..c323add3 100644 --- a/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveCopyOption.java +++ b/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveCopyOption.java @@ -23,10 +23,10 @@ public enum GoogleDriveCopyOption implements CopyOption { EXPORT_AS_GDOCS("application/vnd.google-apps.document"); /** */ - private String value; + private final String value; /** */ - private GoogleDriveCopyOption(String value) { + GoogleDriveCopyOption(String value) { this.value = value; } diff --git a/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveOpenOption.java b/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveOpenOption.java index c6c7c47e..f7d51882 100644 --- a/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveOpenOption.java +++ b/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveOpenOption.java @@ -33,10 +33,10 @@ public enum GoogleDriveOpenOption implements OpenOption { IMPORT_AS_NEW_REVISION(null); /** depends on enum stuff */ - private String value; + private final String value; /** */ - private GoogleDriveOpenOption(String value) { + GoogleDriveOpenOption(String value) { this.value = value; } diff --git a/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveUserDefinedFileAttributesProvider.java b/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveUserDefinedFileAttributesProvider.java index 1098ed9d..f4a253bb 100644 --- a/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveUserDefinedFileAttributesProvider.java +++ b/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveUserDefinedFileAttributesProvider.java @@ -168,9 +168,7 @@ public int read(Metadata entry, ByteBuffer dst) throws IOException { @Override public int write(Metadata entry, ByteBuffer src) throws IOException { String[] revisions = RevisionsUtil.split(src.array()); -Arrays.stream(revisions).forEach(r -> { - Debug.println(Level.FINE, "write " + name() + ": " + r); -}); +Arrays.stream(revisions).forEach(r -> Debug.println(Level.FINE, "write " + name() + ": " + r)); // to be deleted List toDeleted = new ArrayList<>(); Arrays.stream(revisions) @@ -180,7 +178,7 @@ public int write(Metadata entry, ByteBuffer src) throws IOException { toDeleted.addAll(getRevisions(entry).stream() .map(x -> (String) gson.fromJson(x, Map.class).get("id")) .filter(a -> !a.equals(b)) - .collect(Collectors.toList())); + .toList()); } catch (IOException e) { Debug.printStackTrace(Level.WARNING, e); } @@ -272,11 +270,11 @@ public int write(Metadata entry, ByteBuffer src) throws IOException { entry.driver.setThumbnail(entry.file, thumbnail); return thumbnail.length; } - }; + } } /** */ - private static Gson gson = new GsonBuilder().create(); + private static final Gson gson = new GsonBuilder().create(); /** utility */ public static class RevisionsUtil { @@ -291,7 +289,7 @@ public static byte[] getLatestOnly(byte[] revisions) { OffsetDateTime odt2 = OffsetDateTime.parse(o2.get("modifiedTime")); return odt2.compareTo(odt1); }) - .collect(Collectors.toList()); + .toList(); //revisionList.forEach(System.err::println); return gson.toJson(revisionList.get(0)).getBytes(); } diff --git a/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveWatchService.java b/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveWatchService.java index 3e7a8c5d..2358e806 100644 --- a/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveWatchService.java +++ b/vavi-nio-file-googledrive/src/main/java/vavi/nio/file/googledrive/GoogleDriveWatchService.java @@ -52,7 +52,7 @@ public class GoogleDriveWatchService extends WebHookBaseWatchService callback; + private final Consumer callback; /** * @param args 0: uuid for channel id diff --git a/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/SearcherTest.java b/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/SearcherTest.java index 0939cd0a..657dcceb 100644 --- a/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/SearcherTest.java +++ b/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/SearcherTest.java @@ -16,7 +16,6 @@ import java.util.List; import java.util.Map; import java.util.logging.Level; -import java.util.stream.Stream; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfSystemProperty; @@ -55,7 +54,7 @@ void test1() throws Exception { if (results.size() > 1) { Debug.println(Level.WARNING, "ambiguous: " + query); results.forEach(System.err::println); - } else if (results.size() == 0) { + } else if (results.isEmpty()) { Debug.println(Level.WARNING, "none: " + query); } else { Debug.println(Level.INFO, "found: " + query); diff --git a/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WatchDirectoryTest.java b/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WatchDirectoryTest.java index 8e40b3dd..141ad156 100644 --- a/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WatchDirectoryTest.java +++ b/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WatchDirectoryTest.java @@ -104,7 +104,7 @@ public void testEventForDirectory() throws Exception { public void testEventForDirectoryWatchKey() throws Exception { generateFile(basePath.resolve("newTextFile.txt"), 10); List> eventList = basePathWatchKey.pollEvents(); - while (eventList.size() == 0 ){ + while (eventList.isEmpty()){ eventList = basePathWatchKey.pollEvents(); Thread.sleep(10000); } @@ -115,7 +115,7 @@ public void testEventForDirectoryWatchKey() throws Exception { basePathWatchKey.reset(); generateFile(basePath.resolve("newTextFileII.txt"), 10); generateFile(basePath.resolve("newTextFileIII.txt"), 10); - while (eventList.size() == 0 ){ + while (eventList.isEmpty()){ eventList = basePathWatchKey.pollEvents(); Thread.sleep(10000); } diff --git a/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WatchServiceTest.java b/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WatchServiceTest.java index 96d120dd..a035954f 100644 --- a/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WatchServiceTest.java +++ b/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WatchServiceTest.java @@ -21,7 +21,6 @@ import java.nio.file.FileSystem; import java.nio.file.Files; import java.nio.file.NoSuchFileException; -import java.nio.file.NotDirectoryException; import java.nio.file.Path; import java.nio.file.WatchEvent; import java.nio.file.WatchEvent.Kind; @@ -49,7 +48,6 @@ import static org.junit.jupiter.api.Assertions.assertIterableEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; /** @@ -98,18 +96,14 @@ public void testRegister() throws IOException { @Test public void testRegister_fileDoesNotExist() throws IOException { - assertThrows(NoSuchFileException.class, () -> { - watcher.register(fs.getPath("/a/b/c"), ImmutableList.of(ENTRY_CREATE)); - }); + assertThrows(NoSuchFileException.class, () -> watcher.register(fs.getPath("/a/b/c"), ImmutableList.of(ENTRY_CREATE))); } @Test public void testRegister_fileIsNotDirectory() throws IOException { Path path = fs.getPath("/a.txt"); Files.createFile(path); - assertThrows(NoSuchFileException.class, () -> { - watcher.register(path, ImmutableList.of(ENTRY_CREATE)); - }); + assertThrows(NoSuchFileException.class, () -> watcher.register(path, ImmutableList.of(ENTRY_CREATE))); } @Test @@ -219,7 +213,7 @@ public void testWatchForMultipleEventTypes() throws IOException, InterruptedExce } private void assertWatcherHasEvents(WatchEvent... events) throws InterruptedException { - assertWatcherHasEvents(Arrays.asList(events), ImmutableList.> of()); + assertWatcherHasEvents(Arrays.asList(events), ImmutableList.of()); } private void assertWatcherHasEvents(List> expected, @@ -241,7 +235,7 @@ private static void ensureTimeToPoll() { } private Path createDirectory() throws IOException { - Path path = fs.getPath("/" + UUID.randomUUID().toString()); + Path path = fs.getPath("/" + UUID.randomUUID()); Files.createDirectory(path); return path; } diff --git a/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WebHookTest.java b/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WebHookTest.java index 4f9defc7..1b6bb2c7 100644 --- a/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WebHookTest.java +++ b/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WebHookTest.java @@ -13,7 +13,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Arrays; import java.util.Base64; import java.util.Collections; import java.util.List; @@ -33,8 +32,6 @@ import com.google.api.client.auth.oauth2.Credential; import com.google.api.client.googleapis.notifications.UnparsedNotification; -import com.google.api.client.http.HttpRequest; -import com.google.api.client.http.HttpRequestInitializer; import com.google.api.services.drive.Drive; import com.google.api.services.drive.model.Change; import com.google.api.services.drive.model.ChangeList; @@ -106,7 +103,7 @@ public static class AuthorizationConfigurator extends ClientEndpointConfig.Confi public void beforeRequest(Map> headers) { headers.put("Authorization", Collections.singletonList("Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes()))); } - }; + } static class Service { Drive driveService; diff --git a/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WebHookTest3.java b/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WebHookTest3.java index ef06fe25..62e8da83 100644 --- a/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WebHookTest3.java +++ b/vavi-nio-file-googledrive/src/test/java/vavi/nio/file/googledrive/WebHookTest3.java @@ -6,7 +6,6 @@ package vavi.nio.file.googledrive; -import java.io.IOException; import java.net.URI; import java.nio.file.FileSystem; import java.nio.file.FileSystems; @@ -16,8 +15,6 @@ import java.util.Collections; import com.google.api.client.auth.oauth2.Credential; -import com.google.api.client.http.HttpRequest; -import com.google.api.client.http.HttpRequestInitializer; import com.google.api.services.drive.Drive; import vavi.net.auth.WithTotpUserCredential; @@ -58,13 +55,10 @@ void test() throws Exception { Credential credential = new GoogleOAuth2(appCredential).authorize(userCredential); Drive driveService = new Drive.Builder(GoogleOAuth2.getHttpTransport(), GoogleOAuth2.getJsonFactory(), credential) - .setHttpRequestInitializer(new HttpRequestInitializer() { - @Override - public void initialize(HttpRequest httpRequest) throws IOException { - credential.initialize(httpRequest); - httpRequest.setConnectTimeout(30 * 1000); - httpRequest.setReadTimeout(30 * 1000); - } + .setHttpRequestInitializer(httpRequest -> { + credential.initialize(httpRequest); + httpRequest.setConnectTimeout(30 * 1000); + httpRequest.setReadTimeout(30 * 1000); }) .setApplicationName(appCredential.getClientId()) .build(); diff --git a/vavi-nio-file-hfs/src/main/java/vavi/nio/file/hfs/HfsBasicFileAttributesProvider.java b/vavi-nio-file-hfs/src/main/java/vavi/nio/file/hfs/HfsBasicFileAttributesProvider.java index 0f5cf295..063289ac 100644 --- a/vavi-nio-file-hfs/src/main/java/vavi/nio/file/hfs/HfsBasicFileAttributesProvider.java +++ b/vavi-nio-file-hfs/src/main/java/vavi/nio/file/hfs/HfsBasicFileAttributesProvider.java @@ -38,7 +38,7 @@ */ public final class HfsBasicFileAttributesProvider extends BasicFileAttributesProvider implements PosixFileAttributes { - private FSEntry entry; // TODO + private final FSEntry entry; // TODO public HfsBasicFileAttributesProvider(@Nonnull final FSEntry entry) throws IOException { this.entry = entry; @@ -65,7 +65,7 @@ public FileTime lastModifiedTime() { */ @Override public boolean isRegularFile() { - return FSFile.class.isInstance(entry); + return entry instanceof FSFile; } /** @@ -73,7 +73,7 @@ public boolean isRegularFile() { */ @Override public boolean isDirectory() { - return FSFolder.class.isInstance(entry); + return entry instanceof FSFolder; } /** diff --git a/vavi-nio-file-hfs/src/main/java/vavi/nio/file/hfs/HfsFileStore.java b/vavi-nio-file-hfs/src/main/java/vavi/nio/file/hfs/HfsFileStore.java index 3809958b..d01f50bf 100644 --- a/vavi-nio-file-hfs/src/main/java/vavi/nio/file/hfs/HfsFileStore.java +++ b/vavi-nio-file-hfs/src/main/java/vavi/nio/file/hfs/HfsFileStore.java @@ -11,7 +11,6 @@ import java.util.logging.Level; import org.catacombae.storage.fs.FSFolder; -import org.catacombae.storage.fs.FSForkType; import org.catacombae.storage.fs.hfscommon.HFSCommonFileSystemHandler; import com.github.fge.filesystem.attributes.FileAttributesFactory; diff --git a/vavi-nio-file-hfs/src/main/java/vavi/nio/file/hfs/HfsFileSystemRepository.java b/vavi-nio-file-hfs/src/main/java/vavi/nio/file/hfs/HfsFileSystemRepository.java index 2ed0e06e..b0f6007d 100644 --- a/vavi-nio-file-hfs/src/main/java/vavi/nio/file/hfs/HfsFileSystemRepository.java +++ b/vavi-nio-file-hfs/src/main/java/vavi/nio/file/hfs/HfsFileSystemRepository.java @@ -126,13 +126,12 @@ private HFSCommonFileSystemHandler loadFSWithUDIFAutodetect(String filename) { throw e; } -Debug.println( - "Unsupported AES key size: " + - "If you were trying to load an AES-256 encrypted image and\n" + - "are using Sun/Oracle's Java Runtime Environment, then \n" + - "please check if you have installed the Java Cryptography\n" + - "Extension (JCE) Unlimited Strength Jurisdiction Policy\n" + - "Files, which are required for AES-256 support in Java."); +Debug.println(""" + Unsupported AES key size: If you were trying to load an AES-256 encrypted image and + are using Sun/Oracle's Java Runtime Environment, then\s + please check if you have installed the Java Cryptography + Extension (JCE) Unlimited Strength Jurisdiction Policy + Files, which are required for AES-256 support in Java."""); } } catch (Exception e) { throw new IllegalArgumentException("Reading encrypted disk image...: " + "Incorrect password."); @@ -210,11 +209,11 @@ private HFSCommonFileSystemHandler loadFS(SynchronizedReadableRandomAccessStream PartitionSystemType[] matchingTypes = PartitionSystemDetector.detectPartitionSystem(syncStream, false); if (matchingTypes.length > 1) { - String message = "Multiple partition system types detected:"; + StringBuilder message = new StringBuilder("Multiple partition system types detected:"); for (PartitionSystemType type : matchingTypes) { - message += "\n" + type; + message.append("\n").append(type); } - throw new IllegalArgumentException(message); + throw new IllegalArgumentException(message.toString()); } else if (matchingTypes.length == 1) { PartitionSystemType psType = matchingTypes[0]; @@ -289,23 +288,14 @@ private HFSCommonFileSystemHandler loadFS(SynchronizedReadableRandomAccessStream case HFS_PLUS: case HFSX: - final FileSystemMajorType fsMajorType; - switch (fsType) { - case HFS: - fsMajorType = FileSystemMajorType.APPLE_HFS; - break; - case HFS_PLUS: - case HFS_WRAPPED_HFS_PLUS: - fsMajorType = FileSystemMajorType.APPLE_HFS_PLUS; - break; - case HFSX: - fsMajorType = FileSystemMajorType.APPLE_HFSX; - break; - default: - throw new IllegalArgumentException("Unhandled type: " + fsType); - } + final FileSystemMajorType fsMajorType = switch (fsType) { + case HFS -> FileSystemMajorType.APPLE_HFS; + case HFS_PLUS, HFS_WRAPPED_HFS_PLUS -> FileSystemMajorType.APPLE_HFS_PLUS; + case HFSX -> FileSystemMajorType.APPLE_HFSX; + default -> throw new IllegalArgumentException("Unhandled type: " + fsType); + }; -boolean cachingEnabled = true; // TODO env + boolean cachingEnabled = true; // TODO env FileSystemHandlerFactory factory = fsMajorType.createDefaultHandlerFactory(); if (factory.isSupported(StandardAttribute.CACHING_ENABLED)) { factory.getCreateAttributes().setBooleanAttribute( diff --git a/vavi-nio-file-hfs/src/test/java/vavi/nio/file/hfs/HfsFileSystemProviderTest.java b/vavi-nio-file-hfs/src/test/java/vavi/nio/file/hfs/HfsFileSystemProviderTest.java index 6ce50b38..77c36151 100644 --- a/vavi-nio-file-hfs/src/test/java/vavi/nio/file/hfs/HfsFileSystemProviderTest.java +++ b/vavi-nio-file-hfs/src/test/java/vavi/nio/file/hfs/HfsFileSystemProviderTest.java @@ -18,7 +18,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledIf; import vavi.util.Debug; import vavi.util.properties.annotation.Property; diff --git a/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/OneDriveFileSystemDriver.java b/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/OneDriveFileSystemDriver.java index 00c2cf71..31f0808b 100644 --- a/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/OneDriveFileSystemDriver.java +++ b/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/OneDriveFileSystemDriver.java @@ -169,9 +169,7 @@ protected void onClosed() throws IOException { /** OneDriveUploadOption */ private OutputStream uploadEntry(OneItem parentEntry, Path path, int size) throws IOException { - OneUpload uploader = asFolder(parentEntry).upload(toFilenameString(path), size, newEntry -> { - updateEntry(path, newEntry); - }); + OneUpload uploader = asFolder(parentEntry).upload(toFilenameString(path), size, newEntry -> updateEntry(path, newEntry)); return new BufferedOutputStream(uploader.upload(), Util.BUFFER_SIZE); } @@ -187,7 +185,7 @@ protected OneItem createDirectoryEntry(OneItem parentEntry, Path dir) throws IOE @Override protected boolean hasChildren(OneItem dirEntry, Path dir) throws IOException { - return client.getFolderByPath(toPathString(dir)).getChildren().size() > 0; + return !client.getFolderByPath(toPathString(dir)).getChildren().isEmpty(); } @Override diff --git a/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/OneDriveFileSystemRepository.java b/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/OneDriveFileSystemRepository.java index 084db41c..26e1161e 100644 --- a/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/OneDriveFileSystemRepository.java +++ b/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/OneDriveFileSystemRepository.java @@ -58,7 +58,7 @@ public FileSystemDriver createDriver(final URI uri, final Map env) th WithTotpUserCredential userCredential = null; if (env.containsKey(OneDriveFileSystemProvider.ENV_USER_CREDENTIAL)) { - userCredential = WithTotpUserCredential.class.cast(env.get(OneDriveFileSystemProvider.ENV_USER_CREDENTIAL)); + userCredential = (WithTotpUserCredential) env.get(OneDriveFileSystemProvider.ENV_USER_CREDENTIAL); } Map params = getParamsMap(uri); @@ -76,7 +76,7 @@ public FileSystemDriver createDriver(final URI uri, final Map env) th OAuth2AppCredential appCredential = null; if (env.containsKey(OneDriveFileSystemProvider.ENV_APP_CREDENTIAL)) { - appCredential = OAuth2AppCredential.class.cast(env.get(OneDriveFileSystemProvider.ENV_APP_CREDENTIAL)); + appCredential = (OAuth2AppCredential) env.get(OneDriveFileSystemProvider.ENV_APP_CREDENTIAL); } if (appCredential == null) { @@ -117,7 +117,7 @@ public FileSystemDriver createDriver(final URI uri, final Map env) th } }; oauth2.writeRefreshToken(callback); - client.startSessionAutoRefresh(() -> { oauth2.writeRefreshToken(callback); }); + client.startSessionAutoRefresh(() -> oauth2.writeRefreshToken(callback)); final OneDriveFileStore fileStore = new OneDriveFileStore(client, factoryProvider.getAttributesFactory()); return new OneDriveFileSystemDriver(fileStore, factoryProvider, client, env); diff --git a/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/OneDriveUploadOption.java b/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/OneDriveUploadOption.java index b832f58d..0cb43c88 100644 --- a/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/OneDriveUploadOption.java +++ b/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/OneDriveUploadOption.java @@ -6,6 +6,8 @@ package vavi.nio.file.onedrive; +import java.io.Serial; +import java.io.Serializable; import java.nio.file.CopyOption; import java.nio.file.OpenOption; import java.nio.file.Path; @@ -23,13 +25,14 @@ * @author Naohide Sano (umjammer) * @version 0.00 2020/05/31 umjammer initial version
*/ -public class OneDriveUploadOption implements OpenOption, CopyOption { +public class OneDriveUploadOption implements OpenOption, CopyOption, Serializable { /** */ + @Serial private static final long serialVersionUID = -3760090552182064957L; /** */ - private Path source; + private final Path source; /** */ public OneDriveUploadOption(Path source) { @@ -43,7 +46,7 @@ public Path getSource() { @Override public boolean equals(Object other) { - return other != null && OneDriveUploadOption.class.isInstance(other); // TODO ad-hoc + return other instanceof OneDriveUploadOption; // TODO ad-hoc } @Override diff --git a/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/webhook/websocket/OneDriveWebSocketNotification.java b/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/webhook/websocket/OneDriveWebSocketNotification.java index ac7d9d42..cf238e2c 100644 --- a/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/webhook/websocket/OneDriveWebSocketNotification.java +++ b/vavi-nio-file-onedrive/src/main/java/vavi/nio/file/onedrive/webhook/websocket/OneDriveWebSocketNotification.java @@ -37,7 +37,7 @@ public class OneDriveWebSocketNotification extends StringWebSocketNotification { private static final URI uri = URI.create(websocketBaseUrl + websocketPath); - private Consumer callback; + private final Consumer callback; /** * @param args diff --git a/vavi-nio-file-onedrive/src/test/java/vavi/nio/file/onedrive/App.java b/vavi-nio-file-onedrive/src/test/java/vavi/nio/file/onedrive/App.java index 763d707b..5419ad34 100644 --- a/vavi-nio-file-onedrive/src/test/java/vavi/nio/file/onedrive/App.java +++ b/vavi-nio-file-onedrive/src/test/java/vavi/nio/file/onedrive/App.java @@ -50,7 +50,7 @@ public class App { private static OneFolder currentFolder; - ExecutorService executor = Executors.newFixedThreadPool(5); + final ExecutorService executor = Executors.newFixedThreadPool(5); private OneDriveSDK api; private Map currentFolderFiles = Maps.newHashMap(); private Map currentFolderFolders = Maps.newHashMap(); @@ -177,7 +177,7 @@ public void deleteItem(@Param(name = "index", description = "Index of file you w item = (OneItem) this.currentFolderFolders.get(index); if (item != null) { - System.out.println(String.format("Deleting %s", item.getName())); + System.out.printf("Deleting %s%n", item.getName()); item.delete(); } else { System.out.println("Can not find item with index '" + index + "'"); @@ -187,14 +187,14 @@ public void deleteItem(@Param(name = "index", description = "Index of file you w @Command(description = "Creates a subfolder in the currentFolder") public void createFolder(@Param(name = "folderName", description = "The name of the new Folder that should be created") String folderName) throws IOException, OneDriveException { - System.out.println(String.format("Creating %s in %s", folderName, currentFolder.getName())); + System.out.printf("Creating %s in %s%n", folderName, currentFolder.getName()); currentFolder.createFolder(folderName); } @Command public void downloadItem(@Param(name = "index", description = "Index of the file you want to download") String index, @Param(name = "targetFileName", description = "path where to download to") String pathToDownload) throws IOException { - System.out.println(String.format("Downloading %s to %s", currentFolderFiles.get(index).getName(), pathToDownload)); + System.out.printf("Downloading %s to %s%n", currentFolderFiles.get(index).getName(), pathToDownload); OneFile tmpFile = currentFolderFiles.get(index); try { tmpFile.download(new File(pathToDownload)).startDownload(); @@ -221,7 +221,7 @@ private void printItemList(Map map) { List itemKeys = new ArrayList<>(map.keySet()); Collections.sort(itemKeys); for (String key : itemKeys) { - System.out.println(String.format("Item %s = %s", key, map.get(key))); + System.out.printf("Item %s = %s%n", key, map.get(key)); } } } diff --git a/vavi-nio-file-onedrive/src/test/java/vavi/nio/file/onedrive/Rename.java b/vavi-nio-file-onedrive/src/test/java/vavi/nio/file/onedrive/Rename.java index f9bb7f29..62ea8b04 100644 --- a/vavi-nio-file-onedrive/src/test/java/vavi/nio/file/onedrive/Rename.java +++ b/vavi-nio-file-onedrive/src/test/java/vavi/nio/file/onedrive/Rename.java @@ -98,7 +98,7 @@ interface Replacer { this.replacer = replacer; } - class Pair { + static class Pair { Pair(Path source, Path target) { this.source = source; this.target = target; diff --git a/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/OneDriveFileSystemDriver.java b/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/OneDriveFileSystemDriver.java index 740b9f89..03f6311c 100644 --- a/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/OneDriveFileSystemDriver.java +++ b/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/OneDriveFileSystemDriver.java @@ -12,6 +12,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.nio.file.CopyOption; import java.nio.file.FileStore; import java.nio.file.OpenOption; @@ -174,14 +175,12 @@ protected void onClosed() throws IOException { private OutputStream uploadEntry(DriveItem.Metadata parentEntry, Path path, int size) throws IOException { DriveItem file = new DriveItem(asDriveItem(parentEntry), toItemPathString(toFilenameString(path))); final UploadSession uploadSession = Files.createUploadSession(file); - return new BufferedOutputStream(new OneDriveOutputStream(uploadSession, path, size, newEntry -> { - updateEntry(path, newEntry); - }), Util.BUFFER_SIZE); + return new BufferedOutputStream(new OneDriveOutputStream(uploadSession, path, size, newEntry -> updateEntry(path, newEntry)), Util.BUFFER_SIZE); } /** ms-graph doesn't accept '+' in a path string */ private String toItemPathString(String pathString) throws IOException { - return URLEncoder.encode(pathString, "utf-8").replace("+", "%20"); + return URLEncoder.encode(pathString, StandardCharsets.UTF_8).replace("+", "%20"); } @Override @@ -213,12 +212,10 @@ protected DriveItem.Metadata copyEntry(DriveItem.Metadata sourceEntry, DriveItem Debug.println(Level.FINE, "target: " + targetParentEntry.getName()); operation.copy(asDriveItem(targetParentEntry)); OneDriveLongRunningAction action = Files.copy(asDriveItem(sourceEntry), operation); - action.await(statusObject -> { -Debug.printf(Level.FINE, "Copy Progress Operation %s progress %.0f %%, status %s", - statusObject.getOperation(), - statusObject.getPercentage(), - statusObject.getStatus()); - }); + action.await(statusObject -> Debug.printf(Level.FINE, "Copy Progress Operation %s progress %.0f %%, status %s", + statusObject.getOperation(), + statusObject.getPercentage(), + statusObject.getStatus())); return getEntry(null, target); } diff --git a/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/OneDriveFileSystemRepository.java b/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/OneDriveFileSystemRepository.java index ebc8e99a..f8f416f7 100644 --- a/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/OneDriveFileSystemRepository.java +++ b/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/OneDriveFileSystemRepository.java @@ -59,7 +59,7 @@ public FileSystemDriver createDriver(final URI uri, final Map env) th WithTotpUserCredential userCredential = null; if (env.containsKey(OneDriveFileSystemProvider.ENV_USER_CREDENTIAL)) { - userCredential = WithTotpUserCredential.class.cast(env.get(OneDriveFileSystemProvider.ENV_USER_CREDENTIAL)); + userCredential = (WithTotpUserCredential) env.get(OneDriveFileSystemProvider.ENV_USER_CREDENTIAL); } Map params = getParamsMap(uri); diff --git a/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/OneDriveUploadOption.java b/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/OneDriveUploadOption.java index 6bd08a82..de7c2b6f 100644 --- a/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/OneDriveUploadOption.java +++ b/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/OneDriveUploadOption.java @@ -6,6 +6,7 @@ package vavi.nio.file.onedrive3; +import java.io.Serial; import java.io.Serializable; import java.nio.file.CopyOption; import java.nio.file.OpenOption; @@ -29,6 +30,7 @@ public class OneDriveUploadOption implements OpenOption, CopyOption, Serializable { /** */ + @Serial private static final long serialVersionUID = 5575546140441990410L; /** */ diff --git a/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/webhook/websocket/MicrosoftWebSocketNotification.java b/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/webhook/websocket/MicrosoftWebSocketNotification.java index f4c09b11..09e404e4 100644 --- a/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/webhook/websocket/MicrosoftWebSocketNotification.java +++ b/vavi-nio-file-onedrive3/src/main/java/vavi/nio/file/onedrive3/webhook/websocket/MicrosoftWebSocketNotification.java @@ -37,7 +37,7 @@ public class MicrosoftWebSocketNotification extends StringWebSocketNotification private static final URI uri = URI.create(websocketBaseUrl + websocketPath); - private Consumer callback; + private final Consumer callback; /** * @param args diff --git a/vavi-nio-file-onedrive3/src/test/java/vavi/nio/file/onedrive3/WebHookApiTest.java b/vavi-nio-file-onedrive3/src/test/java/vavi/nio/file/onedrive3/WebHookApiTest.java index 90ae7e71..aa395bae 100644 --- a/vavi-nio-file-onedrive3/src/test/java/vavi/nio/file/onedrive3/WebHookApiTest.java +++ b/vavi-nio-file-onedrive3/src/test/java/vavi/nio/file/onedrive3/WebHookApiTest.java @@ -107,7 +107,7 @@ public String getEmailURL() { DriveItem.Metadata child = i.next(); if (child.getName().equals("TEST_WEBHOOK")) { System.out.println("rmdir " + child.getName()); - Files.delete(DriveItem.class.cast(child.getItem())); + Files.delete((DriveItem) child.getItem()); } } System.out.println("mkdir " + "TEST_WEBHOOK"); diff --git a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveFileStore.java b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveFileStore.java index 0db4ba7d..49f2bdd2 100644 --- a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveFileStore.java +++ b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveFileStore.java @@ -111,11 +111,12 @@ private Quota getQuota() throws IOException { if (cache != null) { return cache; } else { - client.drive().buildRequest().get(new ICallback() { + client.drive().buildRequest().get(new ICallback<>() { @Override public void success(final Drive result) { cache = result.quota; } + @Override public void failure(ClientException ex) { } diff --git a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveFileSystemDriver.java b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveFileSystemDriver.java index ef41647c..d3eb5aec 100644 --- a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveFileSystemDriver.java +++ b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveFileSystemDriver.java @@ -11,6 +11,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.nio.file.CopyOption; import java.nio.file.FileStore; import java.nio.file.Files; @@ -196,21 +197,23 @@ private OutputStream uploadEntry(Path path, int size) throws IOException { UploadSession uploadSession = client.drive().root().itemWithPath(toItemPathString(toPathString(path))).createUploadSession(new DriveItemUploadableProperties()).buildRequest().post(); vavi.nio.file.onedrive4.graph.ChunkedUploadProvider chunkedUploadProvider = new vavi.nio.file.onedrive4.graph.ChunkedUploadProvider<>(uploadSession, client, size, DriveItem.class); - return new BufferedOutputStream(chunkedUploadProvider.upload(new IProgressCallback() { - @Override - public void progress(final long current, final long max) { -Debug.println(current + "/" + max); - } - @Override - public void success(final DriveItem result) { - updateEntry(path, result); -Debug.println("upload done: " + result.name); - } - @Override - public void failure(final ClientException ex) { - // never called - } - }), threshold); + return new BufferedOutputStream(chunkedUploadProvider.upload(new IProgressCallback<>() { + @Override + public void progress(final long current, final long max) { + Debug.println(current + "/" + max); + } + + @Override + public void success(final DriveItem result) { + updateEntry(path, result); + Debug.println("upload done: " + result.name); + } + + @Override + public void failure(final ClientException ex) { + // never called + } + }), threshold); } else { return new Util.OutputStreamForUploading() { @Override @@ -229,21 +232,23 @@ private void uploadEntry(Path path, InputStream is, int size) throws IOException UploadSession uploadSession = client.drive().root().itemWithPath(toItemPathString(toPathString(path))).createUploadSession(new DriveItemUploadableProperties()).buildRequest().post(); ChunkedUploadProvider chunkedUploadProvider = new ChunkedUploadProvider<>(uploadSession, client, is, size, DriveItem.class); - chunkedUploadProvider.upload(new IProgressCallback() { - @Override - public void progress(final long current, final long max) { -Debug.println(current + "/" + max); - } - @Override - public void success(final DriveItem result) { - updateEntry(path, result); -Debug.println("upload done: " + result.name); - } - @Override - public void failure(final ClientException ex) { - throw ex; - } - }); + chunkedUploadProvider.upload(new IProgressCallback<>() { + @Override + public void progress(final long current, final long max) { + Debug.println(current + "/" + max); + } + + @Override + public void success(final DriveItem result) { + updateEntry(path, result); + Debug.println("upload done: " + result.name); + } + + @Override + public void failure(final ClientException ex) { + throw ex; + } + }); } else { DriveItem newEntry = client.drive().root().itemWithPath(toItemPathString(toPathString(path))).content().buildRequest().put(ByteStreams.toByteArray(is)); // TODO depends on guava updateEntry(path, newEntry); @@ -252,7 +257,7 @@ public void failure(final ClientException ex) { /** ms-graph doesn't accept '+' in a path string */ private String toItemPathString(String pathString) throws IOException { - return URLEncoder.encode(pathString.replaceFirst("^\\/", ""), "utf-8").replace("+", "%20"); + return URLEncoder.encode(pathString.replaceFirst("^\\/", ""), StandardCharsets.UTF_8).replace("+", "%20"); } @Override @@ -303,16 +308,18 @@ protected DriveItem copyEntry(DriveItem sourceEntry, DriveItem targetParentEntry @SuppressWarnings({ "unchecked", "rawtypes" }) // TODO LraSession copySession = client.getHttpProvider().send((IHttpRequest) request, LraMonitorResult.class, body, (IStatefulResponseHandler) handler).getSession(); LraMonitorProvider copyMonitorProvider = new LraMonitorProvider<>(copySession, client, DriveItem.class); - copyMonitorProvider.monitor(new IProgressCallback() { + copyMonitorProvider.monitor(new IProgressCallback<>() { @Override public void progress(final long current, final long max) { -Debug.println("copy progress: " + current + "/" + max); + Debug.println("copy progress: " + current + "/" + max); } + @Override public void success(final DriveItem result) { -Debug.println("copy done: " + result.id); + Debug.println("copy done: " + result.id); updateEntry(target, result); } + @Override public void failure(final ClientException ex) { throw new IllegalStateException(ex); diff --git a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveFileSystemRepository.java b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveFileSystemRepository.java index e5250430..07c836da 100644 --- a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveFileSystemRepository.java +++ b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveFileSystemRepository.java @@ -17,7 +17,6 @@ import com.github.fge.filesystem.driver.FileSystemDriver; import com.github.fge.filesystem.provider.FileSystemRepositoryBase; import com.microsoft.graph.authentication.IAuthenticationProvider; -import com.microsoft.graph.http.IHttpRequest; import com.microsoft.graph.models.extensions.IGraphServiceClient; import com.microsoft.graph.requests.extensions.GraphServiceClient; diff --git a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveUploadOption.java b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveUploadOption.java index 83f38eb3..803f02ac 100644 --- a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveUploadOption.java +++ b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveUploadOption.java @@ -6,6 +6,8 @@ package vavi.nio.file.onedrive4; +import java.io.Serial; +import java.io.Serializable; import java.nio.file.CopyOption; import java.nio.file.OpenOption; import java.nio.file.Path; @@ -23,13 +25,14 @@ * @author Naohide Sano (umjammer) * @version 0.00 2020/05/31 umjammer initial version
*/ -public class OneDriveUploadOption implements OpenOption, CopyOption { +public class OneDriveUploadOption implements OpenOption, CopyOption, Serializable { /** */ + @Serial private static final long serialVersionUID = -3760090552182064957L; /** */ - private Path source; + private final Path source; /** */ public OneDriveUploadOption(Path source) { @@ -43,7 +46,7 @@ public Path getSource() { @Override public boolean equals(Object other) { - return other != null && OneDriveUploadOption.class.isInstance(other); // TODO ad-hoc + return other instanceof OneDriveUploadOption; // TODO ad-hoc } @Override diff --git a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveUserDefinedFileAttributesProvider.java b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveUserDefinedFileAttributesProvider.java index fe1e2443..38af5541 100644 --- a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveUserDefinedFileAttributesProvider.java +++ b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/OneDriveUserDefinedFileAttributesProvider.java @@ -95,7 +95,7 @@ public int write(Metadata entry, ByteBuffer src) throws IOException { /** whole image file */ thumbnail { /** */ - Map thumbnailCache = new ConcurrentHashMap<>(); // TODO LRU + final Map thumbnailCache = new ConcurrentHashMap<>(); // TODO LRU /** */ private String getUrl(Metadata entry) throws IOException { @@ -155,7 +155,7 @@ public int write(Metadata entry, ByteBuffer src) throws IOException { entry.driver.setThumbnail(entry.driveItem, thumbnail); return thumbnail.length; } - }; + } } } diff --git a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/LraMonitorProvider.java b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/LraMonitorProvider.java index 137f7d9b..19cf7be8 100644 --- a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/LraMonitorProvider.java +++ b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/LraMonitorProvider.java @@ -96,8 +96,8 @@ public void monitor(final IProgressCallback callback, final int... while (!finished) { try { - Thread.sleep(1 << timeout); - } catch (InterruptedException e) { + Thread.sleep(1L << timeout); + } catch (InterruptedException ignored) { } LraMonitorRequest request = new LraMonitorRequest(this.monitorUrl, this.client); diff --git a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/LraMonitorRequest.java b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/LraMonitorRequest.java index 779db189..d10fb60e 100644 --- a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/LraMonitorRequest.java +++ b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/LraMonitorRequest.java @@ -6,11 +6,8 @@ package vavi.nio.file.onedrive4.graph; -import com.microsoft.graph.authentication.IAuthenticationProvider; import com.microsoft.graph.http.BaseRequest; import com.microsoft.graph.http.HttpMethod; -import com.microsoft.graph.http.IHttpRequest; -import com.microsoft.graph.http.IStatefulResponseHandler; import com.microsoft.graph.models.extensions.IGraphServiceClient; import com.microsoft.graph.requests.extensions.GraphServiceClient; @@ -33,10 +30,7 @@ public class LraMonitorRequest { */ public LraMonitorRequest(final String requestUrl, IGraphServiceClient client) { IGraphServiceClient clientWithoutAuth = GraphServiceClient.builder() - .authenticationProvider(new IAuthenticationProvider() { - @Override - public void authenticateRequest(IHttpRequest request) { - } + .authenticationProvider(request -> { }) .logger(client.getLogger()) .buildClient(); @@ -55,9 +49,9 @@ public void authenticateRequest(IHttpRequest request) { public LraMonitorResult monitor(final LraMonitorResponseHandler responseHandler) { return this.baseRequest.getClient() .getHttpProvider() - .send((IHttpRequest) baseRequest, + .send(baseRequest, LraMonitorResult.class, null, - (IStatefulResponseHandler) responseHandler); + responseHandler); } } diff --git a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/MonitorObject.java b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/MonitorObject.java index 671cb754..27e20378 100644 --- a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/MonitorObject.java +++ b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/MonitorObject.java @@ -40,7 +40,7 @@ public void setRawObject(ISerializer serializer, JsonObject json) { Debug.println(json); } - private transient AdditionalDataManager additionalDataManager = new AdditionalDataManager(this); + private final transient AdditionalDataManager additionalDataManager = new AdditionalDataManager(this); @Override public final AdditionalDataManager additionalDataManager() { diff --git a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/ThumbnailUploadProvider.java b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/ThumbnailUploadProvider.java index e2b6943c..11829e2c 100644 --- a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/ThumbnailUploadProvider.java +++ b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/graph/ThumbnailUploadProvider.java @@ -6,14 +6,12 @@ package vavi.nio.file.onedrive4.graph; - import java.io.IOException; import java.security.InvalidParameterException; import com.microsoft.graph.http.BaseRequest; import com.microsoft.graph.http.HttpMethod; import com.microsoft.graph.http.HttpResponseCode; -import com.microsoft.graph.http.IHttpRequest; import com.microsoft.graph.models.extensions.DriveItem; import com.microsoft.graph.models.extensions.IGraphServiceClient; @@ -22,8 +20,6 @@ /** * ThumbnailUpload service provider - * - * @param the upload item type */ public class ThumbnailUploadProvider { @@ -40,13 +36,10 @@ public class ThumbnailUploadProvider { /** * Creates the ChunkedUploadProvider * - * @param uploadSession the initial upload session - * @param client the Graph client - * @param streamSize the stream size - * @param uploadTypeClass the upload type class + * @param item the upload item + * @param client the Graph client */ - public ThumbnailUploadProvider(final DriveItem item, - final IGraphServiceClient client) { + public ThumbnailUploadProvider(DriveItem item, IGraphServiceClient client) { if (item == null) { throw new InvalidParameterException("item is null."); } @@ -66,17 +59,16 @@ public ThumbnailUploadProvider(final DriveItem item, * @param image the thumbnail bytes * @throws IOException the IO exception that occurred during upload */ - public void upload(byte[] image) - throws IOException { + public void upload(byte[] image) throws IOException { BaseRequest request = new BaseRequest(uploadUrl, client, null, Integer.class) {{ setHttpMethod(HttpMethod.PUT); }}; int result = client.getHttpProvider().send( - (IHttpRequest) request, - Integer.class, - image, - new ThumbnailUploadResponseHandler()); + request, + Integer.class, + image, + new ThumbnailUploadResponseHandler()); if (result != HttpResponseCode.HTTP_OK) { throw new IOException(String.valueOf(result)); diff --git a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/webhook/websocket/MicrosoftWebSocketNotification.java b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/webhook/websocket/MicrosoftWebSocketNotification.java index d12f3bde..0245392c 100644 --- a/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/webhook/websocket/MicrosoftWebSocketNotification.java +++ b/vavi-nio-file-onedrive4/src/main/java/vavi/nio/file/onedrive4/webhook/websocket/MicrosoftWebSocketNotification.java @@ -37,7 +37,7 @@ public class MicrosoftWebSocketNotification extends StringWebSocketNotification private static final URI uri = URI.create(websocketBaseUrl + websocketPath); - private Consumer callback; + private final Consumer callback; /** * @param args diff --git a/vavi-nio-file-onedrive4/src/test/java/vavi/nio/file/onedrive4/OneDriveEasyFS.java b/vavi-nio-file-onedrive4/src/test/java/vavi/nio/file/onedrive4/OneDriveEasyFS.java index edb633bf..279749dc 100644 --- a/vavi-nio-file-onedrive4/src/test/java/vavi/nio/file/onedrive4/OneDriveEasyFS.java +++ b/vavi-nio-file-onedrive4/src/test/java/vavi/nio/file/onedrive4/OneDriveEasyFS.java @@ -33,9 +33,9 @@ public class OneDriveEasyFS implements EasyFS { /** */ - private MicrosoftGraphOAuth2 auth2; + private final MicrosoftGraphOAuth2 auth2; /** */ - private IGraphServiceClient client; + private final IGraphServiceClient client; /** */ public OneDriveEasyFS(String email) throws IOException { diff --git a/vavi-nio-file-onedrive4/src/test/java/vavi/nio/file/onedrive4/TestGraph.java b/vavi-nio-file-onedrive4/src/test/java/vavi/nio/file/onedrive4/TestGraph.java index ff428156..79652552 100644 --- a/vavi-nio-file-onedrive4/src/test/java/vavi/nio/file/onedrive4/TestGraph.java +++ b/vavi-nio-file-onedrive4/src/test/java/vavi/nio/file/onedrive4/TestGraph.java @@ -10,13 +10,13 @@ import java.io.InputStream; import java.net.URL; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.Collections; -import com.microsoft.graph.authentication.IAuthenticationProvider; import com.microsoft.graph.concurrency.ChunkedUploadProvider; import com.microsoft.graph.concurrency.IProgressCallback; import com.microsoft.graph.core.ClientException; @@ -109,9 +109,9 @@ void auth(String email) throws IOException { void testList() throws IOException { client.me().drive().root().children().buildRequest().get().getCurrentPage().forEach(e -> System.err.println(e.name)); - client.me().drive().root().itemWithPath(URLEncoder.encode("Books/Novels", "utf-8")).children().buildRequest().get().getCurrentPage().forEach(e -> System.err.println(e.name)); + client.me().drive().root().itemWithPath(URLEncoder.encode("Books/Novels", StandardCharsets.UTF_8)).children().buildRequest().get().getCurrentPage().forEach(e -> System.err.println(e.name)); - client.me().drive().root().itemWithPath(URLEncoder.encode("Books/Novels/あ", "utf-8")).children().buildRequest().get().getCurrentPage().forEach(e -> System.err.println(e.name)); + client.me().drive().root().itemWithPath(URLEncoder.encode("Books/Novels/あ", StandardCharsets.UTF_8)).children().buildRequest().get().getCurrentPage().forEach(e -> System.err.println(e.name)); } /** */ @@ -120,29 +120,31 @@ void testUpload() throws IOException { Path path = Paths.get(System.getenv("HOME"), "Music/0/rc.wav"); InputStream is = Files.newInputStream(path.toFile().toPath()); - UploadSession uploadSession = client.drive().root().itemWithPath(URLEncoder.encode("test/テスト.wav", "utf-8")).createUploadSession(new DriveItemUploadableProperties()).buildRequest().post(); + UploadSession uploadSession = client.drive().root().itemWithPath(URLEncoder.encode("test/テスト.wav", StandardCharsets.UTF_8)).createUploadSession(new DriveItemUploadableProperties()).buildRequest().post(); ChunkedUploadProvider chunkedUploadProvider = new ChunkedUploadProvider<>(uploadSession, client, is, is.available(), DriveItem.class); - chunkedUploadProvider.upload(new IProgressCallback() { - @Override - public void progress(final long current, final long max) { - System.err.println(current + "/" + max); - } - @Override - public void success(final DriveItem result) { - System.err.println("done"); - } - @Override - public void failure(final ClientException ex) { - throw new IllegalStateException(ex); - } - }); + chunkedUploadProvider.upload(new IProgressCallback<>() { + @Override + public void progress(final long current, final long max) { + System.err.println(current + "/" + max); + } + + @Override + public void success(final DriveItem result) { + System.err.println("done"); + } + + @Override + public void failure(final ClientException ex) { + throw new IllegalStateException(ex); + } + }); } /** */ void testDelete(String name) throws IOException { try { - client.drive().root().itemWithPath(URLEncoder.encode(name, "utf-8")).buildRequest().delete(); + client.drive().root().itemWithPath(URLEncoder.encode(name, StandardCharsets.UTF_8)).buildRequest().delete(); } catch (GraphServiceException e) { if (!e.getMessage().startsWith("Error code: itemNotFound")) { throw e; @@ -156,8 +158,8 @@ void testDelete(String name) throws IOException { void testCopy() throws IOException { testDelete("test/フォルダー/コピー.wav"); - DriveItem src = client.drive().root().itemWithPath(URLEncoder.encode("test/テスト.wav", "utf-8")).buildRequest().get(); - DriveItem dst = client.drive().root().itemWithPath(URLEncoder.encode("test/フォルダー", "utf-8")).buildRequest().get(); + DriveItem src = client.drive().root().itemWithPath(URLEncoder.encode("test/テスト.wav", StandardCharsets.UTF_8)).buildRequest().get(); + DriveItem dst = client.drive().root().itemWithPath(URLEncoder.encode("test/フォルダー", StandardCharsets.UTF_8)).buildRequest().get(); ItemReference ir = new ItemReference(); @@ -171,20 +173,22 @@ void testCopy() throws IOException { @SuppressWarnings({ "unchecked", "rawtypes" }) // TODO LraSession copySession = client.getHttpProvider().send((IHttpRequest) request, LraMonitorResult.class, body, (IStatefulResponseHandler) handler).getSession(); LraMonitorProvider copyMonitorProvider = new LraMonitorProvider<>(copySession, client, DriveItem.class); - copyMonitorProvider.monitor(new IProgressCallback() { - @Override - public void progress(final long current, final long max) { - System.err.println(current + "/" + max); - } - @Override - public void success(final DriveItem result) { - System.err.println("done: " + result.getRawObject()); - } - @Override - public void failure(final ClientException ex) { - ex.printStackTrace(); - } - }); + copyMonitorProvider.monitor(new IProgressCallback<>() { + @Override + public void progress(final long current, final long max) { + System.err.println(current + "/" + max); + } + + @Override + public void success(final DriveItem result) { + System.err.println("done: " + result.getRawObject()); + } + + @Override + public void failure(final ClientException ex) { + ex.printStackTrace(); + } + }); } /** */ diff --git a/vavi-nio-file-onedrive4/src/test/java/vavi/nio/file/onedrive4/WebHookApiTest.java b/vavi-nio-file-onedrive4/src/test/java/vavi/nio/file/onedrive4/WebHookApiTest.java index 4be798cd..c300b873 100644 --- a/vavi-nio-file-onedrive4/src/test/java/vavi/nio/file/onedrive4/WebHookApiTest.java +++ b/vavi-nio-file-onedrive4/src/test/java/vavi/nio/file/onedrive4/WebHookApiTest.java @@ -10,7 +10,6 @@ import java.util.Calendar; import com.microsoft.graph.authentication.IAuthenticationProvider; -import com.microsoft.graph.http.IHttpRequest; import com.microsoft.graph.models.extensions.DriveItem; import com.microsoft.graph.models.extensions.Folder; import com.microsoft.graph.models.extensions.IGraphServiceClient; @@ -60,12 +59,7 @@ public static void main(String[] args) throws Exception { String accessToken = new MicrosoftGraphOAuth2(appCredential, true).authorize(userCredential); //Debug.println("accessToken: " + accessToken); - IAuthenticationProvider authenticationProvider = new IAuthenticationProvider() { - @Override - public void authenticateRequest(IHttpRequest request) { - request.addHeader("Authorization", "Bearer " + accessToken); - } - }; + IAuthenticationProvider authenticationProvider = request -> request.addHeader("Authorization", "Bearer " + accessToken); IGraphServiceClient graphClient = GraphServiceClient.builder() .authenticationProvider(authenticationProvider) .logger(new MyLogger()) diff --git a/vavi-nio-file-sandbox/src/test/java/Classification2.java b/vavi-nio-file-sandbox/src/test/java/Classification2.java index 8ccf7d07..cbb99165 100644 --- a/vavi-nio-file-sandbox/src/test/java/Classification2.java +++ b/vavi-nio-file-sandbox/src/test/java/Classification2.java @@ -121,12 +121,12 @@ private static String toKana(String text) throws IOException{ } } //System.err.println(sb); - return sb.length() == 0 ? text : sb.toString(); + return sb.isEmpty() ? text : sb.toString(); } static class MyFileVisitor extends SimpleFileVisitor { - private List list = new ArrayList<>(); + private final List list = new ArrayList<>(); Path root; diff --git a/vavi-nio-file-sandbox/src/test/java/Classification3.java b/vavi-nio-file-sandbox/src/test/java/Classification3.java index e72f29a4..8c6dd70a 100644 --- a/vavi-nio-file-sandbox/src/test/java/Classification3.java +++ b/vavi-nio-file-sandbox/src/test/java/Classification3.java @@ -86,7 +86,7 @@ void classify(Path root) throws IOException { /** */ static class MyFileVisitor extends SimpleFileVisitor { - private List list = new ArrayList<>(); + private final List list = new ArrayList<>(); Pattern pattern = Pattern.compile("[あかさたなはまやらわ]"); diff --git a/vavi-nio-file-sandbox/src/test/java/CloserFinder.java b/vavi-nio-file-sandbox/src/test/java/CloserFinder.java index 5b75b45f..52587bda 100644 --- a/vavi-nio-file-sandbox/src/test/java/CloserFinder.java +++ b/vavi-nio-file-sandbox/src/test/java/CloserFinder.java @@ -46,30 +46,28 @@ public static void main(String[] args) throws IOException { MyFileVisitor fileSearcher = new MyFileVisitor(); Files.walkFileTree(root, fileSearcher); fileSearcher.result().parallelStream() - .forEach(path1 -> { - fileSearcher.result().parallelStream() - .forEach(path2 -> { - try { - if (!path1.equals(path2)) { - String filename1 = Util.toFilenameString(path1); - String filename2 = Util.toFilenameString(path2); - int d = LevenshteinDistance.calculate(filename1, filename2); - if (d > 1 && d < 5) { - System.err.println(path1 + ": " + path2); - } + .forEach(path1 -> fileSearcher.result().parallelStream() + .forEach(path2 -> { + try { + if (!path1.equals(path2)) { + String filename1 = Util.toFilenameString(path1); + String filename2 = Util.toFilenameString(path2); + int d = LevenshteinDistance.calculate(filename1, filename2); + if (d > 1 && d < 5) { + System.err.println(path1 + ": " + path2); } - } catch (IOException e) { - throw new IllegalStateException(e); } - }); - }); + } catch (IOException e) { + throw new IllegalStateException(e); + } + })); fs.close(); } static class MyFileVisitor extends SimpleFileVisitor { - private List list = new ArrayList<>(); + private final List list = new ArrayList<>(); @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attr) { diff --git a/vavi-nio-file-sandbox/src/test/java/Descriptor.java b/vavi-nio-file-sandbox/src/test/java/Descriptor.java index 721ac474..d5f74d20 100644 --- a/vavi-nio-file-sandbox/src/test/java/Descriptor.java +++ b/vavi-nio-file-sandbox/src/test/java/Descriptor.java @@ -79,21 +79,20 @@ public static class Result { String isbn13; @Override public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("Result [title="); - builder.append(title); - builder.append(", authors="); - builder.append(authors); - builder.append(", publishedDate="); - builder.append(publishedDate); - builder.append(", description="); - builder.append(description); - builder.append(", isbn10="); - builder.append(isbn10); - builder.append(", isbn13="); - builder.append(isbn13); - builder.append("]"); - return builder.toString(); + String builder = "Result [title=" + + title + + ", authors=" + + authors + + ", publishedDate=" + + publishedDate + + ", description=" + + description + + ", isbn10=" + + isbn10 + + ", isbn13=" + + isbn13 + + "]"; + return builder; } public String toFormatedString() { StringBuilder builder = new StringBuilder(); diff --git a/vavi-nio-file-sandbox/src/test/java/GoogleDriveDeletedChecker.java b/vavi-nio-file-sandbox/src/test/java/GoogleDriveDeletedChecker.java index daa8d996..57b0ba64 100644 --- a/vavi-nio-file-sandbox/src/test/java/GoogleDriveDeletedChecker.java +++ b/vavi-nio-file-sandbox/src/test/java/GoogleDriveDeletedChecker.java @@ -5,23 +5,17 @@ */ import java.io.IOException; -import java.io.OutputStream; import java.net.URI; import java.nio.file.FileSystem; import java.nio.file.FileSystems; -import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.logging.Level; -import java.util.stream.Stream; import vavi.nio.file.Util; import vavi.nio.file.googledrive.GoogleDriveFileSystemProvider; -import vavi.nio.file.googledrive.GoogleDriveOpenOption; -import vavi.nio.file.googledrive.GoogleDriveUserDefinedFileAttributesProvider; import vavi.util.Debug; import static vavi.nio.file.googledrive.GoogleDriveFileSystemDriver.fileSearcher; @@ -77,7 +71,7 @@ void func1(Path file) { if (results.size() > 1) { Debug.println(Level.WARNING, "ambiguous: " + normalized); results.forEach(System.err::println); - } else if (results.size() == 0) { + } else if (results.isEmpty()) { Debug.println(Level.WARNING, "none: " + normalized); } else { count++; diff --git a/vavi-nio-file-sandbox/src/test/java/GoogleDriveFilename.java b/vavi-nio-file-sandbox/src/test/java/GoogleDriveFilename.java index 75b5d37a..6ac7ffae 100644 --- a/vavi-nio-file-sandbox/src/test/java/GoogleDriveFilename.java +++ b/vavi-nio-file-sandbox/src/test/java/GoogleDriveFilename.java @@ -20,7 +20,6 @@ import vavi.nio.file.Util; import vavi.nio.file.googledrive.GoogleDriveFileSystemProvider; -import vavi.util.Debug; import static java.nio.file.FileVisitResult.CONTINUE; diff --git a/vavi-nio-file-sandbox/src/test/java/GoogleDriveThumbnail.java b/vavi-nio-file-sandbox/src/test/java/GoogleDriveThumbnail.java index ec7e8634..5bf8c50c 100644 --- a/vavi-nio-file-sandbox/src/test/java/GoogleDriveThumbnail.java +++ b/vavi-nio-file-sandbox/src/test/java/GoogleDriveThumbnail.java @@ -198,7 +198,7 @@ void func2(Path file) throws IOException { return a.compareTo(b); } }); - if (names.size() == 0) { + if (names.isEmpty()) { zis = new ZipInputStream(new BufferedInputStream(Files.newInputStream(file))); while ((entry = zis.getNextEntry()) != null) { System.err.println(entry.getName()); diff --git a/vavi-nio-file-sandbox/src/test/java/GoogleDriveUploader.java b/vavi-nio-file-sandbox/src/test/java/GoogleDriveUploader.java index 5be3d136..755632eb 100644 --- a/vavi-nio-file-sandbox/src/test/java/GoogleDriveUploader.java +++ b/vavi-nio-file-sandbox/src/test/java/GoogleDriveUploader.java @@ -84,7 +84,7 @@ void func1(Path file) { Debug.println(Level.WARNING, "ambiguous: " + query); results.forEach(System.err::println); return; - } else if (results.size() == 0) { + } else if (results.isEmpty()) { Debug.println(Level.WARNING, "none: " + query); return; } else { diff --git a/vavi-nio-file-sandbox/src/test/java/OneDriveThumbnail.java b/vavi-nio-file-sandbox/src/test/java/OneDriveThumbnail.java index 31ba6b3f..872ee12e 100644 --- a/vavi-nio-file-sandbox/src/test/java/OneDriveThumbnail.java +++ b/vavi-nio-file-sandbox/src/test/java/OneDriveThumbnail.java @@ -190,7 +190,7 @@ static void func2(Path file) throws IOException { } // determine cover - Collections.sort(names, (a, b) -> { + names.sort((a, b) -> { if (a.contains("表紙") && !b.contains("表紙")) { return -1; } else if (!a.contains("表紙") && b.contains("表紙")) { @@ -203,7 +203,7 @@ static void func2(Path file) throws IOException { return a.compareTo(b); } }); - if (names.size() == 0) { + if (names.isEmpty()) { ZipInputStream zis = new ZipInputStream(new BufferedInputStream(Files.newInputStream(file)), Charset.forName(sjis ? "MS932" : "UTF-8")); while ((entry = zis.getNextEntry()) != null) { System.err.println(entry.getName()); @@ -257,9 +257,9 @@ static void func3(Path file) throws Exception { // exec // convert path from google drive fs to default fs - // because "zipfs" dosn't accept googledrive as sub scheme + // because "zipfs" doesn't accept googledrive as sub scheme Path gd = Paths.get("/Volumes/GoogleDrive/My Drive", file.toString()); - URI uri = URI.create("jar:" + gd.toUri().toString()); + URI uri = URI.create("jar:" + gd.toUri()); Debug.println("uri: " + uri); FileSystem fs = FileSystems.newFileSystem(uri, Collections.emptyMap()); diff --git a/vavi-nio-file-sandbox/src/test/java/ShowEmptyFolder.java b/vavi-nio-file-sandbox/src/test/java/ShowEmptyFolder.java index 7ded0c0b..2859f717 100644 --- a/vavi-nio-file-sandbox/src/test/java/ShowEmptyFolder.java +++ b/vavi-nio-file-sandbox/src/test/java/ShowEmptyFolder.java @@ -75,7 +75,7 @@ public FileVisitResult visitFileFailed(Path file, IOException exc) { } boolean filter1(Path path) throws IOException { - return Files.list(path).count() == 0; + return Files.list(path).findAny().isEmpty(); } boolean filter2(Path path) throws IOException { diff --git a/vavi-nio-file-sandbox/src/test/java/Synchronizer.java b/vavi-nio-file-sandbox/src/test/java/Synchronizer.java index 39d9a9a5..d250b672 100644 --- a/vavi-nio-file-sandbox/src/test/java/Synchronizer.java +++ b/vavi-nio-file-sandbox/src/test/java/Synchronizer.java @@ -76,7 +76,7 @@ public static void main(String[] args) throws IOException { static class MyFileVisitor extends SimpleFileVisitor { - private List list = new ArrayList<>(); + private final List list = new ArrayList<>(); @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attr) { diff --git a/vavi-nio-file-sandbox/src/test/java/Test1.java b/vavi-nio-file-sandbox/src/test/java/Test1.java index 52d00712..3f0c90f8 100644 --- a/vavi-nio-file-sandbox/src/test/java/Test1.java +++ b/vavi-nio-file-sandbox/src/test/java/Test1.java @@ -61,11 +61,11 @@ void setup() throws Exception { public void test() { String location = "https://login.live.com/oauth20_authorize.srf?client_id=0000000040184284&scope=wl.offline_access&response_type=code&redirect_uri=https%3A%2F%2Fvast-plateau-97564.herokuapp.com%2Fonedrive_set"; String url = "https://login.live.com/oauth20_authorize.srf"; - assertTrue(location.indexOf(url) == 0); + assertEquals(0, location.indexOf(url)); String location2 = "https://vast-plateau-97564.herokuapp.com/onedrive_set?code=M2739c1c0-460c-2ac5-8e94-f9b8fdf3dd5c"; String redirectUrl = "https://vast-plateau-97564.herokuapp.com/onedrive_set"; - assertTrue(location2.indexOf(redirectUrl) == 0); + assertEquals(0, location2.indexOf(redirectUrl)); } @Test diff --git a/vavi-nio-file-sandbox/src/test/java/TestAozora.java b/vavi-nio-file-sandbox/src/test/java/TestAozora.java index 921ea63e..4211d469 100644 --- a/vavi-nio-file-sandbox/src/test/java/TestAozora.java +++ b/vavi-nio-file-sandbox/src/test/java/TestAozora.java @@ -77,7 +77,7 @@ public String getAuthor() { static class MyFileVisitor extends SimpleFileVisitor { - private List list = new ArrayList<>(); + private final List list = new ArrayList<>(); @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attr) { diff --git a/vavi-nio-file-sandbox/src/test/java/vavi/nio/file/watch/WatchServiceTest.java b/vavi-nio-file-sandbox/src/test/java/vavi/nio/file/watch/WatchServiceTest.java index 39db84d9..ea19b27f 100644 --- a/vavi-nio-file-sandbox/src/test/java/vavi/nio/file/watch/WatchServiceTest.java +++ b/vavi-nio-file-sandbox/src/test/java/vavi/nio/file/watch/WatchServiceTest.java @@ -1,4 +1,3 @@ -package vavi.nio.file.watch; /* * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -22,24 +21,17 @@ * questions. */ -/* @test - * @bug 4313887 6838333 7017446 8011537 8042470 - * @summary Unit test for java.nio.file.WatchService - * @library .. - * @run main Basic - */ - - +package vavi.nio.file.watch; import java.io.IOException; import java.io.OutputStream; import java.net.URI; +import java.nio.charset.StandardCharsets; import java.nio.file.ClosedWatchServiceException; import java.nio.file.FileSystem; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardOpenOption; -import java.nio.file.StandardWatchEventKinds; import java.nio.file.WatchEvent; import java.nio.file.WatchKey; import java.nio.file.WatchService; @@ -50,18 +42,21 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; - import vavi.nio.file.googledrive.GoogleDriveFileSystemProvider; +import vavi.util.Debug; import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE; import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE; import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY; import static java.nio.file.StandardWatchEventKinds.OVERFLOW; +import static org.junit.jupiter.api.Assertions.assertThrows; import static vavi.nio.file.Base.removeTree; /** * Unit test for WatchService that exercises all methods in various scenarios. + * + * @bug 4313887 6838333 7017446 8011537 8042470 */ @Disabled public class WatchServiceTest { @@ -74,7 +69,7 @@ void checkKey(WatchKey key, Path dir) { } void takeExpectedKey(WatchService watcher, WatchKey expected) { - System.out.println("take events..."); + Debug.println("take events..."); WatchKey key; try { key = watcher.take(); @@ -88,10 +83,9 @@ void takeExpectedKey(WatchService watcher, WatchKey expected) { void checkExpectedEvent(Iterable> events, WatchEvent.Kind expectedKind, - Object expectedContext) - { + Object expectedContext) { WatchEvent event = events.iterator().next(); - System.out.format("got event: type=%s, count=%d, context=%s\n", + Debug.printf("got event: type=%s, count=%d, context=%s\n", event.kind(), event.count(), event.context()); if (event.kind() != expectedKind) throw new RuntimeException("unexpected event"); @@ -106,7 +100,7 @@ void checkExpectedEvent(Iterable> events, */ @Test void testEvents() throws IOException { - System.out.println("-- Standard Events --"); + Debug.println("-- Standard Events --"); Path name = fs.getPath("foo"); @@ -114,70 +108,64 @@ void testEvents() throws IOException { // --- ENTRY_CREATE --- // register for event - System.out.format("register %s for ENTRY_CREATE\n", dir); - WatchKey myKey = dir.register(watcher, - new WatchEvent.Kind[]{ ENTRY_CREATE }); + Debug.printf("register %s for ENTRY_CREATE\n", dir); + WatchKey myKey = dir.register(watcher, ENTRY_CREATE); checkKey(myKey, dir); // create file Path file = dir.resolve("foo"); - System.out.format("create %s\n", file); + Debug.printf("create %s\n", file); Files.createFile(file); // remove key and check that we got the ENTRY_CREATE event takeExpectedKey(watcher, myKey); - checkExpectedEvent(myKey.pollEvents(), - StandardWatchEventKinds.ENTRY_CREATE, name); + checkExpectedEvent(myKey.pollEvents(), ENTRY_CREATE, name); - System.out.println("reset key"); + Debug.println("reset key"); if (!myKey.reset()) throw new RuntimeException("key has been cancalled"); - System.out.println("OKAY"); + Debug.println("OKAY"); // --- ENTRY_DELETE --- - System.out.format("register %s for ENTRY_DELETE\n", dir); - WatchKey deleteKey = dir.register(watcher, - new WatchEvent.Kind[]{ ENTRY_DELETE }); + Debug.printf("register %s for ENTRY_DELETE\n", dir); + WatchKey deleteKey = dir.register(watcher, ENTRY_DELETE); if (deleteKey != myKey) throw new RuntimeException("register did not return existing key"); checkKey(deleteKey, dir); - System.out.format("delete %s\n", file); + Debug.printf("delete %s\n", file); Files.delete(file); takeExpectedKey(watcher, myKey); - checkExpectedEvent(myKey.pollEvents(), - StandardWatchEventKinds.ENTRY_DELETE, name); + checkExpectedEvent(myKey.pollEvents(), ENTRY_DELETE, name); - System.out.println("reset key"); + Debug.println("reset key"); if (!myKey.reset()) throw new RuntimeException("key has been cancalled"); - System.out.println("OKAY"); + Debug.println("OKAY"); // create the file for the next test Files.createFile(file); // --- ENTRY_MODIFY --- - System.out.format("register %s for ENTRY_MODIFY\n", dir); - WatchKey newKey = dir.register(watcher, - new WatchEvent.Kind[]{ ENTRY_MODIFY }); + Debug.printf("register %s for ENTRY_MODIFY\n", dir); + WatchKey newKey = dir.register(watcher, ENTRY_MODIFY); if (newKey != myKey) throw new RuntimeException("register did not return existing key"); checkKey(newKey, dir); - System.out.format("update: %s\n", file); + Debug.printf("update: %s\n", file); try (OutputStream out = Files.newOutputStream(file, StandardOpenOption.APPEND)) { - out.write("I am a small file".getBytes("UTF-8")); + out.write("I am a small file".getBytes(StandardCharsets.UTF_8)); } // remove key and check that we got the ENTRY_MODIFY event takeExpectedKey(watcher, myKey); - checkExpectedEvent(myKey.pollEvents(), - StandardWatchEventKinds.ENTRY_MODIFY, name); - System.out.println("OKAY"); + checkExpectedEvent(myKey.pollEvents(), ENTRY_MODIFY, name); + Debug.println("OKAY"); // done Files.delete(file); @@ -189,25 +177,24 @@ void testEvents() throws IOException { */ @Test void testCancel() throws IOException { - System.out.println("-- Cancel --"); + Debug.println("-- Cancel --"); try (WatchService watcher = fs.newWatchService()) { - System.out.format("register %s for events\n", dir); - WatchKey myKey = dir.register(watcher, - new WatchEvent.Kind[]{ ENTRY_CREATE }); + Debug.printf("register %s for events\n", dir); + WatchKey myKey = dir.register(watcher, ENTRY_CREATE); checkKey(myKey, dir); - System.out.println("cancel key"); + Debug.println("cancel key"); myKey.cancel(); // create a file in the directory Path file = dir.resolve("mars"); - System.out.format("create: %s\n", file); + Debug.printf("create: %s\n", file); Files.createFile(file); // poll for keys - there will be none - System.out.println("poll..."); + Debug.println("poll..."); try { WatchKey key = watcher.poll(3000, TimeUnit.MILLISECONDS); if (key != null) @@ -219,7 +206,7 @@ void testCancel() throws IOException { // done Files.delete(file); - System.out.println("OKAY"); + Debug.println("OKAY"); } } @@ -229,28 +216,26 @@ void testCancel() throws IOException { */ @Test void testAutomaticCancel() throws IOException { - System.out.println("-- Automatic Cancel --"); + Debug.println("-- Automatic Cancel --"); Path subdir = Files.createDirectory(dir.resolve("bar")); try (WatchService watcher = fs.newWatchService()) { - System.out.format("register %s for events\n", subdir); - WatchKey myKey = subdir.register(watcher, - new WatchEvent.Kind[]{ ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY }); + Debug.printf("register %s for events\n", subdir); + WatchKey myKey = subdir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY); - System.out.format("delete: %s\n", subdir); + Debug.printf("delete: %s\n", subdir); Files.delete(subdir); takeExpectedKey(watcher, myKey); - System.out.println("reset key"); + Debug.println("reset key"); if (myKey.reset()) throw new RuntimeException("Key was not cancelled"); if (myKey.isValid()) throw new RuntimeException("Key is still valid"); - System.out.println("OKAY"); - + Debug.println("OKAY"); } } @@ -259,19 +244,15 @@ void testAutomaticCancel() throws IOException { */ @Test void testWakeup() throws IOException { - System.out.println("-- Wakeup Tests --"); + Debug.println("-- Wakeup Tests --"); final WatchService watcher = fs.newWatchService(); - Runnable r = new Runnable() { - public void run() { - try { - Thread.sleep(5000); - System.out.println("close WatchService..."); - watcher.close(); - } catch (InterruptedException x) { - x.printStackTrace(); - } catch (IOException x) { - x.printStackTrace(); - } + Runnable r = () -> { + try { + Thread.sleep(5000); + Debug.println("close WatchService..."); + watcher.close(); + } catch (InterruptedException | IOException x) { + Debug.printStackTrace(x); } }; @@ -279,16 +260,16 @@ public void run() { new Thread(r).start(); try { - System.out.println("take..."); + Debug.println("take..."); watcher.take(); throw new RuntimeException("ClosedWatchServiceException not thrown"); } catch (InterruptedException x) { throw new RuntimeException(x); } catch (ClosedWatchServiceException x) { - System.out.println("ClosedWatchServiceException thrown"); + Debug.println("ClosedWatchServiceException thrown"); } - System.out.println("OKAY"); + Debug.println("OKAY"); } /** @@ -296,20 +277,21 @@ public void run() { */ @Test void testExceptions() throws IOException { - System.out.println("-- Exceptions and other simple tests --"); + Debug.println("-- Exceptions and other simple tests --"); WatchService watcher = fs.newWatchService(); - try { + + try (watcher) { // Poll tests WatchKey key; - System.out.println("poll..."); + Debug.println("poll..."); key = watcher.poll(); if (key != null) throw new RuntimeException("no keys registered"); - System.out.println("poll with timeout..."); + Debug.println("poll with timeout..."); try { long start = System.nanoTime(); key = watcher.poll(3000, TimeUnit.MILLISECONDS); @@ -323,105 +305,74 @@ void testExceptions() throws IOException { } // IllegalArgumentException - System.out.println("IllegalArgumentException tests..."); - try { - dir.register(watcher /*empty event list*/); - throw new RuntimeException("IllegalArgumentException not thrown"); - } catch (IllegalArgumentException x) { - } - try { - // OVERFLOW is ignored so this is equivalent to the empty set - dir.register(watcher, OVERFLOW); - throw new RuntimeException("IllegalArgumentException not thrown"); - } catch (IllegalArgumentException x) { - } - try { - // OVERFLOW is ignored even if specified multiple times - dir.register(watcher, OVERFLOW, OVERFLOW); - throw new RuntimeException("IllegalArgumentException not thrown"); - } catch (IllegalArgumentException x) { - } + Debug.println("IllegalArgumentException tests..."); + assertThrows(IllegalArgumentException.class, + () -> dir.register(watcher /*empty event list*/), + "IllegalArgumentException not thrown"); + assertThrows(IllegalArgumentException.class, + // OVERFLOW is ignored so this is equivalent to the empty set + () -> dir.register(watcher, OVERFLOW), + "IllegalArgumentException not thrown"); + assertThrows(IllegalArgumentException.class, + // OVERFLOW is ignored even if specified multiple times + () -> dir.register(watcher, OVERFLOW, OVERFLOW), + "IllegalArgumentException not thrown"); // UnsupportedOperationException - try { - dir.register(watcher, - new WatchEvent.Kind() { - @Override public String name() { return "custom"; } - @Override public Class type() { return Object.class; } - }); - throw new RuntimeException("UnsupportedOperationException not thrown"); - } catch (UnsupportedOperationException x) { - } - try { - dir.register(watcher, - new WatchEvent.Kind[]{ ENTRY_CREATE }, - new WatchEvent.Modifier() { - @Override public String name() { return "custom"; } - }); - throw new RuntimeException("UnsupportedOperationException not thrown"); - } catch (UnsupportedOperationException x) { - } + assertThrows(UnsupportedOperationException.class, + () -> dir.register(watcher, new WatchEvent.Kind<>() { + @Override public String name() { return "custom"; } + @Override public Class type() { return Object.class; } + }), + "UnsupportedOperationException not thrown"); + assertThrows(UnsupportedOperationException.class, + () -> dir.register(watcher, new WatchEvent.Kind[]{ ENTRY_CREATE }, () -> "custom"), + "UnsupportedOperationException not thrown"); // NullPointerException - System.out.println("NullPointerException tests..."); - try { - dir.register(null, ENTRY_CREATE); - throw new RuntimeException("NullPointerException not thrown"); - } catch (NullPointerException x) { - } - try { - dir.register(watcher, new WatchEvent.Kind[]{ null }); - throw new RuntimeException("NullPointerException not thrown"); - } catch (NullPointerException x) { - } - try { - dir.register(watcher, new WatchEvent.Kind[]{ ENTRY_CREATE }, - (WatchEvent.Modifier)null); - throw new RuntimeException("NullPointerException not thrown"); - } catch (NullPointerException x) { - } - } finally { - watcher.close(); + Debug.println("NullPointerException tests..."); + assertThrows(NullPointerException.class, + () -> dir.register(null, ENTRY_CREATE), + "NullPointerException not thrown"); + assertThrows(NullPointerException.class, + () -> dir.register(watcher, new WatchEvent.Kind[]{ null }), + "NullPointerException not thrown"); + assertThrows(NullPointerException.class, + () -> dir.register(watcher, new WatchEvent.Kind[]{ ENTRY_CREATE }, (WatchEvent.Modifier) null), + "NullPointerException not thrown"); } // -- ClosedWatchServiceException -- - System.out.println("ClosedWatchServiceException tests..."); + Debug.println("ClosedWatchServiceException tests..."); - try { - watcher.poll(); - throw new RuntimeException("ClosedWatchServiceException not thrown"); - } catch (ClosedWatchServiceException x) { - } + assertThrows(ClosedWatchServiceException.class, watcher::poll, + "ClosedWatchServiceException not thrown"); // assume that poll throws exception immediately long start = System.nanoTime(); - try { - watcher.poll(10000, TimeUnit.MILLISECONDS); - throw new RuntimeException("ClosedWatchServiceException not thrown"); - } catch (InterruptedException x) { - throw new RuntimeException(x); - } catch (ClosedWatchServiceException x) { - long waited = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start); - if (waited > 5000) - throw new RuntimeException("poll was too long"); - } + assertThrows(ClosedWatchServiceException.class, () -> { + try { + watcher.poll(10000, TimeUnit.MILLISECONDS); + } catch (InterruptedException x) { + throw new RuntimeException(x); + } + }, "ClosedWatchServiceException not thrown"); + long waited = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start); + if (waited > 5000) + throw new RuntimeException("poll was too long"); - try { - watcher.take(); - throw new RuntimeException("ClosedWatchServiceException not thrown"); - } catch (InterruptedException x) { - throw new RuntimeException(x); - } catch (ClosedWatchServiceException x) { - } + assertThrows(ClosedWatchServiceException.class, () -> { + try { + watcher.take(); + } catch (InterruptedException x) { + throw new RuntimeException(x); + } + }, "ClosedWatchServiceException not thrown"); - try { - dir.register(watcher, new WatchEvent.Kind[]{ ENTRY_CREATE }); - throw new RuntimeException("ClosedWatchServiceException not thrown"); - } catch (ClosedWatchServiceException x) { - } + assertThrows(ClosedWatchServiceException.class, () -> dir.register(watcher, ENTRY_CREATE), "ClosedWatchServiceException not thrown"); - System.out.println("OKAY"); + Debug.println("OKAY"); } /** @@ -430,38 +381,35 @@ void testExceptions() throws IOException { */ @Test void testTwoWatchers() throws IOException { - System.out.println("-- Two watchers test --"); + Debug.println("-- Two watchers test --"); + + try (WatchService watcher1 = fs.newWatchService(); + WatchService watcher2 = fs.newWatchService()) { - WatchService watcher1 = fs.newWatchService(); - WatchService watcher2 = fs.newWatchService(); - try { Path name1 = fs.getPath("gus1"); Path name2 = fs.getPath("gus2"); // create gus1 Path file1 = dir.resolve(name1); - System.out.format("create %s\n", file1); + Debug.printf("create %s\n", file1); Files.createFile(file1); // register with both watch services (different events) - System.out.println("register for different events"); - WatchKey key1 = dir.register(watcher1, - new WatchEvent.Kind[]{ ENTRY_CREATE }); - WatchKey key2 = dir.register(watcher2, - new WatchEvent.Kind[]{ ENTRY_DELETE }); + Debug.println("register for different events"); + WatchKey key1 = dir.register(watcher1, ENTRY_CREATE); + WatchKey key2 = dir.register(watcher2, ENTRY_DELETE); if (key1 == key2) throw new RuntimeException("keys should be different"); // create gus2 Path file2 = dir.resolve(name2); - System.out.format("create %s\n", file2); + Debug.printf("create %s\n", file2); Files.createFile(file2); // check that key1 got ENTRY_CREATE takeExpectedKey(watcher1, key1); - checkExpectedEvent(key1.pollEvents(), - StandardWatchEventKinds.ENTRY_CREATE, name2); + checkExpectedEvent(key1.pollEvents(), ENTRY_CREATE, name2); // check that key2 got zero events WatchKey key = watcher2.poll(); @@ -473,8 +421,7 @@ void testTwoWatchers() throws IOException { // check that key2 got ENTRY_DELETE takeExpectedKey(watcher2, key2); - checkExpectedEvent(key2.pollEvents(), - StandardWatchEventKinds.ENTRY_DELETE, name1); + checkExpectedEvent(key2.pollEvents(), ENTRY_DELETE, name1); // check that key1 got zero events key = watcher1.poll(); @@ -487,21 +434,16 @@ void testTwoWatchers() throws IOException { // change registration with watcher2 so that they are both // registered for the same event - System.out.println("register for same event"); - key2 = dir.register(watcher2, new WatchEvent.Kind[]{ ENTRY_CREATE }); + Debug.println("register for same event"); + key2 = dir.register(watcher2, ENTRY_CREATE); // create file and key2 should be queued - System.out.format("create %s\n", file1); + Debug.printf("create %s\n", file1); Files.createFile(file1); takeExpectedKey(watcher2, key2); - checkExpectedEvent(key2.pollEvents(), - StandardWatchEventKinds.ENTRY_CREATE, name1); - - System.out.println("OKAY"); + checkExpectedEvent(key2.pollEvents(), ENTRY_CREATE, name1); - } finally { - watcher2.close(); - watcher1.close(); + Debug.println("OKAY"); } } @@ -511,17 +453,17 @@ void testTwoWatchers() throws IOException { */ @Test void testThreadInterrupt() throws IOException { - System.out.println("-- Thread interrupted status test --"); + Debug.println("-- Thread interrupted status test --"); Thread curr = Thread.currentThread(); try (WatchService watcher = fs.newWatchService()) { - System.out.println("interrupting current thread"); + Debug.println("interrupting current thread"); curr.interrupt(); dir.register(watcher, ENTRY_CREATE); if (!curr.isInterrupted()) throw new RuntimeException("thread should remain interrupted"); - System.out.println("current thread is still interrupted"); - System.out.println("OKAY"); + Debug.println("current thread is still interrupted"); + Debug.println("OKAY"); } finally { Thread.interrupted(); } @@ -534,7 +476,7 @@ static void before() throws IOException { String email = System.getenv("GOOGLE_TEST_ACCOUNT"); URI uri = URI.create("googledrive:///?id=" + email); - fs = new GoogleDriveFileSystemProvider().newFileSystem(uri, Collections.EMPTY_MAP); + fs = new GoogleDriveFileSystemProvider().newFileSystem(uri, Collections.emptyMap()); dir = Files.createTempDirectory(fs.getRootDirectories().iterator().next(), "VAVIFUSE-TEST-WATCHSERVICE"); } diff --git a/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/SftpVfsAuthenticator.java b/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/SftpVfsAuthenticator.java index aae32272..09c6f39e 100644 --- a/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/SftpVfsAuthenticator.java +++ b/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/SftpVfsAuthenticator.java @@ -140,7 +140,7 @@ public boolean promptYesNo(String str) { @Override public FileSystemOptions authorize(VfsCredential credential) throws IOException { - SftpVfsCredential c = SftpVfsCredential.class.cast(credential); + SftpVfsCredential c = (SftpVfsCredential) credential; boolean pkc = c.passphrase != null; FileSystemOptions options = new FileSystemOptions(); diff --git a/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/SmbVfsAuthenticator.java b/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/SmbVfsAuthenticator.java index b6fd93be..03f5cd9a 100644 --- a/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/SmbVfsAuthenticator.java +++ b/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/SmbVfsAuthenticator.java @@ -106,7 +106,7 @@ public VfsCredential getCredential(String alias, URI uri) { @Override public FileSystemOptions authorize(VfsCredential credential) throws IOException { - SmbVfsCredential c = SmbVfsCredential.class.cast(credential); + SmbVfsCredential c = (SmbVfsCredential) credential; FileSystemOptions options = new FileSystemOptions(); StaticUserAuthenticator auth = new StaticUserAuthenticator(c.domain, c.username, c.password); diff --git a/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/VfsAuthenticator.java b/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/VfsAuthenticator.java index 4bc44f17..63551590 100644 --- a/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/VfsAuthenticator.java +++ b/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/VfsAuthenticator.java @@ -27,13 +27,12 @@ public interface VfsAuthenticator extends Authenticator new SmbVfsAuthenticator(); + case "sftp" -> new SftpVfsAuthenticator(); + case "webdav4s" -> new WebdavVfsAuthenticator(); + default -> throw new IllegalArgumentException(scheme); + }; } } diff --git a/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/VfsCredential.java b/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/VfsCredential.java index c000f766..1285fc35 100644 --- a/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/VfsCredential.java +++ b/vavi-nio-file-vfs/src/main/java/vavi/net/auth/proprietary/vfs/VfsCredential.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.net.URI; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import vavi.net.auth.AppCredential; import vavi.net.auth.UserCredential; @@ -113,31 +114,27 @@ public int getPort() { /** */ public String buildBaseUrl() { - try { - StringBuilder sb = new StringBuilder(); - sb.append(getClientId()); - sb.append("://"); - if (username != null) { - sb.append(URLEncoder.encode(username, "utf-8")); - } - if (password != null) { - sb.append(":"); - sb.append(password); - } - if (host != null) { - if (username != null || password != null) { - sb.append("@"); - } - sb.append(host); - } - if (port != -1) { - sb.append(":"); - sb.append(port); + StringBuilder sb = new StringBuilder(); + sb.append(getClientId()); + sb.append("://"); + if (username != null) { + sb.append(URLEncoder.encode(username, StandardCharsets.UTF_8)); + } + if (password != null) { + sb.append(":"); + sb.append(password); + } + if (host != null) { + if (username != null || password != null) { + sb.append("@"); } - return sb.toString(); - } catch (IOException e) { - throw new IllegalStateException(e); + sb.append(host); + } + if (port != -1) { + sb.append(":"); + sb.append(port); } + return sb.toString(); } } diff --git a/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main.java b/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main.java index f16f1207..5cbe383f 100644 --- a/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main.java +++ b/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main.java @@ -8,6 +8,7 @@ import java.net.URI; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.time.Instant; import java.time.LocalDateTime; import java.util.Collections; @@ -76,10 +77,10 @@ public class Main { @EnabledIfEnvironmentVariable(named = "TEST_SFTP_PATH", matches = ".+"), }) void test01() throws Exception { - String username = URLEncoder.encode(System.getenv("TEST_SFTP_ACCOUNT"), "utf-8"); - String passPhrase = URLEncoder.encode(System.getenv("TEST_SFTP_PASSPHRASE"), "utf-8"); + String username = URLEncoder.encode(System.getenv("TEST_SFTP_ACCOUNT"), StandardCharsets.UTF_8); + String passPhrase = URLEncoder.encode(System.getenv("TEST_SFTP_PASSPHRASE"), StandardCharsets.UTF_8); String host = System.getenv("TEST_SFTP_HOST"); - String keyPath = URLEncoder.encode(System.getenv("TEST_SFTP_KEYPATH"), "utf-8"); + String keyPath = URLEncoder.encode(System.getenv("TEST_SFTP_KEYPATH"), StandardCharsets.UTF_8); String path = System.getenv("TEST_SFTP_PATH"); URI uri = URI.create(String.format("vfs:sftp://%s@%s%s?keyPath=%s&passphrase=%s", username, host, path, keyPath, passPhrase)); @@ -110,7 +111,7 @@ void test01() throws Exception { @EnabledIfEnvironmentVariable(named = "TEST_WEBDAV_PATH", matches = ".+"), }) void test02() throws Exception { - String username = URLEncoder.encode(System.getenv("TEST_WEBDAV_ACCOUNT"), "utf-8"); + String username = URLEncoder.encode(System.getenv("TEST_WEBDAV_ACCOUNT"), StandardCharsets.UTF_8); String password = System.getenv("TEST_WEBDAV_PASSWORD"); String host = System.getenv("TEST_WEBDAV_HOST"); String port = System.getenv("TEST_WEBDAV_PORT"); diff --git a/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main2.java b/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main2.java index 0ae6b02e..79f32202 100644 --- a/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main2.java +++ b/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main2.java @@ -8,6 +8,7 @@ import java.net.URI; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.nio.file.FileSystem; import java.util.Collections; @@ -36,7 +37,7 @@ public class Main2 { */ @Test void test01() throws Exception { - String username = URLEncoder.encode(System.getenv("TEST_SFTP_ACCOUNT"), "utf-8"); + String username = URLEncoder.encode(System.getenv("TEST_SFTP_ACCOUNT"), StandardCharsets.UTF_8); String passPhrase = System.getenv("TEST_SFTP_PASSPHRASE"); String host = System.getenv("TEST_SFTP_HOST"); String keyPath = System.getenv("TEST_SFTP_KEYPATH"); diff --git a/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main3.java b/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main3.java index 63840ba5..d25bfa1d 100644 --- a/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main3.java +++ b/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main3.java @@ -8,6 +8,7 @@ import java.net.URI; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.nio.file.FileSystem; import java.util.Collections; @@ -36,7 +37,7 @@ public class Main3 { */ @Test void test01() throws Exception { - String username = URLEncoder.encode(System.getenv("TEST_SFTP_ACCOUNT"), "utf-8"); + String username = URLEncoder.encode(System.getenv("TEST_SFTP_ACCOUNT"), StandardCharsets.UTF_8); String passPhrase = System.getenv("TEST_SFTP_PASSPHRASE"); String host = System.getenv("TEST_SFTP_HOST"); String keyPath = System.getenv("TEST_SFTP_KEYPATH"); diff --git a/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main4.java b/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main4.java index a6d1f725..8fe50b45 100644 --- a/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main4.java +++ b/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/Main4.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.net.URI; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.nio.file.FileSystem; import java.nio.file.FileSystems; import java.util.HashMap; @@ -47,10 +48,10 @@ public class Main4 { @BeforeEach public void before() throws Exception { mountPoint = System.getenv("TEST4_MOUNT_POINT"); - String username = URLEncoder.encode(System.getenv("TEST4_SFTP_ACCOUNT"), "utf-8"); - String passPhrase = URLEncoder.encode(System.getenv("TEST4_SFTP_PASSPHRASE"), "utf-8"); + String username = URLEncoder.encode(System.getenv("TEST4_SFTP_ACCOUNT"), StandardCharsets.UTF_8); + String passPhrase = URLEncoder.encode(System.getenv("TEST4_SFTP_PASSPHRASE"), StandardCharsets.UTF_8); String host = System.getenv("TEST4_SFTP_HOST"); - String keyPath = URLEncoder.encode(System.getenv("TEST4_SFTP_KEYPATH"), "utf-8"); + String keyPath = URLEncoder.encode(System.getenv("TEST4_SFTP_KEYPATH"), StandardCharsets.UTF_8); String path = System.getenv("TEST4_SFTP_PATH"); URI uri = URI.create(String.format("vfs:sftp://%s@%s%s?keyPath=%s&passphrase=%s", username, host, path, keyPath, passPhrase)); diff --git a/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/TestVfsWebdav.java b/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/TestVfsWebdav.java index 76cce34f..7c30ca61 100644 --- a/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/TestVfsWebdav.java +++ b/vavi-nio-file-vfs/src/test/java/vavi/nio/file/vfs/TestVfsWebdav.java @@ -8,6 +8,7 @@ import java.io.IOException; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import org.apache.commons.vfs2.FileObject; import org.apache.commons.vfs2.FileSystemManager; @@ -61,7 +62,7 @@ void proceed() throws IOException { FileSystemManager fs = VFS.getManager(); if (!fs.hasProvider("webdav")) throw new RuntimeException("Provider missing: webdav"); - String baseUrl = String.format(this.baseUrl, username, password, host, port, URLEncoder.encode(component, "utf-8")); + String baseUrl = String.format(this.baseUrl, username, password, host, port, URLEncoder.encode(component, StandardCharsets.UTF_8)); System.err.println("Connecting \"" + baseUrl + "\" with " + options); FileObject davFile = fs.resolveFile(baseUrl, options); // added opts! //System.err.println(smbFile.exists() + " " + smbFile.getContent().getLastModifiedTime()); From 735a27225b0c855b3dbe10c9e8b87de537e7f15d Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Wed, 28 Feb 2024 00:41:01 +0900 Subject: [PATCH 4/5] update settings --- .github/workflows/codeql-analysis.yml | 10 +++-- .github/workflows/maven.yml | 4 +- README.md | 54 +++++++++++++++------------ pom.xml | 9 +---- vavi-nio-file-amazondrive/pom.xml | 1 - vavi-nio-file-archive/pom.xml | 2 +- 6 files changed, 41 insertions(+), 39 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 9aa5f489..0627c5a1 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -18,6 +18,10 @@ jobs: analyze: name: Analyze runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write strategy: fail-fast: false @@ -34,7 +38,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v3 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -43,7 +47,7 @@ jobs: # queries: ./path/to/local/query, your-org/your-repo/queries@main - name: Set up JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '17' distribution: 'temurin' @@ -62,4 +66,4 @@ jobs: FUSE_MOUNT_POINT: tmp/fuse - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 212a554f..af070664 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -1,7 +1,7 @@ # This workflow will build a Java project with Maven # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven -name: Java CI with Maven +name: Java CI on: push: @@ -23,7 +23,7 @@ jobs: run: grep "" pom.xml | head -1 | grep -v SNAPSHOT - name: Set up JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '17' distribution: 'temurin' diff --git a/README.md b/README.md index 78871ded..4966e0a9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![Release](https://jitpack.io/v/umjammer/vavi-apps-fuse.svg)](https://jitpack.io/#umjammer/vavi-apps-fuse) -[![Java CI](https://github.com/umjammer/vavi-apps-fuse/actions/workflows/maven.yml/badge.svg)](https://github.com/umjammer/vavi-apps-fuse/actions) +[![Java CI](https://github.com/umjammer/vavi-apps-fuse/actions/workflows/maven.yml/badge.svg)](https://github.com/umjammer/vavi-apps-fuse/actions/workflows/maven.yml) [![CodeQL](https://github.com/umjammer/vavi-apps-fuse/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/umjammer/vavi-apps-fuse/actions/workflows/codeql-analysis.yml) ![Java](https://img.shields.io/badge/Java-17-b07219) @@ -9,30 +9,30 @@ ## Status -| fs | list | upload | download | copy | move | rm | mkdir | cache | watch | project | library | -|--------------------|------|--------|----------|------|------|----|-------|-------|-------|---------|---------------------------------------------------------------------------------------------------------------------------------------------| -| google drive (v3) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 🚧 | [sub module](vavi-nio-file-googledrive) | [google-api-services-drive](https://developers.google.com/api-client-library/java/) | -| one drive (v1) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 🚧 | [sub module](vavi-nio-file-onedrive) | [OneDriveJavaSDK](https://github.com/umjammer/OneDriveJavaSDK) | -| one drive (graph) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 🚧 | [sub module](vavi-nio-file-onedrive3) | [onedrive-java-client](https://github.com/iterate-ch/onedrive-java-client) | -| one drive (graph) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 🚧 | [sub module](vavi-nio-file-onedrive4) | [msgraph-sdk-java](https://github.com/microsoftgraph/msgraph-sdk-java) | -| dropbox (v2) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 🚧 | [java7-fs-dropbox](https://github.com/umjammer/java7-fs-dropbox) | | -| box (v2) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 🚧 | [java7-fs-box](https://github.com/umjammer/java7-fs-box) | | -| vfs (sftp) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | - | | [sub module](vavi-nio-file-vfs) | [commons-vfs2](https://commons.apache.org/proper/commons-vfs/), [jsch](http://www.jcraft.com/jsch/) | -| vfs (smb:cifs-ng) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | - | | [sub module](vavi-nio-file-vfs) | [commons-vfs2-cifs](https://github.com/vbauer/commons-vfs2-cifs), [jcifs-ng](https://github.com/AgNO3/jcifs-ng) | -| vfs (smb:smbj) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | - | | [sub module](vavi-nio-file-vfs) | [commons-vfs2-smb](https://github.com/umjammer/commons-vfs2-smb) | -| vfs (webdav ssh) | 🚧 | | | | | | | | | [sub module](vavi-nio-file-vfs) | [commons-vfs2-jackrabbit2](https://commons.apache.org/proper/commons-vfs/commons-vfs2-jackrabbit2/) | -| vfs (smb:cifs) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | - | | [sub module](vavi-nio-file-vfs) | [commons-vfs2-sandbox](https://commons.apache.org/proper/commons-vfs/commons-vfs2-sandbox/), [jcifs-ng](https://github.com/AgNO3/jcifs-ng/) | -| archive | ✅ | - | ✅ | - | - | - | - | - | | [sub module](vavi-nio-file-archive) | [vavi-util-archive](https://github.com/umjammer/vavi-util-archive) | -| hfs+ (dmg) | ✅ | | ✅ | | | | | | | [sub module](vavi-nio-file-hfs) | [hfsexplorer](https://github.com/umjammer/hfsexplorer) | -| [gathered](https://github.com/umjammer/vavi-apps-fuse/wiki/GatheredFileSystem) | ✅ | - | ✅ | - | - | - | - | - | | [sub module](vavi-nio-file-gathered) | - | -| cyberduck (webdav ssh) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | [vavi-nio-file-cyberduck](https://github.com/umjammer/vavi-nio-file-cyberduck) | [cyberduck.webdav](https://github.com/iterate-ch/cyberduck/) | -| cyberduck (sftp) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | [vavi-nio-file-cyberduck](https://github.com/umjammer/vavi-nio-file-cyberduck) | [cyberduck.ssh](https://github.com/iterate-ch/cyberduck/) | -| discutils (vdi/ntfs) | ✅ | | ✅ | | | | | | | [vavi-nio-file-discutils](https://github.com/umjammer/vavi-nio-file-discutils) | | +| fs | list | upload | download | copy | move | rm | mkdir | cache | watch | project | library | +|--------------------|------|--------|----------|------|------|----|-------|-------|-------|--------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------| +| google drive (v3) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 🚧 | [sub module](vavi-nio-file-googledrive) | [google-api-services-drive](https://developers.google.com/api-client-library/java/) | +| one drive (v1) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 🚧 | [sub module](vavi-nio-file-onedrive) | [OneDriveJavaSDK](https://github.com/umjammer/OneDriveJavaSDK) | +| one drive (graph) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 🚧 | [sub module](vavi-nio-file-onedrive3) | [onedrive-java-client](https://github.com/iterate-ch/onedrive-java-client) | +| one drive (graph) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 🚧 | [sub module](vavi-nio-file-onedrive4) | [msgraph-sdk-java](https://github.com/microsoftgraph/msgraph-sdk-java) | +| dropbox (v2) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 🚧 | [vavi-nio-file-dropbox](https://github.com/umjammer/vavi-nio-file-dropbox) | | +| box (v2) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 🚧 | [vavi-nio-file-box](https://github.com/umjammer/vavi-nio-file-box) | | +| vfs (sftp) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | - | | [sub module](vavi-nio-file-vfs) | [commons-vfs2](https://commons.apache.org/proper/commons-vfs/), [jsch](http://www.jcraft.com/jsch/) | +| vfs (smb:cifs-ng) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | - | | [sub module](vavi-nio-file-vfs) | [commons-vfs2-cifs](https://github.com/vbauer/commons-vfs2-cifs), [jcifs-ng](https://github.com/AgNO3/jcifs-ng) | +| vfs (smb:smbj) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | - | | [sub module](vavi-nio-file-vfs) | [commons-vfs2-smb](https://github.com/umjammer/commons-vfs2-smb) | +| vfs (webdav ssh) | 🚧 | | | | | | | | | [sub module](vavi-nio-file-vfs) | [commons-vfs2-jackrabbit2](https://commons.apache.org/proper/commons-vfs/commons-vfs2-jackrabbit2/) | +| vfs (smb:cifs) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | - | | [sub module](vavi-nio-file-vfs) | [commons-vfs2-sandbox](https://commons.apache.org/proper/commons-vfs/commons-vfs2-sandbox/), [jcifs-ng](https://github.com/AgNO3/jcifs-ng/) | +| archive | ✅ | - | ✅ | - | - | - | - | - | | [sub module](vavi-nio-file-archive) | [vavi-util-archive](https://github.com/umjammer/vavi-util-archive) | +| hfs+ (dmg) | ✅ | | ✅ | | | | | | | [sub module](vavi-nio-file-hfs) | [hfsexplorer](https://github.com/umjammer/hfsexplorer) | +| [gathered](https://github.com/umjammer/vavi-apps-fuse/wiki/GatheredFileSystem) | ✅ | - | ✅ | - | - | - | - | - | | [sub module](vavi-nio-file-gathered) | - | +| cyberduck (webdav ssh) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | [vavi-nio-file-cyberduck](https://github.com/umjammer/vavi-nio-file-cyberduck) | [cyberduck.webdav](https://github.com/iterate-ch/cyberduck/) | +| cyberduck (sftp) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | [vavi-nio-file-cyberduck](https://github.com/umjammer/vavi-nio-file-cyberduck) | [cyberduck.ssh](https://github.com/iterate-ch/cyberduck/) | +| discutils (vdi/ntfs) | ✅ | | ✅ | | | | | | | [vavi-nio-file-discutils](https://github.com/umjammer/vavi-nio-file-discutils) | | | ~~google play music~~ | ✅ | - | ✅ | - | - | - | - | - | | [vavi-nio-file-googleplaymusic](https://github.com/umjammer/vavi-nio-file-googleplaymusic) | [gplaymusic](https://github.com/umjammer/gplaymusic) | |||||| -| fuse (javafs) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | [sub module](vavi-net-fuse) | [javafs](https://github.com/umjammer/javafs) | -| fuse (fuse-jna) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | [sub module](vavi-net-fuse) | [fuse-jna](https://github.com/EtiennePerot/fuse-jna) | -| fuse (jnr-fuse) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | [sub module](vavi-net-fuse) | [jnr-fuse](https://github.com/SerCeMan/jnr-fuse) | +| fuse (javafs) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | [vavi-nio-file-fuse](https://github.com/umjammer/vavi-nio-file-fuse) | [javafs](https://github.com/umjammer/javafs) | +| fuse (fuse-jna) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | [vavi-nio-file-fuse](https://github.com/umjammer/vavi-nio-file-fuse) | [fuse-jna](https://github.com/EtiennePerot/fuse-jna) | +| fuse (jnr-fuse) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | [vavi-nio-file-fuse](https://github.com/umjammer/vavi-nio-file-fuse) | [jnr-fuse](https://github.com/SerCeMan/jnr-fuse) | ## Usage @@ -79,7 +79,9 @@ * retry handler * option * SeekableByteChannel + * how about upload? * https://github.com/unsound/jfuse (jni) + * https://github.com/uw-dims/fuse4j ## TODO @@ -94,7 +96,11 @@ * ~~mincraft nbt~~ (deal in [tree view](https://github.com/umjammer/vavi-apps-treeview)) * ~~credential from uri~~ * ~~https://github.com/cryptomator/fuse-nio-adapter~~ + * watch + * [base](https://github.com/umjammer/vavi-nio-file-base) + * [webhook](https://github.com/umjammer/vavi-apps-webhook) * https://github.com/mucommander/mucommander * trash,recent * ~~separate vavi-nio-file-commons and merge into vavi-nio-file-base~~ - * separate fuse part (use obsoleted vavi-nio-file -> vavi-nio-file-fuse) + * ~~separate fuse part (use obsoleted vavi-nio-file -> vavi-nio-file-fuse)~~ + * rename project like vavi-nio-file-collection diff --git a/pom.xml b/pom.xml index 8d1c00a0..6c77b78d 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ - com.github.umjammer.vavi-net-auth + com.github.umjammer.vavi-net-auth 0.1.9 com.github.umjammer @@ -76,7 +76,6 @@ - ${vavi-nio-file-base.groupId} vavi-nio-file-base ${vavi-nio-file-base.version} @@ -88,12 +87,6 @@ 3.0.2 - - vavi - vavi-net-fuse - 0.1.9 - - org.junit junit-bom diff --git a/vavi-nio-file-amazondrive/pom.xml b/vavi-nio-file-amazondrive/pom.xml index 0427b4b6..23387999 100644 --- a/vavi-nio-file-amazondrive/pom.xml +++ b/vavi-nio-file-amazondrive/pom.xml @@ -28,7 +28,6 @@ - ${vavi-nio-file-base.groupId} vavi-nio-file-base diff --git a/vavi-nio-file-archive/pom.xml b/vavi-nio-file-archive/pom.xml index 33a9ac8b..523fd124 100644 --- a/vavi-nio-file-archive/pom.xml +++ b/vavi-nio-file-archive/pom.xml @@ -37,7 +37,7 @@ com.github.umjammer vavi-util-archive - 1.1.2 + 1.1.5 com.sun From acd01e03d379c3f61b4e03386d7ca121645adbc7 Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Wed, 28 Feb 2024 00:44:07 +0900 Subject: [PATCH 5/5] bump version --- pom.xml | 2 +- vavi-nio-file-amazondrive/pom.xml | 2 +- vavi-nio-file-archive/pom.xml | 2 +- vavi-nio-file-flickr/pom.xml | 2 +- vavi-nio-file-gathered/pom.xml | 6 +++--- vavi-nio-file-googledrive/pom.xml | 2 +- vavi-nio-file-hfs/pom.xml | 2 +- vavi-nio-file-onedrive/pom.xml | 2 +- vavi-nio-file-onedrive3/pom.xml | 2 +- vavi-nio-file-onedrive4/pom.xml | 2 +- vavi-nio-file-sandbox/pom.xml | 10 +++++----- vavi-nio-file-vfs/pom.xml | 2 +- 12 files changed, 18 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index 6c77b78d..37584dde 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ vavi vavi-apps-fuse - 0.1.9 + 0.1.10 pom diff --git a/vavi-nio-file-amazondrive/pom.xml b/vavi-nio-file-amazondrive/pom.xml index 23387999..a3cf704f 100644 --- a/vavi-nio-file-amazondrive/pom.xml +++ b/vavi-nio-file-amazondrive/pom.xml @@ -5,7 +5,7 @@ vavi vavi-apps-fuse - 0.1.9 + 0.1.10 vavi-nio-file-amazondrive diff --git a/vavi-nio-file-archive/pom.xml b/vavi-nio-file-archive/pom.xml index 523fd124..3bdf56e7 100644 --- a/vavi-nio-file-archive/pom.xml +++ b/vavi-nio-file-archive/pom.xml @@ -5,7 +5,7 @@ vavi vavi-apps-fuse - 0.1.9 + 0.1.10 vavi-nio-file-archive diff --git a/vavi-nio-file-flickr/pom.xml b/vavi-nio-file-flickr/pom.xml index 8f2f9be1..b401cb00 100644 --- a/vavi-nio-file-flickr/pom.xml +++ b/vavi-nio-file-flickr/pom.xml @@ -5,7 +5,7 @@ vavi vavi-apps-fuse - 0.1.9 + 0.1.10 vavi-nio-file-flickr diff --git a/vavi-nio-file-gathered/pom.xml b/vavi-nio-file-gathered/pom.xml index 4c2f7276..632d299c 100644 --- a/vavi-nio-file-gathered/pom.xml +++ b/vavi-nio-file-gathered/pom.xml @@ -5,7 +5,7 @@ vavi vavi-apps-fuse - 0.1.9 + 0.1.10 vavi-nio-file-gathered @@ -90,13 +90,13 @@ vavi vavi-nio-file-googledrive - 0.1.9 + 0.1.10 test vavi vavi-nio-file-onedrive4 - 0.1.9 + 0.1.10 test diff --git a/vavi-nio-file-googledrive/pom.xml b/vavi-nio-file-googledrive/pom.xml index 2a77b89b..311e2de6 100644 --- a/vavi-nio-file-googledrive/pom.xml +++ b/vavi-nio-file-googledrive/pom.xml @@ -5,7 +5,7 @@ vavi vavi-apps-fuse - 0.1.9 + 0.1.10 vavi-nio-file-googledrive diff --git a/vavi-nio-file-hfs/pom.xml b/vavi-nio-file-hfs/pom.xml index c5e6a2e7..e73164c9 100644 --- a/vavi-nio-file-hfs/pom.xml +++ b/vavi-nio-file-hfs/pom.xml @@ -5,7 +5,7 @@ vavi vavi-apps-fuse - 0.1.9 + 0.1.10 vavi-nio-file-hfs diff --git a/vavi-nio-file-onedrive/pom.xml b/vavi-nio-file-onedrive/pom.xml index d7e043ac..aed58fd3 100644 --- a/vavi-nio-file-onedrive/pom.xml +++ b/vavi-nio-file-onedrive/pom.xml @@ -5,7 +5,7 @@ vavi vavi-apps-fuse - 0.1.9 + 0.1.10 vavi-nio-file-onedrive diff --git a/vavi-nio-file-onedrive3/pom.xml b/vavi-nio-file-onedrive3/pom.xml index 45630212..5757a25c 100644 --- a/vavi-nio-file-onedrive3/pom.xml +++ b/vavi-nio-file-onedrive3/pom.xml @@ -4,7 +4,7 @@ vavi-apps-fuse vavi - 0.1.9 + 0.1.10 vavi-nio-file-onedrive3 diff --git a/vavi-nio-file-onedrive4/pom.xml b/vavi-nio-file-onedrive4/pom.xml index dc823ef9..84ba906f 100644 --- a/vavi-nio-file-onedrive4/pom.xml +++ b/vavi-nio-file-onedrive4/pom.xml @@ -5,7 +5,7 @@ vavi vavi-apps-fuse - 0.1.9 + 0.1.10 vavi-nio-file-onedrive4 diff --git a/vavi-nio-file-sandbox/pom.xml b/vavi-nio-file-sandbox/pom.xml index 651e4be9..93efd7ce 100644 --- a/vavi-nio-file-sandbox/pom.xml +++ b/vavi-nio-file-sandbox/pom.xml @@ -7,7 +7,7 @@ vavi vavi-apps-fuse - 0.1.9 + 0.1.10 vavi-nio-file-sandbox @@ -188,25 +188,25 @@ vavi vavi-nio-file-onedrive - 0.1.9 + 0.1.10 test vavi vavi-nio-file-onedrive4 - 0.1.9 + 0.1.10 test vavi vavi-nio-file-googledrive - 0.1.9 + 0.1.10 test vavi vavi-nio-file-archive - 0.1.9 + 0.1.10 test diff --git a/vavi-nio-file-vfs/pom.xml b/vavi-nio-file-vfs/pom.xml index 125135a2..f12270c6 100644 --- a/vavi-nio-file-vfs/pom.xml +++ b/vavi-nio-file-vfs/pom.xml @@ -5,7 +5,7 @@ vavi-apps-fuse vavi - 0.1.9 + 0.1.10 vavi-nio-file-vfs