Skip to content

Commit

Permalink
Merge branch 'develop' into release/1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
overheadhunter committed Mar 7, 2022
2 parents 6fd93ef + 70fb01c commit 0f9c99a
Show file tree
Hide file tree
Showing 18 changed files with 304 additions and 38 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ jobs:
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
- uses: actions/setup-java@v2
with:
java-version: 11
- uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
distribution: 'temurin'
java-version: 17
cache: 'maven'
- name: Ensure to use tagged version
if: startsWith(github.ref, 'refs/tags/')
run: mvn versions:set --file ./pom.xml -DnewVersion=${GITHUB_REF##*/}
Expand Down
12 changes: 4 additions & 8 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@ jobs:
- uses: actions/checkout@v2
with:
fetch-depth: 2
- uses: actions/setup-java@v1
- uses: actions/setup-java@v2
with:
java-version: 11
- uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
distribution: 'temurin'
java-version: 17
cache: 'maven'
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
Expand Down
12 changes: 4 additions & 8 deletions .github/workflows/publish-central.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,16 @@ jobs:
- uses: actions/checkout@v2
with:
ref: "refs/tags/${{ github.event.inputs.tag }}"
- uses: actions/setup-java@v1
- uses: actions/setup-java@v2
with:
java-version: 11
distribution: 'temurin'
java-version: 17
cache: 'maven'
server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml
server-username: MAVEN_USERNAME # env variable for username in deploy
server-password: MAVEN_PASSWORD # env variable for token in deploy
gpg-private-key: ${{ secrets.RELEASES_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
- uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Enforce project version ${{ github.event.inputs.tag }}
run: mvn versions:set -B -DnewVersion=${{ github.event.inputs.tag }}
- name: Deploy
Expand Down
12 changes: 4 additions & 8 deletions .github/workflows/publish-github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@ jobs:
if: startsWith(github.ref, 'refs/tags/') # only allow publishing tagged versions
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
- uses: actions/setup-java@v2
with:
java-version: 11
distribution: 'temurin'
java-version: 17
cache: 'maven'
gpg-private-key: ${{ secrets.RELEASES_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
- uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Enforce project version ${{ github.event.release.tag_name }}
run: mvn versions:set -B -DnewVersion=${{ github.event.release.tag_name }}
- name: Deploy
Expand Down
21 changes: 15 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,23 @@
</license>
</licenses>

<dependencies>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.9.0</version>
<configuration>
<release>11</release>
<release>17</release>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -72,7 +81,7 @@
</executions>
<configuration>
<quiet>true</quiet>
<release>11</release>
<release>17</release>
<tags>
<!-- workaround for "unknown tag: implNote", see https://blog.codefx.org/java/new-javadoc-tags/#Maven -->
<tag>
Expand Down Expand Up @@ -110,7 +119,7 @@
<plugins>
<plugin>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<version>3.0.1</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand All @@ -137,7 +146,7 @@
<repository>
<id>ossrh</id>
<name>Maven Central</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<build>
Expand All @@ -149,7 +158,7 @@
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/module-info.java
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;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
package org.cryptomator.integrations.autostart;

import org.cryptomator.integrations.common.IntegrationsLoader;
import org.jetbrains.annotations.Blocking;

import java.util.Optional;

public interface AutoStartProvider {

/**
* Loads the best-suited AutoStartProvider.
*
* @return preferred AutoStartProvider (if any)
* @since 1.1.0
*/
static Optional<AutoStartProvider> get() {
return IntegrationsLoader.load(AutoStartProvider.class);
}

@Blocking
void enable() throws ToggleAutoStartFailedException;

@Blocking
void disable() throws ToggleAutoStartFailedException;

boolean isEnabled();
Expand Down
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);
}

}
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 src/main/java/org/cryptomator/integrations/common/Priority.java
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;
}
Loading

0 comments on commit 0f9c99a

Please sign in to comment.