Skip to content

Commit 9bbe52c

Browse files
authored
Merge pull request #49 from cryptomator/feature/clean-up
Chores: Remove dependencies and clean up code
2 parents 6c00398 + 0f6a426 commit 9bbe52c

File tree

6 files changed

+40
-33
lines changed

6 files changed

+40
-33
lines changed

pom.xml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@
4444
<secret-service.version>2.0.0-alpha</secret-service.version>
4545
<kdewallet.version>1.3.3</kdewallet.version>
4646
<appindicator.version>1.3.6</appindicator.version>
47-
<guava.version>32.1.3-jre</guava.version>
4847
<slf4j.version>2.0.9</slf4j.version>
49-
<commons-lang3.version>3.13.0</commons-lang3.version>
5048

5149
<!-- test dependencies -->
5250
<junit.version>5.10.1</junit.version>
@@ -67,11 +65,6 @@
6765
<artifactId>slf4j-api</artifactId>
6866
<version>${slf4j.version}</version>
6967
</dependency>
70-
<dependency>
71-
<groupId>com.google.guava</groupId>
72-
<artifactId>guava</artifactId>
73-
<version>${guava.version}</version>
74-
</dependency>
7568
<dependency>
7669
<groupId>de.swiesend</groupId>
7770
<artifactId>secret-service</artifactId>
@@ -82,12 +75,6 @@
8275
<artifactId>kdewallet</artifactId>
8376
<version>${kdewallet.version}</version>
8477
</dependency>
85-
<!-- Apache Commons -->
86-
<dependency>
87-
<groupId>org.apache.commons</groupId>
88-
<artifactId>commons-lang3</artifactId>
89-
<version>${commons-lang3.version}</version>
90-
</dependency>
9178
<!-- Java bindings for appindicator -->
9279
<dependency>
9380
<groupId>org.purejava</groupId>

src/main/java/module-info.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
module org.cryptomator.integrations.linux {
1010
requires org.cryptomator.integrations.api;
1111
requires org.slf4j;
12-
requires com.google.common;
13-
requires org.apache.commons.lang3;
1412
requires org.freedesktop.dbus;
1513
requires org.purejava.appindicator;
1614
requires org.purejava.kwallet;

src/main/java/org/cryptomator/linux/keychain/KDEWalletKeychainAccess.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package org.cryptomator.linux.keychain;
22

3-
import com.google.common.base.Preconditions;
43
import org.cryptomator.integrations.common.OperatingSystem;
54
import org.cryptomator.integrations.common.Priority;
65
import org.cryptomator.integrations.keychain.KeychainAccessException;
76
import org.cryptomator.integrations.keychain.KeychainAccessProvider;
7+
import org.cryptomator.linux.util.CheckUtil;
88
import org.freedesktop.dbus.connections.impl.DBusConnection;
99
import org.freedesktop.dbus.connections.impl.DBusConnectionBuilder;
1010
import org.freedesktop.dbus.exceptions.DBusConnectionException;
@@ -49,25 +49,25 @@ public boolean isLocked() {
4949

5050
@Override
5151
public void storePassphrase(String key, String displayName, CharSequence passphrase) throws KeychainAccessException {
52-
Preconditions.checkState(wallet.isPresent(), "Keychain not supported.");
52+
CheckUtil.checkState(wallet.isPresent(), "Keychain not supported.");
5353
wallet.get().storePassphrase(key, passphrase);
5454
}
5555

5656
@Override
5757
public char[] loadPassphrase(String key) throws KeychainAccessException {
58-
Preconditions.checkState(wallet.isPresent(), "Keychain not supported.");
58+
CheckUtil.checkState(wallet.isPresent(), "Keychain not supported.");
5959
return wallet.get().loadPassphrase(key);
6060
}
6161

6262
@Override
6363
public void deletePassphrase(String key) throws KeychainAccessException {
64-
Preconditions.checkState(wallet.isPresent(), "Keychain not supported.");
64+
CheckUtil.checkState(wallet.isPresent(), "Keychain not supported.");
6565
wallet.get().deletePassphrase(key);
6666
}
6767

6868
@Override
6969
public void changePassphrase(String key, String displayName, CharSequence passphrase) throws KeychainAccessException {
70-
Preconditions.checkState(wallet.isPresent(), "Keychain not supported.");
70+
CheckUtil.checkState(wallet.isPresent(), "Keychain not supported.");
7171
wallet.get().changePassphrase(key, passphrase);
7272
}
7373

@@ -95,11 +95,7 @@ private static DBusConnection getNewConnection() throws DBusException {
9595
} catch (DBusConnectionException | DBusExecutionException de) {
9696
LOG.warn("Connecting to SESSION bus failed.", de);
9797
LOG.warn("Falling back to SYSTEM DBus");
98-
try {
99-
return DBusConnectionBuilder.forSystemBus().build();
100-
} catch (DBusException e) {
101-
throw e;
102-
}
98+
return DBusConnectionBuilder.forSystemBus().build();
10399
}
104100
}
105101

@@ -144,7 +140,7 @@ public char[] loadPassphrase(String key) throws KeychainAccessException {
144140
} else {
145141
LOG.debug("loadPassphrase: wallet is closed.");
146142
}
147-
return (password.equals("")) ? null : password.toCharArray();
143+
return (password.isEmpty()) ? null : password.toCharArray();
148144
} catch (RuntimeException e) {
149145
throw new KeychainAccessException("Loading the passphrase failed.", e);
150146
}

