From 93011dc7549f6af763c18f07d9a31e0045510990 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Thu, 7 May 2020 16:32:12 +0200 Subject: [PATCH] cleanup --- .../common/settings/VaultSettings.java | 19 +++++++++---------- .../settings/VaultSettingsJsonAdapter.java | 18 ++++++++++-------- .../common/settings/VolumeImpl.java | 16 ---------------- .../common/settings/WebDavUrlScheme.java | 16 ---------------- .../common/vaults/DokanyVolume.java | 4 ++-- .../cryptomator/common/vaults/FuseVolume.java | 2 +- .../org/cryptomator/common/vaults/Vault.java | 2 +- .../VaultSettingsJsonAdapterTest.java | 3 +-- .../UnlockInvalidMountPointController.java | 2 +- .../vaultoptions/MountOptionsController.java | 14 +++++++------- 10 files changed, 32 insertions(+), 64 deletions(-) diff --git a/main/commons/src/main/java/org/cryptomator/common/settings/VaultSettings.java b/main/commons/src/main/java/org/cryptomator/common/settings/VaultSettings.java index 04dd2b447..16a6de8fb 100644 --- a/main/commons/src/main/java/org/cryptomator/common/settings/VaultSettings.java +++ b/main/commons/src/main/java/org/cryptomator/common/settings/VaultSettings.java @@ -26,7 +26,6 @@ import java.util.Random; /** * The settings specific to a single vault. - * TODO: Change the name of individualMountPath and its derivatives to customMountPath */ public class VaultSettings { @@ -45,8 +44,8 @@ public class VaultSettings { private final StringProperty winDriveLetter = new SimpleStringProperty(); private final BooleanProperty unlockAfterStartup = new SimpleBooleanProperty(DEFAULT_UNLOCK_AFTER_STARTUP); private final BooleanProperty revealAfterMount = new SimpleBooleanProperty(DEFAULT_REAVEAL_AFTER_MOUNT); - private final BooleanProperty usesIndividualMountPath = new SimpleBooleanProperty(DEFAULT_USES_INDIVIDUAL_MOUNTPATH); - private final StringProperty individualMountPath = new SimpleStringProperty(); + private final BooleanProperty useCustomMountPath = new SimpleBooleanProperty(DEFAULT_USES_INDIVIDUAL_MOUNTPATH); + private final StringProperty customMountPath = new SimpleStringProperty(); private final BooleanProperty usesReadOnlyMode = new SimpleBooleanProperty(DEFAULT_USES_READONLY_MODE); private final StringProperty mountFlags = new SimpleStringProperty(DEFAULT_MOUNT_FLAGS); private final IntegerProperty filenameLengthLimit = new SimpleIntegerProperty(DEFAULT_FILENAME_LENGTH_LIMIT); @@ -122,17 +121,17 @@ public class VaultSettings { return revealAfterMount; } - public BooleanProperty usesIndividualMountPath() { - return usesIndividualMountPath; + public BooleanProperty useCustomMountPath() { + return useCustomMountPath; } - public StringProperty individualMountPath() { - return individualMountPath; + public StringProperty customMountPath() { + return customMountPath; } - public Optional getIndividualMountPath() { - if (usesIndividualMountPath.get()) { - return Optional.ofNullable(Strings.emptyToNull(individualMountPath.get())); + public Optional getCustomMountPath() { + if (useCustomMountPath.get()) { + return Optional.ofNullable(Strings.emptyToNull(customMountPath.get())); } else { return Optional.empty(); } diff --git a/main/commons/src/main/java/org/cryptomator/common/settings/VaultSettingsJsonAdapter.java b/main/commons/src/main/java/org/cryptomator/common/settings/VaultSettingsJsonAdapter.java index 8e87a16e7..a26781bb9 100644 --- a/main/commons/src/main/java/org/cryptomator/common/settings/VaultSettingsJsonAdapter.java +++ b/main/commons/src/main/java/org/cryptomator/common/settings/VaultSettingsJsonAdapter.java @@ -25,8 +25,8 @@ class VaultSettingsJsonAdapter { out.name("winDriveLetter").value(value.winDriveLetter().get()); out.name("unlockAfterStartup").value(value.unlockAfterStartup().get()); out.name("revealAfterMount").value(value.revealAfterMount().get()); - out.name("usesIndividualMountPath").value(value.usesIndividualMountPath().get()); - out.name("individualMountPath").value(value.individualMountPath().get()); + out.name("useCustomMountPath").value(value.useCustomMountPath().get()); + out.name("customMountPath").value(value.customMountPath().get()); out.name("usesReadOnlyMode").value(value.usesReadOnlyMode().get()); out.name("mountFlags").value(value.mountFlags().get()); out.name("filenameLengthLimit").value(value.filenameLengthLimit().get()); @@ -37,11 +37,11 @@ class VaultSettingsJsonAdapter { String id = null; String path = null; String mountName = null; - String individualMountPath = null; + String customMountPath = null; String winDriveLetter = null; boolean unlockAfterStartup = VaultSettings.DEFAULT_UNLOCK_AFTER_STARTUP; boolean revealAfterMount = VaultSettings.DEFAULT_REAVEAL_AFTER_MOUNT; - boolean usesIndividualMountPath = VaultSettings.DEFAULT_USES_INDIVIDUAL_MOUNTPATH; + boolean useCustomMountPath = VaultSettings.DEFAULT_USES_INDIVIDUAL_MOUNTPATH; boolean usesReadOnlyMode = VaultSettings.DEFAULT_USES_READONLY_MODE; String mountFlags = VaultSettings.DEFAULT_MOUNT_FLAGS; int filenameLengthLimit = VaultSettings.DEFAULT_FILENAME_LENGTH_LIMIT; @@ -69,10 +69,12 @@ class VaultSettingsJsonAdapter { revealAfterMount = in.nextBoolean(); break; case "usesIndividualMountPath": - usesIndividualMountPath = in.nextBoolean(); + case "useCustomMountPath": + useCustomMountPath = in.nextBoolean(); break; case "individualMountPath": - individualMountPath = in.nextString(); + case "customMountPath": + customMountPath = in.nextString(); break; case "usesReadOnlyMode": usesReadOnlyMode = in.nextBoolean(); @@ -97,8 +99,8 @@ class VaultSettingsJsonAdapter { vaultSettings.winDriveLetter().set(winDriveLetter); vaultSettings.unlockAfterStartup().set(unlockAfterStartup); vaultSettings.revealAfterMount().set(revealAfterMount); - vaultSettings.usesIndividualMountPath().set(usesIndividualMountPath); - vaultSettings.individualMountPath().set(individualMountPath); + vaultSettings.useCustomMountPath().set(useCustomMountPath); + vaultSettings.customMountPath().set(customMountPath); vaultSettings.usesReadOnlyMode().set(usesReadOnlyMode); vaultSettings.mountFlags().set(mountFlags); vaultSettings.filenameLengthLimit().set(filenameLengthLimit); diff --git a/main/commons/src/main/java/org/cryptomator/common/settings/VolumeImpl.java b/main/commons/src/main/java/org/cryptomator/common/settings/VolumeImpl.java index e475ff0d9..473596fc4 100644 --- a/main/commons/src/main/java/org/cryptomator/common/settings/VolumeImpl.java +++ b/main/commons/src/main/java/org/cryptomator/common/settings/VolumeImpl.java @@ -1,7 +1,5 @@ package org.cryptomator.common.settings; -import java.util.Arrays; - public enum VolumeImpl { WEBDAV("WebDAV"), FUSE("FUSE"), @@ -17,18 +15,4 @@ public enum VolumeImpl { return displayName; } - /** - * Finds a VolumeImpl by display name. - * - * @param displayName Display name of the VolumeImpl - * @return VolumeImpl with the given displayName. - * @throws IllegalArgumentException if not volumeImpl with the given displayName was found. - */ - public static VolumeImpl forDisplayName(String displayName) throws IllegalArgumentException { - return Arrays.stream(values()) // - .filter(impl -> impl.displayName.equals(displayName)) // - .findAny() // - .orElseThrow(IllegalArgumentException::new); - } - } diff --git a/main/commons/src/main/java/org/cryptomator/common/settings/WebDavUrlScheme.java b/main/commons/src/main/java/org/cryptomator/common/settings/WebDavUrlScheme.java index b34956c90..0dcb4ac9d 100644 --- a/main/commons/src/main/java/org/cryptomator/common/settings/WebDavUrlScheme.java +++ b/main/commons/src/main/java/org/cryptomator/common/settings/WebDavUrlScheme.java @@ -1,7 +1,5 @@ package org.cryptomator.common.settings; -import java.util.Arrays; - public enum WebDavUrlScheme { DAV("dav", "dav:// (Gnome, Nautilus, ...)"), WEBDAV("webdav", "webdav:// (KDE, Dolphin, ...)"); @@ -20,18 +18,4 @@ public enum WebDavUrlScheme { public String getDisplayName() { return displayName; } - - /** - * Finds a WebDavUrlScheme by prefix. - * - * @param prefix Prefix of the WebDavUrlScheme - * @return WebDavUrlScheme with the given prefix. - * @throws IllegalArgumentException if not WebDavUrlScheme with the given prefix was found. - */ - public static WebDavUrlScheme forPrefix(String prefix) throws IllegalArgumentException { - return Arrays.stream(values()) // - .filter(impl -> impl.prefix.equals(prefix)) // - .findAny() // - .orElseThrow(IllegalArgumentException::new); - } } diff --git a/main/commons/src/main/java/org/cryptomator/common/vaults/DokanyVolume.java b/main/commons/src/main/java/org/cryptomator/common/vaults/DokanyVolume.java index 4b54076bd..1bfd813e3 100644 --- a/main/commons/src/main/java/org/cryptomator/common/vaults/DokanyVolume.java +++ b/main/commons/src/main/java/org/cryptomator/common/vaults/DokanyVolume.java @@ -51,7 +51,7 @@ public class DokanyVolume implements Volume { try { this.mount = mountFactory.mount(fs.getPath("/"), mountPoint, mountName, FS_TYPE_NAME, mountFlags.strip()); } catch (MountFailedException e) { - if (vaultSettings.getIndividualMountPath().isPresent()) { + if (vaultSettings.getCustomMountPath().isPresent()) { LOG.warn("Failed to mount vault into {}. Is this directory currently accessed by another process (e.g. Windows Explorer)?", mountPoint); } throw new VolumeException("Unable to mount Filesystem", e); @@ -59,7 +59,7 @@ public class DokanyVolume implements Volume { } private Path determineMountPoint() throws VolumeException, IOException { - Optional optionalCustomMountPoint = vaultSettings.getIndividualMountPath(); + Optional optionalCustomMountPoint = vaultSettings.getCustomMountPath(); if (optionalCustomMountPoint.isPresent()) { Path customMountPoint = Paths.get(optionalCustomMountPoint.get()); checkProvidedMountPoint(customMountPoint); diff --git a/main/commons/src/main/java/org/cryptomator/common/vaults/FuseVolume.java b/main/commons/src/main/java/org/cryptomator/common/vaults/FuseVolume.java index c73459e6b..4b6918be9 100644 --- a/main/commons/src/main/java/org/cryptomator/common/vaults/FuseVolume.java +++ b/main/commons/src/main/java/org/cryptomator/common/vaults/FuseVolume.java @@ -45,7 +45,7 @@ public class FuseVolume implements Volume { @Override public void mount(CryptoFileSystem fs, String mountFlags) throws IOException, FuseNotSupportedException, VolumeException { - Optional optionalCustomMountPoint = vaultSettings.getIndividualMountPath(); + Optional optionalCustomMountPoint = vaultSettings.getCustomMountPath(); if (optionalCustomMountPoint.isPresent()) { Path customMountPoint = Paths.get(optionalCustomMountPoint.get()); checkProvidedMountPoint(customMountPoint); diff --git a/main/commons/src/main/java/org/cryptomator/common/vaults/Vault.java b/main/commons/src/main/java/org/cryptomator/common/vaults/Vault.java index 5b0fd3bd6..bc461c1d9 100644 --- a/main/commons/src/main/java/org/cryptomator/common/vaults/Vault.java +++ b/main/commons/src/main/java/org/cryptomator/common/vaults/Vault.java @@ -121,7 +121,7 @@ public class Vault { } public synchronized void unlock(CharSequence passphrase) throws CryptoException, IOException, Volume.VolumeException { - if (vaultSettings.usesIndividualMountPath().get() && Strings.isNullOrEmpty(vaultSettings.individualMountPath().get())) { + if (vaultSettings.useCustomMountPath().get() && Strings.isNullOrEmpty(vaultSettings.customMountPath().get())) { throw new NotDirectoryException(""); } CryptoFileSystem fs = getCryptoFileSystem(passphrase); diff --git a/main/commons/src/test/java/org/cryptomator/common/settings/VaultSettingsJsonAdapterTest.java b/main/commons/src/test/java/org/cryptomator/common/settings/VaultSettingsJsonAdapterTest.java index f7698d2ba..237b00904 100644 --- a/main/commons/src/test/java/org/cryptomator/common/settings/VaultSettingsJsonAdapterTest.java +++ b/main/commons/src/test/java/org/cryptomator/common/settings/VaultSettingsJsonAdapterTest.java @@ -16,7 +16,6 @@ import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; import java.nio.file.Paths; -import java.util.Arrays; public class VaultSettingsJsonAdapterTest { @@ -32,7 +31,7 @@ public class VaultSettingsJsonAdapterTest { Assertions.assertEquals(Paths.get("/foo/bar"), vaultSettings.path().get()); Assertions.assertEquals("test", vaultSettings.mountName().get()); Assertions.assertEquals("X", vaultSettings.winDriveLetter().get()); - Assertions.assertEquals("/home/test/crypto", vaultSettings.individualMountPath().get()); + Assertions.assertEquals("/home/test/crypto", vaultSettings.customMountPath().get()); Assertions.assertEquals("--foo --bar", vaultSettings.mountFlags().get()); diff --git a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java index d73c96c07..f9cf4293e 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java @@ -33,7 +33,7 @@ public class UnlockInvalidMountPointController implements FxController { /* Getter/Setter */ public String getMountPoint() { - return vault.getVaultSettings().getIndividualMountPath().orElse("AUTO"); + return vault.getVaultSettings().getCustomMountPath().orElse("AUTO"); } } diff --git a/main/ui/src/main/java/org/cryptomator/ui/vaultoptions/MountOptionsController.java b/main/ui/src/main/java/org/cryptomator/ui/vaultoptions/MountOptionsController.java index 1556d0f74..81753d83a 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/vaultoptions/MountOptionsController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/vaultoptions/MountOptionsController.java @@ -85,7 +85,7 @@ public class MountOptionsController implements FxController { driveLetterSelection.setConverter(new WinDriveLetterLabelConverter(windowsDriveLetters, resourceBundle)); driveLetterSelection.setValue(vault.getVaultSettings().winDriveLetter().get()); - if (vault.getVaultSettings().usesIndividualMountPath().get()) { + if (vault.getVaultSettings().useCustomMountPath().get()) { mountPoint.selectToggle(mountPointCustomDir); } else if (!Strings.isNullOrEmpty(vault.getVaultSettings().winDriveLetter().get())) { mountPoint.selectToggle(mountPointWinDriveLetter); @@ -93,7 +93,7 @@ public class MountOptionsController implements FxController { mountPoint.selectToggle(mountPointAuto); } - vault.getVaultSettings().usesIndividualMountPath().bind(mountPoint.selectedToggleProperty().isEqualTo(mountPointCustomDir)); + vault.getVaultSettings().useCustomMountPath().bind(mountPoint.selectedToggleProperty().isEqualTo(mountPointCustomDir)); vault.getVaultSettings().winDriveLetter().bind( // Bindings.when(mountPoint.selectedToggleProperty().isEqualTo(mountPointWinDriveLetter)) // .then(driveLetterSelection.getSelectionModel().selectedItemProperty()) // @@ -126,14 +126,14 @@ public class MountOptionsController implements FxController { } File file = directoryChooser.showDialog(window); if (file != null) { - vault.getVaultSettings().individualMountPath().set(file.getAbsolutePath()); + vault.getVaultSettings().customMountPath().set(file.getAbsolutePath()); } else { - vault.getVaultSettings().individualMountPath().set(null); + vault.getVaultSettings().customMountPath().set(null); } } private void toggleMountPoint(@SuppressWarnings("unused") ObservableValue observable, @SuppressWarnings("unused") Toggle oldValue, Toggle newValue) { - if (mountPointCustomDir.equals(newValue) && Strings.isNullOrEmpty(vault.getVaultSettings().individualMountPath().get())) { + if (mountPointCustomDir.equals(newValue) && Strings.isNullOrEmpty(vault.getVaultSettings().customMountPath().get())) { chooseCustomMountPoint(); } } @@ -186,11 +186,11 @@ public class MountOptionsController implements FxController { } public StringProperty customMountPathProperty() { - return vault.getVaultSettings().individualMountPath(); + return vault.getVaultSettings().customMountPath(); } public String getCustomMountPath() { - return vault.getVaultSettings().individualMountPath().get(); + return vault.getVaultSettings().customMountPath().get(); } }