-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into release/1.1.0
- Loading branch information
Showing
18 changed files
with
304 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,21 @@ | ||
import org.cryptomator.integrations.tray.TrayMenuController; | ||
import org.cryptomator.integrations.autostart.AutoStartProvider; | ||
import org.cryptomator.integrations.keychain.KeychainAccessProvider; | ||
import org.cryptomator.integrations.tray.TrayIntegrationProvider; | ||
import org.cryptomator.integrations.uiappearance.UiAppearanceProvider; | ||
|
||
|
||
module org.cryptomator.integrations.api { | ||
requires static org.jetbrains.annotations; | ||
|
||
exports org.cryptomator.integrations.autostart; | ||
exports org.cryptomator.integrations.keychain; | ||
exports org.cryptomator.integrations.tray; | ||
exports org.cryptomator.integrations.uiappearance; | ||
|
||
uses AutoStartProvider; | ||
uses KeychainAccessProvider; | ||
uses TrayIntegrationProvider; | ||
uses TrayMenuController; | ||
uses UiAppearanceProvider; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/org/cryptomator/integrations/autostart/AutoStartProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/org/cryptomator/integrations/common/IntegrationsLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.cryptomator.integrations.common; | ||
|
||
import java.util.Arrays; | ||
import java.util.Comparator; | ||
import java.util.Optional; | ||
import java.util.ServiceLoader; | ||
import java.util.stream.Stream; | ||
|
||
public class IntegrationsLoader { | ||
|
||
/** | ||
* Loads the best suited service, i.e. the one with the highest priority that is supported. | ||
* <p> | ||
* If two services are available with the same priority, it is unspecified which one will be returned. | ||
* | ||
* @param clazz Service class | ||
* @param <T> Type of the service | ||
* @return Highest priority service or empty if no supported service was found | ||
*/ | ||
public static <T> Optional<T> load(Class<T> clazz) { | ||
return loadAll(clazz).findFirst(); | ||
} | ||
|
||
/** | ||
* Loads all suited services ordered by priority in descending order. | ||
* | ||
* @param clazz Service class | ||
* @param <T> Type of the service | ||
* @return An ordered stream of all suited service candidates | ||
*/ | ||
public static <T> Stream<T> loadAll(Class<T> clazz) { | ||
return ServiceLoader.load(clazz) | ||
.stream() | ||
.filter(IntegrationsLoader::isSupportedOperatingSystem) | ||
.sorted(Comparator.comparingInt(IntegrationsLoader::getPriority).reversed()) | ||
.map(ServiceLoader.Provider::get); | ||
} | ||
|
||
private static int getPriority(ServiceLoader.Provider<?> provider) { | ||
var prio = provider.type().getAnnotation(Priority.class); | ||
return prio == null ? Priority.DEFAULT : prio.value(); | ||
} | ||
|
||
private static boolean isSupportedOperatingSystem(ServiceLoader.Provider<?> provider) { | ||
var annotations = provider.type().getAnnotationsByType(OperatingSystem.class); | ||
return annotations.length == 0 || Arrays.stream(annotations).anyMatch(OperatingSystem.Value::isCurrent); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/org/cryptomator/integrations/common/OperatingSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.cryptomator.integrations.common; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Repeatable; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Restricts the annotated integration provider to one or more operating system(s). | ||
* | ||
* @since 1.1.0 | ||
*/ | ||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE}) | ||
@Repeatable(OperatingSystem.OperatingSystems.class) | ||
public @interface OperatingSystem { | ||
Value value() default Value.UNKNOWN; | ||
|
||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE}) | ||
@interface OperatingSystems { | ||
OperatingSystem[] value(); | ||
} | ||
|
||
enum Value { | ||
LINUX, | ||
MAC, | ||
WINDOWS, | ||
UNKNOWN; | ||
|
||
private static final String OS_NAME = System.getProperty("os.name", "").toLowerCase(); | ||
|
||
public static Value current() { | ||
if (OS_NAME.contains("linux")) { | ||
return LINUX; | ||
} else if (OS_NAME.contains("mac")) { | ||
return MAC; | ||
} else if (OS_NAME.contains("windows")) { | ||
return WINDOWS; | ||
} else { | ||
return UNKNOWN; | ||
} | ||
} | ||
|
||
public static boolean isCurrent(OperatingSystem os) { | ||
return current().equals(os.value()); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/org/cryptomator/integrations/common/Priority.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.cryptomator.integrations.common; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Repeatable; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Integration Priority. | ||
* <p> | ||
* If multiple implementations for an integration can be provided, the provider with the highest priority will be used. | ||
* | ||
* @since 1.1.0 | ||
*/ | ||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE}) | ||
public @interface Priority { | ||
int DEFAULT = 0; | ||
int FALLBACK = Integer.MIN_VALUE; | ||
|
||
int value() default DEFAULT; | ||
} |
Oops, something went wrong.