From 55da767dabb312ad1339d4ae264b7f26e96c7dce Mon Sep 17 00:00:00 2001 From: Christopher Schnick Date: Sat, 15 Oct 2022 16:06:02 +0200 Subject: [PATCH] Refactor --- .../main/java/io/xpipe/api/DataSource.java | 10 +- .../main/java/io/xpipe/api/DataStores.java | 4 +- .../xpipe/api/connector/XPipeConnection.java | 72 +++---- .../java/io/xpipe/api/impl/DataRawImpl.java | 10 +- .../io/xpipe/api/impl/DataSourceImpl.java | 76 ++++---- .../io/xpipe/api/impl/DataStructureImpl.java | 10 +- .../api/impl/DataTableAccumulatorImpl.java | 10 +- .../java/io/xpipe/api/impl/DataTableImpl.java | 33 ++-- .../java/io/xpipe/api/impl/DataTextImpl.java | 15 +- .../io/xpipe/api/util/QuietDialogHandler.java | 11 +- .../io/xpipe/api/util/TypeDescriptor.java | 5 +- api/src/main/java/module-info.java | 2 +- .../api/test/DataTableAccumulatorTest.java | 8 +- .../java/io/xpipe/api/test/DataTableTest.java | 3 +- api/src/test/java/module-info.java | 2 +- .../java/io/xpipe/beacon/BeaconClient.java | 61 +++--- .../java/io/xpipe/beacon/BeaconConfig.java | 29 +-- .../io/xpipe/beacon/BeaconConnection.java | 21 +- .../java/io/xpipe/beacon/BeaconException.java | 3 +- .../java/io/xpipe/beacon/BeaconServer.java | 75 ++++---- .../java/io/xpipe/beacon/ClientException.java | 3 +- .../io/xpipe/beacon/ConnectorException.java | 3 +- .../java/io/xpipe/beacon/RequestMessage.java | 4 +- .../java/io/xpipe/beacon/ResponseMessage.java | 4 +- .../java/io/xpipe/beacon/ServerException.java | 3 +- .../beacon/exchange/AddSourceExchange.java | 4 +- .../beacon/exchange/ForwardExchange.java | 3 +- .../beacon/exchange/MessageExchanges.java | 11 +- .../exchange/QueryDataSourceExchange.java | 4 + .../beacon/exchange/ReadExecuteExchange.java | 3 +- .../xpipe/beacon/exchange/StopExchange.java | 3 +- .../beacon/exchange/StoreStreamExchange.java | 3 +- .../exchange/api/QueryRawDataExchange.java | 5 +- .../exchange/api/QueryTableDataExchange.java | 5 +- .../exchange/api/QueryTextDataExchange.java | 5 +- .../beacon/exchange/cli/ConvertExchange.java | 2 +- .../beacon/exchange/cli/DialogExchange.java | 3 +- .../exchange/cli/EditStoreExchange.java | 3 +- .../beacon/exchange/cli/InstanceExchange.java | 4 +- .../exchange/cli/ListCollectionsExchange.java | 8 +- .../exchange/cli/ListEntriesExchange.java | 4 +- .../exchange/cli/ListStoresExchange.java | 8 +- .../beacon/exchange/cli/ModeExchange.java | 6 +- .../cli/RemoveCollectionExchange.java | 5 +- .../exchange/cli/RemoveEntryExchange.java | 2 +- .../exchange/cli/RemoveStoreExchange.java | 5 +- .../cli/RenameCollectionExchange.java | 6 +- .../exchange/cli/RenameEntryExchange.java | 5 +- .../exchange/cli/RenameStoreExchange.java | 6 +- .../beacon/exchange/cli/SelectExchange.java | 5 +- .../cli/SourceProviderListExchange.java | 10 +- .../beacon/exchange/cli/StatusExchange.java | 5 +- .../beacon/exchange/cli/StoreAddExchange.java | 2 +- .../cli/StoreProviderListExchange.java | 6 +- .../beacon/exchange/cli/VersionExchange.java | 6 +- .../exchange/cli/WriteExecuteExchange.java | 5 +- .../cli/WritePreparationExchange.java | 2 + beacon/src/main/java/module-info.java | 7 +- core/build.gradle | 2 +- .../io/xpipe/core/charsetter/Charsetter.java | 91 ++++----- .../core/charsetter/CharsetterContext.java | 12 +- .../io/xpipe/core/charsetter/NewLine.java | 27 +-- .../xpipe/core/charsetter/StreamCharset.java | 91 ++++----- .../core/data/generic/GenericArrayReader.java | 6 +- .../generic/GenericDataStreamCallback.java | 19 +- .../GenericDataStructureNodeReader.java | 1 - .../core/data/generic/GenericTupleReader.java | 4 +- .../io/xpipe/core/data/node/ArrayNode.java | 11 +- .../core/data/node/DataStructureNode.java | 23 +-- .../data/node/DataStructureNodePointer.java | 8 +- .../xpipe/core/data/node/LinkedTupleNode.java | 8 +- .../xpipe/core/data/node/SimpleArrayNode.java | 4 - .../xpipe/core/data/node/SimpleValueNode.java | 7 +- .../io/xpipe/core/data/node/TupleNode.java | 32 +-- .../io/xpipe/core/data/node/ValueNode.java | 53 +++-- .../xpipe/core/data/type/DataTypeVisitor.java | 12 +- .../core/data/type/DataTypeVisitors.java | 4 +- .../io/xpipe/core/data/type/WildcardType.java | 4 +- .../data/typed/TypedDataStreamCallback.java | 24 +-- .../data/typed/TypedDataStreamParser.java | 9 +- .../typed/TypedDataStructureNodeReader.java | 18 +- .../xpipe/core/dialog/BaseQueryElement.java | 3 +- .../io/xpipe/core/dialog/ChoiceElement.java | 27 +-- .../java/io/xpipe/core/dialog/Dialog.java | 182 ++++++++++-------- .../core/dialog/DialogCancelException.java | 6 +- .../io/xpipe/core/dialog/QueryConverter.java | 40 ++-- .../io/xpipe/core/dialog/QueryElement.java | 9 +- .../core/impl/BatchTableWriteConnection.java | 2 - .../java/io/xpipe/core/impl/BinarySource.java | 1 - .../core/impl/LimitTableReadConnection.java | 3 +- .../impl/PreservingTableWriteConnection.java | 6 +- .../impl/PreservingTextWriteConnection.java | 5 +- .../core/impl/PreservingWriteConnection.java | 12 +- .../xpipe/core/impl/TextReadConnection.java | 1 - .../java/io/xpipe/core/impl/TextSource.java | 2 +- .../xpipe/core/impl/XpbsWriteConnection.java | 2 +- .../xpipe/core/impl/XpbtReadConnection.java | 23 ++- .../java/io/xpipe/core/impl/XpbtSource.java | 2 - .../xpipe/core/impl/XpbtWriteConnection.java | 3 +- .../core/source/CollectionReadConnection.java | 6 +- .../java/io/xpipe/core/source/DataSource.java | 21 +- .../io/xpipe/core/source/DataSourceId.java | 6 +- .../io/xpipe/core/source/DataSourceInfo.java | 111 ++++++----- .../core/source/DataSourceReference.java | 14 +- .../io/xpipe/core/source/DataSourceType.java | 1 - .../xpipe/core/source/RawReadConnection.java | 4 +- .../core/source/StreamReadConnection.java | 4 +- .../core/source/StreamWriteConnection.java | 5 +- .../core/source/TableReadConnection.java | 3 +- .../core/source/TableWriteConnection.java | 2 +- .../io/xpipe/core/source/TextDataSource.java | 5 - .../xpipe/core/source/TextReadConnection.java | 6 +- .../java/io/xpipe/core/source/WriteMode.java | 9 +- .../core/store/CollectionEntryDataStore.java | 1 - .../java/io/xpipe/core/store/DataFlow.java | 1 - .../java/io/xpipe/core/store/DataStore.java | 8 +- .../xpipe/core/store/DataStoreFormatter.java | 1 - .../java/io/xpipe/core/store/FileStore.java | 18 +- .../io/xpipe/core/store/FilenameStore.java | 3 +- .../io/xpipe/core/store/InMemoryStore.java | 3 +- .../core/store/LocalDirectoryDataStore.java | 1 - .../java/io/xpipe/core/store/LocalStore.java | 105 +++++----- .../io/xpipe/core/store/ProcessControl.java | 1 + .../core/store/ProcessOutputException.java | 5 +- .../java/io/xpipe/core/store/ShellStore.java | 3 +- .../java/io/xpipe/core/store/ShellTypes.java | 28 ++- .../xpipe/core/store/StandardShellStore.java | 91 +++++---- .../io/xpipe/core/store/StdinDataStore.java | 3 +- .../io/xpipe/core/store/StdoutDataStore.java | 3 +- .../io/xpipe/core/store/StreamDataStore.java | 1 - .../io/xpipe/core/store/URLDataStore.java | 1 - .../io/xpipe/core/util/CoreJacksonModule.java | 34 ++-- .../io/xpipe/core/util/JacksonMapper.java | 20 +- .../io/xpipe/core/util/JacksonizedValue.java | 4 +- .../java/io/xpipe/core/util/SecretValue.java | 4 +- core/src/main/java/module-info.java | 6 +- .../io/xpipe/core/test/DataSourceIdTest.java | 1 - .../xpipe/core/test/DataStructureTests.java | 72 ++++--- core/src/test/java/module-info.java | 2 +- extension/README.md | 1 + extension/publish.gradle | 1 - .../main/java/io/xpipe/extension/Cache.java | 8 +- .../xpipe/extension/DataSourceProvider.java | 32 ++- .../xpipe/extension/DataSourceProviders.java | 85 ++++---- .../io/xpipe/extension/DataStoreProvider.java | 18 +- .../xpipe/extension/DataStoreProviders.java | 33 ++-- .../xpipe/extension/ExtensionException.java | 3 +- .../main/java/io/xpipe/extension/I18n.java | 1 - .../SupportedApplicationProvider.java | 52 +++-- .../SupportedApplicationProviders.java | 3 +- .../xpipe/extension/comp/CharChoiceComp.java | 5 +- .../extension/comp/CharsetChoiceComp.java | 13 +- .../io/xpipe/extension/comp/ChoiceComp.java | 6 +- .../xpipe/extension/comp/ChoicePaneComp.java | 11 +- .../io/xpipe/extension/comp/CodeSnippet.java | 34 ++-- .../xpipe/extension/comp/CodeSnippetComp.java | 12 +- .../comp/DataStoreFlowChoiceComp.java | 15 +- .../extension/comp/DynamicOptionsComp.java | 42 ++-- .../extension/comp/FancyTooltipAugment.java | 7 +- .../io/xpipe/extension/comp/FilterComp.java | 46 +++-- .../io/xpipe/extension/comp/IntFieldComp.java | 5 +- .../extension/comp/MultiVariantComp.java | 3 +- .../java/io/xpipe/extension/comp/SvgComp.java | 49 +++-- .../io/xpipe/extension/comp/TabPaneComp.java | 23 +-- .../xpipe/extension/comp/TextFieldComp.java | 1 - .../xpipe/extension/comp/ToggleGroupComp.java | 3 +- .../extension/comp/WriteModeChoiceComp.java | 37 ++-- .../io/xpipe/extension/event/ErrorEvent.java | 81 ++++---- .../extension/event/ExceptionConverter.java | 1 - .../io/xpipe/extension/event/TrackEvent.java | 69 +++---- .../xpipe/extension/prefs/PrefsHandler.java | 2 +- .../xpipe/extension/prefs/PrefsProviders.java | 3 +- .../extension/util/ChainedValidator.java | 20 +- .../extension/util/CustomComboBoxBuilder.java | 40 ++-- .../io/xpipe/extension/util/DialogHelper.java | 50 ++--- .../extension/util/DynamicOptionsBuilder.java | 37 ++-- .../extension/util/ExclusiveValidator.java | 11 +- .../xpipe/extension/util/ExtensionTest.java | 1 - .../xpipe/extension/util/NamedCharacter.java | 26 ++- .../xpipe/extension/util/PrettyListView.java | 136 +++++++------ .../extension/util/PropertiesHelper.java | 5 +- .../util/SimpleFileDataSourceProvider.java | 6 +- .../xpipe/extension/util/SimpleValidator.java | 30 +-- .../util/UniformDataSourceProvider.java | 1 - .../io/xpipe/extension/util/XPipeDaemon.java | 23 ++- extension/src/main/java/module-info.java | 2 +- 186 files changed, 1541 insertions(+), 1606 deletions(-) diff --git a/api/src/main/java/io/xpipe/api/DataSource.java b/api/src/main/java/io/xpipe/api/DataSource.java index 18c2fa0ce..4ba595956 100644 --- a/api/src/main/java/io/xpipe/api/DataSource.java +++ b/api/src/main/java/io/xpipe/api/DataSource.java @@ -27,10 +27,6 @@ import java.nio.file.Path; */ public interface DataSource { - void forwardTo(DataSource target); - - void appendTo(DataSource target); - /** * NOT YET IMPLEMENTED! * @@ -126,7 +122,6 @@ public interface DataSource { } } - /** * Wrapper for {@link #create(DataSourceId, String, InputStream)} that creates an anonymous data source. */ @@ -168,6 +163,10 @@ public interface DataSource { return DataSourceImpl.create(id, type, in); } + void forwardTo(DataSource target); + + void appendTo(DataSource target); + public io.xpipe.core.source.DataSource getInternalSource(); /** @@ -180,7 +179,6 @@ public interface DataSource { */ DataSourceType getType(); - DataSourceConfig getConfig(); /** diff --git a/api/src/main/java/io/xpipe/api/DataStores.java b/api/src/main/java/io/xpipe/api/DataStores.java index e55336733..4f1e353eb 100644 --- a/api/src/main/java/io/xpipe/api/DataStores.java +++ b/api/src/main/java/io/xpipe/api/DataStores.java @@ -12,7 +12,9 @@ public class DataStores { public static void addNamedStore(DataStore store, String name) { XPipeConnection.execute(con -> { var req = StoreAddExchange.Request.builder() - .storeInput(store).name(name).build(); + .storeInput(store) + .name(name) + .build(); StoreAddExchange.Response res = con.performSimpleExchange(req); new QuietDialogHandler(res.getConfig(), con, Map.of()).handle(); diff --git a/api/src/main/java/io/xpipe/api/connector/XPipeConnection.java b/api/src/main/java/io/xpipe/api/connector/XPipeConnection.java index 5009d8211..c24dddbf7 100644 --- a/api/src/main/java/io/xpipe/api/connector/XPipeConnection.java +++ b/api/src/main/java/io/xpipe/api/connector/XPipeConnection.java @@ -8,6 +8,8 @@ import java.util.Optional; public final class XPipeConnection extends BeaconConnection { + private XPipeConnection() {} + public static XPipeConnection open() { var con = new XPipeConnection(); con.constructSocket(); @@ -23,7 +25,9 @@ public final class XPipeConnection extends BeaconConnection { throw new IllegalStateException(); } - DialogExchange.Response response = con.performSimpleExchange(DialogExchange.Request.builder().dialogKey(reference.getDialogId()).build()); + DialogExchange.Response response = con.performSimpleExchange(DialogExchange.Request.builder() + .dialogKey(reference.getDialogId()) + .build()); element = response.getElement(); if (response.getElement() == null) { break; @@ -58,40 +62,6 @@ public final class XPipeConnection extends BeaconConnection { } } - private XPipeConnection() { - } - - @Override - protected void constructSocket() { - if (!BeaconServer.isRunning()) { - try { - start(); - } catch (Exception ex) { - throw new BeaconException("Unable to start xpipe daemon", ex); - } - - var r = waitForStartup(null); - if (r.isEmpty()) { - throw new BeaconException("Wait for xpipe daemon timed out"); - } else { - beaconClient = r.get(); - return; - } - } - - try { - beaconClient = new BeaconClient(); - } catch (Exception ex) { - throw new BeaconException("Unable to connect to running xpipe daemon", ex); - } - } - - private void start() throws Exception { - if (BeaconServer.tryStart() == null) { - throw new UnsupportedOperationException("Unable to determine xpipe daemon launch command"); - }; - } - public static Optional waitForStartup(Process process) { for (int i = 0; i < 160; i++) { if (process != null && !process.isAlive()) { @@ -125,6 +95,38 @@ public final class XPipeConnection extends BeaconConnection { } } + @Override + protected void constructSocket() { + if (!BeaconServer.isRunning()) { + try { + start(); + } catch (Exception ex) { + throw new BeaconException("Unable to start xpipe daemon", ex); + } + + var r = waitForStartup(null); + if (r.isEmpty()) { + throw new BeaconException("Wait for xpipe daemon timed out"); + } else { + beaconClient = r.get(); + return; + } + } + + try { + beaconClient = new BeaconClient(); + } catch (Exception ex) { + throw new BeaconException("Unable to connect to running xpipe daemon", ex); + } + } + + private void start() throws Exception { + if (BeaconServer.tryStart() == null) { + throw new UnsupportedOperationException("Unable to determine xpipe daemon launch command"); + } + ; + } + @FunctionalInterface public static interface Handler { diff --git a/api/src/main/java/io/xpipe/api/impl/DataRawImpl.java b/api/src/main/java/io/xpipe/api/impl/DataRawImpl.java index 23ce61ec0..be07fc394 100644 --- a/api/src/main/java/io/xpipe/api/impl/DataRawImpl.java +++ b/api/src/main/java/io/xpipe/api/impl/DataRawImpl.java @@ -2,7 +2,9 @@ package io.xpipe.api.impl; import io.xpipe.api.DataRaw; import io.xpipe.api.DataSourceConfig; -import io.xpipe.core.source.*; +import io.xpipe.core.source.DataSourceId; +import io.xpipe.core.source.DataSourceInfo; +import io.xpipe.core.source.DataSourceType; import java.io.InputStream; @@ -10,7 +12,11 @@ public class DataRawImpl extends DataSourceImpl implements DataRaw { private final DataSourceInfo.Raw info; - public DataRawImpl(DataSourceId sourceId, DataSourceConfig sourceConfig, DataSourceInfo.Raw info, io.xpipe.core.source.DataSource internalSource) { + public DataRawImpl( + DataSourceId sourceId, + DataSourceConfig sourceConfig, + DataSourceInfo.Raw info, + io.xpipe.core.source.DataSource internalSource) { super(sourceId, sourceConfig, internalSource); this.info = info; } diff --git a/api/src/main/java/io/xpipe/api/impl/DataSourceImpl.java b/api/src/main/java/io/xpipe/api/impl/DataSourceImpl.java index 408c378bc..265f318c5 100644 --- a/api/src/main/java/io/xpipe/api/impl/DataSourceImpl.java +++ b/api/src/main/java/io/xpipe/api/impl/DataSourceImpl.java @@ -13,28 +13,15 @@ import java.io.InputStream; public abstract class DataSourceImpl implements DataSource { - @Override - public void forwardTo(DataSource target) { - XPipeConnection.execute(con -> { - var req = ForwardExchange.Request.builder() - .source(DataSourceReference.id(sourceId)) - .target(DataSourceReference.id(target.getId())) - .build(); - ForwardExchange.Response res = con.performSimpleExchange(req); - }); - } - - @Override - public void appendTo(DataSource target) { - XPipeConnection.execute(con -> { - var req = ForwardExchange.Request.builder() - .source(DataSourceReference.id(sourceId)) - .target(DataSourceReference.id(target.getId())) - .append(true) - .build(); - ForwardExchange.Response res = con.performSimpleExchange(req); - }); + private final DataSourceId sourceId; + private final DataSourceConfig config; + private final io.xpipe.core.source.DataSource internalSource; + public DataSourceImpl( + DataSourceId sourceId, DataSourceConfig config, io.xpipe.core.source.DataSource internalSource) { + this.sourceId = sourceId; + this.config = config; + this.internalSource = internalSource; } public static DataSource get(DataSourceReference ds) { @@ -59,17 +46,17 @@ public abstract class DataSourceImpl implements DataSource { var info = res.getInfo().asRaw(); yield new DataRawImpl(res.getId(), config, info, res.getInternalSource()); } - case COLLECTION -> throw new UnsupportedOperationException("Unimplemented case: " + res.getInfo().getType()); - default -> throw new IllegalArgumentException("Unexpected value: " + res.getInfo().getType()); + case COLLECTION -> throw new UnsupportedOperationException( + "Unimplemented case: " + res.getInfo().getType()); + default -> throw new IllegalArgumentException( + "Unexpected value: " + res.getInfo().getType()); }; }); } public static DataSource create(DataSourceId id, io.xpipe.core.source.DataSource source) { - var startReq = AddSourceExchange.Request.builder() - .source(source) - .target(id) - .build(); + var startReq = + AddSourceExchange.Request.builder().source(source).target(id).build(); var returnedId = XPipeConnection.execute(con -> { AddSourceExchange.Response r = con.performSimpleExchange(startReq); return r.getId(); @@ -108,9 +95,7 @@ public abstract class DataSourceImpl implements DataSource { var configInstance = startRes.getConfig(); XPipeConnection.finishDialog(configInstance); - var ref = id != null ? - DataSourceReference.id(id) : - DataSourceReference.latest(); + var ref = id != null ? DataSourceReference.id(id) : DataSourceReference.latest(); return get(ref); } @@ -137,20 +122,31 @@ public abstract class DataSourceImpl implements DataSource { var configInstance = startRes.getConfig(); XPipeConnection.finishDialog(configInstance); - var ref = id != null ? - DataSourceReference.id(id) : - DataSourceReference.latest(); + var ref = id != null ? DataSourceReference.id(id) : DataSourceReference.latest(); return get(ref); } - private final DataSourceId sourceId; - private final DataSourceConfig config; - private final io.xpipe.core.source.DataSource internalSource; + @Override + public void forwardTo(DataSource target) { + XPipeConnection.execute(con -> { + var req = ForwardExchange.Request.builder() + .source(DataSourceReference.id(sourceId)) + .target(DataSourceReference.id(target.getId())) + .build(); + ForwardExchange.Response res = con.performSimpleExchange(req); + }); + } - public DataSourceImpl(DataSourceId sourceId, DataSourceConfig config, io.xpipe.core.source.DataSource internalSource) { - this.sourceId = sourceId; - this.config = config; - this.internalSource = internalSource; + @Override + public void appendTo(DataSource target) { + XPipeConnection.execute(con -> { + var req = ForwardExchange.Request.builder() + .source(DataSourceReference.id(sourceId)) + .target(DataSourceReference.id(target.getId())) + .append(true) + .build(); + ForwardExchange.Response res = con.performSimpleExchange(req); + }); } public io.xpipe.core.source.DataSource getInternalSource() { diff --git a/api/src/main/java/io/xpipe/api/impl/DataStructureImpl.java b/api/src/main/java/io/xpipe/api/impl/DataStructureImpl.java index 0f8cee40d..2f6202a03 100644 --- a/api/src/main/java/io/xpipe/api/impl/DataStructureImpl.java +++ b/api/src/main/java/io/xpipe/api/impl/DataStructureImpl.java @@ -3,13 +3,19 @@ package io.xpipe.api.impl; import io.xpipe.api.DataSourceConfig; import io.xpipe.api.DataStructure; import io.xpipe.core.data.node.DataStructureNode; -import io.xpipe.core.source.*; +import io.xpipe.core.source.DataSourceId; +import io.xpipe.core.source.DataSourceInfo; +import io.xpipe.core.source.DataSourceType; public class DataStructureImpl extends DataSourceImpl implements DataStructure { private final DataSourceInfo.Structure info; - public DataStructureImpl(DataSourceId sourceId, DataSourceConfig sourceConfig, DataSourceInfo.Structure info, io.xpipe.core.source.DataSource internalSource) { + public DataStructureImpl( + DataSourceId sourceId, + DataSourceConfig sourceConfig, + DataSourceInfo.Structure info, + io.xpipe.core.source.DataSource internalSource) { super(sourceId, sourceConfig, internalSource); this.info = info; } diff --git a/api/src/main/java/io/xpipe/api/impl/DataTableAccumulatorImpl.java b/api/src/main/java/io/xpipe/api/impl/DataTableAccumulatorImpl.java index 4b427ba9b..76fe54500 100644 --- a/api/src/main/java/io/xpipe/api/impl/DataTableAccumulatorImpl.java +++ b/api/src/main/java/io/xpipe/api/impl/DataTableAccumulatorImpl.java @@ -47,7 +47,11 @@ public class DataTableAccumulatorImpl implements DataTableAccumulator { connection.close(); var req = ReadExchange.Request.builder() - .target(id).store(res.getStore()).provider("xpbt").configureAll(false).build(); + .target(id) + .store(res.getStore()) + .provider("xpbt") + .configureAll(false) + .build(); ReadExchange.Response response = XPipeConnection.execute(con -> { return con.performSimpleExchange(req); }); @@ -71,7 +75,9 @@ public class DataTableAccumulatorImpl implements DataTableAccumulator { @Override public synchronized void add(DataStructureNode row) { - TupleNode toUse = type.matches(row) ? row.asTuple() : type.convert(row).orElseThrow().asTuple(); + TupleNode toUse = type.matches(row) + ? row.asTuple() + : type.convert(row).orElseThrow().asTuple(); connection.withOutputStream(out -> { writeDescriptor(); TypedDataStreamWriter.writeStructure(out, toUse, writtenDescriptor); diff --git a/api/src/main/java/io/xpipe/api/impl/DataTableImpl.java b/api/src/main/java/io/xpipe/api/impl/DataTableImpl.java index 30be11139..ad088c7a3 100644 --- a/api/src/main/java/io/xpipe/api/impl/DataTableImpl.java +++ b/api/src/main/java/io/xpipe/api/impl/DataTableImpl.java @@ -27,7 +27,11 @@ public class DataTableImpl extends DataSourceImpl implements DataTable { private final DataSourceInfo.Table info; - DataTableImpl(DataSourceId id, DataSourceConfig sourceConfig, DataSourceInfo.Table info, io.xpipe.core.source.DataSource internalSource) { + DataTableImpl( + DataSourceId id, + DataSourceConfig sourceConfig, + DataSourceInfo.Table info, + io.xpipe.core.source.DataSource internalSource) { super(id, sourceConfig, internalSource); this.info = info; } @@ -44,8 +48,8 @@ public class DataTableImpl extends DataSourceImpl implements DataTable { public Stream stream() { var iterator = new TableIterator(); - return StreamSupport.stream( - Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false).onClose(iterator::finish); + return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false) + .onClose(iterator::finish); } @Override @@ -63,15 +67,23 @@ public class DataTableImpl extends DataSourceImpl implements DataTable { List nodes = new ArrayList<>(); XPipeConnection.execute(con -> { var req = QueryTableDataExchange.Request.builder() - .ref(DataSourceReference.id(getId())).maxRows(maxRows).build(); + .ref(DataSourceReference.id(getId())) + .maxRows(maxRows) + .build(); con.performInputExchange(req, (QueryTableDataExchange.Response res, InputStream in) -> { - var r = new TypedDataStreamParser(info.getDataType()); - r.parseStructures(in, TypedDataStructureNodeReader.of(info.getDataType()), nodes::add); + var r = new TypedDataStreamParser(info.getDataType()); + r.parseStructures(in, TypedDataStructureNodeReader.of(info.getDataType()), nodes::add); }); }); return ArrayNode.of(nodes); } + @Override + public Iterator iterator() { + return new TableIterator(); + } + ; + private class TableIterator implements Iterator { private final BeaconConnection connection; @@ -85,7 +97,9 @@ public class DataTableImpl extends DataSourceImpl implements DataTable { connection = XPipeConnection.open(); var req = QueryTableDataExchange.Request.builder() - .ref(DataSourceReference.id(getId())).maxRows(Integer.MAX_VALUE).build(); + .ref(DataSourceReference.id(getId())) + .maxRows(Integer.MAX_VALUE) + .build(); connection.sendRequest(req); connection.receiveResponse(); connection.receiveBody(); @@ -116,10 +130,5 @@ public class DataTableImpl extends DataSourceImpl implements DataTable { return node; } - }; - - @Override - public Iterator iterator() { - return new TableIterator(); } } diff --git a/api/src/main/java/io/xpipe/api/impl/DataTextImpl.java b/api/src/main/java/io/xpipe/api/impl/DataTextImpl.java index af19f8d6b..4d5f27c4c 100644 --- a/api/src/main/java/io/xpipe/api/impl/DataTextImpl.java +++ b/api/src/main/java/io/xpipe/api/impl/DataTextImpl.java @@ -27,7 +27,11 @@ public class DataTextImpl extends DataSourceImpl implements DataText { private final DataSourceInfo.Text info; - public DataTextImpl(DataSourceId sourceId, DataSourceConfig sourceConfig, DataSourceInfo.Text info, io.xpipe.core.source.DataSource internalSource) { + public DataTextImpl( + DataSourceId sourceId, + DataSourceConfig sourceConfig, + DataSourceInfo.Text info, + io.xpipe.core.source.DataSource internalSource) { super(sourceId, sourceConfig, internalSource); this.info = info; } @@ -70,7 +74,9 @@ public class DataTextImpl extends DataSourceImpl implements DataText { { connection = XPipeConnection.open(); var req = QueryTextDataExchange.Request.builder() - .ref(DataSourceReference.id(getId())).maxLines(-1).build(); + .ref(DataSourceReference.id(getId())) + .maxLines(-1) + .build(); connection.sendRequest(req); connection.receiveResponse(); reader = new BufferedReader(new InputStreamReader(connection.receiveBody(), StandardCharsets.UTF_8)); @@ -98,8 +104,7 @@ public class DataTextImpl extends DataSourceImpl implements DataText { } }; - return StreamSupport - .stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false) + return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false) .onClose(iterator::close); } @@ -123,6 +128,4 @@ public class DataTextImpl extends DataSourceImpl implements DataText { }); return builder.toString(); } - - } diff --git a/api/src/main/java/io/xpipe/api/util/QuietDialogHandler.java b/api/src/main/java/io/xpipe/api/util/QuietDialogHandler.java index b1d453529..55cefef84 100644 --- a/api/src/main/java/io/xpipe/api/util/QuietDialogHandler.java +++ b/api/src/main/java/io/xpipe/api/util/QuietDialogHandler.java @@ -14,9 +14,9 @@ import java.util.UUID; public class QuietDialogHandler { private final UUID dialogKey; - private DialogElement element; private final BeaconConnection connection; private final Map overrides; + private DialogElement element; public QuietDialogHandler(DialogReference ref, BeaconConnection connection, Map overrides) { this.dialogKey = ref.getDialogId(); @@ -36,10 +36,13 @@ public class QuietDialogHandler { response = handleQuery(q); } - DialogExchange.Response res = connection.performSimpleExchange( - DialogExchange.Request.builder().dialogKey(dialogKey).value(response).build()); + DialogExchange.Response res = connection.performSimpleExchange(DialogExchange.Request.builder() + .dialogKey(dialogKey) + .value(response) + .build()); if (res.getElement() != null && element.equals(res.getElement())) { - throw new ClientException("Invalid value for key " + res.getElement().toDisplayString()); + throw new ClientException( + "Invalid value for key " + res.getElement().toDisplayString()); } element = res.getElement(); diff --git a/api/src/main/java/io/xpipe/api/util/TypeDescriptor.java b/api/src/main/java/io/xpipe/api/util/TypeDescriptor.java index 42e8bf90a..2434da388 100644 --- a/api/src/main/java/io/xpipe/api/util/TypeDescriptor.java +++ b/api/src/main/java/io/xpipe/api/util/TypeDescriptor.java @@ -6,8 +6,7 @@ import java.util.stream.Collectors; public class TypeDescriptor { public static String create(List names) { - return "[" + names.stream() - .map(n -> n != null ? "\"" + n + "\"" : null) - .collect(Collectors.joining(",")) + "]\n"; + return "[" + names.stream().map(n -> n != null ? "\"" + n + "\"" : null).collect(Collectors.joining(",")) + + "]\n"; } } diff --git a/api/src/main/java/module-info.java b/api/src/main/java/module-info.java index 063b86acc..cd277a4bf 100644 --- a/api/src/main/java/module-info.java +++ b/api/src/main/java/module-info.java @@ -5,4 +5,4 @@ module io.xpipe.api { requires transitive io.xpipe.core; requires io.xpipe.beacon; -} \ No newline at end of file +} diff --git a/api/src/test/java/io/xpipe/api/test/DataTableAccumulatorTest.java b/api/src/test/java/io/xpipe/api/test/DataTableAccumulatorTest.java index 2e4c8f45e..f7bb250a7 100644 --- a/api/src/test/java/io/xpipe/api/test/DataTableAccumulatorTest.java +++ b/api/src/test/java/io/xpipe/api/test/DataTableAccumulatorTest.java @@ -15,13 +15,11 @@ public class DataTableAccumulatorTest extends ApiTest { @Test public void test() { - var type = TupleType.of( - List.of("col1", "col2"), - List.of(ValueType.of(), ValueType.of())); + var type = TupleType.of(List.of("col1", "col2"), List.of(ValueType.of(), ValueType.of())); var acc = DataTableAccumulator.create(type); - var val = type.convert( - TupleNode.of(List.of(ValueNode.of("val1"), ValueNode.of("val2")))).orElseThrow(); + var val = type.convert(TupleNode.of(List.of(ValueNode.of("val1"), ValueNode.of("val2")))) + .orElseThrow(); acc.add(val); var table = acc.finish(":test"); diff --git a/api/src/test/java/io/xpipe/api/test/DataTableTest.java b/api/src/test/java/io/xpipe/api/test/DataTableTest.java index c733f20f5..e8138be46 100644 --- a/api/src/test/java/io/xpipe/api/test/DataTableTest.java +++ b/api/src/test/java/io/xpipe/api/test/DataTableTest.java @@ -9,7 +9,8 @@ public class DataTableTest extends ApiTest { @BeforeAll public static void setupStorage() throws Exception { - DataSource.create(DataSourceId.fromString(":usernames"), "csv", DataTableTest.class.getResource("username.csv")); + DataSource.create( + DataSourceId.fromString(":usernames"), "csv", DataTableTest.class.getResource("username.csv")); } @Test diff --git a/api/src/test/java/module-info.java b/api/src/test/java/module-info.java index 234dfe6d1..f51c38c52 100644 --- a/api/src/test/java/module-info.java +++ b/api/src/test/java/module-info.java @@ -6,4 +6,4 @@ module io.xpipe.api.test { opens io.xpipe.api.test; exports io.xpipe.api.test; -} \ No newline at end of file +} diff --git a/beacon/src/main/java/io/xpipe/beacon/BeaconClient.java b/beacon/src/main/java/io/xpipe/beacon/BeaconClient.java index 7e9e9bf42..db4b1c04a 100644 --- a/beacon/src/main/java/io/xpipe/beacon/BeaconClient.java +++ b/beacon/src/main/java/io/xpipe/beacon/BeaconClient.java @@ -23,32 +23,6 @@ import static io.xpipe.beacon.BeaconConfig.BODY_SEPARATOR; public class BeaconClient implements AutoCloseable { - @FunctionalInterface - public interface FailableBiConsumer { - - void accept(T var1, U var2) throws E; - } - - @FunctionalInterface - public interface FailableConsumer { - - void accept(T var1) throws E; - } - - @FunctionalInterface - public interface FailableRunnable { - - void run() throws E; - } - - public static Optional tryConnect() { - try { - return Optional.of(new BeaconClient()); - } catch (IOException ex) { - return Optional.empty(); - } - } - private final Closeable closeable; private final InputStream in; private final OutputStream out; @@ -66,6 +40,14 @@ public class BeaconClient implements AutoCloseable { this.out = out; } + public static Optional tryConnect() { + try { + return Optional.of(new BeaconClient()); + } catch (IOException ex) { + return Optional.empty(); + } + } + public void close() throws ConnectorException { try { closeable.close(); @@ -104,12 +86,13 @@ public class BeaconClient implements AutoCloseable { json.set("messageType", new TextNode(prov.get().getId())); json.set("messagePhase", new TextNode("request")); - //json.set("id", new TextNode(UUID.randomUUID().toString())); + // json.set("id", new TextNode(UUID.randomUUID().toString())); var msg = JsonNodeFactory.instance.objectNode(); msg.set("xPipeMessage", json); if (BeaconConfig.printMessages()) { - System.out.println("Sending request to server of type " + req.getClass().getName()); + System.out.println( + "Sending request to server of type " + req.getClass().getName()); } var writer = new StringWriter(); @@ -198,13 +181,13 @@ public class BeaconClient implements AutoCloseable { var type = content.required("messageType").textValue(); var phase = content.required("messagePhase").textValue(); - //var requestId = UUID.fromString(content.required("id").textValue()); + // var requestId = UUID.fromString(content.required("id").textValue()); if (!phase.equals("response")) { throw new IllegalArgumentException(); } content.remove("messageType"); content.remove("messagePhase"); - //content.remove("id"); + // content.remove("id"); var prov = MessageExchanges.byId(type); if (prov.isEmpty()) { @@ -226,4 +209,22 @@ public class BeaconClient implements AutoCloseable { public OutputStream getRawOutputStream() { return out; } + + @FunctionalInterface + public interface FailableBiConsumer { + + void accept(T var1, U var2) throws E; + } + + @FunctionalInterface + public interface FailableConsumer { + + void accept(T var1) throws E; + } + + @FunctionalInterface + public interface FailableRunnable { + + void run() throws E; + } } diff --git a/beacon/src/main/java/io/xpipe/beacon/BeaconConfig.java b/beacon/src/main/java/io/xpipe/beacon/BeaconConfig.java index d37dd3591..47b8a6106 100644 --- a/beacon/src/main/java/io/xpipe/beacon/BeaconConfig.java +++ b/beacon/src/main/java/io/xpipe/beacon/BeaconConfig.java @@ -8,8 +8,14 @@ import java.nio.charset.StandardCharsets; public class BeaconConfig { public static final byte[] BODY_SEPARATOR = "\n\n".getBytes(StandardCharsets.UTF_8); - + public static final String BEACON_PORT_PROP = "io.xpipe.beacon.port"; + public static final int DEFAULT_PORT = System.getProperty("os.name").startsWith("Windows") ? 21721 : 21722; private static final String PRINT_MESSAGES_PROPERTY = "io.xpipe.beacon.printMessages"; + private static final String LAUNCH_DAEMON_IN_DEBUG_PROP = "io.xpipe.beacon.launchDebugDaemon"; + private static final String ATTACH_DEBUGGER_PROP = "io.xpipe.beacon.attachDebuggerToDaemon"; + private static final String EXEC_DEBUG_PROP = "io.xpipe.beacon.printDaemonOutput"; + private static final String EXEC_PROCESS_PROP = "io.xpipe.beacon.customDaemonCommand"; + private static final String DAEMON_ARGUMENTS_PROP = "io.xpipe.beacon.daemonArgs"; public static boolean printMessages() { if (System.getProperty(PRINT_MESSAGES_PROPERTY) != null) { @@ -18,8 +24,6 @@ public class BeaconConfig { return false; } - private static final String LAUNCH_DAEMON_IN_DEBUG_PROP = "io.xpipe.beacon.launchDebugDaemon"; - public static boolean launchDaemonInDebugMode() { if (System.getProperty(LAUNCH_DAEMON_IN_DEBUG_PROP) != null) { return Boolean.parseBoolean(System.getProperty(LAUNCH_DAEMON_IN_DEBUG_PROP)); @@ -27,8 +31,6 @@ public class BeaconConfig { return false; } - private static final String ATTACH_DEBUGGER_PROP = "io.xpipe.beacon.attachDebuggerToDaemon"; - public static boolean attachDebuggerToDaemon() { if (System.getProperty(ATTACH_DEBUGGER_PROP) != null) { return Boolean.parseBoolean(System.getProperty(ATTACH_DEBUGGER_PROP)); @@ -36,10 +38,6 @@ public class BeaconConfig { return false; } - - - private static final String EXEC_DEBUG_PROP = "io.xpipe.beacon.printDaemonOutput"; - public static boolean printDaemonOutput() { if (System.getProperty(EXEC_DEBUG_PROP) != null) { return Boolean.parseBoolean(System.getProperty(EXEC_DEBUG_PROP)); @@ -47,11 +45,6 @@ public class BeaconConfig { return false; } - - - public static final String BEACON_PORT_PROP = "io.xpipe.beacon.port"; - public static final int DEFAULT_PORT = System.getProperty("os.name").startsWith("Windows") ? 21721 : 21722; - public static int getUsedPort() { if (System.getProperty(BEACON_PORT_PROP) != null) { return Integer.parseInt(System.getProperty(BEACON_PORT_PROP)); @@ -60,10 +53,6 @@ public class BeaconConfig { return DEFAULT_PORT; } - - - private static final String EXEC_PROCESS_PROP = "io.xpipe.beacon.customDaemonCommand"; - public static String getCustomDaemonCommand() { if (System.getProperty(EXEC_PROCESS_PROP) != null) { return System.getProperty(EXEC_PROCESS_PROP); @@ -72,8 +61,6 @@ public class BeaconConfig { return null; } - private static final String DAEMON_ARGUMENTS_PROP = "io.xpipe.beacon.daemonArgs"; - public static String getDaemonArguments() { if (System.getProperty(DAEMON_ARGUMENTS_PROP) != null) { return System.getProperty(DAEMON_ARGUMENTS_PROP); @@ -82,5 +69,3 @@ public class BeaconConfig { return null; } } - - diff --git a/beacon/src/main/java/io/xpipe/beacon/BeaconConnection.java b/beacon/src/main/java/io/xpipe/beacon/BeaconConnection.java index b6b720e11..f6c36b490 100644 --- a/beacon/src/main/java/io/xpipe/beacon/BeaconConnection.java +++ b/beacon/src/main/java/io/xpipe/beacon/BeaconConnection.java @@ -6,7 +6,6 @@ import java.io.OutputStream; public abstract class BeaconConnection implements AutoCloseable { - protected BeaconClient beaconClient; private InputStream bodyInput; @@ -74,9 +73,7 @@ public abstract class BeaconConnection implements AutoCloseable { } public void performInputExchange( - REQ req, - BeaconClient.FailableBiConsumer responseConsumer - ) { + REQ req, BeaconClient.FailableBiConsumer responseConsumer) { checkClosed(); performInputOutputExchange(req, null, responseConsumer); @@ -85,8 +82,7 @@ public abstract class BeaconConnection implements AutoCloseable { public void performInputOutputExchange( REQ req, BeaconClient.FailableConsumer reqWriter, - BeaconClient.FailableBiConsumer responseConsumer - ) { + BeaconClient.FailableBiConsumer responseConsumer) { checkClosed(); try { @@ -105,9 +101,7 @@ public abstract class BeaconConnection implements AutoCloseable { } } - public void sendRequest( - REQ req - ) { + public void sendRequest(REQ req) { checkClosed(); try { @@ -150,9 +144,7 @@ public abstract class BeaconConnection implements AutoCloseable { } public RES performOutputExchange( - REQ req, - BeaconClient.FailableConsumer reqWriter - ) { + REQ req, BeaconClient.FailableConsumer reqWriter) { checkClosed(); try { @@ -166,9 +158,7 @@ public abstract class BeaconConnection implements AutoCloseable { } } - public RES performSimpleExchange( - REQ req - ) { + public RES performSimpleExchange(REQ req) { checkClosed(); try { @@ -192,7 +182,6 @@ public abstract class BeaconConnection implements AutoCloseable { return new BeaconException("A beacon connection error occurred", s.getCause()); } - return new BeaconException("An unexpected error occurred", exception); } } diff --git a/beacon/src/main/java/io/xpipe/beacon/BeaconException.java b/beacon/src/main/java/io/xpipe/beacon/BeaconException.java index 66d0980bd..5c4bd3b63 100644 --- a/beacon/src/main/java/io/xpipe/beacon/BeaconException.java +++ b/beacon/src/main/java/io/xpipe/beacon/BeaconException.java @@ -5,8 +5,7 @@ package io.xpipe.beacon; */ public class BeaconException extends RuntimeException { - public BeaconException() { - } + public BeaconException() {} public BeaconException(String message) { super(message); diff --git a/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java b/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java index a7ad6e4a4..da43b4673 100644 --- a/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java +++ b/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java @@ -34,9 +34,8 @@ public class BeaconServer { public static Process tryStartCustom() throws Exception { var custom = BeaconConfig.getCustomDaemonCommand(); if (custom != null) { - var command = custom + " " + (BeaconConfig.getDaemonArguments() != null ? - BeaconConfig.getDaemonArguments() : - ""); + var command = + custom + " " + (BeaconConfig.getDaemonArguments() != null ? BeaconConfig.getDaemonArguments() : ""); Process process = Runtime.getRuntime().exec(command); printDaemonOutput(process, command); return process; @@ -47,9 +46,8 @@ public class BeaconServer { public static Process tryStart() throws Exception { var daemonExecutable = getDaemonExecutable(); if (daemonExecutable.isPresent()) { - var command = "\"" + daemonExecutable.get() + "\" --external " + (BeaconConfig.getDaemonArguments() != null ? - BeaconConfig.getDaemonArguments() : - ""); + var command = "\"" + daemonExecutable.get() + "\" --external " + + (BeaconConfig.getDaemonArguments() != null ? BeaconConfig.getDaemonArguments() : ""); // Tell daemon that we launched from an external tool Process process = Runtime.getRuntime().exec(command); printDaemonOutput(process, command); @@ -65,35 +63,43 @@ public class BeaconServer { System.out.println("Starting daemon: " + command); } - new Thread(null, () -> { - try { - InputStreamReader isr = new InputStreamReader(proc.getInputStream()); - BufferedReader br = new BufferedReader(isr); - String line; - while ((line = br.readLine()) != null) { - if (print) { - System.out.println("[xpiped] " + line); - } - } - } catch (Exception ioe) { - ioe.printStackTrace(); - } - }, "daemon sysout").start(); + new Thread( + null, + () -> { + try { + InputStreamReader isr = new InputStreamReader(proc.getInputStream()); + BufferedReader br = new BufferedReader(isr); + String line; + while ((line = br.readLine()) != null) { + if (print) { + System.out.println("[xpiped] " + line); + } + } + } catch (Exception ioe) { + ioe.printStackTrace(); + } + }, + "daemon sysout") + .start(); - new Thread(null, () -> { - try { - InputStreamReader isr = new InputStreamReader(proc.getErrorStream()); - BufferedReader br = new BufferedReader(isr); - String line; - while ((line = br.readLine()) != null) { - if (print) { - System.err.println("[xpiped] " + line); - } - } - } catch (Exception ioe) { - ioe.printStackTrace(); - } - }, "daemon syserr").start(); + new Thread( + null, + () -> { + try { + InputStreamReader isr = new InputStreamReader(proc.getErrorStream()); + BufferedReader br = new BufferedReader(isr); + String line; + while ((line = br.readLine()) != null) { + if (print) { + System.err.println("[xpiped] " + line); + } + } + } catch (Exception ioe) { + ioe.printStackTrace(); + } + }, + "daemon syserr") + .start(); } public static boolean tryStop(BeaconClient client) throws Exception { @@ -111,7 +117,6 @@ public class BeaconServer { } catch (Exception ex) { } - if (base == null) { if (System.getProperty("os.name").startsWith("Windows")) { base = Path.of(System.getenv("LOCALAPPDATA"), "X-Pipe"); diff --git a/beacon/src/main/java/io/xpipe/beacon/ClientException.java b/beacon/src/main/java/io/xpipe/beacon/ClientException.java index 74f4364a1..784d9b642 100644 --- a/beacon/src/main/java/io/xpipe/beacon/ClientException.java +++ b/beacon/src/main/java/io/xpipe/beacon/ClientException.java @@ -5,8 +5,7 @@ package io.xpipe.beacon; */ public class ClientException extends Exception { - public ClientException() { - } + public ClientException() {} public ClientException(String message) { super(message); diff --git a/beacon/src/main/java/io/xpipe/beacon/ConnectorException.java b/beacon/src/main/java/io/xpipe/beacon/ConnectorException.java index 8f5841f54..83a14dbcf 100644 --- a/beacon/src/main/java/io/xpipe/beacon/ConnectorException.java +++ b/beacon/src/main/java/io/xpipe/beacon/ConnectorException.java @@ -5,8 +5,7 @@ package io.xpipe.beacon; */ public class ConnectorException extends Exception { - public ConnectorException() { - } + public ConnectorException() {} public ConnectorException(String message) { super(message); diff --git a/beacon/src/main/java/io/xpipe/beacon/RequestMessage.java b/beacon/src/main/java/io/xpipe/beacon/RequestMessage.java index c6fd015a3..9f9a5c2da 100644 --- a/beacon/src/main/java/io/xpipe/beacon/RequestMessage.java +++ b/beacon/src/main/java/io/xpipe/beacon/RequestMessage.java @@ -1,5 +1,3 @@ package io.xpipe.beacon; -public interface RequestMessage { - -} +public interface RequestMessage {} diff --git a/beacon/src/main/java/io/xpipe/beacon/ResponseMessage.java b/beacon/src/main/java/io/xpipe/beacon/ResponseMessage.java index 33b82e751..ec167994d 100644 --- a/beacon/src/main/java/io/xpipe/beacon/ResponseMessage.java +++ b/beacon/src/main/java/io/xpipe/beacon/ResponseMessage.java @@ -1,5 +1,3 @@ package io.xpipe.beacon; -public interface ResponseMessage { - -} +public interface ResponseMessage {} diff --git a/beacon/src/main/java/io/xpipe/beacon/ServerException.java b/beacon/src/main/java/io/xpipe/beacon/ServerException.java index 470f41205..d25c2272e 100644 --- a/beacon/src/main/java/io/xpipe/beacon/ServerException.java +++ b/beacon/src/main/java/io/xpipe/beacon/ServerException.java @@ -5,8 +5,7 @@ package io.xpipe.beacon; */ public class ServerException extends Exception { - public ServerException() { - } + public ServerException() {} public ServerException(String message) { super(message); diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/AddSourceExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/AddSourceExchange.java index 2397f70da..d3c617e26 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/AddSourceExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/AddSourceExchange.java @@ -21,7 +21,9 @@ public class AddSourceExchange implements MessageExchange { @Value public static class Request implements RequestMessage { DataSourceId target; - @NonNull DataSource source; + + @NonNull + DataSource source; } @Jacksonized diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/ForwardExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/ForwardExchange.java index 971d92ac7..a8c7eba75 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/ForwardExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/ForwardExchange.java @@ -31,6 +31,5 @@ public class ForwardExchange implements MessageExchange { @Jacksonized @Builder @Value - public static class Response implements ResponseMessage { - } + public static class Response implements ResponseMessage {} } diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/MessageExchanges.java b/beacon/src/main/java/io/xpipe/beacon/exchange/MessageExchanges.java index c6e1be5b4..20f658cc4 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/MessageExchanges.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/MessageExchanges.java @@ -15,7 +15,8 @@ public class MessageExchanges { private static void loadAll() { if (ALL == null) { ALL = ServiceLoader.load(MessageExchange.class).stream() - .map(ServiceLoader.Provider::get).collect(Collectors.toSet()); + .map(ServiceLoader.Provider::get) + .collect(Collectors.toSet()); } } @@ -26,12 +27,16 @@ public class MessageExchanges { public static Optional byRequest(RQ req) { loadAll(); - return ALL.stream().filter(d -> d.getRequestClass().equals(req.getClass())).findAny(); + return ALL.stream() + .filter(d -> d.getRequestClass().equals(req.getClass())) + .findAny(); } public static Optional byResponse(RP rep) { loadAll(); - return ALL.stream().filter(d -> d.getResponseClass().equals(rep.getClass())).findAny(); + return ALL.stream() + .filter(d -> d.getResponseClass().equals(rep.getClass())) + .findAny(); } public static Set getAll() { diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/QueryDataSourceExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/QueryDataSourceExchange.java index 34166eaa5..9f1293a69 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/QueryDataSourceExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/QueryDataSourceExchange.java @@ -37,14 +37,18 @@ public class QueryDataSourceExchange implements MessageExchange { public static class Response implements ResponseMessage { @NonNull DataSourceId id; + boolean disabled; boolean hidden; + @NonNull DataSourceInfo info; + @NonNull String storeDisplay; String provider; + @NonNull Map config; diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/ReadExecuteExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/ReadExecuteExchange.java index e0f8ffef9..35bf31fad 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/ReadExecuteExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/ReadExecuteExchange.java @@ -32,6 +32,5 @@ public class ReadExecuteExchange implements MessageExchange { @Jacksonized @Builder @Value - public static class Response implements ResponseMessage { - } + public static class Response implements ResponseMessage {} } diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/StopExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/StopExchange.java index 116b27bef..bb7498140 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/StopExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/StopExchange.java @@ -19,8 +19,7 @@ public class StopExchange implements MessageExchange { @Jacksonized @Builder @Value - public static class Request implements RequestMessage { - } + public static class Request implements RequestMessage {} @Jacksonized @Builder diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/StoreStreamExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/StoreStreamExchange.java index 471a5989b..44a01c6b4 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/StoreStreamExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/StoreStreamExchange.java @@ -20,8 +20,7 @@ public class StoreStreamExchange implements MessageExchange { @Jacksonized @Builder @Value - public static class Request implements RequestMessage { - } + public static class Request implements RequestMessage {} @Jacksonized @Builder diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/api/QueryRawDataExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/api/QueryRawDataExchange.java index 726fa4151..73cfa5435 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/api/QueryRawDataExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/api/QueryRawDataExchange.java @@ -1,8 +1,8 @@ package io.xpipe.beacon.exchange.api; -import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.beacon.RequestMessage; import io.xpipe.beacon.ResponseMessage; +import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.core.source.DataSourceReference; import lombok.Builder; import lombok.NonNull; @@ -29,6 +29,5 @@ public class QueryRawDataExchange implements MessageExchange { @Jacksonized @Builder @Value - public static class Response implements ResponseMessage { - } + public static class Response implements ResponseMessage {} } diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/api/QueryTableDataExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/api/QueryTableDataExchange.java index 8408f9d88..9ba81da50 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/api/QueryTableDataExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/api/QueryTableDataExchange.java @@ -1,8 +1,8 @@ package io.xpipe.beacon.exchange.api; -import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.beacon.RequestMessage; import io.xpipe.beacon.ResponseMessage; +import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.core.source.DataSourceReference; import lombok.Builder; import lombok.NonNull; @@ -32,6 +32,5 @@ public class QueryTableDataExchange implements MessageExchange { @Jacksonized @Builder @Value - public static class Response implements ResponseMessage { - } + public static class Response implements ResponseMessage {} } diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/api/QueryTextDataExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/api/QueryTextDataExchange.java index 578327633..0eb5acee1 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/api/QueryTextDataExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/api/QueryTextDataExchange.java @@ -1,8 +1,8 @@ package io.xpipe.beacon.exchange.api; -import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.beacon.RequestMessage; import io.xpipe.beacon.ResponseMessage; +import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.core.source.DataSourceReference; import lombok.Builder; import lombok.NonNull; @@ -30,6 +30,5 @@ public class QueryTextDataExchange implements MessageExchange { @Jacksonized @Builder @Value - public static class Response implements ResponseMessage { - } + public static class Response implements ResponseMessage {} } diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/ConvertExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/ConvertExchange.java index 67f7a74d1..32123884d 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/ConvertExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/ConvertExchange.java @@ -1,8 +1,8 @@ package io.xpipe.beacon.exchange.cli; -import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.beacon.RequestMessage; import io.xpipe.beacon.ResponseMessage; +import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.core.dialog.DialogReference; import io.xpipe.core.source.DataSourceId; import io.xpipe.core.source.DataSourceReference; diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/DialogExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/DialogExchange.java index 464197563..c13f1b15c 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/DialogExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/DialogExchange.java @@ -1,8 +1,8 @@ package io.xpipe.beacon.exchange.cli; -import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.beacon.RequestMessage; import io.xpipe.beacon.ResponseMessage; +import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.core.dialog.DialogElement; import lombok.Builder; import lombok.NonNull; @@ -34,6 +34,7 @@ public class DialogExchange implements MessageExchange { public static class Request implements RequestMessage { @NonNull UUID dialogKey; + String value; boolean cancel; } diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/EditStoreExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/EditStoreExchange.java index db4883179..cbfc7669e 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/EditStoreExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/EditStoreExchange.java @@ -28,6 +28,7 @@ public class EditStoreExchange implements MessageExchange { @Builder @Value public static class Response implements ResponseMessage { - @NonNull DialogReference dialog; + @NonNull + DialogReference dialog; } } diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/InstanceExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/InstanceExchange.java index b237fe426..9f080bb88 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/InstanceExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/InstanceExchange.java @@ -19,9 +19,7 @@ public class InstanceExchange implements MessageExchange { @Jacksonized @Builder @Value - public static class Request implements RequestMessage { - - } + public static class Request implements RequestMessage {} @Jacksonized @Builder diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/ListCollectionsExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/ListCollectionsExchange.java index 1cc11f292..b010c53b0 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/ListCollectionsExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/ListCollectionsExchange.java @@ -1,9 +1,9 @@ package io.xpipe.beacon.exchange.cli; -import io.xpipe.beacon.exchange.MessageExchange; -import io.xpipe.beacon.exchange.data.CollectionListEntry; import io.xpipe.beacon.RequestMessage; import io.xpipe.beacon.ResponseMessage; +import io.xpipe.beacon.exchange.MessageExchange; +import io.xpipe.beacon.exchange.data.CollectionListEntry; import lombok.Builder; import lombok.Value; import lombok.extern.jackson.Jacksonized; @@ -20,9 +20,7 @@ public class ListCollectionsExchange implements MessageExchange { @Jacksonized @Builder @Value - public static class Request implements RequestMessage { - - } + public static class Request implements RequestMessage {} @Jacksonized @Builder diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/ListEntriesExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/ListEntriesExchange.java index 2a649b5ca..dec386260 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/ListEntriesExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/ListEntriesExchange.java @@ -1,9 +1,9 @@ package io.xpipe.beacon.exchange.cli; -import io.xpipe.beacon.exchange.MessageExchange; -import io.xpipe.beacon.exchange.data.EntryListEntry; import io.xpipe.beacon.RequestMessage; import io.xpipe.beacon.ResponseMessage; +import io.xpipe.beacon.exchange.MessageExchange; +import io.xpipe.beacon.exchange.data.EntryListEntry; import lombok.Builder; import lombok.Value; import lombok.extern.jackson.Jacksonized; diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/ListStoresExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/ListStoresExchange.java index 06934c104..da6a507ef 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/ListStoresExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/ListStoresExchange.java @@ -1,9 +1,9 @@ package io.xpipe.beacon.exchange.cli; -import io.xpipe.beacon.exchange.MessageExchange; -import io.xpipe.beacon.exchange.data.StoreListEntry; import io.xpipe.beacon.RequestMessage; import io.xpipe.beacon.ResponseMessage; +import io.xpipe.beacon.exchange.MessageExchange; +import io.xpipe.beacon.exchange.data.StoreListEntry; import lombok.Builder; import lombok.Value; import lombok.extern.jackson.Jacksonized; @@ -20,9 +20,7 @@ public class ListStoresExchange implements MessageExchange { @Jacksonized @Builder @Value - public static class Request implements RequestMessage { - - } + public static class Request implements RequestMessage {} @Jacksonized @Builder diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/ModeExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/ModeExchange.java index 650df0c84..a2806a80c 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/ModeExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/ModeExchange.java @@ -1,8 +1,8 @@ package io.xpipe.beacon.exchange.cli; -import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.beacon.RequestMessage; import io.xpipe.beacon.ResponseMessage; +import io.xpipe.beacon.exchange.MessageExchange; import lombok.Builder; import lombok.NonNull; import lombok.Value; @@ -26,7 +26,5 @@ public class ModeExchange implements MessageExchange { @Jacksonized @Builder @Value - public static class Response implements ResponseMessage { - - } + public static class Response implements ResponseMessage {} } diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/RemoveCollectionExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/RemoveCollectionExchange.java index 9cf3c2a17..357c24579 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/RemoveCollectionExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/RemoveCollectionExchange.java @@ -1,8 +1,8 @@ package io.xpipe.beacon.exchange.cli; -import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.beacon.RequestMessage; import io.xpipe.beacon.ResponseMessage; +import io.xpipe.beacon.exchange.MessageExchange; import lombok.Builder; import lombok.NonNull; import lombok.Value; @@ -26,6 +26,5 @@ public class RemoveCollectionExchange implements MessageExchange { @Jacksonized @Builder @Value - public static class Response implements ResponseMessage { - } + public static class Response implements ResponseMessage {} } diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/RemoveEntryExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/RemoveEntryExchange.java index ce2ce4a43..10249b0a0 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/RemoveEntryExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/RemoveEntryExchange.java @@ -1,8 +1,8 @@ package io.xpipe.beacon.exchange.cli; -import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.beacon.RequestMessage; import io.xpipe.beacon.ResponseMessage; +import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.core.source.DataSourceId; import io.xpipe.core.source.DataSourceReference; import lombok.Builder; diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/RemoveStoreExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/RemoveStoreExchange.java index c4aad66d4..e3dc7e5c6 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/RemoveStoreExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/RemoveStoreExchange.java @@ -1,8 +1,8 @@ package io.xpipe.beacon.exchange.cli; -import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.beacon.RequestMessage; import io.xpipe.beacon.ResponseMessage; +import io.xpipe.beacon.exchange.MessageExchange; import lombok.Builder; import lombok.NonNull; import lombok.Value; @@ -28,6 +28,5 @@ public class RemoveStoreExchange implements MessageExchange { @Jacksonized @Builder @Value - public static class Response implements ResponseMessage { - } + public static class Response implements ResponseMessage {} } diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/RenameCollectionExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/RenameCollectionExchange.java index f233d3463..192fcc346 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/RenameCollectionExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/RenameCollectionExchange.java @@ -1,8 +1,8 @@ package io.xpipe.beacon.exchange.cli; -import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.beacon.RequestMessage; import io.xpipe.beacon.ResponseMessage; +import io.xpipe.beacon.exchange.MessageExchange; import lombok.Builder; import lombok.NonNull; import lombok.Value; @@ -21,6 +21,7 @@ public class RenameCollectionExchange implements MessageExchange { public static class Request implements RequestMessage { @NonNull String collectionName; + @NonNull String newName; } @@ -28,6 +29,5 @@ public class RenameCollectionExchange implements MessageExchange { @Jacksonized @Builder @Value - public static class Response implements ResponseMessage { - } + public static class Response implements ResponseMessage {} } diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/RenameEntryExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/RenameEntryExchange.java index d39d2b0f5..e3e24bd52 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/RenameEntryExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/RenameEntryExchange.java @@ -1,8 +1,8 @@ package io.xpipe.beacon.exchange.cli; -import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.beacon.RequestMessage; import io.xpipe.beacon.ResponseMessage; +import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.core.source.DataSourceId; import io.xpipe.core.source.DataSourceReference; import lombok.Builder; @@ -32,6 +32,7 @@ public class RenameEntryExchange implements MessageExchange { @Builder @Value public static class Response implements ResponseMessage { - @NonNull DataSourceId newId; + @NonNull + DataSourceId newId; } } diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/RenameStoreExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/RenameStoreExchange.java index 7552dbabf..0a2712129 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/RenameStoreExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/RenameStoreExchange.java @@ -1,8 +1,8 @@ package io.xpipe.beacon.exchange.cli; -import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.beacon.RequestMessage; import io.xpipe.beacon.ResponseMessage; +import io.xpipe.beacon.exchange.MessageExchange; import lombok.Builder; import lombok.NonNull; import lombok.Value; @@ -21,6 +21,7 @@ public class RenameStoreExchange implements MessageExchange { public static class Request implements RequestMessage { @NonNull String storeName; + @NonNull String newName; } @@ -28,6 +29,5 @@ public class RenameStoreExchange implements MessageExchange { @Jacksonized @Builder @Value - public static class Response implements ResponseMessage { - } + public static class Response implements ResponseMessage {} } diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/SelectExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/SelectExchange.java index ef021202f..7c0017df0 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/SelectExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/SelectExchange.java @@ -1,8 +1,8 @@ package io.xpipe.beacon.exchange.cli; -import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.beacon.RequestMessage; import io.xpipe.beacon.ResponseMessage; +import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.core.source.DataSourceReference; import lombok.Builder; import lombok.NonNull; @@ -27,6 +27,5 @@ public class SelectExchange implements MessageExchange { @Jacksonized @Builder @Value - public static class Response implements ResponseMessage { - } + public static class Response implements ResponseMessage {} } diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/SourceProviderListExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/SourceProviderListExchange.java index e129e31c9..f0b272f6a 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/SourceProviderListExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/SourceProviderListExchange.java @@ -1,9 +1,9 @@ package io.xpipe.beacon.exchange.cli; -import io.xpipe.beacon.exchange.MessageExchange; -import io.xpipe.beacon.exchange.data.ProviderEntry; import io.xpipe.beacon.RequestMessage; import io.xpipe.beacon.ResponseMessage; +import io.xpipe.beacon.exchange.MessageExchange; +import io.xpipe.beacon.exchange.data.ProviderEntry; import io.xpipe.core.source.DataSourceType; import lombok.Builder; import lombok.NonNull; @@ -23,13 +23,13 @@ public class SourceProviderListExchange implements MessageExchange { @Jacksonized @Builder @Value - public static class Request implements RequestMessage { - } + public static class Request implements RequestMessage {} @Jacksonized @Builder @Value public static class Response implements ResponseMessage { - @NonNull Map> entries; + @NonNull + Map> entries; } } diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/StatusExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/StatusExchange.java index 014d0b153..255a2570c 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/StatusExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/StatusExchange.java @@ -1,8 +1,8 @@ package io.xpipe.beacon.exchange.cli; -import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.beacon.RequestMessage; import io.xpipe.beacon.ResponseMessage; +import io.xpipe.beacon.exchange.MessageExchange; import lombok.Builder; import lombok.Value; import lombok.extern.jackson.Jacksonized; @@ -17,8 +17,7 @@ public class StatusExchange implements MessageExchange { @Jacksonized @Builder @Value - public static class Request implements RequestMessage { - } + public static class Request implements RequestMessage {} @Jacksonized @Builder diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/StoreAddExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/StoreAddExchange.java index 6ef354037..fc91d772f 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/StoreAddExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/StoreAddExchange.java @@ -1,8 +1,8 @@ package io.xpipe.beacon.exchange.cli; -import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.beacon.RequestMessage; import io.xpipe.beacon.ResponseMessage; +import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.core.dialog.DialogReference; import io.xpipe.core.store.DataStore; import lombok.Builder; diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/StoreProviderListExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/StoreProviderListExchange.java index fd1fa2001..653a10629 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/StoreProviderListExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/StoreProviderListExchange.java @@ -21,13 +21,13 @@ public class StoreProviderListExchange implements MessageExchange { @Jacksonized @Builder @Value - public static class Request implements RequestMessage { - } + public static class Request implements RequestMessage {} @Jacksonized @Builder @Value public static class Response implements ResponseMessage { - @NonNull List entries; + @NonNull + List entries; } } diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/VersionExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/VersionExchange.java index deb1a30d8..41a9c0504 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/VersionExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/VersionExchange.java @@ -1,8 +1,8 @@ package io.xpipe.beacon.exchange.cli; -import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.beacon.RequestMessage; import io.xpipe.beacon.ResponseMessage; +import io.xpipe.beacon.exchange.MessageExchange; import lombok.Builder; import lombok.Value; import lombok.extern.jackson.Jacksonized; @@ -17,9 +17,7 @@ public class VersionExchange implements MessageExchange { @lombok.extern.jackson.Jacksonized @lombok.Builder @lombok.Value - public static class Request implements RequestMessage { - - } + public static class Request implements RequestMessage {} @Jacksonized @Builder diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/WriteExecuteExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/WriteExecuteExchange.java index 9e846843e..12a697903 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/WriteExecuteExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/WriteExecuteExchange.java @@ -1,8 +1,8 @@ package io.xpipe.beacon.exchange.cli; -import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.beacon.RequestMessage; import io.xpipe.beacon.ResponseMessage; +import io.xpipe.beacon.exchange.MessageExchange; import io.xpipe.core.source.DataSourceReference; import lombok.Builder; import lombok.NonNull; @@ -35,6 +35,5 @@ public class WriteExecuteExchange implements MessageExchange { @Jacksonized @Builder @Value - public static class Response implements ResponseMessage { - } + public static class Response implements ResponseMessage {} } diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/WritePreparationExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/WritePreparationExchange.java index f9fd93fb9..397ca0187 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/cli/WritePreparationExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/cli/WritePreparationExchange.java @@ -26,8 +26,10 @@ public class WritePreparationExchange implements MessageExchange { @Value public static class Request implements RequestMessage { String type; + @NonNull DataStore output; + @NonNull DataSourceReference source; } diff --git a/beacon/src/main/java/module-info.java b/beacon/src/main/java/module-info.java index 7b64cbeab..395dfb9ee 100644 --- a/beacon/src/main/java/module-info.java +++ b/beacon/src/main/java/module-info.java @@ -1,5 +1,7 @@ import io.xpipe.beacon.exchange.*; -import io.xpipe.beacon.exchange.api.*; +import io.xpipe.beacon.exchange.api.QueryRawDataExchange; +import io.xpipe.beacon.exchange.api.QueryTableDataExchange; +import io.xpipe.beacon.exchange.api.QueryTextDataExchange; import io.xpipe.beacon.exchange.cli.*; module io.xpipe.beacon { @@ -21,6 +23,7 @@ module io.xpipe.beacon { requires static lombok; uses MessageExchange; + provides io.xpipe.beacon.exchange.MessageExchange with ForwardExchange, InstanceExchange, @@ -55,4 +58,4 @@ module io.xpipe.beacon { QueryRawDataExchange, QueryTableDataExchange, VersionExchange; -} \ No newline at end of file +} diff --git a/core/build.gradle b/core/build.gradle index 5f54d4177..da3771470 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -13,7 +13,7 @@ compileJava { options.compilerArgs << '-parameters' } -dependencies{ +dependencies { api group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: "2.13.0" implementation group: 'com.fasterxml.jackson.module', name: 'jackson-module-parameter-names', version: "2.13.0" implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: "2.13.0" diff --git a/core/src/main/java/io/xpipe/core/charsetter/Charsetter.java b/core/src/main/java/io/xpipe/core/charsetter/Charsetter.java index 092a0beca..1cb8f7b1d 100644 --- a/core/src/main/java/io/xpipe/core/charsetter/Charsetter.java +++ b/core/src/main/java/io/xpipe/core/charsetter/Charsetter.java @@ -4,7 +4,10 @@ import io.xpipe.core.store.FileStore; import io.xpipe.core.store.StreamDataStore; import lombok.Value; -import java.io.*; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.*; @@ -15,8 +18,12 @@ import java.util.Map; public abstract class Charsetter { + private static final int MAX_BYTES = 8192; + public static Charsetter INSTANCE; private static CharsetterUniverse universe; + protected Charsetter() {} + protected static void checkInit() { if (universe == null) { throw new IllegalStateException("Charsetter not initialized"); @@ -27,30 +34,25 @@ public abstract class Charsetter { universe = CharsetterUniverse.create(ctx); } - @Value - public static class Result { - StreamCharset charset; - NewLine newLine; - } - - protected Charsetter() { - } - - public static Charsetter INSTANCE; - public static Charsetter get() { return INSTANCE; } - @FunctionalInterface - public interface FailableSupplier { - R get() throws E; - } - - @FunctionalInterface - public interface FailableConsumer { - - void accept(T var1) throws E; + private static int count(byte[] outerArray, byte[] smallerArray) { + int count = 0; + for (int i = 0; i < outerArray.length - smallerArray.length + 1; ++i) { + boolean found = true; + for (int j = 0; j < smallerArray.length; ++j) { + if (outerArray[i + j] != smallerArray[j]) { + found = false; + break; + } + } + if (found) { + count++; + } + } + return count; } public BufferedReader reader(StreamDataStore store, StreamCharset charset) throws Exception { @@ -73,16 +75,15 @@ public abstract class Charsetter { return new BufferedReader(new InputStreamReader(stream, charset.getCharset())); } - public abstract Result read(FailableSupplier in, FailableConsumer con) throws Exception; - - private static final int MAX_BYTES = 8192; + public abstract Result read( + FailableSupplier in, FailableConsumer con) + throws Exception; public Result detect(StreamDataStore store) throws Exception { Result result = new Result(null, null); if (store.canOpen()) { - try (InputStream inputStream = store.openBufferedInput()) { StreamCharset detected = null; for (var charset : StreamCharset.COMMON) { @@ -135,25 +136,10 @@ public abstract class Charsetter { return null; } - return count.entrySet().stream().min(Comparator.comparingInt(Map.Entry::getValue)) - .orElseThrow().getKey(); - } - - private static int count(byte[] outerArray, byte[] smallerArray) { - int count = 0; - for (int i = 0; i < outerArray.length - smallerArray.length + 1; ++i) { - boolean found = true; - for (int j = 0; j < smallerArray.length; ++j) { - if (outerArray[i + j] != smallerArray[j]) { - found = false; - break; - } - } - if (found) { - count++; - } - } - return count; + return count.entrySet().stream() + .min(Comparator.comparingInt(Map.Entry::getValue)) + .orElseThrow() + .getKey(); } public Charset inferCharset(byte[] content) { @@ -179,4 +165,21 @@ public abstract class Charsetter { return StandardCharsets.UTF_8; } + + @FunctionalInterface + public interface FailableSupplier { + R get() throws E; + } + + @FunctionalInterface + public interface FailableConsumer { + + void accept(T var1) throws E; + } + + @Value + public static class Result { + StreamCharset charset; + NewLine newLine; + } } diff --git a/core/src/main/java/io/xpipe/core/charsetter/CharsetterContext.java b/core/src/main/java/io/xpipe/core/charsetter/CharsetterContext.java index 0dbf39c3c..74494e498 100644 --- a/core/src/main/java/io/xpipe/core/charsetter/CharsetterContext.java +++ b/core/src/main/java/io/xpipe/core/charsetter/CharsetterContext.java @@ -11,15 +11,13 @@ import java.util.Locale; @AllArgsConstructor public class CharsetterContext { - public static CharsetterContext empty() { - return new CharsetterContext(Charset.defaultCharset().name(), Locale.getDefault(), Locale.getDefault(), List.of()); - } - String systemCharsetName; - Locale systemLocale; - Locale appLocale; - List observedCharsets; + + public static CharsetterContext empty() { + return new CharsetterContext( + Charset.defaultCharset().name(), Locale.getDefault(), Locale.getDefault(), List.of()); + } } diff --git a/core/src/main/java/io/xpipe/core/charsetter/NewLine.java b/core/src/main/java/io/xpipe/core/charsetter/NewLine.java index 2844bc4bf..b2ca78d74 100644 --- a/core/src/main/java/io/xpipe/core/charsetter/NewLine.java +++ b/core/src/main/java/io/xpipe/core/charsetter/NewLine.java @@ -5,24 +5,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Arrays; public enum NewLine { - @JsonProperty("lf") LF("\n", "lf"), @JsonProperty("crlf") CRLF("\r\n", "crlf"); - public static NewLine platform() { - return Arrays.stream(values()) - .filter(n -> n.getNewLine().equals(System.getProperty("line.separator"))) - .findFirst().orElseThrow(); - } - - public static NewLine id(String id) { - return Arrays.stream(values()) - .filter(n -> n.getId().equalsIgnoreCase(id)) - .findFirst().orElseThrow(); - } - private final String newLine; private final String id; @@ -31,6 +18,20 @@ public enum NewLine { this.id = id; } + public static NewLine platform() { + return Arrays.stream(values()) + .filter(n -> n.getNewLine().equals(System.getProperty("line.separator"))) + .findFirst() + .orElseThrow(); + } + + public static NewLine id(String id) { + return Arrays.stream(values()) + .filter(n -> n.getId().equalsIgnoreCase(id)) + .findFirst() + .orElseThrow(); + } + public String getNewLine() { return newLine; } diff --git a/core/src/main/java/io/xpipe/core/charsetter/StreamCharset.java b/core/src/main/java/io/xpipe/core/charsetter/StreamCharset.java index 0f2cec39f..2c3bbb393 100644 --- a/core/src/main/java/io/xpipe/core/charsetter/StreamCharset.java +++ b/core/src/main/java/io/xpipe/core/charsetter/StreamCharset.java @@ -13,10 +13,42 @@ import java.util.stream.Stream; @Value public class StreamCharset { + public static final StreamCharset UTF8 = new StreamCharset(StandardCharsets.UTF_8, null); + public static final StreamCharset UTF8_BOM = + new StreamCharset(StandardCharsets.UTF_8, new byte[] {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF}); + public static final StreamCharset UTF16 = new StreamCharset(StandardCharsets.UTF_16, null); + public static final StreamCharset UTF16_BOM = + new StreamCharset(StandardCharsets.UTF_16, new byte[] {(byte) 0xFE, (byte) 0xFF}); + public static final StreamCharset UTF16_LE = new StreamCharset(StandardCharsets.UTF_16LE, null); + public static final StreamCharset UTF16_LE_BOM = + new StreamCharset(StandardCharsets.UTF_16LE, new byte[] {(byte) 0xFF, (byte) 0xFE}); + public static final StreamCharset UTF32 = new StreamCharset(Charset.forName("utf-32"), null); + public static final StreamCharset UTF32_BOM = + new StreamCharset(Charset.forName("utf-32"), new byte[] {0x00, 0x00, (byte) 0xFE, (byte) 0xFF}); + public static final List COMMON = List.of( + UTF8, + UTF8_BOM, + UTF16, + UTF16_BOM, + UTF16_LE, + UTF16_LE_BOM, + UTF32, + UTF32_BOM, + new StreamCharset(StandardCharsets.US_ASCII, null), + new StreamCharset(StandardCharsets.ISO_8859_1, null), + new StreamCharset(Charset.forName("Windows-1251"), null), + new StreamCharset(Charset.forName("Windows-1252"), null)); + public static final List RARE = Charset.availableCharsets().values().stream() + .filter(charset -> COMMON.stream().noneMatch(c -> c.getCharset().equals(charset))) + .map(charset -> new StreamCharset(charset, null)) + .toList(); + Charset charset; + byte[] byteOrderMark; + public static StreamCharset get(Charset charset, boolean byteOrderMark) { return Stream.concat(COMMON.stream(), RARE.stream()) - .filter(streamCharset -> streamCharset.getCharset() - .equals(charset) && streamCharset.hasByteOrderMark() == byteOrderMark) + .filter(streamCharset -> + streamCharset.getCharset().equals(charset) && streamCharset.hasByteOrderMark() == byteOrderMark) .findFirst() .orElseThrow(); } @@ -24,66 +56,15 @@ public class StreamCharset { @JsonCreator public static StreamCharset get(String s) { var byteOrderMark = s.endsWith("-bom"); - var charset = Charset.forName(s.substring( - 0, s.length() - (byteOrderMark ? - 4 : - 0))); + var charset = Charset.forName(s.substring(0, s.length() - (byteOrderMark ? 4 : 0))); return StreamCharset.get(charset, byteOrderMark); } - Charset charset; - byte[] byteOrderMark; - @JsonValue public String toString() { - return getCharset() - .name().toLowerCase(Locale.ROOT) + (hasByteOrderMark() ? - "-bom" : - ""); + return getCharset().name().toLowerCase(Locale.ROOT) + (hasByteOrderMark() ? "-bom" : ""); } - public static final StreamCharset UTF8 = new StreamCharset(StandardCharsets.UTF_8, null); - public static final StreamCharset UTF8_BOM = new StreamCharset(StandardCharsets.UTF_8, new byte[]{ - (byte) 0xEF, - (byte) 0xBB, - (byte) 0xBF - }); - - public static final StreamCharset UTF16 = new StreamCharset(StandardCharsets.UTF_16, null); - public static final StreamCharset UTF16_BOM = new StreamCharset(StandardCharsets.UTF_16, new byte[]{ - (byte) 0xFE, - (byte) 0xFF - }); - - public static final StreamCharset UTF16_LE = new StreamCharset(StandardCharsets.UTF_16LE, null); - public static final StreamCharset UTF16_LE_BOM = new StreamCharset(StandardCharsets.UTF_16LE, new byte[]{ - (byte) 0xFF, - (byte) 0xFE - }); - - public static final StreamCharset UTF32 = new StreamCharset(Charset.forName("utf-32"), null); - public static final StreamCharset UTF32_BOM = new StreamCharset(Charset.forName("utf-32"), new byte[]{ - 0x00, - 0x00, - (byte) 0xFE, - (byte) 0xFF - }); - - public static final List COMMON = List.of( - UTF8, UTF8_BOM, UTF16, UTF16_BOM, UTF16_LE, UTF16_LE_BOM, UTF32, UTF32_BOM, new StreamCharset(StandardCharsets.US_ASCII, null), - new StreamCharset(StandardCharsets.ISO_8859_1, null), - new StreamCharset(Charset.forName("Windows-1251"), null), new StreamCharset(Charset.forName("Windows-1252"), null) - ); - - public static final List RARE = Charset.availableCharsets() - .values() - .stream() - .filter(charset -> COMMON.stream() - .noneMatch(c -> c.getCharset() - .equals(charset))) - .map(charset -> new StreamCharset(charset, null)) - .toList(); - public boolean hasByteOrderMark() { return byteOrderMark != null; } diff --git a/core/src/main/java/io/xpipe/core/data/generic/GenericArrayReader.java b/core/src/main/java/io/xpipe/core/data/generic/GenericArrayReader.java index ec39e56c0..739c8bb65 100644 --- a/core/src/main/java/io/xpipe/core/data/generic/GenericArrayReader.java +++ b/core/src/main/java/io/xpipe/core/data/generic/GenericArrayReader.java @@ -1,7 +1,7 @@ package io.xpipe.core.data.generic; -import io.xpipe.core.data.node.DataStructureNode; import io.xpipe.core.data.node.ArrayNode; +import io.xpipe.core.data.node.DataStructureNode; import io.xpipe.core.data.node.ValueNode; import java.util.ArrayList; @@ -16,8 +16,8 @@ public class GenericArrayReader implements GenericAbstractReader { private int currentIndex = 0; private GenericAbstractReader currentReader; private DataStructureNode created; - public GenericArrayReader() { - } + + public GenericArrayReader() {} public static GenericArrayReader newReader(int length) { var ar = new GenericArrayReader(); diff --git a/core/src/main/java/io/xpipe/core/data/generic/GenericDataStreamCallback.java b/core/src/main/java/io/xpipe/core/data/generic/GenericDataStreamCallback.java index 445e99e13..be1e0ba54 100644 --- a/core/src/main/java/io/xpipe/core/data/generic/GenericDataStreamCallback.java +++ b/core/src/main/java/io/xpipe/core/data/generic/GenericDataStreamCallback.java @@ -4,22 +4,15 @@ import java.util.Map; public interface GenericDataStreamCallback { - default void onName(String name) { - } + default void onName(String name) {} - default void onArrayStart(int length) { - } + default void onArrayStart(int length) {} - default void onArrayEnd(Map metaAttributes) { - } + default void onArrayEnd(Map metaAttributes) {} - default void onTupleStart(int length) { - } + default void onTupleStart(int length) {} - default void onTupleEnd(Map metaAttributes) { - } + default void onTupleEnd(Map metaAttributes) {} - - default void onValue(byte[] value, Map metaAttributes) { - } + default void onValue(byte[] value, Map metaAttributes) {} } diff --git a/core/src/main/java/io/xpipe/core/data/generic/GenericDataStructureNodeReader.java b/core/src/main/java/io/xpipe/core/data/generic/GenericDataStructureNodeReader.java index d053d712f..df7039b88 100644 --- a/core/src/main/java/io/xpipe/core/data/generic/GenericDataStructureNodeReader.java +++ b/core/src/main/java/io/xpipe/core/data/generic/GenericDataStructureNodeReader.java @@ -86,7 +86,6 @@ public class GenericDataStructureNodeReader implements GenericDataStreamCallback return; } - node = ValueNode.of(value).tag(metaAttributes); } } diff --git a/core/src/main/java/io/xpipe/core/data/generic/GenericTupleReader.java b/core/src/main/java/io/xpipe/core/data/generic/GenericTupleReader.java index a84d3adc8..af7712d9e 100644 --- a/core/src/main/java/io/xpipe/core/data/generic/GenericTupleReader.java +++ b/core/src/main/java/io/xpipe/core/data/generic/GenericTupleReader.java @@ -18,8 +18,8 @@ public class GenericTupleReader implements GenericAbstractReader { private int currentIndex = 0; private GenericAbstractReader currentReader; private DataStructureNode created; - public GenericTupleReader() { - } + + public GenericTupleReader() {} public static GenericTupleReader newReader(int length) { var tr = new GenericTupleReader(); diff --git a/core/src/main/java/io/xpipe/core/data/node/ArrayNode.java b/core/src/main/java/io/xpipe/core/data/node/ArrayNode.java index 60ace970b..3bcef8ae8 100644 --- a/core/src/main/java/io/xpipe/core/data/node/ArrayNode.java +++ b/core/src/main/java/io/xpipe/core/data/node/ArrayNode.java @@ -8,6 +8,8 @@ import java.util.stream.Collectors; public abstract class ArrayNode extends DataStructureNode { + protected ArrayNode() {} + public static ArrayNode empty() { return of(List.of()); } @@ -20,9 +22,6 @@ public abstract class ArrayNode extends DataStructureNode { return new SimpleArrayNode(nodes); } - protected ArrayNode() { - } - @Override public boolean equals(Object o) { if (this == o) { @@ -32,7 +31,8 @@ public abstract class ArrayNode extends DataStructureNode { return false; } - var toReturn = getNodes().equals(that.getNodes()) && Objects.equals(getMetaAttributes(), that.getMetaAttributes()); + var toReturn = + getNodes().equals(that.getNodes()) && Objects.equals(getMetaAttributes(), that.getMetaAttributes()); // Useful for debugging if (toReturn == false) { @@ -64,6 +64,7 @@ public abstract class ArrayNode extends DataStructureNode { @Override public final ArrayType determineDataType() { - return ArrayType.ofSharedType(getNodes().stream().map(DataStructureNode::determineDataType).toList()); + return ArrayType.ofSharedType( + getNodes().stream().map(DataStructureNode::determineDataType).toList()); } } diff --git a/core/src/main/java/io/xpipe/core/data/node/DataStructureNode.java b/core/src/main/java/io/xpipe/core/data/node/DataStructureNode.java index a026079f7..70985121e 100644 --- a/core/src/main/java/io/xpipe/core/data/node/DataStructureNode.java +++ b/core/src/main/java/io/xpipe/core/data/node/DataStructureNode.java @@ -67,7 +67,6 @@ public abstract class DataStructureNode implements Iterable { return this; } - public String getMetaAttribute(Integer key) { if (metaAttributes == null) { return null; @@ -104,9 +103,6 @@ public abstract class DataStructureNode implements Iterable { throw unsupported("get nodes"); } - public record KeyValue(String key, DataStructureNode value) { - } - protected abstract String getName(); protected UnsupportedOperationException unsupported(String s) { @@ -125,12 +121,15 @@ public abstract class DataStructureNode implements Iterable { } public String metaToString() { - return "(" + (metaAttributes != null ? - metaAttributes.entrySet() - .stream() - .map(e -> e.getValue() != null ? e.getKey() + ":" + e.getValue() : e.getKey().toString()) - .collect(Collectors.joining("|")) : - "") + ")"; + return "(" + + (metaAttributes != null + ? metaAttributes.entrySet().stream() + .map(e -> e.getValue() != null + ? e.getKey() + ":" + e.getValue() + : e.getKey().toString()) + .collect(Collectors.joining("|")) + : "") + + ")"; } public abstract String toString(int indent); @@ -146,11 +145,11 @@ public abstract class DataStructureNode implements Iterable { public boolean isValue() { return false; } + public DataStructureNode set(int index, DataStructureNode node) { throw unsupported("set at index"); } - public final ValueNode asValue() { if (!isValue()) { throw new UnsupportedOperationException(getName() + " is not a value node"); @@ -235,4 +234,6 @@ public abstract class DataStructureNode implements Iterable { public Iterator iterator() { throw unsupported("iterator creation"); } + + public record KeyValue(String key, DataStructureNode value) {} } diff --git a/core/src/main/java/io/xpipe/core/data/node/DataStructureNodePointer.java b/core/src/main/java/io/xpipe/core/data/node/DataStructureNodePointer.java index 104974c8e..7425b9f27 100644 --- a/core/src/main/java/io/xpipe/core/data/node/DataStructureNodePointer.java +++ b/core/src/main/java/io/xpipe/core/data/node/DataStructureNodePointer.java @@ -152,9 +152,7 @@ public class DataStructureNodePointer { @Override public DataStructureNode tryMatch(DataStructureNode n) { - var res = n.stream() - .filter(selector) - .findAny(); + var res = n.stream().filter(selector).findAny(); return res.orElse(null); } @@ -184,7 +182,6 @@ public class DataStructureNodePointer { return new Builder(new ArrayList<>(path)); } - public Builder name(String name) { path.add(new NameElement(name)); return this; @@ -219,7 +216,8 @@ public class DataStructureNodePointer { }); } - public Builder pointerEvaluation(DataStructureNodePointer pointer, Function converter) { + public Builder pointerEvaluation( + DataStructureNodePointer pointer, Function converter) { path.add(new FunctionElement((current) -> { var res = pointer.get(current); if (res != null) { diff --git a/core/src/main/java/io/xpipe/core/data/node/LinkedTupleNode.java b/core/src/main/java/io/xpipe/core/data/node/LinkedTupleNode.java index 9a370d7e6..29fee2489 100644 --- a/core/src/main/java/io/xpipe/core/data/node/LinkedTupleNode.java +++ b/core/src/main/java/io/xpipe/core/data/node/LinkedTupleNode.java @@ -84,7 +84,9 @@ public class LinkedTupleNode extends TupleNode { @Override public DataType determineDataType() { - return TupleType.of(getKeyNames(), getNodes().stream().map(DataStructureNode::determineDataType).toList()); + return TupleType.of( + getKeyNames(), + getNodes().stream().map(DataStructureNode::determineDataType).toList()); } @Override @@ -142,7 +144,6 @@ public class LinkedTupleNode extends TupleNode { return "LinkedTupleNode(" + size() + ")"; } - @Override public int size() { return tupleNodes.stream().mapToInt(TupleNode::size).sum(); @@ -174,6 +175,7 @@ public class LinkedTupleNode extends TupleNode { return this; } - return new LinkedTupleNode(tupleNodes.stream().map(n -> n.isMutable() ? n : n.mutable()).toList()); + return new LinkedTupleNode( + tupleNodes.stream().map(n -> n.isMutable() ? n : n.mutable()).toList()); } } diff --git a/core/src/main/java/io/xpipe/core/data/node/SimpleArrayNode.java b/core/src/main/java/io/xpipe/core/data/node/SimpleArrayNode.java index 001d47c44..2c4b6bccc 100644 --- a/core/src/main/java/io/xpipe/core/data/node/SimpleArrayNode.java +++ b/core/src/main/java/io/xpipe/core/data/node/SimpleArrayNode.java @@ -10,8 +10,6 @@ import java.util.function.Consumer; import java.util.stream.Stream; @AllArgsConstructor - - public class SimpleArrayNode extends ArrayNode { List nodes; @@ -79,6 +77,4 @@ public class SimpleArrayNode extends ArrayNode { nodes.remove(index); return this; } - - } diff --git a/core/src/main/java/io/xpipe/core/data/node/SimpleValueNode.java b/core/src/main/java/io/xpipe/core/data/node/SimpleValueNode.java index ff23d4386..266738350 100644 --- a/core/src/main/java/io/xpipe/core/data/node/SimpleValueNode.java +++ b/core/src/main/java/io/xpipe/core/data/node/SimpleValueNode.java @@ -23,8 +23,11 @@ public class SimpleValueNode extends ValueNode { @Override public String toString(int indent) { - var string = getRawData().length == 0 && !hasMetaAttribute(IS_TEXT) ? "" : new String(getRawData(), StandardCharsets.UTF_8); - return (hasMetaAttribute(IS_TEXT) ? "\"" : "") + string + (hasMetaAttribute(IS_TEXT) ? "\"" : "") + " " + metaToString(); + var string = getRawData().length == 0 && !hasMetaAttribute(IS_TEXT) + ? "" + : new String(getRawData(), StandardCharsets.UTF_8); + return (hasMetaAttribute(IS_TEXT) ? "\"" : "") + string + (hasMetaAttribute(IS_TEXT) ? "\"" : "") + " " + + metaToString(); } @Override diff --git a/core/src/main/java/io/xpipe/core/data/node/TupleNode.java b/core/src/main/java/io/xpipe/core/data/node/TupleNode.java index c6f1077d5..c04b10ebd 100644 --- a/core/src/main/java/io/xpipe/core/data/node/TupleNode.java +++ b/core/src/main/java/io/xpipe/core/data/node/TupleNode.java @@ -5,7 +5,6 @@ import java.util.List; import java.util.Objects; import java.util.stream.Collectors; - public abstract class TupleNode extends DataStructureNode { public static Builder builder() { @@ -46,13 +45,15 @@ public abstract class TupleNode extends DataStructureNode { public String toString(int indent) { var is = " ".repeat(indent); var start = "{\n"; - var kvs = getKeyValuePairs().stream().map(kv -> { - if (kv.key() == null) { - return is + " " + kv.value().toString(indent + 1) + "\n"; - } else { - return is + " " + kv.key() + "=" + kv.value().toString(indent + 1) + "\n"; - } - }).collect(Collectors.joining()); + var kvs = getKeyValuePairs().stream() + .map(kv -> { + if (kv.key() == null) { + return is + " " + kv.value().toString(indent + 1) + "\n"; + } else { + return is + " " + kv.key() + "=" + kv.value().toString(indent + 1) + "\n"; + } + }) + .collect(Collectors.joining()); var end = is + "}"; return start + kvs + end; } @@ -65,8 +66,9 @@ public abstract class TupleNode extends DataStructureNode { if (!(o instanceof TupleNode that)) { return false; } - var toReturn = getKeyNames().equals(that.getKeyNames()) && getNodes().equals(that.getNodes()) && - Objects.equals(getMetaAttributes(), that.getMetaAttributes()); + var toReturn = getKeyNames().equals(that.getKeyNames()) + && getNodes().equals(that.getNodes()) + && Objects.equals(getMetaAttributes(), that.getMetaAttributes()); // Useful for debugging if (toReturn == false) { @@ -98,11 +100,11 @@ public abstract class TupleNode extends DataStructureNode { public TupleNode build() { boolean hasKeys = entries.stream().anyMatch(kv -> kv.key() != null); - return hasKeys ? TupleNode.of( - entries.stream().map(KeyValue::key).toList(), - entries.stream().map(KeyValue::value).toList() - ) : - TupleNode.of(entries.stream().map(KeyValue::value).toList()); + return hasKeys + ? TupleNode.of( + entries.stream().map(KeyValue::key).toList(), + entries.stream().map(KeyValue::value).toList()) + : TupleNode.of(entries.stream().map(KeyValue::value).toList()); } } } diff --git a/core/src/main/java/io/xpipe/core/data/node/ValueNode.java b/core/src/main/java/io/xpipe/core/data/node/ValueNode.java index bdfce276e..4e1090bdc 100644 --- a/core/src/main/java/io/xpipe/core/data/node/ValueNode.java +++ b/core/src/main/java/io/xpipe/core/data/node/ValueNode.java @@ -11,32 +11,7 @@ import java.util.Objects; public abstract class ValueNode extends DataStructureNode { - - protected ValueNode() { - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof ValueNode that)) { - return false; - } - var toReturn = Arrays.equals(getRawData(), that.getRawData()) && Objects.equals(getMetaAttributes(), that.getMetaAttributes()); - - // Useful for debugging - if (toReturn == false) { - return false; - } - - return toReturn; - } - - @Override - public int hashCode() { - return Arrays.hashCode(getRawData()) + Objects.hash(getMetaAttributes()); - } + protected ValueNode() {} public static ValueNode nullValue() { return new SimpleValueNode(new byte[0]).tag(IS_NULL).asValue(); @@ -79,6 +54,7 @@ public abstract class ValueNode extends DataStructureNode { created.tag(IS_FLOATING_POINT); return created; } + public static ValueNode ofBoolean(Boolean bool) { var created = of(bool); created.tag(IS_BOOLEAN); @@ -93,6 +69,30 @@ public abstract class ValueNode extends DataStructureNode { return of(o.toString().getBytes(StandardCharsets.UTF_8)); } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof ValueNode that)) { + return false; + } + var toReturn = Arrays.equals(getRawData(), that.getRawData()) + && Objects.equals(getMetaAttributes(), that.getMetaAttributes()); + + // Useful for debugging + if (toReturn == false) { + return false; + } + + return toReturn; + } + + @Override + public int hashCode() { + return Arrays.hashCode(getRawData()) + Objects.hash(getMetaAttributes()); + } + @Override public final int asInt() { return Integer.parseInt(asString()); @@ -114,5 +114,4 @@ public abstract class ValueNode extends DataStructureNode { } public abstract byte[] getRawData(); - } diff --git a/core/src/main/java/io/xpipe/core/data/type/DataTypeVisitor.java b/core/src/main/java/io/xpipe/core/data/type/DataTypeVisitor.java index aa5139380..5b08de481 100644 --- a/core/src/main/java/io/xpipe/core/data/type/DataTypeVisitor.java +++ b/core/src/main/java/io/xpipe/core/data/type/DataTypeVisitor.java @@ -2,15 +2,11 @@ package io.xpipe.core.data.type; public interface DataTypeVisitor { - default void onValue(ValueType type) { - } + default void onValue(ValueType type) {} - default void onTuple(TupleType type) { - } + default void onTuple(TupleType type) {} - default void onArray(ArrayType type) { - } + default void onArray(ArrayType type) {} - default void onWildcard(WildcardType type) { - } + default void onWildcard(WildcardType type) {} } diff --git a/core/src/main/java/io/xpipe/core/data/type/DataTypeVisitors.java b/core/src/main/java/io/xpipe/core/data/type/DataTypeVisitors.java index 9525fac8a..addda5472 100644 --- a/core/src/main/java/io/xpipe/core/data/type/DataTypeVisitors.java +++ b/core/src/main/java/io/xpipe/core/data/type/DataTypeVisitors.java @@ -41,9 +41,7 @@ public class DataTypeVisitors { * Creates a visitor that allows for visiting possible recursive columns of table. */ public static DataTypeVisitor table( - Consumer newTuple, - Runnable endTuple, - BiConsumer newValue) { + Consumer newTuple, Runnable endTuple, BiConsumer newValue) { return new DataTypeVisitor() { private final Stack tuples = new Stack<>(); private final Stack keyIndices = new Stack<>(); diff --git a/core/src/main/java/io/xpipe/core/data/type/WildcardType.java b/core/src/main/java/io/xpipe/core/data/type/WildcardType.java index 127e096a3..17967c084 100644 --- a/core/src/main/java/io/xpipe/core/data/type/WildcardType.java +++ b/core/src/main/java/io/xpipe/core/data/type/WildcardType.java @@ -17,6 +17,8 @@ import java.util.Optional; @Value public class WildcardType extends DataType { + private WildcardType() {} + /** * Creates a new instance. */ @@ -24,8 +26,6 @@ public class WildcardType extends DataType { return new WildcardType(); } - private WildcardType() {} - @Override public String getName() { return "wildcard"; diff --git a/core/src/main/java/io/xpipe/core/data/typed/TypedDataStreamCallback.java b/core/src/main/java/io/xpipe/core/data/typed/TypedDataStreamCallback.java index 9edea4410..c662614d5 100644 --- a/core/src/main/java/io/xpipe/core/data/typed/TypedDataStreamCallback.java +++ b/core/src/main/java/io/xpipe/core/data/typed/TypedDataStreamCallback.java @@ -7,27 +7,19 @@ import java.util.Map; public interface TypedDataStreamCallback { - default void onValue(byte[] data, Map metaAttributes) { - } + default void onValue(byte[] data, Map metaAttributes) {} - default void onGenericNode(DataStructureNode node) { - } + default void onGenericNode(DataStructureNode node) {} - default void onTupleBegin(TupleType type) { - } + default void onTupleBegin(TupleType type) {} - default void onTupleEnd(Map metaAttributes) { - } + default void onTupleEnd(Map metaAttributes) {} - default void onArrayBegin(int size) { - } + default void onArrayBegin(int size) {} - default void onArrayEnd(Map metaAttributes) { - } + default void onArrayEnd(Map metaAttributes) {} - default void onNodeBegin() { - } + default void onNodeBegin() {} - default void onNodeEnd() { - } + default void onNodeEnd() {} } diff --git a/core/src/main/java/io/xpipe/core/data/typed/TypedDataStreamParser.java b/core/src/main/java/io/xpipe/core/data/typed/TypedDataStreamParser.java index 1ca48ddef..9edbb4af6 100644 --- a/core/src/main/java/io/xpipe/core/data/typed/TypedDataStreamParser.java +++ b/core/src/main/java/io/xpipe/core/data/typed/TypedDataStreamParser.java @@ -1,9 +1,9 @@ package io.xpipe.core.data.typed; -import io.xpipe.core.data.node.DataStructureNode; -import io.xpipe.core.data.node.DataStructureNodeIO; import io.xpipe.core.data.generic.GenericDataStreamParser; import io.xpipe.core.data.generic.GenericDataStructureNodeReader; +import io.xpipe.core.data.node.DataStructureNode; +import io.xpipe.core.data.node.DataStructureNodeIO; import io.xpipe.core.data.type.ArrayType; import io.xpipe.core.data.type.DataType; import io.xpipe.core.data.type.TupleType; @@ -21,7 +21,7 @@ public class TypedDataStreamParser { this.dataType = dataType; } - private boolean hasNext(InputStream in) throws IOException { + private boolean hasNext(InputStream in) throws IOException { var b = in.read(); if (b == -1) { return false; @@ -34,7 +34,8 @@ public class TypedDataStreamParser { return true; } - public void parseStructures(InputStream in, TypedAbstractReader cb, Consumer consumer) throws IOException { + public void parseStructures(InputStream in, TypedAbstractReader cb, Consumer consumer) + throws IOException { while (hasNext(in)) { cb.onNodeBegin(); parse(in, cb, dataType); diff --git a/core/src/main/java/io/xpipe/core/data/typed/TypedDataStructureNodeReader.java b/core/src/main/java/io/xpipe/core/data/typed/TypedDataStructureNodeReader.java index abe0f0280..f927a3909 100644 --- a/core/src/main/java/io/xpipe/core/data/typed/TypedDataStructureNodeReader.java +++ b/core/src/main/java/io/xpipe/core/data/typed/TypedDataStructureNodeReader.java @@ -12,20 +12,13 @@ import java.util.Stack; public class TypedDataStructureNodeReader implements TypedAbstractReader { - public static TypedDataStructureNodeReader of(DataType type) { - return new TypedDataStructureNodeReader(type); - } - - private DataStructureNode readNode; - private final Stack> children; private final Stack nodes; - private int arrayDepth; - private final List flattened; + private DataStructureNode readNode; + private int arrayDepth; private DataType expectedType; private int currentExpectedTypeIndex; - private TypedDataStructureNodeReader(DataType type) { flattened = new ArrayList<>(); type.visit(DataTypeVisitors.flatten(flattened::add)); @@ -34,6 +27,10 @@ public class TypedDataStructureNodeReader implements TypedAbstractReader { expectedType = flattened.get(0); } + public static TypedDataStructureNodeReader of(DataType type) { + return new TypedDataStructureNodeReader(type); + } + @Override public void onNodeBegin() { if (nodes.size() != 0 || children.size() != 0) { @@ -134,7 +131,8 @@ public class TypedDataStructureNodeReader implements TypedAbstractReader { private void moveExpectedType(boolean force) { if (!isInArray() || force) { currentExpectedTypeIndex++; - expectedType = currentExpectedTypeIndex == flattened.size() ? null : flattened.get(currentExpectedTypeIndex); + expectedType = + currentExpectedTypeIndex == flattened.size() ? null : flattened.get(currentExpectedTypeIndex); } } diff --git a/core/src/main/java/io/xpipe/core/dialog/BaseQueryElement.java b/core/src/main/java/io/xpipe/core/dialog/BaseQueryElement.java index 35cbbe9e8..a3aba8414 100644 --- a/core/src/main/java/io/xpipe/core/dialog/BaseQueryElement.java +++ b/core/src/main/java/io/xpipe/core/dialog/BaseQueryElement.java @@ -20,7 +20,8 @@ public class BaseQueryElement extends DialogElement { protected String value; @JsonCreator - public BaseQueryElement(String description, boolean newLine, boolean required, boolean secret, boolean quiet, String value) { + public BaseQueryElement( + String description, boolean newLine, boolean required, boolean secret, boolean quiet, String value) { this.description = description; this.newLine = newLine; this.required = required; diff --git a/core/src/main/java/io/xpipe/core/dialog/ChoiceElement.java b/core/src/main/java/io/xpipe/core/dialog/ChoiceElement.java index a587fa419..9ffd423af 100644 --- a/core/src/main/java/io/xpipe/core/dialog/ChoiceElement.java +++ b/core/src/main/java/io/xpipe/core/dialog/ChoiceElement.java @@ -18,6 +18,18 @@ public class ChoiceElement extends DialogElement { private int selected; + @JsonCreator + public ChoiceElement(String description, List elements, boolean required, int selected) { + if (elements.stream().allMatch(Choice::isDisabled)) { + throw new IllegalArgumentException("All choices are disabled"); + } + + this.description = description; + this.elements = elements; + this.required = required; + this.selected = selected; + } + @Override public boolean requiresExplicitUserInput() { return required && selected == -1; @@ -42,7 +54,8 @@ public class ChoiceElement extends DialogElement { } for (int i = 0; i < elements.size(); i++) { - if (elements.get(i).getCharacter() != null && elements.get(i).getCharacter().equals(c)) { + if (elements.get(i).getCharacter() != null + && elements.get(i).getCharacter().equals(c)) { selected = i; return true; } @@ -59,18 +72,6 @@ public class ChoiceElement extends DialogElement { return false; } - @JsonCreator - public ChoiceElement(String description, List elements, boolean required, int selected) { - if (elements.stream().allMatch(Choice::isDisabled)) { - throw new IllegalArgumentException("All choices are disabled"); - } - - this.description = description; - this.elements = elements; - this.required = required; - this.selected = selected; - } - public List getElements() { return elements; } diff --git a/core/src/main/java/io/xpipe/core/dialog/Dialog.java b/core/src/main/java/io/xpipe/core/dialog/Dialog.java index 9e60307f5..90812732a 100644 --- a/core/src/main/java/io/xpipe/core/dialog/Dialog.java +++ b/core/src/main/java/io/xpipe/core/dialog/Dialog.java @@ -2,7 +2,9 @@ package io.xpipe.core.dialog; import io.xpipe.core.util.SecretValue; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Predicate; @@ -24,6 +26,10 @@ import java.util.function.Supplier; */ public abstract class Dialog { + private final List> completion = new ArrayList<>(); + protected Object eval; + private Supplier evaluation; + /** * Creates an empty dialogue. This dialogue completes immediately and does not handle any questions or answers. */ @@ -43,33 +49,6 @@ public abstract class Dialog { }; } - public static class Choice extends Dialog { - - private final ChoiceElement element; - - private Choice(String description, List elements, boolean required, int selected) { - this.element = new ChoiceElement(description, elements, required, selected); - } - - @Override - public DialogElement start() throws Exception { - return element; - } - - @Override - protected DialogElement next(String answer) throws Exception { - if (element.apply(answer)) { - return null; - } - - return element; - } - - private int getSelected() { - return element.getSelected(); - } - } - /** * Creates a choice dialogue. * @@ -78,7 +57,8 @@ public abstract class Dialog { * @param required signals whether a choice is required or can be left empty * @param selected the selected element index */ - public static Dialog.Choice choice(String description, List elements, boolean required, int selected) { + public static Dialog.Choice choice( + String description, List elements, boolean required, int selected) { Dialog.Choice c = new Dialog.Choice(description, elements, required, selected); c.evaluateTo(c::getSelected); return c; @@ -94,8 +74,11 @@ public abstract class Dialog { * @param vals the range of possible elements */ @SafeVarargs - public static Dialog.Choice choice(String description, Function toString, boolean required, T def, T... vals) { - var elements = Arrays.stream(vals).map(v -> new io.xpipe.core.dialog.Choice(null, toString.apply(v))).toList(); + public static Dialog.Choice choice( + String description, Function toString, boolean required, T def, T... vals) { + var elements = Arrays.stream(vals) + .map(v -> new io.xpipe.core.dialog.Choice(null, toString.apply(v))) + .toList(); var index = Arrays.asList(vals).indexOf(def); if (def != null && index == -1) { throw new IllegalArgumentException("Default value " + def.toString() + " is not in possible values"); @@ -111,38 +94,6 @@ public abstract class Dialog { return c; } - public static class Query extends Dialog { - - private final QueryElement element; - - private Query(String description, boolean newLine, boolean required, boolean quiet, T value, QueryConverter converter, boolean hidden) { - this.element = new QueryElement(description, newLine, required, quiet, value, converter, hidden); - } - - @Override - public DialogElement start() throws Exception { - return element; - } - - @Override - protected DialogElement next(String answer) throws Exception { - if (element.requiresExplicitUserInput() && (answer == null || answer.trim() - .length() == 0)) { - return element; - } - - if (element.apply(answer)) { - return null; - } - - return element; - } - - private T getConvertedValue() { - return element.getConvertedValue(); - } - } - /** * Creates a simple query dialogue. * @@ -155,7 +106,13 @@ public abstract class Dialog { * @param value the default value * @param converter the converter */ - public static Dialog.Query query(String description, boolean newLine, boolean required, boolean quiet, T value, QueryConverter converter) { + public static Dialog.Query query( + String description, + boolean newLine, + boolean required, + boolean quiet, + T value, + QueryConverter converter) { var q = new Dialog.Query(description, newLine, required, quiet, value, converter, false); q.evaluateTo(q::getConvertedValue); return q; @@ -201,8 +158,7 @@ public abstract class Dialog { DialogElement currentElement = ds[current].receive(answer); if (currentElement == null) { DialogElement next = null; - while (current < ds.length - 1 && (next = ds[++current].start()) == null) { - } + while (current < ds.length - 1 && (next = ds[++current].start()) == null) {} ; return next; } @@ -218,7 +174,6 @@ public abstract class Dialog { public static Dialog repeatIf(Dialog d, Predicate shouldRepeat) { return new Dialog() { - @Override public DialogElement start() throws Exception { eval = null; @@ -272,11 +227,6 @@ public abstract class Dialog { return of(new BusyElement()); } - public static interface FailableSupplier { - - T get() throws Exception; - } - /** * Creates a dialogue that will only evaluate when needed. * This allows a dialogue to incorporate completion information about a previous dialogue. @@ -305,7 +255,6 @@ public abstract class Dialog { private static Dialog of(DialogElement e) { return new Dialog() { - @Override public DialogElement start() throws Exception { eval = null; @@ -323,7 +272,6 @@ public abstract class Dialog { }; } - /** * Creates a dialogue that will not be executed if the condition is true. */ @@ -393,7 +341,12 @@ public abstract class Dialog { * @param selected the index of the element that is selected by default * @param c the dialogue index mapping function */ - public static Dialog fork(String description, List elements, boolean required, int selected, Function c) { + public static Dialog fork( + String description, + List elements, + boolean required, + int selected, + Function c) { var choice = new ChoiceElement(description, elements, required, selected); return new Dialog() { @@ -427,13 +380,9 @@ public abstract class Dialog { }; } - protected Object eval; - private Supplier evaluation; - private final List> completion = new ArrayList<>(); - /* TODO: Implement automatic completion mechanism for start as well - * In case start returns null, the completion is not automatically done. - * */ + * In case start returns null, the completion is not automatically done. + * */ public abstract DialogElement start() throws Exception; public Dialog evaluateTo(Dialog d) { @@ -493,4 +442,75 @@ public abstract class Dialog { } protected abstract DialogElement next(String answer) throws Exception; + + public static interface FailableSupplier { + + T get() throws Exception; + } + + public static class Choice extends Dialog { + + private final ChoiceElement element; + + private Choice(String description, List elements, boolean required, int selected) { + this.element = new ChoiceElement(description, elements, required, selected); + } + + @Override + public DialogElement start() throws Exception { + return element; + } + + @Override + protected DialogElement next(String answer) throws Exception { + if (element.apply(answer)) { + return null; + } + + return element; + } + + private int getSelected() { + return element.getSelected(); + } + } + + public static class Query extends Dialog { + + private final QueryElement element; + + private Query( + String description, + boolean newLine, + boolean required, + boolean quiet, + T value, + QueryConverter converter, + boolean hidden) { + this.element = new QueryElement(description, newLine, required, quiet, value, converter, hidden); + } + + @Override + public DialogElement start() throws Exception { + return element; + } + + @Override + protected DialogElement next(String answer) throws Exception { + if (element.requiresExplicitUserInput() + && (answer == null || answer.trim().length() == 0)) { + return element; + } + + if (element.apply(answer)) { + return null; + } + + return element; + } + + private T getConvertedValue() { + return element.getConvertedValue(); + } + } } diff --git a/core/src/main/java/io/xpipe/core/dialog/DialogCancelException.java b/core/src/main/java/io/xpipe/core/dialog/DialogCancelException.java index ba3436dfe..e27b672ff 100644 --- a/core/src/main/java/io/xpipe/core/dialog/DialogCancelException.java +++ b/core/src/main/java/io/xpipe/core/dialog/DialogCancelException.java @@ -5,8 +5,7 @@ package io.xpipe.core.dialog; */ public class DialogCancelException extends Exception { - public DialogCancelException() { - } + public DialogCancelException() {} public DialogCancelException(String message) { super(message); @@ -20,7 +19,8 @@ public class DialogCancelException extends Exception { super(cause); } - public DialogCancelException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + public DialogCancelException( + String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } } diff --git a/core/src/main/java/io/xpipe/core/dialog/QueryConverter.java b/core/src/main/java/io/xpipe/core/dialog/QueryConverter.java index 24c7e9ae9..12f166a6c 100644 --- a/core/src/main/java/io/xpipe/core/dialog/QueryConverter.java +++ b/core/src/main/java/io/xpipe/core/dialog/QueryConverter.java @@ -23,7 +23,6 @@ public abstract class QueryConverter { } }; - public static final QueryConverter CHARSET = new QueryConverter() { @Override protected StreamCharset fromString(String s) { @@ -60,26 +59,27 @@ public abstract class QueryConverter { } }; - public static final QueryConverter> HTTP_HEADER = new QueryConverter>() { - @Override - protected Map.Entry fromString(String s) { - if (!s.contains(":")) { - throw new IllegalArgumentException("Missing colon"); - } + public static final QueryConverter> HTTP_HEADER = + new QueryConverter>() { + @Override + protected Map.Entry fromString(String s) { + if (!s.contains(":")) { + throw new IllegalArgumentException("Missing colon"); + } - var split = s.split(":"); - if (split.length != 2) { - throw new IllegalArgumentException("Too many colons"); - } + var split = s.split(":"); + if (split.length != 2) { + throw new IllegalArgumentException("Too many colons"); + } - return new AbstractMap.SimpleEntry<>(split[0].trim(), split[1].trim()); - } + return new AbstractMap.SimpleEntry<>(split[0].trim(), split[1].trim()); + } - @Override - protected String toString(Map.Entry value) { - return value.getKey() + ": " + value.getValue(); - } - }; + @Override + protected String toString(Map.Entry value) { + return value.getKey() + ": " + value.getValue(); + } + }; public static final QueryConverter URI = new QueryConverter() { @Override @@ -141,9 +141,7 @@ public abstract class QueryConverter { @Override protected String toString(Boolean value) { - return value ? - "yes" : - "no"; + return value ? "yes" : "no"; } }; diff --git a/core/src/main/java/io/xpipe/core/dialog/QueryElement.java b/core/src/main/java/io/xpipe/core/dialog/QueryElement.java index 1d4fdbd96..e2c374cfc 100644 --- a/core/src/main/java/io/xpipe/core/dialog/QueryElement.java +++ b/core/src/main/java/io/xpipe/core/dialog/QueryElement.java @@ -7,7 +7,14 @@ public class QueryElement extends BaseQueryElement { private final QueryConverter converter; - public QueryElement(String description, boolean newLine, boolean required, boolean quiet, T value, QueryConverter converter, boolean hidden) { + public QueryElement( + String description, + boolean newLine, + boolean required, + boolean quiet, + T value, + QueryConverter converter, + boolean hidden) { super(description, newLine, required, hidden, quiet, value != null ? converter.toString(value) : null); this.converter = converter; } diff --git a/core/src/main/java/io/xpipe/core/impl/BatchTableWriteConnection.java b/core/src/main/java/io/xpipe/core/impl/BatchTableWriteConnection.java index 4a9caf615..6b285d93f 100644 --- a/core/src/main/java/io/xpipe/core/impl/BatchTableWriteConnection.java +++ b/core/src/main/java/io/xpipe/core/impl/BatchTableWriteConnection.java @@ -50,5 +50,3 @@ public abstract class BatchTableWriteConnection implements TableWriteConnection protected abstract DataStructureNodeAcceptor writeBatchLinesAcceptor(); } - - diff --git a/core/src/main/java/io/xpipe/core/impl/BinarySource.java b/core/src/main/java/io/xpipe/core/impl/BinarySource.java index 7c9adcde3..aa6e57aa1 100644 --- a/core/src/main/java/io/xpipe/core/impl/BinarySource.java +++ b/core/src/main/java/io/xpipe/core/impl/BinarySource.java @@ -37,7 +37,6 @@ public class BinarySource extends RawDataSource { }; } - @Override protected RawReadConnection newReadConnection() { return new RawReadConnection() { diff --git a/core/src/main/java/io/xpipe/core/impl/LimitTableReadConnection.java b/core/src/main/java/io/xpipe/core/impl/LimitTableReadConnection.java index 595bc52bc..cee48d245 100644 --- a/core/src/main/java/io/xpipe/core/impl/LimitTableReadConnection.java +++ b/core/src/main/java/io/xpipe/core/impl/LimitTableReadConnection.java @@ -48,8 +48,7 @@ public class LimitTableReadConnection implements TableReadConnection { } count++; - var returned = lineAcceptor - .accept(node); + var returned = lineAcceptor.accept(node); localCounter.getAndIncrement(); return returned; diff --git a/core/src/main/java/io/xpipe/core/impl/PreservingTableWriteConnection.java b/core/src/main/java/io/xpipe/core/impl/PreservingTableWriteConnection.java index 286c4a4d6..d35b9cb01 100644 --- a/core/src/main/java/io/xpipe/core/impl/PreservingTableWriteConnection.java +++ b/core/src/main/java/io/xpipe/core/impl/PreservingTableWriteConnection.java @@ -9,14 +9,12 @@ import io.xpipe.core.source.TableWriteConnection; public class PreservingTableWriteConnection extends PreservingWriteConnection implements TableWriteConnection { - public PreservingTableWriteConnection(DataSource source, DataSourceConnection connection, - boolean append - ) { + public PreservingTableWriteConnection(DataSource source, DataSourceConnection connection, boolean append) { super(DataSourceType.TABLE, source, append, connection); } @Override public DataStructureNodeAcceptor writeLinesAcceptor() { - return ((TableWriteConnection)connection).writeLinesAcceptor(); + return ((TableWriteConnection) connection).writeLinesAcceptor(); } } diff --git a/core/src/main/java/io/xpipe/core/impl/PreservingTextWriteConnection.java b/core/src/main/java/io/xpipe/core/impl/PreservingTextWriteConnection.java index 976710afa..ef740011a 100644 --- a/core/src/main/java/io/xpipe/core/impl/PreservingTextWriteConnection.java +++ b/core/src/main/java/io/xpipe/core/impl/PreservingTextWriteConnection.java @@ -7,10 +7,7 @@ import io.xpipe.core.source.TextWriteConnection; public class PreservingTextWriteConnection extends PreservingWriteConnection implements TextWriteConnection { - public PreservingTextWriteConnection( - DataSource source, DataSourceConnection connection, - boolean append - ) { + public PreservingTextWriteConnection(DataSource source, DataSourceConnection connection, boolean append) { super(DataSourceType.TEXT, source, append, connection); } diff --git a/core/src/main/java/io/xpipe/core/impl/PreservingWriteConnection.java b/core/src/main/java/io/xpipe/core/impl/PreservingWriteConnection.java index ff581de78..8b101f7f9 100644 --- a/core/src/main/java/io/xpipe/core/impl/PreservingWriteConnection.java +++ b/core/src/main/java/io/xpipe/core/impl/PreservingWriteConnection.java @@ -9,12 +9,13 @@ import java.nio.file.Files; public class PreservingWriteConnection implements DataSourceConnection { + protected final DataSourceConnection connection; private final DataSourceType type; private final DataSource source; - private final boolean append ; - protected final DataSourceConnection connection; + private final boolean append; - public PreservingWriteConnection(DataSourceType type, DataSource source, boolean append, DataSourceConnection connection) { + public PreservingWriteConnection( + DataSourceType type, DataSource source, boolean append, DataSourceConnection connection) { this.type = type; this.source = source; this.append = append; @@ -26,13 +27,13 @@ public class PreservingWriteConnection implements DataSourceConnection { var nativeStore = FileStore.local(temp); var nativeSource = DataSource.createInternalDataSource(type, nativeStore); if (source.getStore().canOpen()) { - try (var in = source.openReadConnection(); var out = nativeSource.openWriteConnection()) { + try (var in = source.openReadConnection(); + var out = nativeSource.openWriteConnection()) { in.forward(out); } ; } - connection.init(); if (source.getStore().canOpen()) { @@ -45,5 +46,4 @@ public class PreservingWriteConnection implements DataSourceConnection { public void close() throws Exception { connection.close(); } - } diff --git a/core/src/main/java/io/xpipe/core/impl/TextReadConnection.java b/core/src/main/java/io/xpipe/core/impl/TextReadConnection.java index e8bcadae7..a7a72c73d 100644 --- a/core/src/main/java/io/xpipe/core/impl/TextReadConnection.java +++ b/core/src/main/java/io/xpipe/core/impl/TextReadConnection.java @@ -24,7 +24,6 @@ public class TextReadConnection extends StreamReadConnection implements io.xpipe return bufferedReader.lines(); } - @Override public void close() throws Exception { bufferedReader.close(); diff --git a/core/src/main/java/io/xpipe/core/impl/TextSource.java b/core/src/main/java/io/xpipe/core/impl/TextSource.java index f966e07fa..b464d7603 100644 --- a/core/src/main/java/io/xpipe/core/impl/TextSource.java +++ b/core/src/main/java/io/xpipe/core/impl/TextSource.java @@ -14,7 +14,7 @@ import lombok.extern.jackson.Jacksonized; @JsonTypeName("text") @SuperBuilder @Jacksonized -public final class TextSource extends TextDataSource implements Charsettable { +public final class TextSource extends TextDataSource implements Charsettable { private final StreamCharset charset; private final NewLine newLine; diff --git a/core/src/main/java/io/xpipe/core/impl/XpbsWriteConnection.java b/core/src/main/java/io/xpipe/core/impl/XpbsWriteConnection.java index 4186a807d..5cc13e553 100644 --- a/core/src/main/java/io/xpipe/core/impl/XpbsWriteConnection.java +++ b/core/src/main/java/io/xpipe/core/impl/XpbsWriteConnection.java @@ -13,6 +13,6 @@ public class XpbsWriteConnection extends StreamWriteConnection implements Struct @Override public void write(DataStructureNode node) throws Exception { - GenericDataStreamWriter.writeStructure(outputStream,node); + GenericDataStreamWriter.writeStructure(outputStream, node); } } diff --git a/core/src/main/java/io/xpipe/core/impl/XpbtReadConnection.java b/core/src/main/java/io/xpipe/core/impl/XpbtReadConnection.java index 663916c98..61336271d 100644 --- a/core/src/main/java/io/xpipe/core/impl/XpbtReadConnection.java +++ b/core/src/main/java/io/xpipe/core/impl/XpbtReadConnection.java @@ -21,6 +21,15 @@ import java.util.concurrent.atomic.AtomicReference; public class XpbtReadConnection implements TableReadConnection { + private final StreamDataStore store; + private TupleType dataType; + private InputStream inputStream; + private TypedDataStreamParser parser; + private boolean empty; + protected XpbtReadConnection(StreamDataStore store) { + this.store = store; + } + @Override public void init() throws Exception { this.inputStream = store.openBufferedInput(); @@ -36,8 +45,8 @@ public class XpbtReadConnection implements TableReadConnection { this.inputStream.skip(headerLength + 1); List names = JacksonMapper.newMapper() .disable(JsonParser.Feature.AUTO_CLOSE_SOURCE) - .readerFor(new TypeReference>() { - }).readValue(header); + .readerFor(new TypeReference>() {}) + .readValue(header); TupleType dataType = TupleType.tableType(names); this.dataType = dataType; this.parser = new TypedDataStreamParser(dataType); @@ -48,16 +57,6 @@ public class XpbtReadConnection implements TableReadConnection { inputStream.close(); } - private TupleType dataType; - private final StreamDataStore store; - private InputStream inputStream; - private TypedDataStreamParser parser; - private boolean empty; - - protected XpbtReadConnection(StreamDataStore store) { - this.store = store; - } - @Override public TupleType getDataType() { return dataType; diff --git a/core/src/main/java/io/xpipe/core/impl/XpbtSource.java b/core/src/main/java/io/xpipe/core/impl/XpbtSource.java index 8079dac74..a68a62319 100644 --- a/core/src/main/java/io/xpipe/core/impl/XpbtSource.java +++ b/core/src/main/java/io/xpipe/core/impl/XpbtSource.java @@ -13,8 +13,6 @@ import lombok.extern.jackson.Jacksonized; @Jacksonized public class XpbtSource extends TableDataSource { - - @Override protected TableWriteConnection newWriteConnection() { return new XpbtWriteConnection(store); diff --git a/core/src/main/java/io/xpipe/core/impl/XpbtWriteConnection.java b/core/src/main/java/io/xpipe/core/impl/XpbtWriteConnection.java index dd254aceb..843fa249e 100644 --- a/core/src/main/java/io/xpipe/core/impl/XpbtWriteConnection.java +++ b/core/src/main/java/io/xpipe/core/impl/XpbtWriteConnection.java @@ -58,7 +58,8 @@ public class XpbtWriteConnection implements TableWriteConnection { try (JsonGenerator g = f.createGenerator(writer) .disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET) .setPrettyPrinter(new DefaultPrettyPrinter())) { - JacksonMapper.newMapper().disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET) + JacksonMapper.newMapper() + .disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET) .writeValue(g, tupleNode.getKeyNames()); writer.append("\n"); } diff --git a/core/src/main/java/io/xpipe/core/source/CollectionReadConnection.java b/core/src/main/java/io/xpipe/core/source/CollectionReadConnection.java index 2d368ad83..73404f9eb 100644 --- a/core/src/main/java/io/xpipe/core/source/CollectionReadConnection.java +++ b/core/src/main/java/io/xpipe/core/source/CollectionReadConnection.java @@ -14,9 +14,9 @@ public interface CollectionReadConnection extends DataSourceReadConnection { try (var tCon = (CollectionWriteConnection) con) { tCon.init(); listEntries().forEach(s -> { -// try (var subCon = open(s)) { -// ((CollectionWriteConnection) con).write(s, subCon); -// } + // try (var subCon = open(s)) { + // ((CollectionWriteConnection) con).write(s, subCon); + // } }); } } diff --git a/core/src/main/java/io/xpipe/core/source/DataSource.java b/core/src/main/java/io/xpipe/core/source/DataSource.java index 66de27901..abb54d0e2 100644 --- a/core/src/main/java/io/xpipe/core/source/DataSource.java +++ b/core/src/main/java/io/xpipe/core/source/DataSource.java @@ -22,22 +22,23 @@ import java.util.Optional; * This instance is only valid in combination with its associated data store instance. */ @SuperBuilder -@JsonTypeInfo( - use = JsonTypeInfo.Id.NAME, - property = "type" -) +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") public abstract class DataSource extends JacksonizedValue { + protected DS store; public static DataSource createInternalDataSource(DataSourceType t, DataStore store) { try { return switch (t) { - case TABLE -> XpbtSource.builder().store(store.asNeeded()).build(); + case TABLE -> XpbtSource.builder().store(store.asNeeded()).build(); case STRUCTURE -> null; - case TEXT -> TextSource.builder().store(store.asNeeded()).newLine(NewLine.LF).charset( - StreamCharset.UTF8).build(); + case TEXT -> TextSource.builder() + .store(store.asNeeded()) + .newLine(NewLine.LF) + .charset(StreamCharset.UTF8) + .build(); case RAW -> null; - //TODO + // TODO case COLLECTION -> null; }; } catch (Exception ex) { @@ -45,9 +46,6 @@ public abstract class DataSource extends JacksonizedValue } } - protected DS store; - - public void test() throws Exception { store.validate(); } @@ -68,7 +66,6 @@ public abstract class DataSource extends JacksonizedValue return WriteMode.values(); } - public DataFlow getFlow() { if (store == null) { return null; diff --git a/core/src/main/java/io/xpipe/core/source/DataSourceId.java b/core/src/main/java/io/xpipe/core/source/DataSourceId.java index 4f9662399..c43d45b87 100644 --- a/core/src/main/java/io/xpipe/core/source/DataSourceId.java +++ b/core/src/main/java/io/xpipe/core/source/DataSourceId.java @@ -49,7 +49,8 @@ public class DataSourceId { throw new IllegalArgumentException("Trimmed collection name is empty"); } if (collectionName != null && collectionName.contains("" + SEPARATOR)) { - throw new IllegalArgumentException("Separator character " + SEPARATOR + " is not allowed in the collection name"); + throw new IllegalArgumentException( + "Separator character " + SEPARATOR + " is not allowed in the collection name"); } if (entryName == null) { @@ -59,7 +60,8 @@ public class DataSourceId { throw new IllegalArgumentException("Trimmed entry name is empty"); } if (entryName.contains("" + SEPARATOR)) { - throw new IllegalArgumentException("Separator character " + SEPARATOR + " is not allowed in the entry name"); + throw new IllegalArgumentException( + "Separator character " + SEPARATOR + " is not allowed in the entry name"); } return new DataSourceId(collectionName, entryName); diff --git a/core/src/main/java/io/xpipe/core/source/DataSourceInfo.java b/core/src/main/java/io/xpipe/core/source/DataSourceInfo.java index 5a28d942c..7bea823f3 100644 --- a/core/src/main/java/io/xpipe/core/source/DataSourceInfo.java +++ b/core/src/main/java/io/xpipe/core/source/DataSourceInfo.java @@ -23,6 +23,61 @@ public abstract class DataSourceInfo { public abstract DataSourceType getType(); + /** + * Casts this instance to a table info. + */ + public Table asTable() { + if (!getType().equals(DataSourceType.TABLE)) { + throw new IllegalStateException("Not a table"); + } + + return (Table) this; + } + + /** + * Casts this instance to a structure info. + */ + public Structure asStructure() { + if (!getType().equals(DataSourceType.STRUCTURE)) { + throw new IllegalStateException("Not a structure"); + } + + return (Structure) this; + } + + /** + * Casts this instance to a text info. + */ + public Text asText() { + if (!getType().equals(DataSourceType.TEXT)) { + throw new IllegalStateException("Not a text"); + } + + return (Text) this; + } + + /** + * Casts this instance to a raw info. + */ + public Raw asRaw() { + if (!getType().equals(DataSourceType.RAW)) { + throw new IllegalStateException("Not raw"); + } + + return (Raw) this; + } + + /** + * Casts this instance to a collection info. + */ + public Collection asCollection() { + if (!getType().equals(DataSourceType.COLLECTION)) { + throw new IllegalStateException("Not a collection"); + } + + return (Collection) this; + } + @EqualsAndHashCode(callSuper = false) @Value @JsonTypeName("table") @@ -101,7 +156,6 @@ public abstract class DataSourceInfo { } } - @EqualsAndHashCode(callSuper = false) @Value @JsonTypeName("raw") @@ -118,59 +172,4 @@ public abstract class DataSourceInfo { return DataSourceType.RAW; } } - - /** - * Casts this instance to a table info. - */ - public Table asTable() { - if (!getType().equals(DataSourceType.TABLE)) { - throw new IllegalStateException("Not a table"); - } - - return (Table) this; - } - - /** - * Casts this instance to a structure info. - */ - public Structure asStructure() { - if (!getType().equals(DataSourceType.STRUCTURE)) { - throw new IllegalStateException("Not a structure"); - } - - return (Structure) this; - } - - /** - * Casts this instance to a text info. - */ - public Text asText() { - if (!getType().equals(DataSourceType.TEXT)) { - throw new IllegalStateException("Not a text"); - } - - return (Text) this; - } - - /** - * Casts this instance to a raw info. - */ - public Raw asRaw() { - if (!getType().equals(DataSourceType.RAW)) { - throw new IllegalStateException("Not raw"); - } - - return (Raw) this; - } - - /** - * Casts this instance to a collection info. - */ - public Collection asCollection() { - if (!getType().equals(DataSourceType.COLLECTION)) { - throw new IllegalStateException("Not a collection"); - } - - return (Collection) this; - } } diff --git a/core/src/main/java/io/xpipe/core/source/DataSourceReference.java b/core/src/main/java/io/xpipe/core/source/DataSourceReference.java index b3a0bb6d0..07444442e 100644 --- a/core/src/main/java/io/xpipe/core/source/DataSourceReference.java +++ b/core/src/main/java/io/xpipe/core/source/DataSourceReference.java @@ -65,14 +65,10 @@ public interface DataSourceReference { return new Name(s.trim()); } - enum Type { - ID, - NAME, - LATEST - } - Type getType(); + DataSourceId getId(); + String getName(); /** @@ -82,6 +78,12 @@ public interface DataSourceReference { String toString(); + enum Type { + ID, + NAME, + LATEST + } + /** * A wrapper class for {@link DataSourceId} instances. */ diff --git a/core/src/main/java/io/xpipe/core/source/DataSourceType.java b/core/src/main/java/io/xpipe/core/source/DataSourceType.java index d6c617a47..238039819 100644 --- a/core/src/main/java/io/xpipe/core/source/DataSourceType.java +++ b/core/src/main/java/io/xpipe/core/source/DataSourceType.java @@ -7,7 +7,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; * This distinction is necessary as the general workflow differs for each type. */ public enum DataSourceType { - @JsonProperty("table") TABLE, diff --git a/core/src/main/java/io/xpipe/core/source/RawReadConnection.java b/core/src/main/java/io/xpipe/core/source/RawReadConnection.java index fda548788..ece5fb80a 100644 --- a/core/src/main/java/io/xpipe/core/source/RawReadConnection.java +++ b/core/src/main/java/io/xpipe/core/source/RawReadConnection.java @@ -4,10 +4,10 @@ import java.io.OutputStream; public interface RawReadConnection extends DataSourceReadConnection { - byte[] readBytes(int max) throws Exception; - int BUFFER_SIZE = 8192; + byte[] readBytes(int max) throws Exception; + default void forwardBytes(OutputStream out, int maxBytes) throws Exception { if (maxBytes == 0) { return; diff --git a/core/src/main/java/io/xpipe/core/source/StreamReadConnection.java b/core/src/main/java/io/xpipe/core/source/StreamReadConnection.java index 9e60b3551..2e18f3c8a 100644 --- a/core/src/main/java/io/xpipe/core/source/StreamReadConnection.java +++ b/core/src/main/java/io/xpipe/core/source/StreamReadConnection.java @@ -9,10 +9,10 @@ import java.io.Reader; public abstract class StreamReadConnection implements DataSourceReadConnection { + protected final StreamDataStore store; + private final StreamCharset charset; protected InputStream inputStream; protected Reader reader; - private final StreamCharset charset; - protected final StreamDataStore store; public StreamReadConnection(StreamDataStore store, StreamCharset charset) { this.store = store; diff --git a/core/src/main/java/io/xpipe/core/source/StreamWriteConnection.java b/core/src/main/java/io/xpipe/core/source/StreamWriteConnection.java index 92d49e436..b4b66a249 100644 --- a/core/src/main/java/io/xpipe/core/source/StreamWriteConnection.java +++ b/core/src/main/java/io/xpipe/core/source/StreamWriteConnection.java @@ -9,8 +9,8 @@ import java.io.OutputStreamWriter; public class StreamWriteConnection implements DataSourceConnection { protected final StreamDataStore store; - protected OutputStream outputStream; private final StreamCharset charset; + protected OutputStream outputStream; protected OutputStreamWriter writer; public StreamWriteConnection(StreamDataStore store, StreamCharset charset) { @@ -27,8 +27,7 @@ public class StreamWriteConnection implements DataSourceConnection { outputStream = store.openOutput(); if (charset != null) { if (charset.hasByteOrderMark()) { - outputStream - .write(charset.getByteOrderMark()); + outputStream.write(charset.getByteOrderMark()); } writer = new OutputStreamWriter(outputStream, charset.getCharset()); } diff --git a/core/src/main/java/io/xpipe/core/source/TableReadConnection.java b/core/src/main/java/io/xpipe/core/source/TableReadConnection.java index b17afcafa..9f7f3c9b6 100644 --- a/core/src/main/java/io/xpipe/core/source/TableReadConnection.java +++ b/core/src/main/java/io/xpipe/core/source/TableReadConnection.java @@ -1,9 +1,8 @@ package io.xpipe.core.source; - +import io.xpipe.core.data.node.ArrayNode; import io.xpipe.core.data.node.DataStructureNode; import io.xpipe.core.data.node.DataStructureNodeAcceptor; -import io.xpipe.core.data.node.ArrayNode; import io.xpipe.core.data.node.TupleNode; import io.xpipe.core.data.type.TupleType; import io.xpipe.core.data.typed.TypedDataStreamWriter; diff --git a/core/src/main/java/io/xpipe/core/source/TableWriteConnection.java b/core/src/main/java/io/xpipe/core/source/TableWriteConnection.java index 802cb8885..0c342bc89 100644 --- a/core/src/main/java/io/xpipe/core/source/TableWriteConnection.java +++ b/core/src/main/java/io/xpipe/core/source/TableWriteConnection.java @@ -1,8 +1,8 @@ package io.xpipe.core.source; +import io.xpipe.core.data.node.ArrayNode; import io.xpipe.core.data.node.DataStructureNode; import io.xpipe.core.data.node.DataStructureNodeAcceptor; -import io.xpipe.core.data.node.ArrayNode; import io.xpipe.core.data.node.TupleNode; /** diff --git a/core/src/main/java/io/xpipe/core/source/TextDataSource.java b/core/src/main/java/io/xpipe/core/source/TextDataSource.java index dfb9d9650..e9258978e 100644 --- a/core/src/main/java/io/xpipe/core/source/TextDataSource.java +++ b/core/src/main/java/io/xpipe/core/source/TextDataSource.java @@ -50,7 +50,6 @@ public abstract class TextDataSource extends DataSource extends DataSource { - R apply(T input) throws E; - - } - private final FailableFunction, DataSourceConnection, Exception> connectionOpener; WriteMode(FailableFunction, DataSourceConnection, Exception> connectionOpener) { @@ -24,4 +19,8 @@ public enum WriteMode { public DataSourceConnection open(DataSource source) throws Exception { return connectionOpener.apply(source); } + + public static interface FailableFunction { + R apply(T input) throws E; + } } diff --git a/core/src/main/java/io/xpipe/core/store/CollectionEntryDataStore.java b/core/src/main/java/io/xpipe/core/store/CollectionEntryDataStore.java index 7834bafeb..2628ace78 100644 --- a/core/src/main/java/io/xpipe/core/store/CollectionEntryDataStore.java +++ b/core/src/main/java/io/xpipe/core/store/CollectionEntryDataStore.java @@ -6,7 +6,6 @@ public abstract class CollectionEntryDataStore implements FilenameStore, StreamD private final String name; private final DataStore collectionStore; - public CollectionEntryDataStore(boolean directory, String name, DataStore collectionStore) { this.directory = directory; this.name = name; diff --git a/core/src/main/java/io/xpipe/core/store/DataFlow.java b/core/src/main/java/io/xpipe/core/store/DataFlow.java index e62c6dbc2..fa3e0c78b 100644 --- a/core/src/main/java/io/xpipe/core/store/DataFlow.java +++ b/core/src/main/java/io/xpipe/core/store/DataFlow.java @@ -3,7 +3,6 @@ package io.xpipe.core.store; import com.fasterxml.jackson.annotation.JsonProperty; public enum DataFlow { - @JsonProperty("input") INPUT, @JsonProperty("output") diff --git a/core/src/main/java/io/xpipe/core/store/DataStore.java b/core/src/main/java/io/xpipe/core/store/DataStore.java index 0378102d1..bf616dce5 100644 --- a/core/src/main/java/io/xpipe/core/store/DataStore.java +++ b/core/src/main/java/io/xpipe/core/store/DataStore.java @@ -28,7 +28,6 @@ public interface DataStore { return true; } - /** * Indicates whether this data store can only be accessed by the current running application. * One example are standard in and standard out stores. @@ -56,17 +55,14 @@ public interface DataStore { * * @throws Exception if any part of the validation went wrong */ - default void validate() throws Exception { - } + default void validate() throws Exception {} - default void checkComplete() throws Exception { - } + default void checkComplete() throws Exception {} default boolean delete() throws Exception { return false; } - /** * Casts this instance to the required type without checking whether a cast is possible. */ diff --git a/core/src/main/java/io/xpipe/core/store/DataStoreFormatter.java b/core/src/main/java/io/xpipe/core/store/DataStoreFormatter.java index ac8c93f53..3ac0ba1af 100644 --- a/core/src/main/java/io/xpipe/core/store/DataStoreFormatter.java +++ b/core/src/main/java/io/xpipe/core/store/DataStoreFormatter.java @@ -10,7 +10,6 @@ public class DataStoreFormatter { return input; } - public static String specialFormatHostName(String input) { if (input.contains(":")) { input = input.split(":")[0]; diff --git a/core/src/main/java/io/xpipe/core/store/FileStore.java b/core/src/main/java/io/xpipe/core/store/FileStore.java index bd9cb3a31..9188c4ed3 100644 --- a/core/src/main/java/io/xpipe/core/store/FileStore.java +++ b/core/src/main/java/io/xpipe/core/store/FileStore.java @@ -19,6 +19,14 @@ import java.nio.file.Path; @Getter public class FileStore extends JacksonizedValue implements FilenameStore, StreamDataStore { + MachineFileStore machine; + String file; + + public FileStore(MachineFileStore machine, String file) { + this.machine = machine; + this.file = file; + } + public static FileStore local(Path p) { return new FileStore(new LocalStore(), p.toString()); } @@ -30,14 +38,6 @@ public class FileStore extends JacksonizedValue implements FilenameStore, Stream return new FileStore(new LocalStore(), p); } - MachineFileStore machine; - String file; - - public FileStore(MachineFileStore machine, String file) { - this.machine = machine; - this.file = file; - } - @Override public void checkComplete() throws Exception { if (machine == null) { @@ -46,7 +46,6 @@ public class FileStore extends JacksonizedValue implements FilenameStore, Stream if (file == null) { throw new IllegalStateException("File is missing"); } - } @Override @@ -72,5 +71,4 @@ public class FileStore extends JacksonizedValue implements FilenameStore, Stream } return split[split.length - 1]; } - } diff --git a/core/src/main/java/io/xpipe/core/store/FilenameStore.java b/core/src/main/java/io/xpipe/core/store/FilenameStore.java index 224ae56e1..571a66b60 100644 --- a/core/src/main/java/io/xpipe/core/store/FilenameStore.java +++ b/core/src/main/java/io/xpipe/core/store/FilenameStore.java @@ -15,8 +15,7 @@ public interface FilenameStore extends DataStore { return Optional.of(i != -1 ? n.substring(0, i) : n); } - - default String getFileExtension() { + default String getFileExtension() { var split = getFileName().split("[\\\\.]"); if (split.length == 0) { return ""; diff --git a/core/src/main/java/io/xpipe/core/store/InMemoryStore.java b/core/src/main/java/io/xpipe/core/store/InMemoryStore.java index fa25c56e7..3fdb4d3cc 100644 --- a/core/src/main/java/io/xpipe/core/store/InMemoryStore.java +++ b/core/src/main/java/io/xpipe/core/store/InMemoryStore.java @@ -20,7 +20,6 @@ public class InMemoryStore extends JacksonizedValue implements StreamDataStore { private byte[] value; - @JsonCreator public InMemoryStore(byte[] value) { this.value = value; @@ -38,7 +37,7 @@ public class InMemoryStore extends JacksonizedValue implements StreamDataStore { @Override public OutputStream openOutput() throws Exception { - return new ByteArrayOutputStream(){ + return new ByteArrayOutputStream() { @Override public void close() throws IOException { super.close(); diff --git a/core/src/main/java/io/xpipe/core/store/LocalDirectoryDataStore.java b/core/src/main/java/io/xpipe/core/store/LocalDirectoryDataStore.java index c0f075b67..f9c904f9e 100644 --- a/core/src/main/java/io/xpipe/core/store/LocalDirectoryDataStore.java +++ b/core/src/main/java/io/xpipe/core/store/LocalDirectoryDataStore.java @@ -39,5 +39,4 @@ public class LocalDirectoryDataStore implements DataStore { public Path getPath() { return file; } - } diff --git a/core/src/main/java/io/xpipe/core/store/LocalStore.java b/core/src/main/java/io/xpipe/core/store/LocalStore.java index aa590a6ae..5bbe3b727 100644 --- a/core/src/main/java/io/xpipe/core/store/LocalStore.java +++ b/core/src/main/java/io/xpipe/core/store/LocalStore.java @@ -22,7 +22,51 @@ public class LocalStore extends JacksonizedValue implements MachineFileStore, St return true; } - class LocalProcessControl extends ProcessControl { + @Override + public boolean exists(String file) { + return Files.exists(Path.of(file)); + } + + @Override + public void mkdirs(String file) throws Exception { + Files.createDirectories(Path.of(file).getParent()); + } + + @Override + public NewLine getNewLine() { + return ShellTypes.getDefault().getNewLine(); + } + + @Override + public InputStream openInput(String file) throws Exception { + var p = Path.of(file); + return Files.newInputStream(p); + } + + @Override + public OutputStream openOutput(String file) throws Exception { + mkdirs(file); + var p = Path.of(file); + return Files.newOutputStream(p); + } + + @Override + public ProcessControl prepareCommand(List input, List cmd, Integer timeout) { + return new LocalProcessControl(input, cmd, getEffectiveTimeOut(timeout)); + } + + @Override + public ProcessControl preparePrivilegedCommand(List input, List cmd, Integer timeOut) + throws Exception { + return new LocalProcessControl(input, cmd, getEffectiveTimeOut(timeOut)); + } + + @Override + public ShellType determineType() throws Exception { + return ShellTypes.getDefault(); + } + + class LocalProcessControl extends ProcessControl { private final List input; private final Integer timeout; @@ -38,7 +82,8 @@ public class LocalStore extends JacksonizedValue implements MachineFileStore, St } private InputStream createInputStream() { - var string = input.stream().map(secret -> secret.getSecretValue()).collect(Collectors.joining("\n")) + "\r\n"; + var string = + input.stream().map(secret -> secret.getSecretValue()).collect(Collectors.joining("\n")) + "\r\n"; return new ByteArrayInputStream(string.getBytes(StandardCharsets.US_ASCII)); } @@ -51,7 +96,7 @@ public class LocalStore extends JacksonizedValue implements MachineFileStore, St charset = type.determineCharset(LocalStore.this); var t = new Thread(() -> { - try (var inputStream = createInputStream()){ + try (var inputStream = createInputStream()) { process.getOutputStream().flush(); inputStream.transferTo(process.getOutputStream()); process.getOutputStream().close(); @@ -77,12 +122,12 @@ public class LocalStore extends JacksonizedValue implements MachineFileStore, St return process.getInputStream(); } - @Override - public OutputStream getStdin() { - return process.getOutputStream(); - } + @Override + public OutputStream getStdin() { + return process.getOutputStream(); + } - @Override + @Override public InputStream getStderr() { return process.getErrorStream(); } @@ -96,48 +141,4 @@ public class LocalStore extends JacksonizedValue implements MachineFileStore, St return timeout; } } - - @Override - public boolean exists(String file) { - return Files.exists(Path.of(file)); - } - - @Override - public void mkdirs(String file) throws Exception { - Files.createDirectories(Path.of(file).getParent()); - } - - @Override - public NewLine getNewLine() { - return ShellTypes.getDefault().getNewLine(); - } - - - @Override - public InputStream openInput(String file) throws Exception { - var p = Path.of(file); - return Files.newInputStream(p); - } - - @Override - public OutputStream openOutput(String file) throws Exception { - mkdirs(file); - var p = Path.of(file); - return Files.newOutputStream(p); - } - - @Override - public ProcessControl prepareCommand(List input, List cmd, Integer timeout) { - return new LocalProcessControl(input, cmd, getEffectiveTimeOut(timeout)); - } - - @Override - public ProcessControl preparePrivilegedCommand(List input, List cmd, Integer timeOut) throws Exception { - return new LocalProcessControl(input, cmd, getEffectiveTimeOut(timeOut)); - } - - @Override - public ShellType determineType() throws Exception { - return ShellTypes.getDefault(); - } } diff --git a/core/src/main/java/io/xpipe/core/store/ProcessControl.java b/core/src/main/java/io/xpipe/core/store/ProcessControl.java index d9bafa843..1768a187a 100644 --- a/core/src/main/java/io/xpipe/core/store/ProcessControl.java +++ b/core/src/main/java/io/xpipe/core/store/ProcessControl.java @@ -68,6 +68,7 @@ public abstract class ProcessControl { public abstract int waitFor() throws Exception; public abstract InputStream getStdout(); + public abstract OutputStream getStdin(); public abstract InputStream getStderr(); diff --git a/core/src/main/java/io/xpipe/core/store/ProcessOutputException.java b/core/src/main/java/io/xpipe/core/store/ProcessOutputException.java index 523dc91c1..c5a1e86b4 100644 --- a/core/src/main/java/io/xpipe/core/store/ProcessOutputException.java +++ b/core/src/main/java/io/xpipe/core/store/ProcessOutputException.java @@ -1,6 +1,6 @@ package io.xpipe.core.store; -public class ProcessOutputException extends Exception{ +public class ProcessOutputException extends Exception { public ProcessOutputException() { super(); } @@ -17,7 +17,8 @@ public class ProcessOutputException extends Exception{ super(cause); } - protected ProcessOutputException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + protected ProcessOutputException( + String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } } diff --git a/core/src/main/java/io/xpipe/core/store/ShellStore.java b/core/src/main/java/io/xpipe/core/store/ShellStore.java index cc593daac..8935583bf 100644 --- a/core/src/main/java/io/xpipe/core/store/ShellStore.java +++ b/core/src/main/java/io/xpipe/core/store/ShellStore.java @@ -62,7 +62,8 @@ public interface ShellStore extends DataStore { if (ec == 0 && !(read.get().isEmpty() && !readError.get().isEmpty())) { return read.get().trim(); } else { - throw new ProcessOutputException("Command returned with " + ec + ": " + readError.get().trim()); + throw new ProcessOutputException( + "Command returned with " + ec + ": " + readError.get().trim()); } } diff --git a/core/src/main/java/io/xpipe/core/store/ShellTypes.java b/core/src/main/java/io/xpipe/core/store/ShellTypes.java index b32f98f6c..31c050e54 100644 --- a/core/src/main/java/io/xpipe/core/store/ShellTypes.java +++ b/core/src/main/java/io/xpipe/core/store/ShellTypes.java @@ -13,12 +13,17 @@ import java.util.List; public class ShellTypes { + public static final StandardShellStore.ShellType POWERSHELL = new PowerShell(); + public static final StandardShellStore.ShellType CMD = new Cmd(); + public static final StandardShellStore.ShellType SH = new Sh(); + public static StandardShellStore.ShellType determine(ShellStore store) throws Exception { var o = store.executeAndCheckOut(List.of(), List.of("echo", "$0"), null).strip(); if (!o.equals("$0")) { return SH; } else { - o = store.executeAndCheckOut(List.of(), List.of("(dir 2>&1 *`|echo CMD);&<# rem #>echo PowerShell"), null).trim(); + o = store.executeAndCheckOut(List.of(), List.of("(dir 2>&1 *`|echo CMD);&<# rem #>echo PowerShell"), null) + .trim(); if (o.equals("PowerShell")) { return POWERSHELL; } else { @@ -36,13 +41,6 @@ public class ShellTypes { } } - public static final StandardShellStore.ShellType POWERSHELL = new PowerShell(); - - - public static final StandardShellStore.ShellType CMD = new Cmd(); - - public static final StandardShellStore.ShellType SH = new Sh(); - public static StandardShellStore.ShellType getDefault() { if (System.getProperty("os.name").startsWith("Windows")) { return CMD; @@ -51,16 +49,12 @@ public class ShellTypes { } } - public static StandardShellStore.ShellType[] getWindowsShells() { - return new StandardShellStore.ShellType[]{ - CMD, - POWERSHELL - }; + return new StandardShellStore.ShellType[] {CMD, POWERSHELL}; } public static StandardShellStore.ShellType[] getLinuxShells() { - return new StandardShellStore.ShellType[]{SH}; + return new StandardShellStore.ShellType[] {SH}; } @JsonTypeName("cmd") @@ -85,7 +79,8 @@ public class ShellTypes { } @Override - public ProcessControl prepareElevatedCommand(ShellStore st, List in, List cmd, Integer timeout, String pw) throws Exception { + public ProcessControl prepareElevatedCommand( + ShellStore st, List in, List cmd, Integer timeout, String pw) throws Exception { var l = List.of("net", "session", ";", "if", "%errorLevel%", "!=", "0"); return st.prepareCommand(List.of(), l, timeout); } @@ -188,7 +183,8 @@ public class ShellTypes { } @Override - public ProcessControl prepareElevatedCommand(ShellStore st, List in, List cmd, Integer timeout, String pw) throws Exception { + public ProcessControl prepareElevatedCommand( + ShellStore st, List in, List cmd, Integer timeout, String pw) throws Exception { var l = new ArrayList<>(cmd); l.add(0, "sudo"); l.add(1, "-S"); diff --git a/core/src/main/java/io/xpipe/core/store/StandardShellStore.java b/core/src/main/java/io/xpipe/core/store/StandardShellStore.java index 10da2e3de..9b6076c04 100644 --- a/core/src/main/java/io/xpipe/core/store/StandardShellStore.java +++ b/core/src/main/java/io/xpipe/core/store/StandardShellStore.java @@ -15,12 +15,55 @@ public interface StandardShellStore extends MachineFileStore, ShellStore { return false; } + public default NewLine getNewLine() throws Exception { + return determineType().getNewLine(); + } + + public abstract ShellType determineType() throws Exception; + + public default String querySystemName() throws Exception { + var result = executeAndCheckOut(List.of(), determineType().getOperatingSystemNameCommand(), getTimeout()); + return result.strip(); + } + + @Override + public default InputStream openInput(String file) throws Exception { + var type = determineType(); + var cmd = type.createFileReadCommand(file); + var p = prepareCommand(List.of(), cmd, null); + p.start(); + return p.getStdout(); + } + + @Override + public default OutputStream openOutput(String file) throws Exception { + return null; + // var type = determineType(); + // var cmd = type.createFileWriteCommand(file); + // var p = prepare(cmd).redirectErrorStream(true); + // var proc = p.start(); + // return proc.getOutputStream(); + } + + @Override + public default boolean exists(String file) throws Exception { + var type = determineType(); + var cmd = type.createFileExistsCommand(file); + var p = prepareCommand(List.of(), cmd, null); + p.start(); + return p.waitFor() == 0; + } + + @Override + public default void mkdirs(String file) throws Exception {} + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") public static interface ShellType { List switchTo(List cmd); - default ProcessControl prepareElevatedCommand(ShellStore st, List in, List cmd, Integer timeout, String pw) throws Exception { + default ProcessControl prepareElevatedCommand( + ShellStore st, List in, List cmd, Integer timeout, String pw) throws Exception { return st.prepareCommand(in, cmd, timeout); } @@ -40,50 +83,4 @@ public interface StandardShellStore extends MachineFileStore, ShellStore { List getOperatingSystemNameCommand(); } - - - public default NewLine getNewLine() throws Exception { - return determineType().getNewLine(); - } - - public abstract ShellType determineType() throws Exception; - - public default String querySystemName() throws Exception { - var result = executeAndCheckOut(List.of(), determineType().getOperatingSystemNameCommand(), getTimeout()); - return result.strip(); - } - - @Override - public default InputStream openInput(String file) throws Exception { - var type = determineType(); - var cmd = type.createFileReadCommand(file); - var p = prepareCommand(List.of(), cmd, null); - p.start(); - return p.getStdout(); - } - - @Override - public default OutputStream openOutput(String file) throws Exception { - return null; -// var type = determineType(); -// var cmd = type.createFileWriteCommand(file); -// var p = prepare(cmd).redirectErrorStream(true); -// var proc = p.start(); -// return proc.getOutputStream(); - } - - @Override - - public default boolean exists(String file) throws Exception { - var type = determineType(); - var cmd = type.createFileExistsCommand(file); - var p = prepareCommand(List.of(), cmd, null); - p.start(); - return p.waitFor() == 0; - } - - @Override - public default void mkdirs(String file) throws Exception { - - } } diff --git a/core/src/main/java/io/xpipe/core/store/StdinDataStore.java b/core/src/main/java/io/xpipe/core/store/StdinDataStore.java index cfe1aa5a7..277a1147b 100644 --- a/core/src/main/java/io/xpipe/core/store/StdinDataStore.java +++ b/core/src/main/java/io/xpipe/core/store/StdinDataStore.java @@ -70,8 +70,7 @@ public class StdinDataStore extends JacksonizedValue implements StreamDataStore } @Override - public void close() throws IOException { - } + public void close() throws IOException {} @Override public synchronized void mark(int readlimit) { diff --git a/core/src/main/java/io/xpipe/core/store/StdoutDataStore.java b/core/src/main/java/io/xpipe/core/store/StdoutDataStore.java index a4c90ffef..7c38afffa 100644 --- a/core/src/main/java/io/xpipe/core/store/StdoutDataStore.java +++ b/core/src/main/java/io/xpipe/core/store/StdoutDataStore.java @@ -48,8 +48,7 @@ public class StdoutDataStore extends JacksonizedValue implements StreamDataStore } @Override - public void close() throws IOException { - } + public void close() throws IOException {} }; } } diff --git a/core/src/main/java/io/xpipe/core/store/StreamDataStore.java b/core/src/main/java/io/xpipe/core/store/StreamDataStore.java index eaa18fc77..510a7ccea 100644 --- a/core/src/main/java/io/xpipe/core/store/StreamDataStore.java +++ b/core/src/main/java/io/xpipe/core/store/StreamDataStore.java @@ -9,7 +9,6 @@ import java.io.OutputStream; */ public interface StreamDataStore extends DataStore { - /** * Opens an input stream that can be used to read its data. */ diff --git a/core/src/main/java/io/xpipe/core/store/URLDataStore.java b/core/src/main/java/io/xpipe/core/store/URLDataStore.java index a845389cc..2451ffb14 100644 --- a/core/src/main/java/io/xpipe/core/store/URLDataStore.java +++ b/core/src/main/java/io/xpipe/core/store/URLDataStore.java @@ -7,7 +7,6 @@ import lombok.extern.jackson.Jacksonized; import java.io.InputStream; import java.net.URL; - @JsonTypeName("url") @SuperBuilder @Jacksonized diff --git a/core/src/main/java/io/xpipe/core/util/CoreJacksonModule.java b/core/src/main/java/io/xpipe/core/util/CoreJacksonModule.java index e6473e9ee..4a9561389 100644 --- a/core/src/main/java/io/xpipe/core/util/CoreJacksonModule.java +++ b/core/src/main/java/io/xpipe/core/util/CoreJacksonModule.java @@ -38,7 +38,6 @@ public class CoreJacksonModule extends SimpleModule { context.registerSubtypes( new NamedType(TextSource.class), new NamedType(XpbtSource.class), - new NamedType(FileStore.class), new NamedType(StdinDataStore.class), new NamedType(StdoutDataStore.class), @@ -47,27 +46,22 @@ public class CoreJacksonModule extends SimpleModule { new NamedType(InMemoryStore.class), new NamedType(LocalStore.class), new NamedType(NamedStore.class), - new NamedType(ValueType.class), new NamedType(TupleType.class), new NamedType(ArrayType.class), new NamedType(WildcardType.class), - new NamedType(ShellTypes.Cmd.class), new NamedType(ShellTypes.PowerShell.class), new NamedType(ShellTypes.Sh.class), - new NamedType(DataSourceInfo.Table.class), new NamedType(DataSourceInfo.Structure.class), new NamedType(DataSourceInfo.Text.class), new NamedType(DataSourceInfo.Collection.class), new NamedType(DataSourceInfo.Raw.class), - new NamedType(BaseQueryElement.class), new NamedType(ChoiceElement.class), new NamedType(BusyElement.class), - new NamedType(HeaderElement.class) - ); + new NamedType(HeaderElement.class)); addSerializer(Charset.class, new CharsetSerializer()); addDeserializer(Charset.class, new CharsetDeserializer()); @@ -98,12 +92,6 @@ public class CoreJacksonModule extends SimpleModule { } } - public class NullSerializer extends JsonSerializer { - public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { - jgen.writeNull(); - } - } - public static class NullDeserializer extends JsonDeserializer { @Override @@ -112,7 +100,6 @@ public class CoreJacksonModule extends SimpleModule { } } - public static class DataSourceReferenceSerializer extends JsonSerializer { @Override @@ -133,8 +120,7 @@ public class CoreJacksonModule extends SimpleModule { public static class CharsetSerializer extends JsonSerializer { @Override - public void serialize(Charset value, JsonGenerator jgen, SerializerProvider provider) - throws IOException { + public void serialize(Charset value, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeString(value.name()); } } @@ -150,8 +136,7 @@ public class CoreJacksonModule extends SimpleModule { public static class LocalPathSerializer extends JsonSerializer { @Override - public void serialize(Path value, JsonGenerator jgen, SerializerProvider provider) - throws IOException { + public void serialize(Path value, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeString(value.toString()); } } @@ -167,8 +152,7 @@ public class CoreJacksonModule extends SimpleModule { public static class SecretSerializer extends JsonSerializer { @Override - public void serialize(SecretValue value, JsonGenerator jgen, SerializerProvider provider) - throws IOException { + public void serialize(SecretValue value, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeString(value.getEncryptedValue()); } } @@ -184,11 +168,17 @@ public class CoreJacksonModule extends SimpleModule { @JsonSerialize(as = Throwable.class) public abstract static class ThrowableTypeMixIn { - @JsonIdentityInfo(generator= ObjectIdGenerators.StringIdGenerator.class, property="$id") + @JsonIdentityInfo(generator = ObjectIdGenerators.StringIdGenerator.class, property = "$id") private Throwable cause; } @JsonSerialize(as = DataSourceReference.class) - public abstract static class DataSourceReferenceTypeMixIn { + public abstract static class DataSourceReferenceTypeMixIn {} + + public class NullSerializer extends JsonSerializer { + public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) + throws IOException, JsonProcessingException { + jgen.writeNull(); + } } } diff --git a/core/src/main/java/io/xpipe/core/util/JacksonMapper.java b/core/src/main/java/io/xpipe/core/util/JacksonMapper.java index b7e4839f9..c6771ca0b 100644 --- a/core/src/main/java/io/xpipe/core/util/JacksonMapper.java +++ b/core/src/main/java/io/xpipe/core/util/JacksonMapper.java @@ -14,8 +14,8 @@ import java.util.function.Consumer; public class JacksonMapper { private static final ObjectMapper BASE = new ObjectMapper(); - private static ObjectMapper INSTANCE = new ObjectMapper(); private static final ObjectMapper DEFAULT; + private static ObjectMapper INSTANCE = new ObjectMapper(); private static boolean init = false; static { @@ -24,12 +24,14 @@ public class JacksonMapper { objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); objectMapper.disable(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE); - objectMapper.setVisibility(objectMapper.getSerializationConfig().getDefaultVisibilityChecker() - .withFieldVisibility(JsonAutoDetect.Visibility.ANY) - .withGetterVisibility(JsonAutoDetect.Visibility.NONE) - .withSetterVisibility(JsonAutoDetect.Visibility.NONE) - .withCreatorVisibility(JsonAutoDetect.Visibility.NONE) - .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)); + objectMapper.setVisibility(objectMapper + .getSerializationConfig() + .getDefaultVisibilityChecker() + .withFieldVisibility(JsonAutoDetect.Visibility.ANY) + .withGetterVisibility(JsonAutoDetect.Visibility.NONE) + .withSetterVisibility(JsonAutoDetect.Visibility.NONE) + .withCreatorVisibility(JsonAutoDetect.Visibility.NONE) + .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)); var modules = findModules(ModuleLayer.boot()); objectMapper.registerModules(modules); @@ -54,8 +56,8 @@ public class JacksonMapper { private static List findModules(ModuleLayer layer) { ArrayList modules = new ArrayList(); - ServiceLoader loader = layer != null ? - ServiceLoader.load(layer, Module.class) : ServiceLoader.load(Module.class); + ServiceLoader loader = + layer != null ? ServiceLoader.load(layer, Module.class) : ServiceLoader.load(Module.class); for (Module module : loader) { modules.add(module); } diff --git a/core/src/main/java/io/xpipe/core/util/JacksonizedValue.java b/core/src/main/java/io/xpipe/core/util/JacksonizedValue.java index b4dbb3a66..c56c79b3b 100644 --- a/core/src/main/java/io/xpipe/core/util/JacksonizedValue.java +++ b/core/src/main/java/io/xpipe/core/util/JacksonizedValue.java @@ -6,8 +6,7 @@ import lombok.experimental.SuperBuilder; @SuperBuilder public class JacksonizedValue { - public JacksonizedValue() { - } + public JacksonizedValue() {} @SneakyThrows public final String toString() { @@ -34,5 +33,4 @@ public class JacksonizedValue { var tree = JacksonMapper.newMapper().valueToTree(this); return tree.hashCode(); } - } diff --git a/core/src/main/java/io/xpipe/core/util/SecretValue.java b/core/src/main/java/io/xpipe/core/util/SecretValue.java index de5c822a9..9950155ab 100644 --- a/core/src/main/java/io/xpipe/core/util/SecretValue.java +++ b/core/src/main/java/io/xpipe/core/util/SecretValue.java @@ -10,6 +10,8 @@ import java.util.Base64; @EqualsAndHashCode public class SecretValue { + String value; + public static SecretValue createForSecretValue(String s) { if (s == null) { return null; @@ -22,8 +24,6 @@ public class SecretValue { return new SecretValue(Base64.getEncoder().encodeToString(s.getBytes(StandardCharsets.UTF_8))); } - String value; - public String getDisplay() { return "*".repeat(value.length()); } diff --git a/core/src/main/java/module-info.java b/core/src/main/java/module-info.java index 37d62bdce..ff2dcc0b2 100644 --- a/core/src/main/java/module-info.java +++ b/core/src/main/java/module-info.java @@ -20,5 +20,7 @@ open module io.xpipe.core { requires static lombok; uses com.fasterxml.jackson.databind.Module; - provides com.fasterxml.jackson.databind.Module with CoreJacksonModule; -} \ No newline at end of file + + provides com.fasterxml.jackson.databind.Module with + CoreJacksonModule; +} diff --git a/core/src/test/java/io/xpipe/core/test/DataSourceIdTest.java b/core/src/test/java/io/xpipe/core/test/DataSourceIdTest.java index 1bc50cc5d..1f4eec15e 100644 --- a/core/src/test/java/io/xpipe/core/test/DataSourceIdTest.java +++ b/core/src/test/java/io/xpipe/core/test/DataSourceIdTest.java @@ -20,7 +20,6 @@ public class DataSourceIdTest { DataSourceId.create("", "abc"); }); - Assertions.assertThrows(IllegalArgumentException.class, () -> { DataSourceId.create("abc", null); }); diff --git a/core/src/test/java/io/xpipe/core/test/DataStructureTests.java b/core/src/test/java/io/xpipe/core/test/DataStructureTests.java index a74c5a792..39e4e6eda 100644 --- a/core/src/test/java/io/xpipe/core/test/DataStructureTests.java +++ b/core/src/test/java/io/xpipe/core/test/DataStructureTests.java @@ -1,7 +1,7 @@ package io.xpipe.core.test; -import io.xpipe.core.data.node.DataStructureNode; import io.xpipe.core.data.node.ArrayNode; +import io.xpipe.core.data.node.DataStructureNode; import io.xpipe.core.data.node.TupleNode; import io.xpipe.core.data.node.ValueNode; import io.xpipe.core.data.type.*; @@ -13,37 +13,6 @@ import java.util.List; public class DataStructureTests { - @AllArgsConstructor - - public static enum TypedDataset { - - // Variety - DATA_1(createTestDataType1(), List.of(createTestData11(), createTestData12())), - - // Multiple nested arrays - DATA_2(createTestDataType2(), List.of(createTestData21(), createTestData22())), - - // Array with wildcard type - DATA_3(createTestData31().determineDataType(), List.of(createTestData31(), createTestData32())), - - // Simple values - DATA_4(ValueType.of(), List.of(createTestData41(), createTestData42())), - - // Array with wildcard type - DATA_5(createTestDataType5(), List.of(createTestData51(), createTestData52(), createTestData53())), - - // Tuple with wildcard type - DATA_6(createTestDataType6(), List.of(createTestData61(), createTestData62())), - - // Wildcard type - DATA_7(createTestDataType7(), List.of(createTestData71(), createTestData72(), createTestData73())); - - - public DataType type; - public List nodes; - - } - private static DataStructureNode createTestData11() { var val = ValueNode.of("value".getBytes(StandardCharsets.UTF_8)); var flatArray = ArrayNode.of(List.of(ValueNode.of(1), ValueNode.of(2))); @@ -101,7 +70,10 @@ public class DataStructureTests { public static DataStructureNode createTestData32() { var val = ValueNode.of("value2".getBytes(StandardCharsets.UTF_8)); - var flatTuple = TupleNode.builder().add("key1", ValueNode.nullValue()).add("key2", ValueNode.nullValue()).build(); + var flatTuple = TupleNode.builder() + .add("key1", ValueNode.nullValue()) + .add("key2", ValueNode.nullValue()) + .build(); var flatArray = ArrayNode.of(List.of(val, flatTuple)); return flatArray; } @@ -144,8 +116,7 @@ public class DataStructureTests { public static DataStructureNode createTestData61() { var val = ValueNode.of("value".getBytes(StandardCharsets.UTF_8)); var array = ArrayNode.of(List.of(val, ValueNode.nullValue())); - var tuple = TupleNode.builder() - .add(val).add("key2", array).build(); + var tuple = TupleNode.builder().add(val).add("key2", array).build(); return tuple; } @@ -153,8 +124,7 @@ public class DataStructureTests { var val = ValueNode.of("value2".getBytes(StandardCharsets.UTF_8)); var flatTuple = TupleNode.builder().add("key1", val).build(); - var tuple = TupleNode.builder() - .add(flatTuple).add("key2", val).build(); + var tuple = TupleNode.builder().add(flatTuple).add("key2", val).build(); return tuple; } @@ -183,4 +153,32 @@ public class DataStructureTests { public static DataType createTestDataType7() { return WildcardType.of(); } + + @AllArgsConstructor + public static enum TypedDataset { + + // Variety + DATA_1(createTestDataType1(), List.of(createTestData11(), createTestData12())), + + // Multiple nested arrays + DATA_2(createTestDataType2(), List.of(createTestData21(), createTestData22())), + + // Array with wildcard type + DATA_3(createTestData31().determineDataType(), List.of(createTestData31(), createTestData32())), + + // Simple values + DATA_4(ValueType.of(), List.of(createTestData41(), createTestData42())), + + // Array with wildcard type + DATA_5(createTestDataType5(), List.of(createTestData51(), createTestData52(), createTestData53())), + + // Tuple with wildcard type + DATA_6(createTestDataType6(), List.of(createTestData61(), createTestData62())), + + // Wildcard type + DATA_7(createTestDataType7(), List.of(createTestData71(), createTestData72(), createTestData73())); + + public DataType type; + public List nodes; + } } diff --git a/core/src/test/java/module-info.java b/core/src/test/java/module-info.java index 65dcea4a2..bf08780de 100644 --- a/core/src/test/java/module-info.java +++ b/core/src/test/java/module-info.java @@ -5,4 +5,4 @@ module io.xpipe.core.test { requires org.junit.jupiter.params; requires io.xpipe.core; requires static lombok; -} \ No newline at end of file +} diff --git a/extension/README.md b/extension/README.md index ca7ef8391..b7b2739aa 100644 --- a/extension/README.md +++ b/extension/README.md @@ -5,6 +5,7 @@ The X-Pipe extension API allows you to create extensions of any kind for X-Pipe. This includes: + - Custom data stores, including configuration GUI and CLI - Custom data sources, including configuration GUI and CLI - Custom preferences entries diff --git a/extension/publish.gradle b/extension/publish.gradle index 077b1b2b2..70e4f1936 100644 --- a/extension/publish.gradle +++ b/extension/publish.gradle @@ -1,4 +1,3 @@ - publishing { publications { mavenJava(MavenPublication) { diff --git a/extension/src/main/java/io/xpipe/extension/Cache.java b/extension/src/main/java/io/xpipe/extension/Cache.java index 27a742b05..d4fcfc9ef 100644 --- a/extension/src/main/java/io/xpipe/extension/Cache.java +++ b/extension/src/main/java/io/xpipe/extension/Cache.java @@ -8,8 +8,6 @@ public interface Cache { Cache INSTANCE = ServiceLoader.load(Cache.class).findFirst().orElseThrow(); - public T getValue(String key, Class type, Supplier notPresent); - public static T get(String key, Class type, Supplier notPresent) { return INSTANCE.getValue(key, type, notPresent); } @@ -18,9 +16,11 @@ public interface Cache { return Optional.ofNullable(get(key, type, () -> null)); } - public void updateValue(String key, T val); - public static void update(String key, T val) { INSTANCE.updateValue(key, key); } + + public T getValue(String key, Class type, Supplier notPresent); + + public void updateValue(String key, T val); } diff --git a/extension/src/main/java/io/xpipe/extension/DataSourceProvider.java b/extension/src/main/java/io/xpipe/extension/DataSourceProvider.java index 54ab73500..68a070124 100644 --- a/extension/src/main/java/io/xpipe/extension/DataSourceProvider.java +++ b/extension/src/main/java/io/xpipe/extension/DataSourceProvider.java @@ -12,11 +12,6 @@ import java.util.Map; public interface DataSourceProvider> { - static enum Category { - FILE, - DATABASE; - } - default void validate() throws Exception { getCategory(); getSourceClass(); @@ -38,8 +33,7 @@ public interface DataSourceProvider> { throw new ExtensionException(); } - default void init() throws Exception { - } + default void init() throws Exception {} default String i18n(String key) { return I18n.get(i18nKey(key)); @@ -71,20 +65,10 @@ public interface DataSourceProvider> { return getModuleName() + ":" + getId() + "_icon.png"; } - default String getSourceDescription(T source) { return getDisplayName(); } - interface FileProvider { - - String getFileName(); - - Map> getFileExtensions(); - } - - - Dialog configDialog(T source, boolean all); default boolean shouldShow(DataSourceType type) { @@ -125,7 +109,6 @@ public interface DataSourceProvider> { return getPossibleNames().get(0); } - /** * Attempt to create a useful data source descriptor from a data store. * The result does not need to be always right, it should only reflect the best effort. @@ -134,6 +117,17 @@ public interface DataSourceProvider> { Class getSourceClass(); - List getPossibleNames(); + + static enum Category { + FILE, + DATABASE; + } + + interface FileProvider { + + String getFileName(); + + Map> getFileExtensions(); + } } diff --git a/extension/src/main/java/io/xpipe/extension/DataSourceProviders.java b/extension/src/main/java/io/xpipe/extension/DataSourceProviders.java index 8f47285ff..e4d0eab90 100644 --- a/extension/src/main/java/io/xpipe/extension/DataSourceProviders.java +++ b/extension/src/main/java/io/xpipe/extension/DataSourceProviders.java @@ -6,7 +6,10 @@ import io.xpipe.core.store.FileStore; import io.xpipe.extension.event.ErrorEvent; import lombok.SneakyThrows; -import java.util.*; +import java.util.Comparator; +import java.util.List; +import java.util.Optional; +import java.util.ServiceLoader; import java.util.stream.Collectors; public class DataSourceProviders { @@ -15,8 +18,7 @@ public class DataSourceProviders { public static void init(ModuleLayer layer) { if (ALL == null) { - ALL = ServiceLoader.load(layer, DataSourceProvider.class) - .stream() + ALL = ServiceLoader.load(layer, DataSourceProvider.class).stream() .map(p -> (DataSourceProvider) p.get()) .sorted(Comparator.comparing(DataSourceProvider::getId)) .collect(Collectors.toList()); @@ -26,8 +28,7 @@ public class DataSourceProviders { p.validate(); return false; } catch (Exception e) { - ErrorEvent.fromThrowable(e) - .handle(); + ErrorEvent.fromThrowable(e).handle(); return true; } }); @@ -41,7 +42,7 @@ public class DataSourceProviders { case STRUCTURE -> DataSourceProviders.byId("xpbs"); case TEXT -> DataSourceProviders.byId("text"); case RAW -> DataSourceProviders.byId("binary"); - //TODO + // TODO case COLLECTION -> null; }; } catch (Exception ex) { @@ -52,46 +53,46 @@ public class DataSourceProviders { @SuppressWarnings("unchecked") @SneakyThrows public static StructureDataSource createLocalStructureDescriptor(DataStore store) { - return (StructureDataSource) - DataSourceProviders.byId("xpbs") - .getSourceClass() - .getDeclaredConstructors()[0].newInstance(store); + return (StructureDataSource) DataSourceProviders.byId("xpbs") + .getSourceClass() + .getDeclaredConstructors()[0] + .newInstance(store); } @SuppressWarnings("unchecked") @SneakyThrows public static RawDataSource createLocalRawDescriptor(DataStore store) { - return (RawDataSource) - DataSourceProviders.byId("binary") - .getSourceClass() - .getDeclaredConstructors()[0].newInstance(store); + return (RawDataSource) DataSourceProviders.byId("binary") + .getSourceClass() + .getDeclaredConstructors()[0] + .newInstance(store); } @SuppressWarnings("unchecked") @SneakyThrows public static RawDataSource createLocalCollectionDescriptor(DataStore store) { - return (RawDataSource) - DataSourceProviders.byId("br") - .getSourceClass() - .getDeclaredConstructors()[0].newInstance(store); + return (RawDataSource) DataSourceProviders.byId("br") + .getSourceClass() + .getDeclaredConstructors()[0] + .newInstance(store); } @SuppressWarnings("unchecked") @SneakyThrows public static TextDataSource createLocalTextDescriptor(DataStore store) { - return (TextDataSource) - DataSourceProviders.byId("text") - .getSourceClass() - .getDeclaredConstructors()[0].newInstance(store); + return (TextDataSource) DataSourceProviders.byId("text") + .getSourceClass() + .getDeclaredConstructors()[0] + .newInstance(store); } @SuppressWarnings("unchecked") @SneakyThrows public static TableDataSource createLocalTableDescriptor(DataStore store) { - return (TableDataSource) - DataSourceProviders.byId("xpbt") - .getSourceClass() - .getDeclaredConstructors()[0].newInstance(store); + return (TableDataSource) DataSourceProviders.byId("xpbt") + .getSourceClass() + .getDeclaredConstructors()[0] + .newInstance(store); } @SuppressWarnings("unchecked") @@ -101,13 +102,11 @@ public class DataSourceProviders { } return (T) ALL.stream() - .filter(d -> d.getId() - .equals(name)) + .filter(d -> d.getId().equals(name)) .findAny() .orElseThrow(() -> new IllegalArgumentException("Provider " + name + " not found")); } - @SuppressWarnings("unchecked") public static , T extends DataSourceProvider> T byDataSourceClass(Class c) { if (ALL == null) { @@ -115,8 +114,7 @@ public class DataSourceProviders { } return (T) ALL.stream() - .filter(d -> d.getSourceClass() - .equals(c)) + .filter(d -> d.getSourceClass().equals(c)) .findAny() .orElseThrow(() -> new IllegalArgumentException("Provider for " + c.getSimpleName() + " not found")); } @@ -127,24 +125,21 @@ public class DataSourceProviders { } return ALL.stream() - .filter(d -> d.getPossibleNames() - .stream() - .anyMatch(s -> nameAlternatives(s).stream().anyMatch(s1 -> s1.equalsIgnoreCase(name))) || d.getId().equalsIgnoreCase(name)) + .filter(d -> d.getPossibleNames().stream() + .anyMatch(s -> nameAlternatives(s).stream().anyMatch(s1 -> s1.equalsIgnoreCase(name))) + || d.getId().equalsIgnoreCase(name)) .findAny(); } private static List nameAlternatives(String name) { var split = List.of(name.split("_")); - return List.of(String.join(" ", split), String.join( - "_", split - ), String.join( - "-", split - ), split.stream() - .map(s -> s.equals(split.get(0)) ? - s : - s.substring(0, 1) - .toUpperCase() + s.substring(1)) - .collect(Collectors.joining())); + return List.of( + String.join(" ", split), + String.join("_", split), + String.join("-", split), + split.stream() + .map(s -> s.equals(split.get(0)) ? s : s.substring(0, 1).toUpperCase() + s.substring(1)) + .collect(Collectors.joining())); } public static Optional> byPreferredStore(DataStore store, DataSourceType type) { @@ -153,7 +148,7 @@ public class DataSourceProviders { } return ALL.stream() - .filter(d -> type == null || d.getPrimaryType() == type) + .filter(d -> type == null || d.getPrimaryType() == type) .filter(d -> d.getFileProvider() != null) .filter(d -> d.prefersStore(store, type)) .findAny(); diff --git a/extension/src/main/java/io/xpipe/extension/DataStoreProvider.java b/extension/src/main/java/io/xpipe/extension/DataStoreProvider.java index 0c664a43e..999bd9ed9 100644 --- a/extension/src/main/java/io/xpipe/extension/DataStoreProvider.java +++ b/extension/src/main/java/io/xpipe/extension/DataStoreProvider.java @@ -9,22 +9,16 @@ import java.util.List; public interface DataStoreProvider { - enum Category { - STREAM, - MACHINE, - DATABASE; - } - default void validate() throws Exception { getCategory(); for (Class storeClass : getStoreClasses()) { if (!JacksonizedValue.class.isAssignableFrom(storeClass)) { - throw new ExtensionException(String.format("Store class %s is not a Jacksonized value", storeClass.getSimpleName())); + throw new ExtensionException( + String.format("Store class %s is not a Jacksonized value", storeClass.getSimpleName())); } } } - default Category getCategory() { var c = getStoreClasses().get(0); if (StreamDataStore.class.isAssignableFrom(c)) { @@ -97,6 +91,12 @@ public interface DataStoreProvider { List> getStoreClasses(); default DataFlow[] getPossibleFlows() { - return new DataFlow[]{DataFlow.INPUT}; + return new DataFlow[] {DataFlow.INPUT}; + } + + enum Category { + STREAM, + MACHINE, + DATABASE; } } diff --git a/extension/src/main/java/io/xpipe/extension/DataStoreProviders.java b/extension/src/main/java/io/xpipe/extension/DataStoreProviders.java index b6fab5871..533265828 100644 --- a/extension/src/main/java/io/xpipe/extension/DataStoreProviders.java +++ b/extension/src/main/java/io/xpipe/extension/DataStoreProviders.java @@ -23,8 +23,7 @@ public class DataStoreProviders { p.validate(); return false; } catch (Exception e) { - ErrorEvent.fromThrowable(e) - .handle(); + ErrorEvent.fromThrowable(e).handle(); return true; } }); @@ -36,25 +35,27 @@ public class DataStoreProviders { throw new IllegalStateException("Not initialized"); } - return ALL.stream().filter(d -> d.getPossibleNames().stream() - .anyMatch(s -> s.equalsIgnoreCase(name))).findAny(); + return ALL.stream() + .filter(d -> d.getPossibleNames().stream().anyMatch(s -> s.equalsIgnoreCase(name))) + .findAny(); } - public static Optional byString(String s) { if (ALL == null) { throw new IllegalStateException("Not initialized"); } - return ALL.stream().map(d -> { - var store = d.storeForString(s); - if (store != null) { - return d.dialogForStore(store); - } else { - return null; - } - } - ).filter(Objects::nonNull).findAny(); + return ALL.stream() + .map(d -> { + var store = d.storeForString(s); + if (store != null) { + return d.dialogForStore(store); + } else { + return null; + } + }) + .filter(Objects::nonNull) + .findAny(); } @SuppressWarnings("unchecked") @@ -68,8 +69,8 @@ public class DataStoreProviders { throw new IllegalStateException("Not initialized"); } - - return (Optional) ALL.stream().filter(d -> d.getStoreClasses().contains(c)).findAny(); + return (Optional) + ALL.stream().filter(d -> d.getStoreClasses().contains(c)).findAny(); } public static List getAll() { diff --git a/extension/src/main/java/io/xpipe/extension/ExtensionException.java b/extension/src/main/java/io/xpipe/extension/ExtensionException.java index fab3705c3..2670e8d44 100644 --- a/extension/src/main/java/io/xpipe/extension/ExtensionException.java +++ b/extension/src/main/java/io/xpipe/extension/ExtensionException.java @@ -2,8 +2,7 @@ package io.xpipe.extension; public class ExtensionException extends RuntimeException { - public ExtensionException() { - } + public ExtensionException() {} public ExtensionException(String message) { super(message); diff --git a/extension/src/main/java/io/xpipe/extension/I18n.java b/extension/src/main/java/io/xpipe/extension/I18n.java index c3c9fbcf2..b4786fe9b 100644 --- a/extension/src/main/java/io/xpipe/extension/I18n.java +++ b/extension/src/main/java/io/xpipe/extension/I18n.java @@ -9,7 +9,6 @@ public interface I18n { I18n INSTANCE = ServiceLoader.load(I18n.class).findFirst().orElseThrow(); - public static ObservableValue observable(String s, Object... vars) { if (s == null) { return null; diff --git a/extension/src/main/java/io/xpipe/extension/SupportedApplicationProvider.java b/extension/src/main/java/io/xpipe/extension/SupportedApplicationProvider.java index b4aac7197..70c9a322a 100644 --- a/extension/src/main/java/io/xpipe/extension/SupportedApplicationProvider.java +++ b/extension/src/main/java/io/xpipe/extension/SupportedApplicationProvider.java @@ -9,32 +9,6 @@ import lombok.Value; public interface SupportedApplicationProvider { - enum Category { - PROGRAMMING_LANGUAGE, - APPLICATION, - OTHER - } - - enum AccessType { - ACTIVE, - PASSIVE - } - - @Value - @AllArgsConstructor - public static class InstructionsDisplay { - Region region; - Runnable onFinish; - Validator validator; - - public InstructionsDisplay(Region region) { - this.region = region; - onFinish = null; - validator = null; - } - } - - default InstructionsDisplay createRetrievalInstructions(DataSource source, ObservableValue id) { return null; } @@ -60,5 +34,29 @@ public interface SupportedApplicationProvider { default boolean isApplicable(DataSource source) { return true; } -} + enum Category { + PROGRAMMING_LANGUAGE, + APPLICATION, + OTHER + } + + enum AccessType { + ACTIVE, + PASSIVE + } + + @Value + @AllArgsConstructor + public static class InstructionsDisplay { + Region region; + Runnable onFinish; + Validator validator; + + public InstructionsDisplay(Region region) { + this.region = region; + onFinish = null; + validator = null; + } + } +} diff --git a/extension/src/main/java/io/xpipe/extension/SupportedApplicationProviders.java b/extension/src/main/java/io/xpipe/extension/SupportedApplicationProviders.java index 0fc9534c3..f8eccd760 100644 --- a/extension/src/main/java/io/xpipe/extension/SupportedApplicationProviders.java +++ b/extension/src/main/java/io/xpipe/extension/SupportedApplicationProviders.java @@ -12,7 +12,8 @@ public class SupportedApplicationProviders { public static void loadAll(ModuleLayer layer) { if (ALL == null) { ALL = ServiceLoader.load(layer, SupportedApplicationProvider.class).stream() - .map(ServiceLoader.Provider::get).collect(Collectors.toSet()); + .map(ServiceLoader.Provider::get) + .collect(Collectors.toSet()); } } diff --git a/extension/src/main/java/io/xpipe/extension/comp/CharChoiceComp.java b/extension/src/main/java/io/xpipe/extension/comp/CharChoiceComp.java index ac1b00a6c..53c8a3aac 100644 --- a/extension/src/main/java/io/xpipe/extension/comp/CharChoiceComp.java +++ b/extension/src/main/java/io/xpipe/extension/comp/CharChoiceComp.java @@ -17,7 +17,10 @@ public class CharChoiceComp extends Comp> { private final Map> range; private final ObservableValue customName; - public CharChoiceComp(Property value, Map> range, ObservableValue customName) { + public CharChoiceComp( + Property value, + Map> range, + ObservableValue customName) { this.value = value; this.range = range; this.customName = customName; diff --git a/extension/src/main/java/io/xpipe/extension/comp/CharsetChoiceComp.java b/extension/src/main/java/io/xpipe/extension/comp/CharsetChoiceComp.java index afdefc96f..4e373ff29 100644 --- a/extension/src/main/java/io/xpipe/extension/comp/CharsetChoiceComp.java +++ b/extension/src/main/java/io/xpipe/extension/comp/CharsetChoiceComp.java @@ -18,11 +18,14 @@ public class CharsetChoiceComp extends SimpleComp { @Override protected Region createSimple() { - var builder = new CustomComboBoxBuilder<>(charset, streamCharset -> { - return new Label(streamCharset.getCharset().displayName() + (streamCharset.hasByteOrderMark() ? - " (BOM)" : - "")); - }, new Label(I18n.get("extension.none")), null); + var builder = new CustomComboBoxBuilder<>( + charset, + streamCharset -> { + return new Label(streamCharset.getCharset().displayName() + + (streamCharset.hasByteOrderMark() ? " (BOM)" : "")); + }, + new Label(I18n.get("extension.none")), + null); builder.addHeader(I18n.get("extension.common")); for (var e : StreamCharset.COMMON) { builder.add(e); diff --git a/extension/src/main/java/io/xpipe/extension/comp/ChoiceComp.java b/extension/src/main/java/io/xpipe/extension/comp/ChoiceComp.java index ccfbceede..cd05a7801 100644 --- a/extension/src/main/java/io/xpipe/extension/comp/ChoiceComp.java +++ b/extension/src/main/java/io/xpipe/extension/comp/ChoiceComp.java @@ -17,10 +17,7 @@ import lombok.experimental.FieldDefaults; import java.util.Map; -@FieldDefaults( - makeFinal = true, - level = AccessLevel.PRIVATE -) +@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) public class ChoiceComp extends Comp>> { Property value; @@ -54,7 +51,6 @@ public class ChoiceComp extends Comp>> { return found.getValue(); } - @Override public T fromString(String string) { throw new UnsupportedOperationException(); diff --git a/extension/src/main/java/io/xpipe/extension/comp/ChoicePaneComp.java b/extension/src/main/java/io/xpipe/extension/comp/ChoicePaneComp.java index d18c28b7c..40b9035be 100644 --- a/extension/src/main/java/io/xpipe/extension/comp/ChoicePaneComp.java +++ b/extension/src/main/java/io/xpipe/extension/comp/ChoicePaneComp.java @@ -20,10 +20,7 @@ import lombok.experimental.FieldDefaults; import java.util.List; import java.util.function.Function; -@FieldDefaults( - makeFinal = true, - level = AccessLevel.PRIVATE -) +@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @AllArgsConstructor public class ChoicePaneComp extends Comp> { @@ -54,7 +51,7 @@ public class ChoicePaneComp extends Comp> { var vbox = new VBox(transformer.apply(cb)); vbox.setFillWidth(true); cb.prefWidthProperty().bind(vbox.widthProperty()); - cb.valueProperty().addListener((c,o,n) -> { + cb.valueProperty().addListener((c, o, n) -> { if (n == null) { vbox.getChildren().remove(1); } else { @@ -78,7 +75,5 @@ public class ChoicePaneComp extends Comp> { return new SimpleCompStructure<>(vbox); } - public static record Entry(ObservableValue name, Comp comp) { - - } + public static record Entry(ObservableValue name, Comp comp) {} } diff --git a/extension/src/main/java/io/xpipe/extension/comp/CodeSnippet.java b/extension/src/main/java/io/xpipe/extension/comp/CodeSnippet.java index 10542159c..e99e0ace9 100644 --- a/extension/src/main/java/io/xpipe/extension/comp/CodeSnippet.java +++ b/extension/src/main/java/io/xpipe/extension/comp/CodeSnippet.java @@ -9,21 +9,7 @@ import java.util.stream.Collectors; public record CodeSnippet(List lines) { public static final ColorScheme LIGHT_MODE = new ColorScheme( - Color.valueOf("0033B3"), - Color.valueOf("000000"), - Color.valueOf("000000"), - Color.valueOf("067D17") - ); - - public String toString() { - return getRawString(); - } - - public String getRawString() { - return lines.stream().map(line -> line.elements().stream() - .map(Element::text).collect(Collectors.joining())) - .collect(Collectors.joining(System.lineSeparator())); - } + Color.valueOf("0033B3"), Color.valueOf("000000"), Color.valueOf("000000"), Color.valueOf("067D17")); public static Builder builder() { return new Builder(LIGHT_MODE); @@ -33,6 +19,16 @@ public record CodeSnippet(List lines) { return new Builder(scheme); } + public String toString() { + return getRawString(); + } + + public String getRawString() { + return lines.stream() + .map(line -> line.elements().stream().map(Element::text).collect(Collectors.joining())) + .collect(Collectors.joining(System.lineSeparator())); + } + public static interface Element { String text(); @@ -124,11 +120,7 @@ public record CodeSnippet(List lines) { } } - public static record Line(List elements) { - } + public static record Line(List elements) {} - public static record ColorScheme( - Color keyword, Color identifier, Color type, Color string) { - - } + public static record ColorScheme(Color keyword, Color identifier, Color type, Color string) {} } diff --git a/extension/src/main/java/io/xpipe/extension/comp/CodeSnippetComp.java b/extension/src/main/java/io/xpipe/extension/comp/CodeSnippetComp.java index dfad6daa7..93b2b82ab 100644 --- a/extension/src/main/java/io/xpipe/extension/comp/CodeSnippetComp.java +++ b/extension/src/main/java/io/xpipe/extension/comp/CodeSnippetComp.java @@ -19,7 +19,6 @@ import java.awt.*; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; - public class CodeSnippetComp extends Comp> { private final ObservableValue showLineNumbers; @@ -36,10 +35,9 @@ public class CodeSnippetComp extends Comp> { } private static String toRGBCode(Color color) { - return String.format("#%02X%02X%02X", - (int) (color.getRed() * 255), - (int) (color.getGreen() * 255), - (int) (color.getBlue() * 255)); + return String.format( + "#%02X%02X%02X", + (int) (color.getRed() * 255), (int) (color.getGreen() * 255), (int) (color.getBlue() * 255)); } private void fillArea(VBox lineNumbers, InlineCssTextArea s) { @@ -94,7 +92,7 @@ public class CodeSnippetComp extends Comp> { var lineNumbers = new VBox(); lineNumbers.getStyleClass().add("line-numbers"); fillArea(lineNumbers, s); - value.addListener((c,o,n) -> { + value.addListener((c, o, n) -> { fillArea(lineNumbers, s); }); @@ -107,7 +105,7 @@ public class CodeSnippetComp extends Comp> { content.getChildren().add(0, lineNumbers); content.getChildren().add(1, spacer); } - showLineNumbers.addListener((c,o,n) -> { + showLineNumbers.addListener((c, o, n) -> { if (n) { content.getChildren().add(0, lineNumbers); content.getChildren().add(1, spacer); diff --git a/extension/src/main/java/io/xpipe/extension/comp/DataStoreFlowChoiceComp.java b/extension/src/main/java/io/xpipe/extension/comp/DataStoreFlowChoiceComp.java index 7c19bb0b3..eb7dc171f 100644 --- a/extension/src/main/java/io/xpipe/extension/comp/DataStoreFlowChoiceComp.java +++ b/extension/src/main/java/io/xpipe/extension/comp/DataStoreFlowChoiceComp.java @@ -24,10 +24,15 @@ public class DataStoreFlowChoiceComp extends SimpleComp { map.put(DataFlow.INPUT, I18n.observable("extension.input")); map.put(DataFlow.OUTPUT, I18n.observable("extension.output")); map.put(DataFlow.INPUT_OUTPUT, I18n.observable("extension.inout")); - return new ToggleGroupComp<>(selected, map).apply(struc -> { - new FancyTooltipAugment<>("extension.inputDescription").augment(struc.get().getChildren().get(0)); - new FancyTooltipAugment<>("extension.outputDescription").augment(struc.get().getChildren().get(1)); - new FancyTooltipAugment<>("extension.inoutDescription").augment(struc.get().getChildren().get(2)); - }).createRegion(); + return new ToggleGroupComp<>(selected, map) + .apply(struc -> { + new FancyTooltipAugment<>("extension.inputDescription") + .augment(struc.get().getChildren().get(0)); + new FancyTooltipAugment<>("extension.outputDescription") + .augment(struc.get().getChildren().get(1)); + new FancyTooltipAugment<>("extension.inoutDescription") + .augment(struc.get().getChildren().get(2)); + }) + .createRegion(); } } diff --git a/extension/src/main/java/io/xpipe/extension/comp/DynamicOptionsComp.java b/extension/src/main/java/io/xpipe/extension/comp/DynamicOptionsComp.java index 3ac3af803..2f4c88229 100644 --- a/extension/src/main/java/io/xpipe/extension/comp/DynamicOptionsComp.java +++ b/extension/src/main/java/io/xpipe/extension/comp/DynamicOptionsComp.java @@ -68,25 +68,35 @@ public class DynamicOptionsComp extends Comp> { } if (wrap) { - var compWidthBinding = Bindings.createDoubleBinding(() -> { - if (compRegions.stream().anyMatch(r -> r.getWidth() == 0)) { - return Region.USE_COMPUTED_SIZE; - } + var compWidthBinding = Bindings.createDoubleBinding( + () -> { + if (compRegions.stream().anyMatch(r -> r.getWidth() == 0)) { + return Region.USE_COMPUTED_SIZE; + } - var m = compRegions.stream().map(Region::getWidth).max(Double::compareTo).orElse(0.0); - return m; - }, compRegions.stream().map(Region::widthProperty).toList().toArray(new Observable[0])); + var m = compRegions.stream() + .map(Region::getWidth) + .max(Double::compareTo) + .orElse(0.0); + return m; + }, + compRegions.stream().map(Region::widthProperty).toList().toArray(new Observable[0])); compRegions.forEach(r -> r.prefWidthProperty().bind(compWidthBinding)); } - var nameWidthBinding = Bindings.createDoubleBinding(() -> { - if (nameRegions.stream().anyMatch(r -> r.getWidth() == 0)) { - return Region.USE_COMPUTED_SIZE; - } + var nameWidthBinding = Bindings.createDoubleBinding( + () -> { + if (nameRegions.stream().anyMatch(r -> r.getWidth() == 0)) { + return Region.USE_COMPUTED_SIZE; + } - var m = nameRegions.stream().map(Region::getWidth).max(Double::compareTo).orElse(0.0); - return m; - }, nameRegions.stream().map(Region::widthProperty).toList().toArray(new Observable[0])); + var m = nameRegions.stream() + .map(Region::getWidth) + .max(Double::compareTo) + .orElse(0.0); + return m; + }, + nameRegions.stream().map(Region::widthProperty).toList().toArray(new Observable[0])); nameRegions.forEach(r -> r.prefWidthProperty().bind(nameWidthBinding)); return new SimpleCompStructure<>(flow); @@ -96,7 +106,5 @@ public class DynamicOptionsComp extends Comp> { return entries; } - public static record Entry(ObservableValue name, Comp comp) { - - } + public static record Entry(ObservableValue name, Comp comp) {} } diff --git a/extension/src/main/java/io/xpipe/extension/comp/FancyTooltipAugment.java b/extension/src/main/java/io/xpipe/extension/comp/FancyTooltipAugment.java index e688a5063..5a02587ca 100644 --- a/extension/src/main/java/io/xpipe/extension/comp/FancyTooltipAugment.java +++ b/extension/src/main/java/io/xpipe/extension/comp/FancyTooltipAugment.java @@ -44,12 +44,12 @@ public class FancyTooltipAugment> implements Augment< tt.getStyleClass().add("fancy-tooltip"); } - public void augment(Node region) { var tt = new FocusTooltip(); var toDisplay = text.getValue(); if (Shortcuts.getShortcut((Region) region) != null) { - toDisplay = toDisplay + " (" + Shortcuts.getShortcut((Region) region).getDisplayText() + ")"; + toDisplay = + toDisplay + " (" + Shortcuts.getShortcut((Region) region).getDisplayText() + ")"; } tt.textProperty().setValue(toDisplay); tt.setStyle("-fx-font-size: 11pt;"); @@ -61,8 +61,7 @@ public class FancyTooltipAugment> implements Augment< private static class FocusTooltip extends JFXTooltip { - public FocusTooltip() { - } + public FocusTooltip() {} public FocusTooltip(String string) { super(string); diff --git a/extension/src/main/java/io/xpipe/extension/comp/FilterComp.java b/extension/src/main/java/io/xpipe/extension/comp/FilterComp.java index 8efe7de5d..fae0df43e 100644 --- a/extension/src/main/java/io/xpipe/extension/comp/FilterComp.java +++ b/extension/src/main/java/io/xpipe/extension/comp/FilterComp.java @@ -16,26 +16,12 @@ import org.kordamp.ikonli.javafx.FontIcon; public class FilterComp extends Comp { + private final Property filterText; + public FilterComp(Property filterText) { this.filterText = filterText; } - @Value - @Builder - public static class Structure implements CompStructure { - StackPane pane; - Node inactiveIcon; - Label inactiveText; - TextField text; - - @Override - public StackPane get() { - return pane; - } - } - - private final Property filterText; - @Override public Structure createBase() { var fi = new FontIcon("mdi2m-magnify"); @@ -50,12 +36,34 @@ public class FilterComp extends Comp { filterText.setValue(newValue); }); - bgLabel.visibleProperty().bind(Bindings.createBooleanBinding(() -> (filter.getText() == null || filter.getText().isEmpty()), - filter.textProperty(), filter.focusedProperty())); + bgLabel.visibleProperty() + .bind(Bindings.createBooleanBinding( + () -> (filter.getText() == null || filter.getText().isEmpty()), + filter.textProperty(), + filter.focusedProperty())); var stack = new StackPane(bgLabel, filter); stack.getStyleClass().add("filter-comp"); - return Structure.builder().inactiveIcon(fi).inactiveText(bgLabel).text(filter).pane(stack).build(); + return Structure.builder() + .inactiveIcon(fi) + .inactiveText(bgLabel) + .text(filter) + .pane(stack) + .build(); + } + + @Value + @Builder + public static class Structure implements CompStructure { + StackPane pane; + Node inactiveIcon; + Label inactiveText; + TextField text; + + @Override + public StackPane get() { + return pane; + } } } diff --git a/extension/src/main/java/io/xpipe/extension/comp/IntFieldComp.java b/extension/src/main/java/io/xpipe/extension/comp/IntFieldComp.java index 0a4106dcd..9618e24de 100644 --- a/extension/src/main/java/io/xpipe/extension/comp/IntFieldComp.java +++ b/extension/src/main/java/io/xpipe/extension/comp/IntFieldComp.java @@ -11,10 +11,7 @@ import javafx.scene.input.KeyEvent; import lombok.AccessLevel; import lombok.experimental.FieldDefaults; -@FieldDefaults( - makeFinal = true, - level = AccessLevel.PRIVATE -) +@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) public class IntFieldComp extends Comp> { Property value; diff --git a/extension/src/main/java/io/xpipe/extension/comp/MultiVariantComp.java b/extension/src/main/java/io/xpipe/extension/comp/MultiVariantComp.java index 66ba3e9bf..6788490f1 100644 --- a/extension/src/main/java/io/xpipe/extension/comp/MultiVariantComp.java +++ b/extension/src/main/java/io/xpipe/extension/comp/MultiVariantComp.java @@ -1,4 +1,3 @@ package io.xpipe.extension.comp; -public class MultiVariantComp { -} +public class MultiVariantComp {} diff --git a/extension/src/main/java/io/xpipe/extension/comp/SvgComp.java b/extension/src/main/java/io/xpipe/extension/comp/SvgComp.java index 2c6c59f26..543214916 100644 --- a/extension/src/main/java/io/xpipe/extension/comp/SvgComp.java +++ b/extension/src/main/java/io/xpipe/extension/comp/SvgComp.java @@ -22,7 +22,17 @@ import java.util.Set; import java.util.regex.Pattern; @Getter -public class SvgComp { +public class SvgComp { + + private final ObservableValue width; + private final ObservableValue height; + private final ObservableValue svgContent; + + public SvgComp(ObservableValue width, ObservableValue height, ObservableValue svgContent) { + this.width = PlatformThread.sync(width); + this.height = PlatformThread.sync(height); + this.svgContent = PlatformThread.sync(svgContent); + } private static Size parseSize(String string) { for (SizeUnits unit : SizeUnits.values()) { @@ -57,28 +67,6 @@ public class SvgComp { return new SvgComp(widthProperty, heightProperty, content); } - @Value - @Builder - public static class Structure implements CompStructure { - StackPane pane; - WebView webView; - - @Override - public StackPane get() { - return pane; - } - } - - private final ObservableValue width; - private final ObservableValue height; - private final ObservableValue svgContent; - - public SvgComp(ObservableValue width, ObservableValue height, ObservableValue svgContent) { - this.width = PlatformThread.sync(width); - this.height = PlatformThread.sync(height); - this.svgContent = PlatformThread.sync(svgContent); - } - private String getHtml(String content) { return "" + content + ""; } @@ -115,10 +103,21 @@ public class SvgComp { return wv; } - public WebView createWebview() { var wv = createWebView(); -wv.getStyleClass().add("svg-comp"); + wv.getStyleClass().add("svg-comp"); return wv; } + + @Value + @Builder + public static class Structure implements CompStructure { + StackPane pane; + WebView webView; + + @Override + public StackPane get() { + return pane; + } + } } diff --git a/extension/src/main/java/io/xpipe/extension/comp/TabPaneComp.java b/extension/src/main/java/io/xpipe/extension/comp/TabPaneComp.java index ac26b4e03..80f4a1caa 100644 --- a/extension/src/main/java/io/xpipe/extension/comp/TabPaneComp.java +++ b/extension/src/main/java/io/xpipe/extension/comp/TabPaneComp.java @@ -18,6 +18,13 @@ import java.util.List; @Getter public class TabPaneComp extends Comp> { + private final Property selected; + private final List entries; + public TabPaneComp(Property selected, List entries) { + this.selected = selected; + this.entries = entries; + } + @Override public CompStructure createBase() { JFXTabPane tabPane = new JFXTabPane(); @@ -40,10 +47,10 @@ public class TabPaneComp extends Comp> { } tabPane.getSelectionModel().select(entries.indexOf(selected.getValue())); - tabPane.getSelectionModel().selectedIndexProperty().addListener((c,o,n) -> { + tabPane.getSelectionModel().selectedIndexProperty().addListener((c, o, n) -> { selected.setValue(entries.get(n.intValue())); }); - selected.addListener((c,o,n) -> { + selected.addListener((c, o, n) -> { PlatformThread.runLaterIfNeeded(() -> { tabPane.getSelectionModel().select(entries.indexOf(n)); }); @@ -52,15 +59,5 @@ public class TabPaneComp extends Comp> { return new SimpleCompStructure<>(tabPane); } - private final Property selected; - private final List entries; - - public TabPaneComp(Property selected, List entries) { - this.selected = selected; - this.entries = entries; - } - - public static record Entry(ObservableValue name, String graphic, Comp comp) { - - } + public static record Entry(ObservableValue name, String graphic, Comp comp) {} } diff --git a/extension/src/main/java/io/xpipe/extension/comp/TextFieldComp.java b/extension/src/main/java/io/xpipe/extension/comp/TextFieldComp.java index 9e4010bb8..9db471e42 100644 --- a/extension/src/main/java/io/xpipe/extension/comp/TextFieldComp.java +++ b/extension/src/main/java/io/xpipe/extension/comp/TextFieldComp.java @@ -18,7 +18,6 @@ public class TextFieldComp extends Comp> { public TextFieldComp(Property value) { this.value = value; this.lazyValue = value; - } public TextFieldComp(Property value, Property lazyValue) { diff --git a/extension/src/main/java/io/xpipe/extension/comp/ToggleGroupComp.java b/extension/src/main/java/io/xpipe/extension/comp/ToggleGroupComp.java index 176e9fbc3..5a64a1c2f 100644 --- a/extension/src/main/java/io/xpipe/extension/comp/ToggleGroupComp.java +++ b/extension/src/main/java/io/xpipe/extension/comp/ToggleGroupComp.java @@ -49,8 +49,7 @@ public class ToggleGroupComp extends Comp> { box.getChildren().get(box.getChildren().size() - 1).getStyleClass().add("last"); group.selectedToggleProperty().addListener((obsVal, oldVal, newVal) -> { - if (newVal == null) - oldVal.setSelected(true); + if (newVal == null) oldVal.setSelected(true); }); return new SimpleCompStructure<>(box); diff --git a/extension/src/main/java/io/xpipe/extension/comp/WriteModeChoiceComp.java b/extension/src/main/java/io/xpipe/extension/comp/WriteModeChoiceComp.java index b45a5cfaa..795ca9ccd 100644 --- a/extension/src/main/java/io/xpipe/extension/comp/WriteModeChoiceComp.java +++ b/extension/src/main/java/io/xpipe/extension/comp/WriteModeChoiceComp.java @@ -26,18 +26,18 @@ public class WriteModeChoiceComp extends SimpleComp implements Validatable { Validator validator = new SimpleValidator(); Check check; - public WriteModeChoiceComp(Property selected, WriteMode[] available) { - this.selected = selected; - this.available = available; - if (available.length == 1) { - selected.setValue(available[0]); - } - check = Validators.nonNull(validator, I18n.observable("mode"), selected); - } + public WriteModeChoiceComp(Property selected, WriteMode[] available) { + this.selected = selected; + this.available = available; + if (available.length == 1) { + selected.setValue(available[0]); + } + check = Validators.nonNull(validator, I18n.observable("mode"), selected); + } @Override protected Region createSimple() { - var a = Arrays.asList(available); + var a = Arrays.asList(available); var map = new LinkedHashMap>(); var replaceIndex = -1; if (a.contains(WriteMode.REPLACE)) { @@ -60,10 +60,19 @@ public class WriteModeChoiceComp extends SimpleComp implements Validatable { int finalReplaceIndex = replaceIndex; int finalAppendIndex = appendIndex; int finalPrependIndex = prependIndex; - return new ToggleGroupComp<>(selected, map).apply(struc -> { - if (finalReplaceIndex != -1) new FancyTooltipAugment<>("extension.replaceDescription").augment(struc.get().getChildren().get(0)); - if (finalAppendIndex != -1) new FancyTooltipAugment<>("extension.appendDescription").augment(struc.get().getChildren().get(finalAppendIndex)); - if (finalPrependIndex != -1) new FancyTooltipAugment<>("extension.prependDescription").augment(struc.get().getChildren().get(finalPrependIndex)); - }).apply(struc -> check.decorates(struc.get())).createRegion(); + return new ToggleGroupComp<>(selected, map) + .apply(struc -> { + if (finalReplaceIndex != -1) + new FancyTooltipAugment<>("extension.replaceDescription") + .augment(struc.get().getChildren().get(0)); + if (finalAppendIndex != -1) + new FancyTooltipAugment<>("extension.appendDescription") + .augment(struc.get().getChildren().get(finalAppendIndex)); + if (finalPrependIndex != -1) + new FancyTooltipAugment<>("extension.prependDescription") + .augment(struc.get().getChildren().get(finalPrependIndex)); + }) + .apply(struc -> check.decorates(struc.get())) + .createRegion(); } } diff --git a/extension/src/main/java/io/xpipe/extension/event/ErrorEvent.java b/extension/src/main/java/io/xpipe/extension/event/ErrorEvent.java index 97588d26b..5b3daf8b8 100644 --- a/extension/src/main/java/io/xpipe/extension/event/ErrorEvent.java +++ b/extension/src/main/java/io/xpipe/extension/event/ErrorEvent.java @@ -12,6 +12,42 @@ import java.util.List; @Getter public class ErrorEvent { + private final List trackEvents = EventHandler.get().snapshotEvents(); + private String description; + private boolean terminal; + @Builder.Default + private boolean omitted = false; + @Builder.Default + private boolean reportable = true; + private Throwable throwable; + @Singular + private List attachments; + + public static ErrorEventBuilder fromThrowable(Throwable t) { + return builder().throwable(t).description(ExceptionConverter.convertMessage(t)); + } + + public static ErrorEventBuilder fromThrowable(String msg, Throwable t) { + return builder().throwable(t).description(msg); + } + + public static ErrorEventBuilder fromMessage(String msg) { + return builder().description(msg); + } + + public void handle() { + EventHandler.get().handle(this); + } + + public void addAttachment(Path file) { + attachments = new ArrayList<>(attachments); + attachments.add(file); + } + + public void clearAttachments() { + attachments = new ArrayList<>(); + } + public static class ErrorEventBuilder { public ErrorEventBuilder omit() { @@ -22,49 +58,4 @@ public class ErrorEvent { build().handle(); } } - - public static ErrorEventBuilder fromThrowable(Throwable t) { - return builder().throwable(t) - .description(ExceptionConverter.convertMessage(t)); - } - - public static ErrorEventBuilder fromThrowable(String msg, Throwable t) { - return builder().throwable(t) - .description(msg); - } - - public static ErrorEventBuilder fromMessage(String msg) { - return builder() - .description(msg); - } - - public void handle() { - EventHandler.get().handle(this); - } - - private String description; - - private boolean terminal; - - @Builder.Default - private boolean omitted = false; - - @Builder.Default - private boolean reportable = true; - - private Throwable throwable; - - @Singular - private List attachments; - - private final List trackEvents = EventHandler.get().snapshotEvents(); - - public void addAttachment(Path file) { - attachments = new ArrayList<>(attachments); - attachments.add(file); - } - - public void clearAttachments() { - attachments = new ArrayList<>(); - } } diff --git a/extension/src/main/java/io/xpipe/extension/event/ExceptionConverter.java b/extension/src/main/java/io/xpipe/extension/event/ExceptionConverter.java index 7ba574a61..4ce7a5d0c 100644 --- a/extension/src/main/java/io/xpipe/extension/event/ExceptionConverter.java +++ b/extension/src/main/java/io/xpipe/extension/event/ExceptionConverter.java @@ -20,7 +20,6 @@ public class ExceptionConverter { return I18n.get("extension.unsupportedOperation", msg); } - if (ex instanceof ClassNotFoundException) { return I18n.get("extension.classNotFound", msg); } diff --git a/extension/src/main/java/io/xpipe/extension/event/TrackEvent.java b/extension/src/main/java/io/xpipe/extension/event/TrackEvent.java index 5ec2628cb..6117216a3 100644 --- a/extension/src/main/java/io/xpipe/extension/event/TrackEvent.java +++ b/extension/src/main/java/io/xpipe/extension/event/TrackEvent.java @@ -13,27 +13,15 @@ import java.util.Map; @Getter public class TrackEvent { - public static class TrackEventBuilder { - - public TrackEventBuilder windowCategory() { - this.category("window"); - return this; - } - - public TrackEventBuilder copy() { - var copy = builder(); - copy.category = category; - copy.message = message; - copy.tags$key = new ArrayList<>(tags$key); - copy.tags$value = new ArrayList<>(tags$value); - copy.type = type; - return copy; - } - - public void handle() { - build().handle(); - } - } + private final Thread thread = Thread.currentThread(); + private final Instant instant = Instant.now(); + private String type; + private String message; + private String category; + @Singular + private Map tags; + @Singular + private List elements; public static TrackEventBuilder fromMessage(String type, String message) { return builder().type(type).message(message); @@ -99,28 +87,13 @@ public class TrackEvent { builder().type("error").message(message).build().handle(); } - private final Thread thread = Thread.currentThread(); - private final Instant instant = Instant.now(); - - private String type; - - private String message; - - private String category; - - @Singular - private Map tags; - - @Singular - private List elements; - public void handle() { EventHandler.get().handle(this); } @Override public String toString() { - var s = message; + var s = message; if (tags.size() > 0) { s += " {\n"; for (var e : tags.entrySet()) { @@ -130,4 +103,26 @@ public class TrackEvent { } return s; } + + public static class TrackEventBuilder { + + public TrackEventBuilder windowCategory() { + this.category("window"); + return this; + } + + public TrackEventBuilder copy() { + var copy = builder(); + copy.category = category; + copy.message = message; + copy.tags$key = new ArrayList<>(tags$key); + copy.tags$value = new ArrayList<>(tags$value); + copy.type = type; + return copy; + } + + public void handle() { + build().handle(); + } + } } diff --git a/extension/src/main/java/io/xpipe/extension/prefs/PrefsHandler.java b/extension/src/main/java/io/xpipe/extension/prefs/PrefsHandler.java index c45d533f6..9d2528c7e 100644 --- a/extension/src/main/java/io/xpipe/extension/prefs/PrefsHandler.java +++ b/extension/src/main/java/io/xpipe/extension/prefs/PrefsHandler.java @@ -2,5 +2,5 @@ package io.xpipe.extension.prefs; public interface PrefsHandler { -// void addSetting(List category, String group, Setting setting); + // void addSetting(List category, String group, Setting setting); } diff --git a/extension/src/main/java/io/xpipe/extension/prefs/PrefsProviders.java b/extension/src/main/java/io/xpipe/extension/prefs/PrefsProviders.java index 6b6ae462d..9fcfd91a8 100644 --- a/extension/src/main/java/io/xpipe/extension/prefs/PrefsProviders.java +++ b/extension/src/main/java/io/xpipe/extension/prefs/PrefsProviders.java @@ -11,7 +11,8 @@ public class PrefsProviders { public static void init(ModuleLayer layer) { if (ALL == null) { ALL = ServiceLoader.load(layer, PrefsProvider.class).stream() - .map(ServiceLoader.Provider::get).collect(Collectors.toSet()); + .map(ServiceLoader.Provider::get) + .collect(Collectors.toSet()); } } diff --git a/extension/src/main/java/io/xpipe/extension/util/ChainedValidator.java b/extension/src/main/java/io/xpipe/extension/util/ChainedValidator.java index 846a280b3..318c6d831 100644 --- a/extension/src/main/java/io/xpipe/extension/util/ChainedValidator.java +++ b/extension/src/main/java/io/xpipe/extension/util/ChainedValidator.java @@ -18,17 +18,18 @@ import java.util.stream.Collectors; public class ChainedValidator implements Validator { private final List validators; - private final ReadOnlyObjectWrapper validationResultProperty = new ReadOnlyObjectWrapper<>(new ValidationResult()); + private final ReadOnlyObjectWrapper validationResultProperty = + new ReadOnlyObjectWrapper<>(new ValidationResult()); private final ReadOnlyBooleanWrapper containsErrorsProperty = new ReadOnlyBooleanWrapper(); public ChainedValidator(List validators) { this.validators = validators; validators.forEach(v -> { - v.containsErrorsProperty().addListener((c,o,n) -> { + v.containsErrorsProperty().addListener((c, o, n) -> { containsErrorsProperty.set(containsErrors()); }); - v.validationResultProperty().addListener((c,o,n) -> { + v.validationResultProperty().addListener((c, o, n) -> { validationResultProperty.set(getValidationResult()); }); }); @@ -94,10 +95,15 @@ public class ChainedValidator implements Validator { @Override public StringBinding createStringBinding(String prefix, String separator) { - var list = new ArrayList(validators.stream().map(Validator::createStringBinding).toList()); + var list = new ArrayList( + validators.stream().map(Validator::createStringBinding).toList()); Observable[] observables = list.toArray(Observable[]::new); - return Bindings.createStringBinding(() -> { - return validators.stream().map(v -> v.createStringBinding(prefix, separator).get()).collect(Collectors.joining("\n")); - }, observables); + return Bindings.createStringBinding( + () -> { + return validators.stream() + .map(v -> v.createStringBinding(prefix, separator).get()) + .collect(Collectors.joining("\n")); + }, + observables); } } diff --git a/extension/src/main/java/io/xpipe/extension/util/CustomComboBoxBuilder.java b/extension/src/main/java/io/xpipe/extension/util/CustomComboBoxBuilder.java index b043dc9d9..7ccfa2b00 100644 --- a/extension/src/main/java/io/xpipe/extension/util/CustomComboBoxBuilder.java +++ b/extension/src/main/java/io/xpipe/extension/util/CustomComboBoxBuilder.java @@ -31,11 +31,19 @@ public class CustomComboBoxBuilder { private final Set disabledNodes = new HashSet<>(); private final Node emptyNode; private final Predicate veto; - private BiPredicate filterPredicate; private final Property filterString = new SimpleStringProperty(); private final List filterable = new ArrayList<>(); + private BiPredicate filterPredicate; private Node filterNode; + public CustomComboBoxBuilder( + Property selected, Function nodeFunction, Node emptyNode, Predicate veto) { + this.selected = selected; + this.nodeFunction = nodeFunction; + this.emptyNode = emptyNode; + this.veto = veto; + } + public void addAction(Node node, Runnable run) { nodes.add(node); actionsMap.put(node, run); @@ -80,13 +88,6 @@ public class CustomComboBoxBuilder { filterNode = header.getText(); } - public CustomComboBoxBuilder(Property selected, Function nodeFunction, Node emptyNode, Predicate veto) { - this.selected = selected; - this.nodeFunction = nodeFunction; - this.emptyNode = emptyNode; - this.veto = veto; - } - public ComboBox build() { var cb = new ComboBox(); cb.getItems().addAll(nodes); @@ -95,7 +96,11 @@ public class CustomComboBoxBuilder { }); cb.setButtonCell(new SelectedCell()); SimpleChangeListener.apply(selected, c -> { - var item = nodeMap.entrySet().stream().filter(e -> e.getValue() != null && e.getValue().equals(c)).map(e -> e.getKey()).findAny().orElse(null); + var item = nodeMap.entrySet().stream() + .filter(e -> e.getValue() != null && e.getValue().equals(c)) + .map(e -> e.getKey()) + .findAny() + .orElse(null); cb.setValue(Optional.ofNullable(item).orElse(emptyNode)); }); cb.valueProperty().addListener((c, o, n) -> { @@ -115,8 +120,13 @@ public class CustomComboBoxBuilder { if (filterPredicate != null) { SimpleChangeListener.apply(filterString, c -> { - var filteredNodes = nodes.stream().filter(e -> e.equals(cb.getValue()) || !(nodeMap.get(e) != null && ( - filterable.contains(nodeMap.get(e)) && filterString.getValue() != null && !filterPredicate.test(nodeMap.get(e), c)))).toList(); + var filteredNodes = nodes.stream() + .filter(e -> e.equals(cb.getValue()) + || !(nodeMap.get(e) != null + && (filterable.contains(nodeMap.get(e)) + && filterString.getValue() != null + && !filterPredicate.test(nodeMap.get(e), c)))) + .toList(); cb.setItems(FXCollections.observableList(filteredNodes)); }); @@ -125,17 +135,13 @@ public class CustomComboBoxBuilder { n.getWindow().focusedProperty().addListener((c2, o2, n2) -> { Platform.runLater(() -> { filterNode.requestFocus(); - }); }); - } Platform.runLater(() -> { filterNode.requestFocus(); - }); }); - } return cb; @@ -182,8 +188,8 @@ public class CustomComboBoxBuilder { setGraphic(item); if (disabledNodes.contains(item)) { this.setDisable(true); -// this.setPadding(Insets.EMPTY); - }else { + // this.setPadding(Insets.EMPTY); + } else { this.setDisable(false); } } diff --git a/extension/src/main/java/io/xpipe/extension/util/DialogHelper.java b/extension/src/main/java/io/xpipe/extension/util/DialogHelper.java index 951edec93..e46f4cb07 100644 --- a/extension/src/main/java/io/xpipe/extension/util/DialogHelper.java +++ b/extension/src/main/java/io/xpipe/extension/util/DialogHelper.java @@ -13,12 +13,6 @@ import java.util.function.Predicate; public class DialogHelper { - @Value - public static class Address { - String hostname; - Integer port; - } - public static Dialog addressQuery(Address address) { var hostNameQuery = Dialog.query("Hostname", false, true, false, address.getHostname(), QueryConverter.STRING); var portQuery = Dialog.query("Port", false, true, false, address.getPort(), QueryConverter.INTEGER); @@ -27,17 +21,14 @@ public class DialogHelper { } public static Dialog machineQuery(DataStore store) { - var storeName = XPipeDaemon.getInstance() - .getStoreName(store) - .orElse("local"); + var storeName = XPipeDaemon.getInstance().getStoreName(store).orElse("local"); return Dialog.query("Machine", false, true, false, storeName, QueryConverter.STRING) .map((String name) -> { if (name.equals("local")) { return new LocalStore(); } - var stored = XPipeDaemon.getInstance() - .getNamedStore(name); + var stored = XPipeDaemon.getInstance().getNamedStore(name); if (stored.isEmpty()) { throw new IllegalArgumentException(String.format("Store not found: %s", name)); } @@ -55,17 +46,14 @@ public class DialogHelper { } public static Dialog shellQuery(DataStore store) { - var storeName = XPipeDaemon.getInstance() - .getStoreName(store) - .orElse("local"); + var storeName = XPipeDaemon.getInstance().getStoreName(store).orElse("local"); return Dialog.query("Shell", false, true, false, storeName, QueryConverter.STRING) .map((String name) -> { if (name.equals("local")) { return new LocalStore(); } - var stored = XPipeDaemon.getInstance() - .getNamedStore(name); + var stored = XPipeDaemon.getInstance().getNamedStore(name); if (stored.isEmpty()) { throw new IllegalArgumentException(String.format("Store not found: %s", name)); } @@ -78,16 +66,15 @@ public class DialogHelper { }); } - public static Dialog charsetQuery(StreamCharset c, boolean all) { - return Dialog.query("Charset", false, true, c != null &&!all, c, QueryConverter.CHARSET); + public static Dialog charsetQuery(StreamCharset c, boolean all) { + return Dialog.query("Charset", false, true, c != null && !all, c, QueryConverter.CHARSET); } public static Dialog newLineQuery(NewLine n, boolean all) { - return Dialog.query("Newline", false, true, n != null &&!all, n, QueryConverter.NEW_LINE); + return Dialog.query("Newline", false, true, n != null && !all, n, QueryConverter.NEW_LINE); } - - public static Dialog query(String desc, T value, boolean required, QueryConverter c, boolean all) { + public static Dialog query(String desc, T value, boolean required, QueryConverter c, boolean all) { return Dialog.query(desc, false, required, value != null && !all, value, c); } @@ -100,14 +87,10 @@ public class DialogHelper { } public static Dialog namedStoreQuery(DataStore store, Class filter) { - var name = XPipeDaemon.getInstance() - .getStoreName(store) - .orElse(null); + var name = XPipeDaemon.getInstance().getStoreName(store).orElse(null); return Dialog.query("Store", false, true, false, name, QueryConverter.STRING) .map((String newName) -> { - var found = XPipeDaemon.getInstance() - .getNamedStore(newName) - .orElseThrow(); + var found = XPipeDaemon.getInstance().getNamedStore(newName).orElseThrow(); if (!filter.isAssignableFrom(found.getClass())) { throw new IllegalArgumentException("Incompatible store type"); } @@ -116,14 +99,10 @@ public class DialogHelper { } public static Dialog sourceQuery(DataSource source, Predicate> filter) { - var id = XPipeDaemon.getInstance() - .getSourceId(source) - .orElse(null); + var id = XPipeDaemon.getInstance().getSourceId(source).orElse(null); return Dialog.query("Source Id", false, true, false, id, QueryConverter.STRING) .map((String newName) -> { - var found = XPipeDaemon.getInstance() - .getSource(newName) - .orElseThrow(); + var found = XPipeDaemon.getInstance().getSource(newName).orElseThrow(); if (!filter.test(found)) { throw new IllegalArgumentException("Incompatible store type"); } @@ -139,4 +118,9 @@ public class DialogHelper { return Dialog.query("Timeout", false, true, false, timeout, QueryConverter.INTEGER); } + @Value + public static class Address { + String hostname; + Integer port; + } } diff --git a/extension/src/main/java/io/xpipe/extension/util/DynamicOptionsBuilder.java b/extension/src/main/java/io/xpipe/extension/util/DynamicOptionsBuilder.java index 88e25691d..9a550a95c 100644 --- a/extension/src/main/java/io/xpipe/extension/util/DynamicOptionsBuilder.java +++ b/extension/src/main/java/io/xpipe/extension/util/DynamicOptionsBuilder.java @@ -21,7 +21,7 @@ import java.util.function.Supplier; public class DynamicOptionsBuilder { - private final List entries = new ArrayList<>(); + private final List entries = new ArrayList<>(); private final List> props = new ArrayList<>(); private final List> lazyProperties = new ArrayList<>(); @@ -42,12 +42,14 @@ public class DynamicOptionsBuilder { this.wrap = false; this.title = title; } + public DynamicOptionsBuilder addTitle(String titleKey) { return addTitle(I18n.observable(titleKey)); } public DynamicOptionsBuilder addTitle(ObservableValue title) { - entries.add(new DynamicOptionsComp.Entry(null, Comp.of(() -> new Label(title.getValue())).styleClass("title-header"))); + entries.add(new DynamicOptionsComp.Entry( + null, Comp.of(() -> new Label(title.getValue())).styleClass("title-header"))); return this; } @@ -81,35 +83,43 @@ public class DynamicOptionsBuilder { return this; } - public DynamicOptionsBuilder addCharacter(Property prop, ObservableValue name, Map> names) { + public DynamicOptionsBuilder addCharacter( + Property prop, ObservableValue name, Map> names) { var comp = new CharChoiceComp(prop, names, null); entries.add(new DynamicOptionsComp.Entry(name, comp)); props.add(prop); return this; } - public DynamicOptionsBuilder addCharacter(Property prop, ObservableValue name, Map> names, ObservableValue customName) { + public DynamicOptionsBuilder addCharacter( + Property prop, + ObservableValue name, + Map> names, + ObservableValue customName) { var comp = new CharChoiceComp(prop, names, customName); entries.add(new DynamicOptionsComp.Entry(name, comp)); props.add(prop); return this; } - public DynamicOptionsBuilder addToggle(Property prop, ObservableValue name, Map> names) { + public DynamicOptionsBuilder addToggle( + Property prop, ObservableValue name, Map> names) { var comp = new ToggleGroupComp<>(prop, names); entries.add(new DynamicOptionsComp.Entry(name, comp)); props.add(prop); return this; } - public DynamicOptionsBuilder addChoice(Property prop, ObservableValue name, Map> names) { + public DynamicOptionsBuilder addChoice( + Property prop, ObservableValue name, Map> names) { var comp = new ChoiceComp<>(prop, names); entries.add(new DynamicOptionsComp.Entry(name, comp)); props.add(prop); return this; } - public DynamicOptionsBuilder addChoice(Property prop, ObservableValue name, ObservableValue>> names) { + public DynamicOptionsBuilder addChoice( + Property prop, ObservableValue name, ObservableValue>> names) { var comp = new ChoiceComp<>(prop, names); entries.add(new DynamicOptionsComp.Entry(name, comp)); props.add(prop); @@ -212,7 +222,7 @@ public class DynamicOptionsBuilder { public DynamicOptionsBuilder bindLazy(Supplier creator, Property toLazySet) { lazyProperties.forEach(prop -> { - prop.addListener((c,o,n) -> { + prop.addListener((c, o, n) -> { toLazySet.setValue(creator.get()); }); }); @@ -221,9 +231,10 @@ public class DynamicOptionsBuilder { return this; } - public final DynamicOptionsBuilder bindChoice(Supplier> creator, Property toSet) { + public final DynamicOptionsBuilder bindChoice( + Supplier> creator, Property toSet) { props.forEach(prop -> { - prop.addListener((c,o,n) -> { + prop.addListener((c, o, n) -> { toSet.unbind(); toSet.bind(creator.get()); }); @@ -234,12 +245,14 @@ public class DynamicOptionsBuilder { public Comp> buildComp() { if (title != null) { - entries.add(0, new DynamicOptionsComp.Entry(null, Comp.of(() -> new Label(title.getValue())).styleClass("title-header"))); + entries.add( + 0, + new DynamicOptionsComp.Entry( + null, Comp.of(() -> new Label(title.getValue())).styleClass("title-header"))); } return new DynamicOptionsComp(entries, wrap); } - public Region build() { return buildComp().createRegion(); } diff --git a/extension/src/main/java/io/xpipe/extension/util/ExclusiveValidator.java b/extension/src/main/java/io/xpipe/extension/util/ExclusiveValidator.java index cabbeff4b..ebe08759e 100644 --- a/extension/src/main/java/io/xpipe/extension/util/ExclusiveValidator.java +++ b/extension/src/main/java/io/xpipe/extension/util/ExclusiveValidator.java @@ -73,11 +73,14 @@ public final class ExclusiveValidator implements Validator { @Override public StringBinding createStringBinding(String prefix, String separator) { - var list = new ArrayList(validators.values().stream().map(Validator::createStringBinding).toList()); + var list = new ArrayList( + validators.values().stream().map(Validator::createStringBinding).toList()); list.add(obs); Observable[] observables = list.toArray(Observable[]::new); - return Bindings.createStringBinding(() -> { - return get().createStringBinding(prefix, separator).get(); - }, observables); + return Bindings.createStringBinding( + () -> { + return get().createStringBinding(prefix, separator).get(); + }, + observables); } } diff --git a/extension/src/main/java/io/xpipe/extension/util/ExtensionTest.java b/extension/src/main/java/io/xpipe/extension/util/ExtensionTest.java index f49841dfb..97aa7c044 100644 --- a/extension/src/main/java/io/xpipe/extension/util/ExtensionTest.java +++ b/extension/src/main/java/io/xpipe/extension/util/ExtensionTest.java @@ -12,7 +12,6 @@ import java.nio.file.Path; public class ExtensionTest { - public static DataStore getResource(String name) { var url = ExtensionTest.class.getClassLoader().getResource(name); if (url == null) { diff --git a/extension/src/main/java/io/xpipe/extension/util/NamedCharacter.java b/extension/src/main/java/io/xpipe/extension/util/NamedCharacter.java index 3e38f7123..11875a07b 100644 --- a/extension/src/main/java/io/xpipe/extension/util/NamedCharacter.java +++ b/extension/src/main/java/io/xpipe/extension/util/NamedCharacter.java @@ -8,6 +8,10 @@ import java.util.List; @Value public class NamedCharacter { + char character; + List names; + String translationKey; + public static QueryConverter converter(List chars, boolean allowOthers) { return new QueryConverter() { @Override @@ -16,15 +20,19 @@ public class NamedCharacter { throw new IllegalArgumentException("No character"); } - var byName = chars.stream().filter(nc -> nc.getNames().stream() + var byName = chars.stream() + .filter(nc -> nc.getNames().stream() .anyMatch(n -> n.toLowerCase().contains(s.toLowerCase()))) - .findFirst().orElse(null); + .findFirst() + .orElse(null); if (byName != null) { return byName.getCharacter(); } - var byChar = chars.stream().filter(nc -> String.valueOf(nc.getCharacter()).equalsIgnoreCase(s)) - .findFirst().orElse(null); + var byChar = chars.stream() + .filter(nc -> String.valueOf(nc.getCharacter()).equalsIgnoreCase(s)) + .findFirst() + .orElse(null); if (byChar != null) { return byChar.getCharacter(); } @@ -38,8 +46,10 @@ public class NamedCharacter { @Override protected String toString(Character value) { - var byChar = chars.stream().filter(nc -> value.equals(nc.getCharacter())) - .findFirst().orElse(null); + var byChar = chars.stream() + .filter(nc -> value.equals(nc.getCharacter())) + .findFirst() + .orElse(null); if (byChar != null) { return byChar.getNames().get(0); } @@ -48,8 +58,4 @@ public class NamedCharacter { } }; } - - char character; - List names; - String translationKey; } diff --git a/extension/src/main/java/io/xpipe/extension/util/PrettyListView.java b/extension/src/main/java/io/xpipe/extension/util/PrettyListView.java index 629b9e08e..cc4dc3cba 100644 --- a/extension/src/main/java/io/xpipe/extension/util/PrettyListView.java +++ b/extension/src/main/java/io/xpipe/extension/util/PrettyListView.java @@ -13,76 +13,8 @@ import java.util.Set; public class PrettyListView extends ListView { - public static class NoSelectionModel extends MultipleSelectionModel { - - @Override - public ObservableList getSelectedIndices() { - return FXCollections.emptyObservableList(); - } - - @Override - public ObservableList getSelectedItems() { - return FXCollections.emptyObservableList(); - } - - @Override - public void selectIndices(int index, int... indices) { - } - - @Override - public void selectAll() { - } - - @Override - public void selectFirst() { - } - - @Override - public void selectLast() { - } - - @Override - public void clearAndSelect(int index) { - } - - @Override - public void select(int index) { - } - - @Override - public void select(T obj) { - } - - @Override - public void clearSelection(int index) { - } - - @Override - public void clearSelection() { - } - - @Override - public boolean isSelected(int index) { - return false; - } - - @Override - public boolean isEmpty() { - return true; - } - - @Override - public void selectPrevious() { - } - - @Override - public void selectNext() { - } - } - private final ScrollBar vBar = new ScrollBar(); private final ScrollBar hBar = new ScrollBar(); - public PrettyListView() { super(); skinProperty().addListener(it -> { @@ -142,9 +74,73 @@ public class PrettyListView extends ListView { double w = getWidth(); double h = getHeight(); final double prefWidth = vBar.prefWidth(-1); - vBar.resizeRelocate(w - prefWidth - insets.getRight(), insets.getTop(), prefWidth, h - insets.getTop() - insets.getBottom()); + vBar.resizeRelocate( + w - prefWidth - insets.getRight(), + insets.getTop(), + prefWidth, + h - insets.getTop() - insets.getBottom()); final double prefHeight = hBar.prefHeight(-1); - hBar.resizeRelocate(insets.getLeft(), h - prefHeight - insets.getBottom(), w - insets.getLeft() - insets.getRight(), prefHeight); + hBar.resizeRelocate( + insets.getLeft(), + h - prefHeight - insets.getBottom(), + w - insets.getLeft() - insets.getRight(), + prefHeight); + } + + public static class NoSelectionModel extends MultipleSelectionModel { + + @Override + public ObservableList getSelectedIndices() { + return FXCollections.emptyObservableList(); + } + + @Override + public ObservableList getSelectedItems() { + return FXCollections.emptyObservableList(); + } + + @Override + public void selectIndices(int index, int... indices) {} + + @Override + public void selectAll() {} + + @Override + public void selectFirst() {} + + @Override + public void selectLast() {} + + @Override + public void clearAndSelect(int index) {} + + @Override + public void select(int index) {} + + @Override + public void select(T obj) {} + + @Override + public void clearSelection(int index) {} + + @Override + public void clearSelection() {} + + @Override + public boolean isSelected(int index) { + return false; + } + + @Override + public boolean isEmpty() { + return true; + } + + @Override + public void selectPrevious() {} + + @Override + public void selectNext() {} } } \ No newline at end of file diff --git a/extension/src/main/java/io/xpipe/extension/util/PropertiesHelper.java b/extension/src/main/java/io/xpipe/extension/util/PropertiesHelper.java index e86cd6752..b1ac71e30 100644 --- a/extension/src/main/java/io/xpipe/extension/util/PropertiesHelper.java +++ b/extension/src/main/java/io/xpipe/extension/util/PropertiesHelper.java @@ -6,8 +6,9 @@ import java.util.Map; public class PropertiesHelper { - public static void bindExclusive(Property selected, Map> map, Property toBind) { - selected.addListener((c,o,n) -> { + public static void bindExclusive( + Property selected, Map> map, Property toBind) { + selected.addListener((c, o, n) -> { toBind.unbind(); toBind.bind(map.get(n)); }); diff --git a/extension/src/main/java/io/xpipe/extension/util/SimpleFileDataSourceProvider.java b/extension/src/main/java/io/xpipe/extension/util/SimpleFileDataSourceProvider.java index 958c92f91..21f374d49 100644 --- a/extension/src/main/java/io/xpipe/extension/util/SimpleFileDataSourceProvider.java +++ b/extension/src/main/java/io/xpipe/extension/util/SimpleFileDataSourceProvider.java @@ -22,8 +22,7 @@ public interface SimpleFileDataSourceProvider> extends D @Override default DataSource convert(T in, DataSourceType t) throws Exception { - return DataSourceProviders.byId("binary") - .createDefaultSource(in.getStore()); + return DataSourceProviders.byId("binary").createDefaultSource(in.getStore()); } @Override @@ -43,8 +42,7 @@ public interface SimpleFileDataSourceProvider> extends D } if (store instanceof FilenameStore l) { - return l.getFileExtension() - .equalsIgnoreCase(ext); + return l.getFileExtension().equalsIgnoreCase(ext); } } } diff --git a/extension/src/main/java/io/xpipe/extension/util/SimpleValidator.java b/extension/src/main/java/io/xpipe/extension/util/SimpleValidator.java index 72b388236..fc9230dca 100644 --- a/extension/src/main/java/io/xpipe/extension/util/SimpleValidator.java +++ b/extension/src/main/java/io/xpipe/extension/util/SimpleValidator.java @@ -12,12 +12,14 @@ import net.synedra.validatorfx.Severity; import net.synedra.validatorfx.ValidationMessage; import net.synedra.validatorfx.ValidationResult; -import java.util.*; +import java.util.LinkedHashMap; +import java.util.Map; public class SimpleValidator implements Validator { private final Map> checks = new LinkedHashMap<>(); - private final ReadOnlyObjectWrapper validationResultProperty = new ReadOnlyObjectWrapper<>(new ValidationResult()); + private final ReadOnlyObjectWrapper validationResultProperty = + new ReadOnlyObjectWrapper<>(new ValidationResult()); private final ReadOnlyBooleanWrapper containsErrorsProperty = new ReadOnlyBooleanWrapper(); /** Create a check that lives within this checker's domain. @@ -79,7 +81,7 @@ public class SimpleValidator implements Validator { for (Check check : checks.keySet()) { check.recheck(); } - return ! containsErrors(); + return !containsErrors(); } private void refreshProperties() { @@ -104,15 +106,17 @@ public class SimpleValidator implements Validator { @Override public StringBinding createStringBinding(String prefix, String separator) { - return Bindings.createStringBinding( () -> { - StringBuilder str = new StringBuilder(); - for (ValidationMessage msg : validationResultProperty.get().getMessages()) { - if (str.length() > 0) { - str.append(separator); - } - str.append(prefix).append(msg.getText()); - } - return str.toString(); - }, validationResultProperty); + return Bindings.createStringBinding( + () -> { + StringBuilder str = new StringBuilder(); + for (ValidationMessage msg : validationResultProperty.get().getMessages()) { + if (str.length() > 0) { + str.append(separator); + } + str.append(prefix).append(msg.getText()); + } + return str.toString(); + }, + validationResultProperty); } } diff --git a/extension/src/main/java/io/xpipe/extension/util/UniformDataSourceProvider.java b/extension/src/main/java/io/xpipe/extension/util/UniformDataSourceProvider.java index ea83ce6e7..e463c79a4 100644 --- a/extension/src/main/java/io/xpipe/extension/util/UniformDataSourceProvider.java +++ b/extension/src/main/java/io/xpipe/extension/util/UniformDataSourceProvider.java @@ -10,5 +10,4 @@ public interface UniformDataSourceProvider> extends Data default Dialog configDialog(T source, boolean all) { return Dialog.empty().evaluateTo(() -> source); } - } diff --git a/extension/src/main/java/io/xpipe/extension/util/XPipeDaemon.java b/extension/src/main/java/io/xpipe/extension/util/XPipeDaemon.java index 54e94aedd..c8d90af54 100644 --- a/extension/src/main/java/io/xpipe/extension/util/XPipeDaemon.java +++ b/extension/src/main/java/io/xpipe/extension/util/XPipeDaemon.java @@ -25,19 +25,24 @@ public interface XPipeDaemon { public Image image(String file); - & Validatable> T streamStoreChooser(Property storeProperty, Property> provider, - boolean showAnonymous, - boolean showSaved); + & Validatable> T streamStoreChooser( + Property storeProperty, + Property> provider, + boolean showAnonymous, + boolean showSaved); - & Validatable> T namedStoreChooser( - ObservableValue> filter, Property selected, DataStoreProvider.Category category - ); + & Validatable> T namedStoreChooser( + ObservableValue> filter, + Property selected, + DataStoreProvider.Category category); Comp namedSourceChooser( - ObservableValue>> filter, Property> selected, DataSourceProvider.Category category - ); + ObservableValue>> filter, + Property> selected, + DataSourceProvider.Category category); - & Validatable> T sourceProviderChooser(Property> provider, DataSourceProvider.Category category, DataSourceType filter); + & Validatable> T sourceProviderChooser( + Property> provider, DataSourceProvider.Category category, DataSourceType filter); Optional getNamedStore(String name); diff --git a/extension/src/main/java/module-info.java b/extension/src/main/java/module-info.java index 40c1f3311..4a28d52ff 100644 --- a/extension/src/main/java/module-info.java +++ b/extension/src/main/java/module-info.java @@ -37,4 +37,4 @@ open module io.xpipe.extension { uses io.xpipe.extension.DataStoreProvider; uses XPipeDaemon; uses io.xpipe.extension.Cache; -} \ No newline at end of file +}