Remove URI support for stores

This commit is contained in:
Christopher Schnick 2022-08-13 15:00:19 +02:00
parent 81d087fa9b
commit 775a046e66
3 changed files with 11 additions and 21 deletions

View file

@ -1,10 +1,12 @@
package io.xpipe.extension; package io.xpipe.extension;
import io.xpipe.core.dialog.Dialog; import io.xpipe.core.dialog.Dialog;
import io.xpipe.core.store.*; import io.xpipe.core.store.DataStore;
import io.xpipe.core.store.MachineFileStore;
import io.xpipe.core.store.ShellStore;
import io.xpipe.core.store.StreamDataStore;
import javafx.beans.property.Property; import javafx.beans.property.Property;
import java.net.URI;
import java.util.List; import java.util.List;
public interface DataStoreProvider { public interface DataStoreProvider {
@ -74,10 +76,6 @@ public interface DataStoreProvider {
return null; return null;
} }
default Dialog dialogForURI(URI uri) {
return null;
}
default Dialog defaultDialog() { default Dialog defaultDialog() {
throw new ExtensionException("CLI Dialog not implemented by provider"); throw new ExtensionException("CLI Dialog not implemented by provider");
} }

View file

@ -4,7 +4,6 @@ import io.xpipe.core.dialog.Dialog;
import io.xpipe.core.store.DataStore; import io.xpipe.core.store.DataStore;
import io.xpipe.extension.event.ErrorEvent; import io.xpipe.extension.event.ErrorEvent;
import java.net.URI;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.ServiceLoader; import java.util.ServiceLoader;
@ -19,11 +18,12 @@ public class DataStoreProviders {
if (ALL == null) { if (ALL == null) {
ALL = ServiceLoader.load(layer, DataStoreProvider.class).stream() ALL = ServiceLoader.load(layer, DataStoreProvider.class).stream()
.map(ServiceLoader.Provider::get).collect(Collectors.toSet()); .map(ServiceLoader.Provider::get).collect(Collectors.toSet());
ALL.forEach(p -> { ALL.removeIf(p -> {
try { try {
p.init(); return !p.init();
} catch (Exception e) { } catch (Exception e) {
ErrorEvent.fromThrowable(e).handle(); ErrorEvent.fromThrowable(e).handle();
return true;
} }
}); });
} }
@ -38,13 +38,6 @@ public class DataStoreProviders {
.anyMatch(s -> s.equalsIgnoreCase(name))).findAny(); .anyMatch(s -> s.equalsIgnoreCase(name))).findAny();
} }
public static Optional<Dialog> byURI(URI uri) {
if (ALL == null) {
throw new IllegalStateException("Not initialized");
}
return ALL.stream().map(d -> d.dialogForURI(uri)).filter(Objects::nonNull).findAny();
}
public static Optional<Dialog> byString(String s) { public static Optional<Dialog> byString(String s) {
if (ALL == null) { if (ALL == null) {
@ -56,17 +49,16 @@ public class DataStoreProviders {
public static <T extends DataStoreProvider> T byStore(DataStore store) { public static <T extends DataStoreProvider> T byStore(DataStore store) {
return byStoreClass(store.getClass()); return (T) byStoreClass(store.getClass()).orElseThrow(() -> new IllegalArgumentException("Provider for " + store.getClass().getSimpleName() + " not found"));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T extends DataStoreProvider> T byStoreClass(Class<?> c) { public static <T extends DataStoreProvider> Optional<T> byStoreClass(Class<?> c) {
if (ALL == null) { if (ALL == null) {
throw new IllegalStateException("Not initialized"); throw new IllegalStateException("Not initialized");
} }
return (T) ALL.stream().filter(d -> d.getStoreClasses().contains(c)).findAny() return (Optional<T>) ALL.stream().filter(d -> d.getStoreClasses().contains(c)).findAny();
.orElseThrow(() -> new IllegalArgumentException("Provider for " + c.getSimpleName() + " not found"));
} }
public static Set<DataStoreProvider> getAll() { public static Set<DataStoreProvider> getAll() {

View file

@ -1 +1 @@
0.0.1.3 0.0.1.4-SNAPSHOT