|
| 1 | +package org.cryptomator.integrations.mount; |
| 2 | + |
| 3 | +import org.cryptomator.integrations.common.IntegrationsLoader; |
| 4 | +import org.jetbrains.annotations.Contract; |
| 5 | +import org.jetbrains.annotations.NotNull; |
| 6 | +import org.jetbrains.annotations.Range; |
| 7 | + |
| 8 | +import java.nio.file.Path; |
| 9 | +import java.util.Set; |
| 10 | +import java.util.stream.Stream; |
| 11 | + |
| 12 | +/** |
| 13 | + * A mechanism to mount a file system. |
| 14 | + * |
| 15 | + * @since 1.2.0 |
| 16 | + */ |
| 17 | +public interface MountProvider { |
| 18 | + |
| 19 | + /** |
| 20 | + * Loads all supported mount providers. |
| 21 | + * |
| 22 | + * @return Stream of supported MountProviders (may be empty) |
| 23 | + */ |
| 24 | + static Stream<MountProvider> get() { |
| 25 | + return IntegrationsLoader.loadAll(MountProvider.class).filter(MountProvider::isSupported); |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Name of this provider. |
| 30 | + * |
| 31 | + * @return A human readable name of this provider |
| 32 | + */ |
| 33 | + String displayName(); |
| 34 | + |
| 35 | + /** |
| 36 | + * Indicates, if this provider can be used. |
| 37 | + * |
| 38 | + * @return true, if this provider is supported in the current OS environment |
| 39 | + * @implSpec This check needs to return fast and in constant time |
| 40 | + */ |
| 41 | + boolean isSupported(); |
| 42 | + |
| 43 | + /** |
| 44 | + * A suitable mount point suggested by this provider. |
| 45 | + * <p> |
| 46 | + * Other than caller-provided mount points, the mount point suggested by this method can be |
| 47 | + * passed to {@link MountBuilder#setMountpoint(Path)} and is guaranteed to fulfill the builder's requirements |
| 48 | + * without further ado. |
| 49 | + * |
| 50 | + * @param mountPointSuffix String used in the generation of a mount point. |
| 51 | + * @return A path to a possible mount point. |
| 52 | + * @throws UnsupportedOperationException If {@link MountFeature#DEFAULT_MOUNT_POINT} is not supported |
| 53 | + */ |
| 54 | + default Path getDefaultMountPoint(String mountPointSuffix) { |
| 55 | + throw new UnsupportedOperationException(); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Default mount flags. May be empty. |
| 60 | + * |
| 61 | + * @param mountName Name of the mount in the OS |
| 62 | + * @return Concatenated String of valid mount flags |
| 63 | + * @throws UnsupportedOperationException If {@link MountFeature#MOUNT_FLAGS} is not supported |
| 64 | + */ |
| 65 | + default String getDefaultMountFlags(String mountName) { |
| 66 | + throw new UnsupportedOperationException(); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * The default TCP port used by this provider. |
| 71 | + * |
| 72 | + * @return fixed TCP port or 0 to use a system-assigned port |
| 73 | + * @throws UnsupportedOperationException If {@link MountFeature#PORT} is not supported |
| 74 | + */ |
| 75 | + @Range(from = 0, to = Short.MAX_VALUE) |
| 76 | + default int getDefaultPort() { |
| 77 | + throw new UnsupportedOperationException(); |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * Mount features supported by this provider. |
| 82 | + * |
| 83 | + * @return Set of supported {@link MountFeature}s |
| 84 | + */ |
| 85 | + Set<MountFeature> supportedFeatures(); |
| 86 | + |
| 87 | + |
| 88 | + /** |
| 89 | + * Creates a new mount builder. |
| 90 | + * |
| 91 | + * @param fileSystemRoot The root of the VFS to be mounted |
| 92 | + * @return New mount builder |
| 93 | + */ |
| 94 | + @Contract("_ -> new") |
| 95 | + MountBuilder forFileSystem(Path fileSystemRoot); |
| 96 | + |
| 97 | +} |
0 commit comments