From ce77d633a48a43f34547c1fad5059d490648ac89 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Fri, 6 Jan 2023 09:41:13 +0100 Subject: [PATCH 01/10] add common service interface --- .../common/IntegrationService.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/org/cryptomator/integrations/common/IntegrationService.java diff --git a/src/main/java/org/cryptomator/integrations/common/IntegrationService.java b/src/main/java/org/cryptomator/integrations/common/IntegrationService.java new file mode 100644 index 0000000..96d077a --- /dev/null +++ b/src/main/java/org/cryptomator/integrations/common/IntegrationService.java @@ -0,0 +1,20 @@ +package org.cryptomator.integrations.common; + +public interface IntegrationService { + + + /** + * Name of this service implementation. + * + * @return A human readable name of this service implementation + */ + String displayName(); + + /** + * Indicates, if this service implemenation can be used. + * + * @return true, if this service implementation is supported in the current OS environment + * @implSpec This check needs to return fast and in constant time + */ + boolean isSupported(); +} From 178b7cc762e42e667ef2d5bc9d5ba6a6e30d8f08 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Sun, 8 Jan 2023 19:00:29 +0100 Subject: [PATCH 02/10] First api suggestion for reveal path service --- src/main/java/module-info.java | 3 ++ .../revealfiles/RevealFailedException.java | 17 ++++++++ .../revealfiles/RevealPathsService.java | 41 +++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 src/main/java/org/cryptomator/integrations/revealfiles/RevealFailedException.java create mode 100644 src/main/java/org/cryptomator/integrations/revealfiles/RevealPathsService.java diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 492b484..3f1ab9f 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -1,4 +1,5 @@ import org.cryptomator.integrations.mount.MountService; +import org.cryptomator.integrations.revealfiles.RevealPathsService; import org.cryptomator.integrations.tray.TrayMenuController; import org.cryptomator.integrations.autostart.AutoStartProvider; import org.cryptomator.integrations.keychain.KeychainAccessProvider; @@ -14,12 +15,14 @@ exports org.cryptomator.integrations.common; exports org.cryptomator.integrations.keychain; exports org.cryptomator.integrations.mount; + exports org.cryptomator.integrations.revealfiles; exports org.cryptomator.integrations.tray; exports org.cryptomator.integrations.uiappearance; uses AutoStartProvider; uses KeychainAccessProvider; uses MountService; + uses RevealPathsService; uses TrayIntegrationProvider; uses TrayMenuController; uses UiAppearanceProvider; diff --git a/src/main/java/org/cryptomator/integrations/revealfiles/RevealFailedException.java b/src/main/java/org/cryptomator/integrations/revealfiles/RevealFailedException.java new file mode 100644 index 0000000..a3e721d --- /dev/null +++ b/src/main/java/org/cryptomator/integrations/revealfiles/RevealFailedException.java @@ -0,0 +1,17 @@ +package org.cryptomator.integrations.revealfiles; + +public class RevealFailedException extends Exception { + + public RevealFailedException(String msg) { + super(msg); + } + + public RevealFailedException(Exception cause) { + super(cause); + } + + public RevealFailedException(String msg, Exception cause) { + super(msg, cause); + } + +} diff --git a/src/main/java/org/cryptomator/integrations/revealfiles/RevealPathsService.java b/src/main/java/org/cryptomator/integrations/revealfiles/RevealPathsService.java new file mode 100644 index 0000000..24f8525 --- /dev/null +++ b/src/main/java/org/cryptomator/integrations/revealfiles/RevealPathsService.java @@ -0,0 +1,41 @@ +package org.cryptomator.integrations.revealfiles; + +import org.cryptomator.integrations.common.IntegrationService; +import org.cryptomator.integrations.common.IntegrationsLoader; + +import java.nio.file.NoSuchFileException; +import java.nio.file.Path; +import java.util.List; +import java.util.stream.Stream; + +public interface RevealPathsService extends IntegrationService { + + /** + * Loads all supported service implementations. + * + * @return Stream of supported RevealPathsService implementations (may be empty) + */ + static Stream get() { + return IntegrationsLoader.loadAll(RevealPathsService.class).filter(RevealPathsService::isSupported); + } + + /** + * Opens the parent of the given path in the system default file manager and highlights the resource the path points to. + * + * @throws RevealFailedException If the file manager could not be opened or {@code p} does not have a parent //TODO: or throw IllegalArgumenException + * @throws java.nio.file.NoSuchFileException If {@code p} does not exist + */ + void reveal(Path p) throws RevealFailedException, NoSuchFileException; + + /** + * Opens the given directory in the system default file manager and highlights all files from the list. + * + * @throws RevealFailedException If the file manager could not be opened + * @throws java.nio.file.NoSuchFileException If {@code directory} does not exist or is not a directory + * @throws RuntimeException If at least one file from the list cannot be found? TODO: this might be unncessary/not possible + * @throws UnsupportedOperationException If this service implementation does not support revealing multiple files + */ + default void reveal(Path directory, List childNames) throws RevealFailedException, NoSuchFileException { + throw new UnsupportedOperationException(); + } +} From e427caf8a3e7050c31279932bb8478adb0af8fcc Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Tue, 10 Jan 2023 13:51:08 +0100 Subject: [PATCH 03/10] Rename packages --- src/main/java/module-info.java | 4 ++-- .../{revealfiles => revealpaths}/RevealFailedException.java | 2 +- .../{revealfiles => revealpaths}/RevealPathsService.java | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-) rename src/main/java/org/cryptomator/integrations/{revealfiles => revealpaths}/RevealFailedException.java (84%) rename src/main/java/org/cryptomator/integrations/{revealfiles => revealpaths}/RevealPathsService.java (89%) diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 3f1ab9f..b7c5e03 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -1,5 +1,5 @@ import org.cryptomator.integrations.mount.MountService; -import org.cryptomator.integrations.revealfiles.RevealPathsService; +import org.cryptomator.integrations.revealpaths.RevealPathsService; import org.cryptomator.integrations.tray.TrayMenuController; import org.cryptomator.integrations.autostart.AutoStartProvider; import org.cryptomator.integrations.keychain.KeychainAccessProvider; @@ -15,7 +15,7 @@ exports org.cryptomator.integrations.common; exports org.cryptomator.integrations.keychain; exports org.cryptomator.integrations.mount; - exports org.cryptomator.integrations.revealfiles; + exports org.cryptomator.integrations.revealpaths; exports org.cryptomator.integrations.tray; exports org.cryptomator.integrations.uiappearance; diff --git a/src/main/java/org/cryptomator/integrations/revealfiles/RevealFailedException.java b/src/main/java/org/cryptomator/integrations/revealpaths/RevealFailedException.java similarity index 84% rename from src/main/java/org/cryptomator/integrations/revealfiles/RevealFailedException.java rename to src/main/java/org/cryptomator/integrations/revealpaths/RevealFailedException.java index a3e721d..1f7ea37 100644 --- a/src/main/java/org/cryptomator/integrations/revealfiles/RevealFailedException.java +++ b/src/main/java/org/cryptomator/integrations/revealpaths/RevealFailedException.java @@ -1,4 +1,4 @@ -package org.cryptomator.integrations.revealfiles; +package org.cryptomator.integrations.revealpaths; public class RevealFailedException extends Exception { diff --git a/src/main/java/org/cryptomator/integrations/revealfiles/RevealPathsService.java b/src/main/java/org/cryptomator/integrations/revealpaths/RevealPathsService.java similarity index 89% rename from src/main/java/org/cryptomator/integrations/revealfiles/RevealPathsService.java rename to src/main/java/org/cryptomator/integrations/revealpaths/RevealPathsService.java index 24f8525..3db0f8d 100644 --- a/src/main/java/org/cryptomator/integrations/revealfiles/RevealPathsService.java +++ b/src/main/java/org/cryptomator/integrations/revealpaths/RevealPathsService.java @@ -1,4 +1,4 @@ -package org.cryptomator.integrations.revealfiles; +package org.cryptomator.integrations.revealpaths; import org.cryptomator.integrations.common.IntegrationService; import org.cryptomator.integrations.common.IntegrationsLoader; @@ -29,13 +29,15 @@ static Stream get() { /** * Opens the given directory in the system default file manager and highlights all files from the list. + * @param directory + * @param childNames * * @throws RevealFailedException If the file manager could not be opened * @throws java.nio.file.NoSuchFileException If {@code directory} does not exist or is not a directory * @throws RuntimeException If at least one file from the list cannot be found? TODO: this might be unncessary/not possible * @throws UnsupportedOperationException If this service implementation does not support revealing multiple files */ - default void reveal(Path directory, List childNames) throws RevealFailedException, NoSuchFileException { + default void reveal(Path directory, List childNames) throws RevealFailedException, NoSuchFileException { throw new UnsupportedOperationException(); } } From 78055f9c091c41c5d62e8684c57add1d051f9813 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Tue, 10 Jan 2023 14:28:05 +0100 Subject: [PATCH 04/10] Improved doc for revealPaths service --- .../integrations/revealpaths/RevealPathsService.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/cryptomator/integrations/revealpaths/RevealPathsService.java b/src/main/java/org/cryptomator/integrations/revealpaths/RevealPathsService.java index 3db0f8d..c2951b4 100644 --- a/src/main/java/org/cryptomator/integrations/revealpaths/RevealPathsService.java +++ b/src/main/java/org/cryptomator/integrations/revealpaths/RevealPathsService.java @@ -22,22 +22,25 @@ static Stream get() { /** * Opens the parent of the given path in the system default file manager and highlights the resource the path points to. * - * @throws RevealFailedException If the file manager could not be opened or {@code p} does not have a parent //TODO: or throw IllegalArgumenException + * @param p Path to reveal + * @throws RevealFailedException If the file manager could not be opened or {@code p} does not have a parent * @throws java.nio.file.NoSuchFileException If {@code p} does not exist */ + //TODO: Throw IllegalArgumenException if p.getParent() == null? void reveal(Path p) throws RevealFailedException, NoSuchFileException; /** * Opens the given directory in the system default file manager and highlights all files from the list. + * * @param directory * @param childNames - * * @throws RevealFailedException If the file manager could not be opened * @throws java.nio.file.NoSuchFileException If {@code directory} does not exist or is not a directory - * @throws RuntimeException If at least one file from the list cannot be found? TODO: this might be unncessary/not possible + * @throws IllegalArgumentException If {@code childNames} contains non-relative paths or paths with a name count != 1 in normalized form * @throws UnsupportedOperationException If this service implementation does not support revealing multiple files */ default void reveal(Path directory, List childNames) throws RevealFailedException, NoSuchFileException { throw new UnsupportedOperationException(); } + } From 53f7b5726c79e238e6c3a7dd5b0ba0235882a7f6 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Tue, 10 Jan 2023 14:28:32 +0100 Subject: [PATCH 05/10] simplify api (for now) --- .../revealpaths/RevealPathsService.java | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/main/java/org/cryptomator/integrations/revealpaths/RevealPathsService.java b/src/main/java/org/cryptomator/integrations/revealpaths/RevealPathsService.java index c2951b4..ce24bae 100644 --- a/src/main/java/org/cryptomator/integrations/revealpaths/RevealPathsService.java +++ b/src/main/java/org/cryptomator/integrations/revealpaths/RevealPathsService.java @@ -29,18 +29,4 @@ static Stream get() { //TODO: Throw IllegalArgumenException if p.getParent() == null? void reveal(Path p) throws RevealFailedException, NoSuchFileException; - /** - * Opens the given directory in the system default file manager and highlights all files from the list. - * - * @param directory - * @param childNames - * @throws RevealFailedException If the file manager could not be opened - * @throws java.nio.file.NoSuchFileException If {@code directory} does not exist or is not a directory - * @throws IllegalArgumentException If {@code childNames} contains non-relative paths or paths with a name count != 1 in normalized form - * @throws UnsupportedOperationException If this service implementation does not support revealing multiple files - */ - default void reveal(Path directory, List childNames) throws RevealFailedException, NoSuchFileException { - throw new UnsupportedOperationException(); - } - } From d3f9a24456ff71bfdf6c4af3e32ad7f076bf043f Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Tue, 10 Jan 2023 16:08:23 +0100 Subject: [PATCH 06/10] Revert "add common service interface" This reverts commit ce77d633a48a43f34547c1fad5059d490648ac89. --- .../common/IntegrationService.java | 20 ------------------- .../revealpaths/RevealPathsService.java | 12 ++++++++--- 2 files changed, 9 insertions(+), 23 deletions(-) delete mode 100644 src/main/java/org/cryptomator/integrations/common/IntegrationService.java diff --git a/src/main/java/org/cryptomator/integrations/common/IntegrationService.java b/src/main/java/org/cryptomator/integrations/common/IntegrationService.java deleted file mode 100644 index 96d077a..0000000 --- a/src/main/java/org/cryptomator/integrations/common/IntegrationService.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.cryptomator.integrations.common; - -public interface IntegrationService { - - - /** - * Name of this service implementation. - * - * @return A human readable name of this service implementation - */ - String displayName(); - - /** - * Indicates, if this service implemenation can be used. - * - * @return true, if this service implementation is supported in the current OS environment - * @implSpec This check needs to return fast and in constant time - */ - boolean isSupported(); -} diff --git a/src/main/java/org/cryptomator/integrations/revealpaths/RevealPathsService.java b/src/main/java/org/cryptomator/integrations/revealpaths/RevealPathsService.java index ce24bae..12252ed 100644 --- a/src/main/java/org/cryptomator/integrations/revealpaths/RevealPathsService.java +++ b/src/main/java/org/cryptomator/integrations/revealpaths/RevealPathsService.java @@ -1,14 +1,12 @@ package org.cryptomator.integrations.revealpaths; -import org.cryptomator.integrations.common.IntegrationService; import org.cryptomator.integrations.common.IntegrationsLoader; import java.nio.file.NoSuchFileException; import java.nio.file.Path; -import java.util.List; import java.util.stream.Stream; -public interface RevealPathsService extends IntegrationService { +public interface RevealPathsService { /** * Loads all supported service implementations. @@ -29,4 +27,12 @@ static Stream get() { //TODO: Throw IllegalArgumenException if p.getParent() == null? void reveal(Path p) throws RevealFailedException, NoSuchFileException; + /** + * Indicates, if this provider can be used. + * + * @return true, if this provider is supported in the current OS environment + * @implSpec This check needs to return fast and in constant time + */ + boolean isSupported(); + } From 38531599b8e99c16638b4670f99def8e2ba61d0b Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Tue, 10 Jan 2023 16:22:44 +0100 Subject: [PATCH 07/10] Change specification --- .../integrations/revealpaths/RevealPathsService.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/cryptomator/integrations/revealpaths/RevealPathsService.java b/src/main/java/org/cryptomator/integrations/revealpaths/RevealPathsService.java index 12252ed..0da91cb 100644 --- a/src/main/java/org/cryptomator/integrations/revealpaths/RevealPathsService.java +++ b/src/main/java/org/cryptomator/integrations/revealpaths/RevealPathsService.java @@ -9,7 +9,7 @@ public interface RevealPathsService { /** - * Loads all supported service implementations. + * Loads all supported service providers. * * @return Stream of supported RevealPathsService implementations (may be empty) */ @@ -21,10 +21,9 @@ static Stream get() { * Opens the parent of the given path in the system default file manager and highlights the resource the path points to. * * @param p Path to reveal - * @throws RevealFailedException If the file manager could not be opened or {@code p} does not have a parent - * @throws java.nio.file.NoSuchFileException If {@code p} does not exist + * @throws RevealFailedException If the file manager could not be opened + * @throws IllegalArgumentException If {@code p} does not have a parent */ - //TODO: Throw IllegalArgumenException if p.getParent() == null? void reveal(Path p) throws RevealFailedException, NoSuchFileException; /** From 9d8080080d09324b0a2e29fadff6eda4b91295ad Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Wed, 11 Jan 2023 10:00:32 +0100 Subject: [PATCH 08/10] Rename service (and package) to singular form --- src/main/java/module-info.java | 6 +++--- .../RevealFailedException.java | 2 +- .../RevealPathService.java} | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) rename src/main/java/org/cryptomator/integrations/{revealpaths => revealpath}/RevealFailedException.java (84%) rename src/main/java/org/cryptomator/integrations/{revealpaths/RevealPathsService.java => revealpath/RevealPathService.java} (80%) diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index b7c5e03..7108775 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -1,5 +1,5 @@ import org.cryptomator.integrations.mount.MountService; -import org.cryptomator.integrations.revealpaths.RevealPathsService; +import org.cryptomator.integrations.revealpath.RevealPathService; import org.cryptomator.integrations.tray.TrayMenuController; import org.cryptomator.integrations.autostart.AutoStartProvider; import org.cryptomator.integrations.keychain.KeychainAccessProvider; @@ -15,14 +15,14 @@ exports org.cryptomator.integrations.common; exports org.cryptomator.integrations.keychain; exports org.cryptomator.integrations.mount; - exports org.cryptomator.integrations.revealpaths; + exports org.cryptomator.integrations.revealpath; exports org.cryptomator.integrations.tray; exports org.cryptomator.integrations.uiappearance; uses AutoStartProvider; uses KeychainAccessProvider; uses MountService; - uses RevealPathsService; + uses RevealPathService; uses TrayIntegrationProvider; uses TrayMenuController; uses UiAppearanceProvider; diff --git a/src/main/java/org/cryptomator/integrations/revealpaths/RevealFailedException.java b/src/main/java/org/cryptomator/integrations/revealpath/RevealFailedException.java similarity index 84% rename from src/main/java/org/cryptomator/integrations/revealpaths/RevealFailedException.java rename to src/main/java/org/cryptomator/integrations/revealpath/RevealFailedException.java index 1f7ea37..c56b6f9 100644 --- a/src/main/java/org/cryptomator/integrations/revealpaths/RevealFailedException.java +++ b/src/main/java/org/cryptomator/integrations/revealpath/RevealFailedException.java @@ -1,4 +1,4 @@ -package org.cryptomator.integrations.revealpaths; +package org.cryptomator.integrations.revealpath; public class RevealFailedException extends Exception { diff --git a/src/main/java/org/cryptomator/integrations/revealpaths/RevealPathsService.java b/src/main/java/org/cryptomator/integrations/revealpath/RevealPathService.java similarity index 80% rename from src/main/java/org/cryptomator/integrations/revealpaths/RevealPathsService.java rename to src/main/java/org/cryptomator/integrations/revealpath/RevealPathService.java index 0da91cb..818ae18 100644 --- a/src/main/java/org/cryptomator/integrations/revealpaths/RevealPathsService.java +++ b/src/main/java/org/cryptomator/integrations/revealpath/RevealPathService.java @@ -1,4 +1,4 @@ -package org.cryptomator.integrations.revealpaths; +package org.cryptomator.integrations.revealpath; import org.cryptomator.integrations.common.IntegrationsLoader; @@ -6,15 +6,15 @@ import java.nio.file.Path; import java.util.stream.Stream; -public interface RevealPathsService { +public interface RevealPathService { /** * Loads all supported service providers. * * @return Stream of supported RevealPathsService implementations (may be empty) */ - static Stream get() { - return IntegrationsLoader.loadAll(RevealPathsService.class).filter(RevealPathsService::isSupported); + static Stream get() { + return IntegrationsLoader.loadAll(RevealPathService.class).filter(RevealPathService::isSupported); } /** From a7b1eb65f32f7e8391455cbd86cc82ff2ac476fd Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Wed, 11 Jan 2023 10:34:28 +0100 Subject: [PATCH 09/10] change spec: * for files, select file in file manager * for directory, just open dir in file manager --- .../integrations/revealpath/RevealPathService.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/cryptomator/integrations/revealpath/RevealPathService.java b/src/main/java/org/cryptomator/integrations/revealpath/RevealPathService.java index 818ae18..4ca0970 100644 --- a/src/main/java/org/cryptomator/integrations/revealpath/RevealPathService.java +++ b/src/main/java/org/cryptomator/integrations/revealpath/RevealPathService.java @@ -2,7 +2,6 @@ import org.cryptomator.integrations.common.IntegrationsLoader; -import java.nio.file.NoSuchFileException; import java.nio.file.Path; import java.util.stream.Stream; @@ -18,13 +17,15 @@ static Stream get() { } /** - * Opens the parent of the given path in the system default file manager and highlights the resource the path points to. + * Reveal the path in the system default file manager. + *

+ * If the path points to a file, the parent of the file is openend and file is selected in the file manager window. + * If the path points to a directory, the directory is opened and its content shown in the file manager window. * * @param p Path to reveal - * @throws RevealFailedException If the file manager could not be opened - * @throws IllegalArgumentException If {@code p} does not have a parent + * @throws RevealFailedException if revealing the path failed */ - void reveal(Path p) throws RevealFailedException, NoSuchFileException; + void reveal(Path p) throws RevealFailedException; /** * Indicates, if this provider can be used. From c08b8a7e588a2fea8dccf1423cb4978eb6b979d3 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Wed, 11 Jan 2023 10:38:55 +0100 Subject: [PATCH 10/10] Apply suggestions from code review Co-authored-by: Tobias Hagemann --- .../integrations/revealpath/RevealPathService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/cryptomator/integrations/revealpath/RevealPathService.java b/src/main/java/org/cryptomator/integrations/revealpath/RevealPathService.java index 4ca0970..db7442e 100644 --- a/src/main/java/org/cryptomator/integrations/revealpath/RevealPathService.java +++ b/src/main/java/org/cryptomator/integrations/revealpath/RevealPathService.java @@ -10,7 +10,7 @@ public interface RevealPathService { /** * Loads all supported service providers. * - * @return Stream of supported RevealPathsService implementations (may be empty) + * @return Stream of supported RevealPathService implementations (may be empty) */ static Stream get() { return IntegrationsLoader.loadAll(RevealPathService.class).filter(RevealPathService::isSupported); @@ -19,7 +19,7 @@ static Stream get() { /** * Reveal the path in the system default file manager. *

- * If the path points to a file, the parent of the file is openend and file is selected in the file manager window. + * If the path points to a file, the parent of the file is opened and the file is selected in the file manager window. * If the path points to a directory, the directory is opened and its content shown in the file manager window. * * @param p Path to reveal