diff --git a/main/commons/src/main/java/org/cryptomator/common/Optionals.java b/main/commons/src/main/java/org/cryptomator/common/Optionals.java index d5b5cac4d..a97eb122a 100644 --- a/main/commons/src/main/java/org/cryptomator/common/Optionals.java +++ b/main/commons/src/main/java/org/cryptomator/common/Optionals.java @@ -8,13 +8,6 @@ public final class Optionals { private Optionals() { } - public static void ifPresent(Optional optional, ConsumerThrowingException consumer) throws E { - final T t = optional.orElse(null); - if (t != null) { - consumer.accept(t); - } - } - /** * Returns a function that is equivalent to the input function but immediately gets the value of the returned optional when invoked. * diff --git a/main/ui/src/main/java/org/cryptomator/ui/ExitUtil.java b/main/ui/src/main/java/org/cryptomator/ui/ExitUtil.java index 64db2ac4c..78fa03ce4 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/ExitUtil.java +++ b/main/ui/src/main/java/org/cryptomator/ui/ExitUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Sebastian Stenzel and others. + * Copyright (c) 2016, 2017 Sebastian Stenzel and others. * This file is licensed under the terms of the MIT license. * See the LICENSE.txt file for more info. * @@ -37,7 +37,7 @@ import org.cryptomator.common.settings.Settings; import org.cryptomator.jni.JniException; import org.cryptomator.jni.MacApplicationUiState; import org.cryptomator.jni.MacFunctions; -import org.cryptomator.ui.settings.Localization; +import org.cryptomator.ui.l10n.Localization; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/main/ui/src/main/java/org/cryptomator/ui/UiModule.java b/main/ui/src/main/java/org/cryptomator/ui/UiModule.java index cecf183f1..e6c31e0ce 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/UiModule.java +++ b/main/ui/src/main/java/org/cryptomator/ui/UiModule.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Sebastian Stenzel and others. + * Copyright (c) 2016, 2017 Sebastian Stenzel and others. * This file is licensed under the terms of the MIT license. * See the LICENSE.txt file for more info. * @@ -24,10 +24,7 @@ import org.cryptomator.jni.JniModule; import org.cryptomator.keychain.KeychainModule; import org.cryptomator.ui.controllers.ViewControllerModule; import org.cryptomator.ui.model.VaultComponent; -import org.cryptomator.ui.util.DeferredCloser; import org.fxmisc.easybind.EasyBind; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import dagger.Module; import dagger.Provides; @@ -36,22 +33,6 @@ import javafx.beans.binding.Binding; @Module(includes = {ViewControllerModule.class, CommonsModule.class, KeychainModule.class, JniModule.class}, subcomponents = {VaultComponent.class}) public class UiModule { - private static final Logger LOG = LoggerFactory.getLogger(UiModule.class); - - @Provides - @Singleton - DeferredCloser provideDeferredCloser(@Named("shutdownTaskScheduler") Consumer shutdownTaskScheduler) { - DeferredCloser closer = new DeferredCloser(); - shutdownTaskScheduler.accept(() -> { - try { - closer.close(); - } catch (Exception e) { - LOG.error("Error during shutdown.", e); - } - }); - return closer; - } - @Provides @Singleton Settings provideSettings(SettingsProvider settingsProvider) { @@ -60,8 +41,10 @@ public class UiModule { @Provides @Singleton - ExecutorService provideExecutorService(DeferredCloser closer) { - return closer.closeLater(Executors.newCachedThreadPool(), ExecutorService::shutdown).get().orElseThrow(IllegalStateException::new); + ExecutorService provideExecutorService(@Named("shutdownTaskScheduler") Consumer shutdownTaskScheduler) { + ExecutorService executorService = Executors.newCachedThreadPool(); + shutdownTaskScheduler.accept(executorService::shutdown); + return executorService; } @Provides diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/ChangePasswordController.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/ChangePasswordController.java index 45b652ce5..d51b6cf2a 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/ChangePasswordController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/ChangePasswordController.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Sebastian Stenzel and others. + * Copyright (c) 2016, 2017 Sebastian Stenzel and others. * This file is licensed under the terms of the MIT license. * See the LICENSE.txt file for more info. * @@ -20,8 +20,8 @@ import javax.inject.Singleton; import org.cryptomator.cryptolib.api.InvalidPassphraseException; import org.cryptomator.cryptolib.api.UnsupportedVaultFormatException; import org.cryptomator.ui.controls.SecPasswordField; +import org.cryptomator.ui.l10n.Localization; import org.cryptomator.ui.model.Vault; -import org.cryptomator.ui.settings.Localization; import org.cryptomator.ui.util.PasswordStrengthUtil; import org.fxmisc.easybind.EasyBind; import org.slf4j.Logger; diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/InitializeController.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/InitializeController.java index 5a21eba91..c4d439077 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/InitializeController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/InitializeController.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2016 Sebastian Stenzel + * Copyright (c) 2014, 2017 Sebastian Stenzel * This file is licensed under the terms of the MIT license. * See the LICENSE.txt file for more info. * @@ -19,8 +19,8 @@ import javax.inject.Inject; import javax.inject.Singleton; import org.cryptomator.ui.controls.SecPasswordField; +import org.cryptomator.ui.l10n.Localization; import org.cryptomator.ui.model.Vault; -import org.cryptomator.ui.settings.Localization; import org.cryptomator.ui.util.PasswordStrengthUtil; import org.fxmisc.easybind.EasyBind; import org.slf4j.Logger; diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/MainController.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/MainController.java index 22b0964b9..ba15b47e1 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/MainController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/MainController.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2016 Sebastian Stenzel + * Copyright (c) 2014, 2017 Sebastian Stenzel * This file is licensed under the terms of the MIT license. * See the LICENSE.txt file for more info. * @@ -29,13 +29,13 @@ import org.apache.commons.lang3.SystemUtils; import org.cryptomator.common.settings.VaultSettings; import org.cryptomator.ui.ExitUtil; import org.cryptomator.ui.controls.DirectoryListCell; +import org.cryptomator.ui.l10n.Localization; import org.cryptomator.ui.model.AutoUnlocker; import org.cryptomator.ui.model.UpgradeStrategies; import org.cryptomator.ui.model.UpgradeStrategy; import org.cryptomator.ui.model.Vault; import org.cryptomator.ui.model.VaultFactory; import org.cryptomator.ui.model.VaultList; -import org.cryptomator.ui.settings.Localization; import org.cryptomator.ui.util.DialogBuilderUtil; import org.fxmisc.easybind.EasyBind; import org.fxmisc.easybind.Subscription; diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/SettingsController.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/SettingsController.java index e0494ee37..44e18e2c7 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/SettingsController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/SettingsController.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2016 Sebastian Stenzel + * Copyright (c) 2014, 2017 Sebastian Stenzel * This file is licensed under the terms of the MIT license. * See the LICENSE.txt file for more info. * @@ -16,7 +16,7 @@ import javax.inject.Singleton; import org.apache.commons.lang3.SystemUtils; import org.cryptomator.common.settings.Settings; -import org.cryptomator.ui.settings.Localization; +import org.cryptomator.ui.l10n.Localization; import com.google.common.base.CharMatcher; import com.google.common.base.Strings; diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java index 065712627..a0554c3e6 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2016 Sebastian Stenzel + * Copyright (c) 2014, 2017 Sebastian Stenzel * This file is licensed under the terms of the MIT license. * See the LICENSE.txt file for more info. * @@ -24,9 +24,9 @@ import org.cryptomator.frontend.webdav.ServerLifecycleException; import org.cryptomator.frontend.webdav.mount.Mounter.CommandFailedException; import org.cryptomator.keychain.KeychainAccess; import org.cryptomator.ui.controls.SecPasswordField; +import org.cryptomator.ui.l10n.Localization; import org.cryptomator.ui.model.Vault; import org.cryptomator.ui.model.WindowsDriveLetters; -import org.cryptomator.ui.settings.Localization; import org.cryptomator.ui.util.AsyncTaskService; import org.cryptomator.ui.util.DialogBuilderUtil; import org.fxmisc.easybind.EasyBind; diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockedController.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockedController.java index 4b04fd1ed..52f70da77 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockedController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockedController.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2016 Sebastian Stenzel + * Copyright (c) 2014, 2017 Sebastian Stenzel * This file is licensed under the terms of the MIT license. * See the LICENSE.txt file for more info. * @@ -14,8 +14,8 @@ import java.util.Optional; import javax.inject.Inject; +import org.cryptomator.ui.l10n.Localization; import org.cryptomator.ui.model.Vault; -import org.cryptomator.ui.settings.Localization; import org.cryptomator.ui.util.AsyncTaskService; import org.cryptomator.ui.util.DialogBuilderUtil; import org.fxmisc.easybind.EasyBind; diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/UpgradeController.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/UpgradeController.java index 63eacdbda..aafd46085 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/UpgradeController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/UpgradeController.java @@ -11,11 +11,11 @@ import java.util.Optional; import javax.inject.Inject; import org.cryptomator.ui.controls.SecPasswordField; +import org.cryptomator.ui.l10n.Localization; import org.cryptomator.ui.model.UpgradeStrategies; import org.cryptomator.ui.model.UpgradeStrategy; import org.cryptomator.ui.model.UpgradeStrategy.UpgradeFailedException; import org.cryptomator.ui.model.Vault; -import org.cryptomator.ui.settings.Localization; import org.cryptomator.ui.util.AsyncTaskService; import org.fxmisc.easybind.EasyBind; diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/ViewController.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/ViewController.java index ba6a641b7..1d27a0598 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/ViewController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/ViewController.java @@ -1,3 +1,8 @@ +/******************************************************************************* + * Copyright (c) 2017 Skymatic UG (haftungsbeschränkt). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the accompanying LICENSE file. + *******************************************************************************/ package org.cryptomator.ui.controllers; import java.net.URL; diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/ViewControllerKey.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/ViewControllerKey.java index 6c47cee49..72af006ea 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/ViewControllerKey.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/ViewControllerKey.java @@ -1,3 +1,8 @@ +/******************************************************************************* + * Copyright (c) 2017 Skymatic UG (haftungsbeschränkt). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the accompanying LICENSE file. + *******************************************************************************/ package org.cryptomator.ui.controllers; import static java.lang.annotation.ElementType.METHOD; diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/ViewControllerLoader.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/ViewControllerLoader.java index 867caea63..b345dafdc 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/ViewControllerLoader.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/ViewControllerLoader.java @@ -1,3 +1,8 @@ +/******************************************************************************* + * Copyright (c) 2017 Skymatic UG (haftungsbeschränkt). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the accompanying LICENSE file. + *******************************************************************************/ package org.cryptomator.ui.controllers; import java.io.IOException; @@ -9,7 +14,7 @@ import javax.inject.Inject; import javax.inject.Provider; import javax.inject.Singleton; -import org.cryptomator.ui.settings.Localization; +import org.cryptomator.ui.l10n.Localization; import javafx.fxml.FXMLLoader; diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/ViewControllerModule.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/ViewControllerModule.java index b8f4a019f..f688f95cf 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/ViewControllerModule.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/ViewControllerModule.java @@ -1,3 +1,8 @@ +/******************************************************************************* + * Copyright (c) 2017 Skymatic UG (haftungsbeschränkt). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the accompanying LICENSE file. + *******************************************************************************/ package org.cryptomator.ui.controllers; import dagger.Module; diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/WelcomeController.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/WelcomeController.java index 8698b3d09..da5c9c572 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/WelcomeController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/WelcomeController.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2016 Sebastian Stenzel + * Copyright (c) 2014, 2017 Sebastian Stenzel * This file is licensed under the terms of the MIT license. * See the LICENSE.txt file for more info. * @@ -30,7 +30,7 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClients; import org.cryptomator.common.settings.Settings; -import org.cryptomator.ui.settings.Localization; +import org.cryptomator.ui.l10n.Localization; import org.cryptomator.ui.util.AsyncTaskService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/main/ui/src/main/java/org/cryptomator/ui/controls/DirectoryListCell.java b/main/ui/src/main/java/org/cryptomator/ui/controls/DirectoryListCell.java index 7676d6dc9..2c549509c 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controls/DirectoryListCell.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controls/DirectoryListCell.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Sebastian Stenzel and others. + * Copyright (c) 2016, 2017 Sebastian Stenzel and others. * This file is licensed under the terms of the MIT license. * See the LICENSE.txt file for more info. * diff --git a/main/ui/src/main/java/org/cryptomator/ui/controls/DraggableListCell.java b/main/ui/src/main/java/org/cryptomator/ui/controls/DraggableListCell.java index 6ab34a3b1..65e32fc1d 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controls/DraggableListCell.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controls/DraggableListCell.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Sebastian Stenzel and others. + * Copyright (c) 2016, 2017 Sebastian Stenzel and others. * This file is licensed under the terms of the MIT license. * See the LICENSE.txt file for more info. * diff --git a/main/ui/src/main/java/org/cryptomator/ui/controls/SecPasswordField.java b/main/ui/src/main/java/org/cryptomator/ui/controls/SecPasswordField.java index c7c6fc8fa..01dfbf6f5 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controls/SecPasswordField.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controls/SecPasswordField.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2016 Sebastian Stenzel + * Copyright (c) 2014, 2017 Sebastian Stenzel * This file is licensed under the terms of the MIT license. * See the LICENSE.txt file for more info. * diff --git a/main/ui/src/main/java/org/cryptomator/ui/settings/Localization.java b/main/ui/src/main/java/org/cryptomator/ui/l10n/Localization.java similarity index 98% rename from main/ui/src/main/java/org/cryptomator/ui/settings/Localization.java rename to main/ui/src/main/java/org/cryptomator/ui/l10n/Localization.java index 99f4e7a55..e5876a5ef 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/settings/Localization.java +++ b/main/ui/src/main/java/org/cryptomator/ui/l10n/Localization.java @@ -3,7 +3,7 @@ * All rights reserved. This program and the accompanying materials * are made available under the terms of the accompanying LICENSE file. *******************************************************************************/ -package org.cryptomator.ui.settings; +package org.cryptomator.ui.l10n; import java.io.IOException; import java.io.InputStream; diff --git a/main/ui/src/main/java/org/cryptomator/ui/model/AutoUnlocker.java b/main/ui/src/main/java/org/cryptomator/ui/model/AutoUnlocker.java index e6612f1cb..124d1f903 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/model/AutoUnlocker.java +++ b/main/ui/src/main/java/org/cryptomator/ui/model/AutoUnlocker.java @@ -1,3 +1,8 @@ +/******************************************************************************* + * Copyright (c) 2017 Skymatic UG (haftungsbeschränkt). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the accompanying LICENSE file. + *******************************************************************************/ package org.cryptomator.ui.model; import java.nio.CharBuffer; diff --git a/main/ui/src/main/java/org/cryptomator/ui/model/UpgradeStrategy.java b/main/ui/src/main/java/org/cryptomator/ui/model/UpgradeStrategy.java index 40105140b..5f7ccf333 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/model/UpgradeStrategy.java +++ b/main/ui/src/main/java/org/cryptomator/ui/model/UpgradeStrategy.java @@ -18,7 +18,7 @@ import org.cryptomator.cryptolib.api.CryptorProvider; import org.cryptomator.cryptolib.api.InvalidPassphraseException; import org.cryptomator.cryptolib.api.KeyFile; import org.cryptomator.cryptolib.api.UnsupportedVaultFormatException; -import org.cryptomator.ui.settings.Localization; +import org.cryptomator.ui.l10n.Localization; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/main/ui/src/main/java/org/cryptomator/ui/model/UpgradeVersion3DropBundleExtension.java b/main/ui/src/main/java/org/cryptomator/ui/model/UpgradeVersion3DropBundleExtension.java index 9bbc5f2d2..1fa8ff306 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/model/UpgradeVersion3DropBundleExtension.java +++ b/main/ui/src/main/java/org/cryptomator/ui/model/UpgradeVersion3DropBundleExtension.java @@ -15,7 +15,7 @@ import javax.inject.Singleton; import org.apache.commons.lang3.StringUtils; import org.cryptomator.cryptolib.Cryptors; import org.cryptomator.cryptolib.api.Cryptor; -import org.cryptomator.ui.settings.Localization; +import org.cryptomator.ui.l10n.Localization; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/main/ui/src/main/java/org/cryptomator/ui/model/UpgradeVersion3to4.java b/main/ui/src/main/java/org/cryptomator/ui/model/UpgradeVersion3to4.java index 8e12c8fd7..3dd4b6010 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/model/UpgradeVersion3to4.java +++ b/main/ui/src/main/java/org/cryptomator/ui/model/UpgradeVersion3to4.java @@ -28,7 +28,7 @@ import org.apache.commons.lang3.StringUtils; import org.cryptomator.cryptolib.Cryptors; import org.cryptomator.cryptolib.api.Cryptor; import org.cryptomator.cryptolib.common.MessageDigestSupplier; -import org.cryptomator.ui.settings.Localization; +import org.cryptomator.ui.l10n.Localization; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/main/ui/src/main/java/org/cryptomator/ui/model/UpgradeVersion4to5.java b/main/ui/src/main/java/org/cryptomator/ui/model/UpgradeVersion4to5.java index ba2207ebc..ae26f75da 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/model/UpgradeVersion4to5.java +++ b/main/ui/src/main/java/org/cryptomator/ui/model/UpgradeVersion4to5.java @@ -24,7 +24,7 @@ import javax.inject.Singleton; import org.cryptomator.cryptolib.Cryptors; import org.cryptomator.cryptolib.api.Cryptor; import org.cryptomator.cryptolib.api.FileHeader; -import org.cryptomator.ui.settings.Localization; +import org.cryptomator.ui.l10n.Localization; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/main/ui/src/main/java/org/cryptomator/ui/model/Vault.java b/main/ui/src/main/java/org/cryptomator/ui/model/Vault.java index 63a93c1c3..f963c03f6 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/model/Vault.java +++ b/main/ui/src/main/java/org/cryptomator/ui/model/Vault.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Sebastian Stenzel and others. + * Copyright (c) 2016, 2017 Sebastian Stenzel and others. * This file is licensed under the terms of the MIT license. * See the LICENSE.txt file for more info. * @@ -40,7 +40,6 @@ import org.cryptomator.frontend.webdav.mount.Mounter.Mount; import org.cryptomator.frontend.webdav.mount.Mounter.UnmountOperation; import org.cryptomator.frontend.webdav.servlet.WebDavServletController; import org.cryptomator.ui.model.VaultModule.PerVault; -import org.cryptomator.ui.util.DeferredCloser; import org.fxmisc.easybind.EasyBind; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,7 +59,6 @@ public class Vault { private final Settings settings; private final VaultSettings vaultSettings; private final WebDavServer server; - private final DeferredCloser closer; private final BooleanProperty unlocked = new SimpleBooleanProperty(); private final BooleanProperty mounted = new SimpleBooleanProperty(); private final AtomicReference cryptoFileSystem = new AtomicReference<>(); @@ -69,11 +67,10 @@ public class Vault { private Mount mount; @Inject - Vault(Settings settings, VaultSettings vaultSettings, WebDavServer server, DeferredCloser closer) { + Vault(Settings settings, VaultSettings vaultSettings, WebDavServer server) { this.settings = settings; this.vaultSettings = vaultSettings; this.server = server; - this.closer = closer; } // ****************************************************************************** @@ -89,9 +86,7 @@ public class Vault { .withPassphrase(passphrase) // .withMasterkeyFilename(MASTERKEY_FILENAME) // .build(); - CryptoFileSystem fs = CryptoFileSystemProvider.newFileSystem(getPath(), fsProps); - closer.closeLater(fs); - return fs; + return CryptoFileSystemProvider.newFileSystem(getPath(), fsProps); } public void create(CharSequence passphrase) throws IOException { @@ -103,7 +98,7 @@ public class Vault { } } if (!isValidVaultDirectory()) { - getCryptoFileSystem(passphrase); // implicitly creates a non-existing vault + createCryptoFileSystem(passphrase).close(); // implicitly creates a non-existing vault } else { throw new FileAlreadyExistsException(getPath().toString()); } diff --git a/main/ui/src/main/java/org/cryptomator/ui/model/VaultFactory.java b/main/ui/src/main/java/org/cryptomator/ui/model/VaultFactory.java index 824b3cc1d..da9448f2c 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/model/VaultFactory.java +++ b/main/ui/src/main/java/org/cryptomator/ui/model/VaultFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Sebastian Stenzel and others. + * Copyright (c) 2016, 2017 Sebastian Stenzel and others. * This file is licensed under the terms of the MIT license. * See the LICENSE.txt file for more info. * diff --git a/main/ui/src/main/java/org/cryptomator/ui/util/AsyncTaskService.java b/main/ui/src/main/java/org/cryptomator/ui/util/AsyncTaskService.java index 8eaf198d5..391d3ae77 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/util/AsyncTaskService.java +++ b/main/ui/src/main/java/org/cryptomator/ui/util/AsyncTaskService.java @@ -49,7 +49,7 @@ public class AsyncTaskService { private ConsumerThrowingException successHandler = value -> { }; - private List> errorHandlers = new ArrayList<>(); + private final List> errorHandlers = new ArrayList<>(); private RunnableThrowingException finallyHandler = () -> { }; diff --git a/main/ui/src/main/java/org/cryptomator/ui/util/DeferredClosable.java b/main/ui/src/main/java/org/cryptomator/ui/util/DeferredClosable.java deleted file mode 100644 index fa8c415ab..000000000 --- a/main/ui/src/main/java/org/cryptomator/ui/util/DeferredClosable.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014, 2016 cryptomator.org - * This file is licensed under the terms of the MIT license. - * See the LICENSE.txt file for more info. - * - * Contributors: - * Tillmann Gaida - initial implementation - ******************************************************************************/ -package org.cryptomator.ui.util; - -import java.util.Optional; - -/** - * Wrapper around an object, which should be closed later - explicitly or by a - * {@link DeferredCloser}. The wrapped object can be accessed as long as the - * resource has not been closed. - * - * @author Tillmann Gaida - * - * @param - * any type - */ -public interface DeferredClosable extends AutoCloseable { - /** - * Returns the wrapped Object. - * - * @return empty if the object has been closed. - */ - public Optional get(); - - /** - * @return an empty object. - */ - public static DeferredClosable empty() { - return DeferredCloser.empty(); - } -} \ No newline at end of file diff --git a/main/ui/src/main/java/org/cryptomator/ui/util/DeferredCloser.java b/main/ui/src/main/java/org/cryptomator/ui/util/DeferredCloser.java deleted file mode 100644 index f2de9324f..000000000 --- a/main/ui/src/main/java/org/cryptomator/ui/util/DeferredCloser.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014, 2016 cryptomator.org - * This file is licensed under the terms of the MIT license. - * See the LICENSE.txt file for more info. - * - * Contributors: - * Tillmann Gaida - initial implementation - ******************************************************************************/ -package org.cryptomator.ui.util; - -import java.util.Iterator; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.concurrent.ConcurrentSkipListMap; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.atomic.AtomicLong; - -import org.cryptomator.common.ConsumerThrowingException; - -import com.google.common.annotations.VisibleForTesting; - -/** - *

- * Tries to bring open-close symmetry in contexts where the resource outlives - * the current scope by introducing a manager, which closes the resources if - * they haven't been closed before. - *

- * - *

- * If you have a {@link DeferredCloser} instance present, call - * {@link #closeLater(Object, ConsumerThrowingException)} immediately after you have opened the - * resource and return a resource handle. If {@link #close()} is called, the - * resource will be closed. Calling {@link DeferredClosable#close()} on the resource - * handle will also close the resource and prevent a second closing by - * {@link #close()}. - *

- * - * @author Tillmann Gaida - */ -public class DeferredCloser implements AutoCloseable { - - @VisibleForTesting - final Map> cleanups = new ConcurrentSkipListMap<>(); - - @VisibleForTesting - final AtomicLong counter = new AtomicLong(); - - private class ManagedResource implements DeferredClosable { - - private final long number = counter.incrementAndGet(); - private final T object; - private final ConsumerThrowingException closer; - private boolean closed = false; - - public ManagedResource(T object, ConsumerThrowingException closer) { - super(); - this.object = Objects.requireNonNull(object); - this.closer = Objects.requireNonNull(closer); - } - - @Override - public synchronized void close() throws Exception { - closer.accept(object); - cleanups.remove(number); - closed = true; - } - - @Override - public Optional get() throws IllegalStateException { - if (closed) { - return Optional.empty(); - } else { - return Optional.of(object); - } - } - } - - /** - * Closes all added objects which have not been closed before and releases references. - */ - @Override - public void close() throws ExecutionException { - ExecutionException exception = null; - for (Iterator> iterator = cleanups.values().iterator(); iterator.hasNext();) { - final ManagedResource closableProvider = iterator.next(); - try { - closableProvider.close(); - iterator.remove(); - } catch (Exception e) { - if (exception == null) { - exception = new ExecutionException(e); - } else { - exception.addSuppressed(e); - } - } - } - if (exception != null) { - throw exception; - } - } - - public DeferredClosable closeLater(T object, ConsumerThrowingException closer) { - Objects.requireNonNull(object); - Objects.requireNonNull(closer); - final ManagedResource resource = new ManagedResource(object, closer); - cleanups.put(resource.number, resource); - return resource; - } - - public DeferredClosable closeLater(T object) { - Objects.requireNonNull(object); - final ManagedResource resource = new ManagedResource(object, AutoCloseable::close); - cleanups.put(resource.number, resource); - return resource; - } - - private static final EmptyResource EMPTY_RESOURCE = new EmptyResource<>(); - - @SuppressWarnings("unchecked") - public static DeferredClosable empty() { - return (DeferredClosable) EMPTY_RESOURCE; - } - - static class EmptyResource implements DeferredClosable { - @Override - public Optional get() { - return Optional.empty(); - } - - @Override - public void close() { - - } - } -} diff --git a/main/ui/src/main/java/org/cryptomator/ui/util/DialogBuilderUtil.java b/main/ui/src/main/java/org/cryptomator/ui/util/DialogBuilderUtil.java index 55f6539a7..11943d1a8 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/util/DialogBuilderUtil.java +++ b/main/ui/src/main/java/org/cryptomator/ui/util/DialogBuilderUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Sebastian Stenzel and others. + * Copyright (c) 2016, 2017 Sebastian Stenzel and others. * This file is licensed under the terms of the MIT license. * See the LICENSE.txt file for more info. * diff --git a/main/ui/src/main/java/org/cryptomator/ui/util/PasswordStrengthUtil.java b/main/ui/src/main/java/org/cryptomator/ui/util/PasswordStrengthUtil.java index 300cee4e1..17f1f54f8 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/util/PasswordStrengthUtil.java +++ b/main/ui/src/main/java/org/cryptomator/ui/util/PasswordStrengthUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Sebastian Stenzel and others. + * Copyright (c) 2016, 2017 Sebastian Stenzel and others. * This file is licensed under the terms of the MIT license. * See the LICENSE.txt file for more info. * @@ -15,7 +15,7 @@ import javax.inject.Inject; import javax.inject.Singleton; import org.apache.commons.lang3.StringUtils; -import org.cryptomator.ui.settings.Localization; +import org.cryptomator.ui.l10n.Localization; import com.nulabinc.zxcvbn.Zxcvbn; diff --git a/main/ui/src/test/java/org/cryptomator/ui/settings/LocalizationTest.java b/main/ui/src/test/java/org/cryptomator/ui/l10n/LocalizationTest.java similarity index 97% rename from main/ui/src/test/java/org/cryptomator/ui/settings/LocalizationTest.java rename to main/ui/src/test/java/org/cryptomator/ui/l10n/LocalizationTest.java index 18f721d3a..b19fa1dfa 100644 --- a/main/ui/src/test/java/org/cryptomator/ui/settings/LocalizationTest.java +++ b/main/ui/src/test/java/org/cryptomator/ui/l10n/LocalizationTest.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2016 Sebastian Stenzel and others. + * Copyright (c) 2016, 2017 Sebastian Stenzel and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the accompanying LICENSE.txt. * * Contributors: * Sebastian Stenzel - initial API and implementation *******************************************************************************/ -package org.cryptomator.ui.settings; +package org.cryptomator.ui.l10n; import java.io.IOException; import java.io.InputStream; diff --git a/main/ui/src/test/java/org/cryptomator/ui/util/DeferredCloserTest.java b/main/ui/src/test/java/org/cryptomator/ui/util/DeferredCloserTest.java deleted file mode 100644 index aa3be4bef..000000000 --- a/main/ui/src/test/java/org/cryptomator/ui/util/DeferredCloserTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Sebastian Stenzel and others. - * This file is licensed under the terms of the MIT license. - * See the LICENSE.txt file for more info. - * - * Contributors: - * Sebastian Stenzel - initial API and implementation - *******************************************************************************/ -package org.cryptomator.ui.util; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; - -import java.io.Closeable; - -import org.junit.Test; - -public class DeferredCloserTest { - @Test - public void testBasicFunctionality() throws Exception { - DeferredCloser closer = new DeferredCloser(); - - final Closeable obj = mock(Closeable.class); - - final DeferredClosable resource = closer.closeLater(obj); - - assertTrue(resource.get().isPresent()); - assertTrue(resource.get().get() == obj); - - closer.close(); - - assertFalse(resource.get().isPresent()); - verify(obj).close(); - } - - @Test - public void testAutoremoval() throws Exception { - DeferredCloser closer = new DeferredCloser(); - - final DeferredClosable resource = closer.closeLater(mock(Closeable.class)); - final DeferredClosable resource2 = closer.closeLater(mock(Closeable.class)); - - resource.close(); - - assertFalse(resource.get().isPresent()); - assertEquals(1, closer.cleanups.size()); - - assertTrue(resource2.get().isPresent()); - - closer.close(); - - assertFalse(resource2.get().isPresent()); - - assertEquals(0, closer.cleanups.size()); - } -}