From 77db435b4fec3a9b39e5c8bab7cc433a538b36dc Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Thu, 21 Jan 2021 12:41:52 +0100 Subject: [PATCH] Refactor reveal call stack to apply facade pattern. --- .../cryptomator/common/vaults/DokanyVolume.java | 16 +++++++++++++--- .../cryptomator/common/vaults/FuseVolume.java | 16 +++++++++++++--- .../org/cryptomator/common/vaults/Vault.java | 2 +- .../org/cryptomator/common/vaults/Volume.java | 13 ++++++------- .../cryptomator/common/vaults/WebDavVolume.java | 16 +++++++++++++--- .../org/cryptomator/ui/common/VaultService.java | 8 ++++---- 6 files changed, 50 insertions(+), 21 deletions(-) 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 0da6452cc..e00c7c6ee 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 @@ -53,12 +53,22 @@ public class DokanyVolume extends AbstractVolume { } @Override - public void reveal(Revealer r) throws VolumeException { + public void reveal(RevealerFacade r) throws VolumeException { try { - mount.reveal(r); + mount.reveal(p -> { + try { + r.reveal(p); + } catch (VolumeException e) { + throw new RevealException(e); + } + }); } catch (RevealException e) { LOG.debug("Revealing the vault in file manger failed: " + e.getMessage()); - throw new VolumeException(e); + if (e.getCause() instanceof VolumeException) { + throw (VolumeException) e.getCause(); + } else { + throw new VolumeException(e); + } } } 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 46db1221c..191b47526 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 @@ -73,12 +73,22 @@ public class FuseVolume extends AbstractVolume { } @Override - public void reveal(Revealer r) throws VolumeException { + public void reveal(RevealerFacade r) throws VolumeException { try { - mount.reveal(r); + mount.reveal(p -> { + try { + r.reveal(p); + } catch (VolumeException e) { + throw new RevealException(e); + } + }); } catch (RevealException e) { LOG.debug("Revealing the vault in file manger failed: " + e.getMessage()); - throw new VolumeException(e); + if (e.getCause() instanceof VolumeException) { + throw (VolumeException) e.getCause(); + } else { + throw new VolumeException(e); + } } } 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 adf39c6f2..fd301c3bd 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 @@ -148,7 +148,7 @@ public class Vault { } } - public void reveal(Volume.Revealer vaultRevealer) throws VolumeException { + public void reveal(Volume.RevealerFacade vaultRevealer) throws VolumeException { volume.reveal(vaultRevealer); } diff --git a/main/commons/src/main/java/org/cryptomator/common/vaults/Volume.java b/main/commons/src/main/java/org/cryptomator/common/vaults/Volume.java index 5760ab1fe..644cd9ac1 100644 --- a/main/commons/src/main/java/org/cryptomator/common/vaults/Volume.java +++ b/main/commons/src/main/java/org/cryptomator/common/vaults/Volume.java @@ -3,8 +3,6 @@ package org.cryptomator.common.vaults; import org.cryptomator.common.mountpoint.InvalidMountPointException; import org.cryptomator.common.settings.VolumeImpl; import org.cryptomator.cryptofs.CryptoFileSystem; -import org.cryptomator.frontend.fuse.mount.Revealer; -import org.cryptomator.frontend.webdav.mount.Mounter; import java.io.IOException; import java.nio.file.Path; @@ -38,9 +36,10 @@ public interface Volume { /** * TODO: refactor, such that this method accepts a (new) interface revealer and document that it could be ignored. + * * @throws VolumeException */ - void reveal(Revealer revealer) throws VolumeException; + void reveal(RevealerFacade revealer) throws VolumeException; void unmount() throws VolumeException; @@ -85,10 +84,10 @@ public interface Volume { } - /** - * Interface to bundle the different revealer interfaces in the used nio-adapters - */ - interface Revealer extends org.cryptomator.frontend.fuse.mount.Revealer, org.cryptomator.frontend.dokany.Revealer, Mounter.Revealer{ + @FunctionalInterface + interface RevealerFacade { + + void reveal(Path p) throws VolumeException; } diff --git a/main/commons/src/main/java/org/cryptomator/common/vaults/WebDavVolume.java b/main/commons/src/main/java/org/cryptomator/common/vaults/WebDavVolume.java index e25e07465..7af21d01a 100644 --- a/main/commons/src/main/java/org/cryptomator/common/vaults/WebDavVolume.java +++ b/main/commons/src/main/java/org/cryptomator/common/vaults/WebDavVolume.java @@ -73,12 +73,22 @@ public class WebDavVolume implements Volume { } @Override - public void reveal(Revealer r) throws VolumeException { + public void reveal(RevealerFacade r) throws VolumeException { try { - mount.reveal(r); + mount.reveal(p -> { + try { + r.reveal(p); + } catch (VolumeException e) { + throw new Mounter.RevealException(e); + } + }); } catch (Mounter.RevealException e) { LOG.debug("Revealing the vault in file manger failed: " + e.getMessage()); - throw new VolumeException(e); + if (e.getCause() instanceof VolumeException) { + throw (VolumeException) e.getCause(); + } else { + throw new VolumeException(e); + } } } diff --git a/main/ui/src/main/java/org/cryptomator/ui/common/VaultService.java b/main/ui/src/main/java/org/cryptomator/ui/common/VaultService.java index 2bd99ef98..4b9226acd 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/common/VaultService.java +++ b/main/ui/src/main/java/org/cryptomator/ui/common/VaultService.java @@ -25,7 +25,7 @@ public class VaultService { private final ExecutorService executorService; - private AtomicReference vaultRevealer; + private AtomicReference vaultRevealer; @Inject public VaultService(ExecutorService executorService) { @@ -37,7 +37,7 @@ public class VaultService { executorService.execute(createRevealTask(vault)); } - public void setVaultRevealer(Volume.Revealer revealer){ + public void setVaultRevealer(Volume.RevealerFacade revealer) { this.vaultRevealer.set(revealer); } @@ -107,13 +107,13 @@ public class VaultService { private static class RevealVaultTask extends Task { private final Vault vault; - private final Volume.Revealer revealer; + private final Volume.RevealerFacade revealer; /** * @param vault The vault to lock * @param revealer The object to use to show the vault content to the user. */ - public RevealVaultTask(Vault vault, Volume.Revealer revealer) { + public RevealVaultTask(Vault vault, Volume.RevealerFacade revealer) { this.vault = vault; this.revealer = revealer;