From 4216528a87d0b00ec1c5865886468d274af7eb5e Mon Sep 17 00:00:00 2001 From: Christopher Schnick Date: Tue, 11 Oct 2022 17:07:34 +0200 Subject: [PATCH] Fixes --- api/build.gradle | 2 +- .../java/io/xpipe/beacon/BeaconFormat.java | 16 ++++++++++++++++ .../io/xpipe/core/data/node/ValueNode.java | 12 ++++++++++++ .../io/xpipe/core/impl/XpbsReadConnection.java | 18 ++++++++++++++++++ .../java/io/xpipe/core/impl/XpbsSource.java | 6 ++++-- .../xpipe/core/impl/XpbsWriteConnection.java | 18 ++++++++++++++++++ .../java/io/xpipe/core/impl/XpbtSource.java | 4 ++++ .../java/io/xpipe/core/store/NamedStore.java | 10 ++++------ .../io/xpipe/core/store/StdinDataStore.java | 2 ++ .../io/xpipe/core/store/StdoutDataStore.java | 2 ++ .../java/io/xpipe/core/store/URLDataStore.java | 11 ++++++++--- .../util/UniformDataSourceProvider.java | 13 ------------- 12 files changed, 89 insertions(+), 25 deletions(-) create mode 100644 core/src/main/java/io/xpipe/core/impl/XpbsReadConnection.java create mode 100644 core/src/main/java/io/xpipe/core/impl/XpbsWriteConnection.java diff --git a/api/build.gradle b/api/build.gradle index 69b50f142..4be70671e 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -9,7 +9,7 @@ apply from: "$rootDir/deps/java.gradle" apply from: "$rootDir/deps/junit.gradle" System.setProperty('excludeExtensionLibrary', 'true') -apply from: "$rootDir/scripts/extension_test.gradle" +apply from: "$rootDir/deps/extension_test.gradle" version = file('../misc/version').text group = 'io.xpipe' diff --git a/beacon/src/main/java/io/xpipe/beacon/BeaconFormat.java b/beacon/src/main/java/io/xpipe/beacon/BeaconFormat.java index 8ebdbae3a..ecca47589 100644 --- a/beacon/src/main/java/io/xpipe/beacon/BeaconFormat.java +++ b/beacon/src/main/java/io/xpipe/beacon/BeaconFormat.java @@ -19,6 +19,10 @@ public class BeaconFormat { @Override public void close() throws IOException { + if (isClosed()) { + return; + } + finishBlock(); out.flush(); index = -1; @@ -26,6 +30,10 @@ public class BeaconFormat { @Override public void write(int b) throws IOException { + if (isClosed()) { + throw new IllegalStateException("Output is closed"); + } + if (index == currentBytes.length) { finishBlock(); } @@ -34,7 +42,15 @@ public class BeaconFormat { index++; } + private boolean isClosed() { + return index == -1; + } + private void finishBlock() throws IOException { + if (isClosed()) { + throw new IllegalStateException("Output is closed"); + } + if (BeaconConfig.printMessages()) { System.out.println("Sending data block of length " + index); } 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 89dff87c6..bdfce276e 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 @@ -56,6 +56,18 @@ public abstract class ValueNode extends DataStructureNode { return created; } + public static ValueNode ofText(String text) { + var created = of(text); + created.tag(IS_TEXT); + return created; + } + + public static ValueNode ofInteger(int integer) { + var created = of(integer); + created.tag(IS_INTEGER); + return created; + } + public static ValueNode ofInteger(BigInteger integer) { var created = of(integer); created.tag(IS_INTEGER); diff --git a/core/src/main/java/io/xpipe/core/impl/XpbsReadConnection.java b/core/src/main/java/io/xpipe/core/impl/XpbsReadConnection.java new file mode 100644 index 000000000..da7b93a44 --- /dev/null +++ b/core/src/main/java/io/xpipe/core/impl/XpbsReadConnection.java @@ -0,0 +1,18 @@ +package io.xpipe.core.impl; + +import io.xpipe.core.data.generic.GenericDataStreamParser; +import io.xpipe.core.data.node.DataStructureNode; +import io.xpipe.core.source.StreamReadConnection; +import io.xpipe.core.source.StructureReadConnection; + +public class XpbsReadConnection extends StreamReadConnection implements StructureReadConnection { + + public XpbsReadConnection(XpbsSource source) { + super(source.getStore(), null); + } + + @Override + public DataStructureNode read() throws Exception { + return GenericDataStreamParser.parse(inputStream); + } +} diff --git a/core/src/main/java/io/xpipe/core/impl/XpbsSource.java b/core/src/main/java/io/xpipe/core/impl/XpbsSource.java index 91601bad5..53bd9f150 100644 --- a/core/src/main/java/io/xpipe/core/impl/XpbsSource.java +++ b/core/src/main/java/io/xpipe/core/impl/XpbsSource.java @@ -6,18 +6,20 @@ import io.xpipe.core.source.StructureReadConnection; import io.xpipe.core.source.StructureWriteConnection; import io.xpipe.core.store.StreamDataStore; import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; @JsonTypeName("xpbs") @SuperBuilder +@Jacksonized public class XpbsSource extends StructureDataSource { @Override protected StructureWriteConnection newWriteConnection() { - return null; + return new XpbsWriteConnection(this); } @Override protected StructureReadConnection newReadConnection() { - return null; + return new XpbsReadConnection(this); } } diff --git a/core/src/main/java/io/xpipe/core/impl/XpbsWriteConnection.java b/core/src/main/java/io/xpipe/core/impl/XpbsWriteConnection.java new file mode 100644 index 000000000..4186a807d --- /dev/null +++ b/core/src/main/java/io/xpipe/core/impl/XpbsWriteConnection.java @@ -0,0 +1,18 @@ +package io.xpipe.core.impl; + +import io.xpipe.core.data.generic.GenericDataStreamWriter; +import io.xpipe.core.data.node.DataStructureNode; +import io.xpipe.core.source.StreamWriteConnection; +import io.xpipe.core.source.StructureWriteConnection; + +public class XpbsWriteConnection extends StreamWriteConnection implements StructureWriteConnection { + + public XpbsWriteConnection(XpbsSource source) { + super(source.getStore(), null); + } + + @Override + public void write(DataStructureNode node) throws Exception { + GenericDataStreamWriter.writeStructure(outputStream,node); + } +} 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 ae3980b78..8079dac74 100644 --- a/core/src/main/java/io/xpipe/core/impl/XpbtSource.java +++ b/core/src/main/java/io/xpipe/core/impl/XpbtSource.java @@ -6,11 +6,15 @@ import io.xpipe.core.source.TableReadConnection; import io.xpipe.core.source.TableWriteConnection; import io.xpipe.core.store.StreamDataStore; import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; @JsonTypeName("xpbt") @SuperBuilder +@Jacksonized public class XpbtSource extends TableDataSource { + + @Override protected TableWriteConnection newWriteConnection() { return new XpbtWriteConnection(store); diff --git a/core/src/main/java/io/xpipe/core/store/NamedStore.java b/core/src/main/java/io/xpipe/core/store/NamedStore.java index 80963dbee..509479668 100644 --- a/core/src/main/java/io/xpipe/core/store/NamedStore.java +++ b/core/src/main/java/io/xpipe/core/store/NamedStore.java @@ -1,8 +1,9 @@ package io.xpipe.core.store; -import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonTypeName; import lombok.Getter; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; import java.time.Instant; import java.util.Optional; @@ -12,16 +13,13 @@ import java.util.Optional; * The referenced store has to be resolved by the caller manually, as this class does not act as a resolver. */ @JsonTypeName("named") +@SuperBuilder +@Jacksonized public final class NamedStore implements DataStore { @Getter private final String name; - @JsonCreator - public NamedStore(String name) { - this.name = name; - } - @Override public void validate() throws Exception { throw new UnsupportedOperationException(); 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 947d932f9..cfe1aa5a7 100644 --- a/core/src/main/java/io/xpipe/core/store/StdinDataStore.java +++ b/core/src/main/java/io/xpipe/core/store/StdinDataStore.java @@ -3,6 +3,7 @@ package io.xpipe.core.store; import com.fasterxml.jackson.annotation.JsonTypeName; import io.xpipe.core.util.JacksonizedValue; import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; import java.io.IOException; import java.io.InputStream; @@ -10,6 +11,7 @@ import java.io.OutputStream; @JsonTypeName("stdin") @SuperBuilder +@Jacksonized public class StdinDataStore extends JacksonizedValue implements StreamDataStore { @Override 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 1ab831baf..a4c90ffef 100644 --- a/core/src/main/java/io/xpipe/core/store/StdoutDataStore.java +++ b/core/src/main/java/io/xpipe/core/store/StdoutDataStore.java @@ -3,12 +3,14 @@ package io.xpipe.core.store; import com.fasterxml.jackson.annotation.JsonTypeName; import io.xpipe.core.util.JacksonizedValue; import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; import java.io.IOException; import java.io.OutputStream; @JsonTypeName("stdout") @SuperBuilder +@Jacksonized public class StdoutDataStore extends JacksonizedValue implements StreamDataStore { @Override 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 a7a1c9347..a845389cc 100644 --- a/core/src/main/java/io/xpipe/core/store/URLDataStore.java +++ b/core/src/main/java/io/xpipe/core/store/URLDataStore.java @@ -1,14 +1,19 @@ package io.xpipe.core.store; -import lombok.Value; +import com.fasterxml.jackson.annotation.JsonTypeName; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; import java.io.InputStream; import java.net.URL; -@Value + +@JsonTypeName("url") +@SuperBuilder +@Jacksonized public class URLDataStore implements StreamDataStore { - URL url; + private final URL url; @Override public InputStream openInput() throws Exception { 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 e6ebbd816..ea83ce6e7 100644 --- a/extension/src/main/java/io/xpipe/extension/util/UniformDataSourceProvider.java +++ b/extension/src/main/java/io/xpipe/extension/util/UniformDataSourceProvider.java @@ -2,11 +2,7 @@ package io.xpipe.extension.util; import io.xpipe.core.dialog.Dialog; import io.xpipe.core.source.DataSource; -import io.xpipe.core.store.DataStore; import io.xpipe.extension.DataSourceProvider; -import io.xpipe.extension.ExtensionException; - -import java.lang.reflect.InvocationTargetException; public interface UniformDataSourceProvider> extends DataSourceProvider { @@ -15,13 +11,4 @@ public interface UniformDataSourceProvider> extends Data return Dialog.empty().evaluateTo(() -> source); } - @Override - @SuppressWarnings("unchecked") - default T createDefaultSource(DataStore input) throws Exception { - try { - return (T) getSourceClass().getDeclaredConstructors()[0].newInstance(input); - } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { - throw new ExtensionException(e); - } - } }