src/main/java/org/cryptomator/linux/revealpath/DBusSendRevealPathService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.cryptomator.linux.revealpath;
22

3-
import com.google.common.base.Preconditions;
43
import org.cryptomator.integrations.revealpath.RevealFailedException;
54
import org.cryptomator.integrations.revealpath.RevealPathService;
65

@@ -91,7 +90,9 @@ public boolean isSupported() {
9190
* @throws IOException if the Inputer reader on the process output cannot be created
9291
*/
9392
private boolean parseOutputForFileManagerInterface(Process fileManager1Process) throws IOException {
94-
Preconditions.checkState(!fileManager1Process.isAlive());
93+
if( fileManager1Process.isAlive()) {
94+
throw new IllegalArgumentException("Process " + fileManager1Process + " must be terminated to read output.");
95+
}
9596
try (var reader = fileManager1Process.inputReader(StandardCharsets.UTF_8)) {
9697
return reader.lines().map(String::trim).anyMatch(FILEMANAGER1_XML_ELEMENT::equals);
9798
}

src/main/java/org/cryptomator/linux/tray/AppindicatorTrayMenuController.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public class AppindicatorTrayMenuController implements TrayMenuController {
3131
private static final Arena ARENA = Arena.global();
3232
private MemorySegment indicator;
3333
private MemorySegment menu = gtk_menu_new();
34-
private Optional<String> svgSourcePath;
3534

3635
@CheckAvailability
3736
public static boolean isAvailable() {
@@ -48,9 +47,9 @@ public void showTrayIcon(Consumer<TrayIconLoader> iconLoader, Runnable runnable,
4847

4948
private void showTrayIconWithSVG(String s) {
5049
try (var arena = Arena.ofConfined()) {
51-
svgSourcePath = Optional.ofNullable(System.getProperty(SVG_SOURCE_PROPERTY));
50+
var svgSourcePath = System.getProperty(SVG_SOURCE_PROPERTY);
5251
// flatpak
53-
if (svgSourcePath.isEmpty()) {
52+
if (svgSourcePath != null) {
5453
indicator = app_indicator_new(arena.allocateUtf8String(APP_INDICATOR_ID),
5554
arena.allocateUtf8String(s),
5655
APP_INDICATOR_CATEGORY_APPLICATION_STATUS());
@@ -60,7 +59,7 @@ private void showTrayIconWithSVG(String s) {
6059
arena.allocateUtf8String(s),
6160
APP_INDICATOR_CATEGORY_APPLICATION_STATUS(),
6261
// find tray icons theme in mounted AppImage / installed on system by ppa
63-
arena.allocateUtf8String(svgSourcePath.get()));
62+
arena.allocateUtf8String(svgSourcePath));
6463
}
6564
}
6665
}
@@ -105,7 +104,7 @@ private void addChildren(MemorySegment menu, List<TrayMenuItem> items) {
105104
}
106105
gtk_menu_shell_append(menu, gtkMenuItem);
107106
}
108-
case SeparatorItem separatorItem -> {
107+
case SeparatorItem _ -> {
109108
var gtkSeparator = gtk_menu_item_new();
110109
gtk_menu_shell_append(menu, gtkSeparator);
111110
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.cryptomator.linux.util;
2+
3+
public class CheckUtil {
4+
5+
6+
/**
7+
* Ensures the truth of an expression involving the state of the calling instance, but not
8+
* involving any parameters to the calling method.
9+
*
10+
* @param expression a boolean expression
11+
* @param errorMessage the exception message to use if the check fails; will be converted to a
12+
* string using {@link String#valueOf(Object)}
13+
* @throws IllegalStateException if {@code expression} is false
14+
*/
15+
public static void checkState(boolean expression, String errorMessage) {
16+
if (!expression) {
17+
throw new IllegalStateException(errorMessage);
18+
}
19+
}
20+
21+
public static void checkState(boolean expression) {
22+
if (!expression) {
23+
throw new IllegalStateException();
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)