From 9154a28acaf17a4a4eb764d2f4746ac3dd8107f9 Mon Sep 17 00:00:00 2001 From: crschnick Date: Mon, 25 Mar 2024 10:55:48 +0000 Subject: [PATCH] Cleanup --- .../io/xpipe/app/core/check/AppSidCheck.java | 2 + .../exchange/cli/ReadStreamExchangeImpl.java | 26 -------- .../exchange/cli/WriteStreamExchangeImpl.java | 21 ------- app/src/main/java/module-info.java | 2 - .../io/xpipe/beacon/BeaconConnection.java | 5 -- .../beacon/exchange/ReadStreamExchange.java | 32 ---------- .../beacon/exchange/WriteStreamExchange.java | 32 ---------- beacon/src/main/java/module-info.java | 2 - .../io/xpipe/core/store/FilenameStore.java | 18 ------ .../io/xpipe/core/store/InputStreamStore.java | 30 ---------- .../store/KnownFormatStreamDataStore.java | 11 ---- .../xpipe/core/store/OutputStreamStore.java | 38 ------------ .../io/xpipe/core/store/StdinDataStore.java | 30 ---------- .../io/xpipe/core/store/StdoutDataStore.java | 34 ----------- .../io/xpipe/core/store/StreamDataStore.java | 60 ------------------- .../io/xpipe/core/util/CoreJacksonModule.java | 4 -- 16 files changed, 2 insertions(+), 345 deletions(-) delete mode 100644 app/src/main/java/io/xpipe/app/exchange/cli/ReadStreamExchangeImpl.java delete mode 100644 app/src/main/java/io/xpipe/app/exchange/cli/WriteStreamExchangeImpl.java delete mode 100644 beacon/src/main/java/io/xpipe/beacon/exchange/ReadStreamExchange.java delete mode 100644 beacon/src/main/java/io/xpipe/beacon/exchange/WriteStreamExchange.java delete mode 100644 core/src/main/java/io/xpipe/core/store/FilenameStore.java delete mode 100644 core/src/main/java/io/xpipe/core/store/InputStreamStore.java delete mode 100644 core/src/main/java/io/xpipe/core/store/KnownFormatStreamDataStore.java delete mode 100644 core/src/main/java/io/xpipe/core/store/OutputStreamStore.java delete mode 100644 core/src/main/java/io/xpipe/core/store/StdinDataStore.java delete mode 100644 core/src/main/java/io/xpipe/core/store/StdoutDataStore.java delete mode 100644 core/src/main/java/io/xpipe/core/store/StreamDataStore.java diff --git a/app/src/main/java/io/xpipe/app/core/check/AppSidCheck.java b/app/src/main/java/io/xpipe/app/core/check/AppSidCheck.java index 371334543..58e90815e 100644 --- a/app/src/main/java/io/xpipe/app/core/check/AppSidCheck.java +++ b/app/src/main/java/io/xpipe/app/core/check/AppSidCheck.java @@ -2,6 +2,7 @@ package io.xpipe.app.core.check; import com.sun.jna.Function; import io.xpipe.app.issue.ErrorEvent; +import io.xpipe.app.issue.TrackEvent; import io.xpipe.core.process.OsType; public class AppSidCheck { @@ -14,6 +15,7 @@ public class AppSidCheck { try { var func = Function.getFunction("c", "setsid"); func.invoke(new Object[0]); + TrackEvent.info("Successfully set process sid"); } catch (Throwable t) { ErrorEvent.fromThrowable(t).omit().handle(); } diff --git a/app/src/main/java/io/xpipe/app/exchange/cli/ReadStreamExchangeImpl.java b/app/src/main/java/io/xpipe/app/exchange/cli/ReadStreamExchangeImpl.java deleted file mode 100644 index e99bf7836..000000000 --- a/app/src/main/java/io/xpipe/app/exchange/cli/ReadStreamExchangeImpl.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.xpipe.app.exchange.cli; - -import io.xpipe.app.exchange.MessageExchangeImpl; -import io.xpipe.beacon.BeaconHandler; -import io.xpipe.beacon.exchange.ReadStreamExchange; -import io.xpipe.core.store.StreamDataStore; - -import java.io.InputStream; - -public class ReadStreamExchangeImpl extends ReadStreamExchange - implements MessageExchangeImpl { - - @Override - public Response handleRequest(BeaconHandler handler, Request msg) throws Exception { - var ds = getStoreEntryByName(msg.getName(), false); - - handler.postResponse(() -> { - StreamDataStore store = ds.getStore().asNeeded(); - try (var output = handler.sendBody(); - InputStream inputStream = store.openInput()) { - inputStream.transferTo(output); - } - }); - return Response.builder().build(); - } -} diff --git a/app/src/main/java/io/xpipe/app/exchange/cli/WriteStreamExchangeImpl.java b/app/src/main/java/io/xpipe/app/exchange/cli/WriteStreamExchangeImpl.java deleted file mode 100644 index a04194411..000000000 --- a/app/src/main/java/io/xpipe/app/exchange/cli/WriteStreamExchangeImpl.java +++ /dev/null @@ -1,21 +0,0 @@ -package io.xpipe.app.exchange.cli; - -import io.xpipe.app.exchange.MessageExchangeImpl; -import io.xpipe.beacon.BeaconHandler; -import io.xpipe.beacon.exchange.WriteStreamExchange; -import io.xpipe.core.store.StreamDataStore; - -public class WriteStreamExchangeImpl extends WriteStreamExchange - implements MessageExchangeImpl { - - @Override - public Response handleRequest(BeaconHandler handler, Request msg) throws Exception { - var ds = getStoreEntryByName(msg.getName(), false); - StreamDataStore store = ds.getStore().asNeeded(); - try (var input = handler.receiveBody(); - var output = store.openOutput()) { - input.transferTo(output); - } - return WriteStreamExchange.Response.builder().build(); - } -} diff --git a/app/src/main/java/module-info.java b/app/src/main/java/module-info.java index 972cbdae0..4bad25c43 100644 --- a/app/src/main/java/module-info.java +++ b/app/src/main/java/module-info.java @@ -150,8 +150,6 @@ open module io.xpipe.app { TerminalWaitExchangeImpl, TerminalLaunchExchangeImpl, QueryStoreExchangeImpl, - WriteStreamExchangeImpl, - ReadStreamExchangeImpl, InstanceExchangeImpl, VersionExchangeImpl; } diff --git a/beacon/src/main/java/io/xpipe/beacon/BeaconConnection.java b/beacon/src/main/java/io/xpipe/beacon/BeaconConnection.java index ecda4b865..b655d031f 100644 --- a/beacon/src/main/java/io/xpipe/beacon/BeaconConnection.java +++ b/beacon/src/main/java/io/xpipe/beacon/BeaconConnection.java @@ -1,6 +1,5 @@ package io.xpipe.beacon; -import io.xpipe.beacon.exchange.WriteStreamExchange; import io.xpipe.core.util.FailableBiConsumer; import io.xpipe.core.util.FailableConsumer; import lombok.Getter; @@ -171,10 +170,6 @@ public abstract class BeaconConnection implements AutoCloseable { } } - public void writeStream(String name, InputStream in) { - performOutputExchange(WriteStreamExchange.Request.builder().name(name).build(), in::transferTo); - } - private BeaconException unwrapException(Exception exception) { if (exception instanceof ServerException s) { return new BeaconException("An internal server error occurred", s); diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/ReadStreamExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/ReadStreamExchange.java deleted file mode 100644 index 6241cae93..000000000 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/ReadStreamExchange.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.xpipe.beacon.exchange; - -import io.xpipe.beacon.RequestMessage; -import io.xpipe.beacon.ResponseMessage; -import lombok.Builder; -import lombok.NonNull; -import lombok.Value; -import lombok.extern.jackson.Jacksonized; - -/** - * Stores a stream of data in a storage. - */ -public class ReadStreamExchange implements MessageExchange { - - @Override - public String getId() { - return "readStream"; - } - - @Jacksonized - @Builder - @Value - public static class Request implements RequestMessage { - @NonNull - String name; - } - - @Jacksonized - @Builder - @Value - public static class Response implements ResponseMessage {} -} diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/WriteStreamExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/WriteStreamExchange.java deleted file mode 100644 index aaed94964..000000000 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/WriteStreamExchange.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.xpipe.beacon.exchange; - -import io.xpipe.beacon.RequestMessage; -import io.xpipe.beacon.ResponseMessage; -import lombok.Builder; -import lombok.NonNull; -import lombok.Value; -import lombok.extern.jackson.Jacksonized; - -/** - * Stores a stream of data in a storage. - */ -public class WriteStreamExchange implements MessageExchange { - - @Override - public String getId() { - return "writeStream"; - } - - @Jacksonized - @Builder - @Value - public static class Request implements RequestMessage { - @NonNull - String name; - } - - @Jacksonized - @Builder - @Value - public static class Response implements ResponseMessage {} -} diff --git a/beacon/src/main/java/module-info.java b/beacon/src/main/java/module-info.java index eac7269bf..53b0602d1 100644 --- a/beacon/src/main/java/module-info.java +++ b/beacon/src/main/java/module-info.java @@ -29,8 +29,6 @@ open module io.xpipe.beacon { LaunchExchange, InstanceExchange, EditStoreExchange, - WriteStreamExchange, - ReadStreamExchange, StoreProviderListExchange, ModeExchange, QueryStoreExchange, diff --git a/core/src/main/java/io/xpipe/core/store/FilenameStore.java b/core/src/main/java/io/xpipe/core/store/FilenameStore.java deleted file mode 100644 index 4a7ec8736..000000000 --- a/core/src/main/java/io/xpipe/core/store/FilenameStore.java +++ /dev/null @@ -1,18 +0,0 @@ -package io.xpipe.core.store; - -/** - * Represents a store that has a filename. - * Note that this does not only apply to file stores but any other store as well that has some kind of file name. - */ -public interface FilenameStore extends DataStore { - - default String getFileExtension() { - var split = getFileName().split("[\\\\.]"); - if (split.length == 0) { - return ""; - } - return split[split.length - 1]; - } - - String getFileName(); -} diff --git a/core/src/main/java/io/xpipe/core/store/InputStreamStore.java b/core/src/main/java/io/xpipe/core/store/InputStreamStore.java deleted file mode 100644 index 8c968ef52..000000000 --- a/core/src/main/java/io/xpipe/core/store/InputStreamStore.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.xpipe.core.store; - -import java.io.InputStream; - -/** - * A data store that is only represented by an InputStream. - */ -public class InputStreamStore implements StreamDataStore { - - private final InputStream in; - - public InputStreamStore(InputStream in) { - this.in = in; - } - - @Override - public DataFlow getFlow() { - return DataFlow.INPUT; - } - - @Override - public boolean canOpen() { - return true; - } - - @Override - public InputStream openInput() { - return in; - } -} \ No newline at end of file diff --git a/core/src/main/java/io/xpipe/core/store/KnownFormatStreamDataStore.java b/core/src/main/java/io/xpipe/core/store/KnownFormatStreamDataStore.java deleted file mode 100644 index 823b85824..000000000 --- a/core/src/main/java/io/xpipe/core/store/KnownFormatStreamDataStore.java +++ /dev/null @@ -1,11 +0,0 @@ -package io.xpipe.core.store; - -import io.xpipe.core.util.NewLine; -import io.xpipe.core.util.StreamCharset; - -public interface KnownFormatStreamDataStore extends StreamDataStore { - - StreamCharset getCharset(); - - NewLine getNewLine(); -} diff --git a/core/src/main/java/io/xpipe/core/store/OutputStreamStore.java b/core/src/main/java/io/xpipe/core/store/OutputStreamStore.java deleted file mode 100644 index 28d6a9d45..000000000 --- a/core/src/main/java/io/xpipe/core/store/OutputStreamStore.java +++ /dev/null @@ -1,38 +0,0 @@ -package io.xpipe.core.store; - -import java.io.InputStream; -import java.io.OutputStream; - -public class OutputStreamStore implements StreamDataStore { - - private final OutputStream out; - - public OutputStreamStore(OutputStream out) { - this.out = out; - } - - @Override - public DataFlow getFlow() { - return DataFlow.OUTPUT; - } - - @Override - public boolean canOpen() { - return false; - } - - @Override - public boolean isContentExclusivelyAccessible() { - return true; - } - - @Override - public InputStream openInput() { - throw new UnsupportedOperationException("No input available"); - } - - @Override - public OutputStream openOutput() { - return out; - } -} diff --git a/core/src/main/java/io/xpipe/core/store/StdinDataStore.java b/core/src/main/java/io/xpipe/core/store/StdinDataStore.java deleted file mode 100644 index 4bbad9549..000000000 --- a/core/src/main/java/io/xpipe/core/store/StdinDataStore.java +++ /dev/null @@ -1,30 +0,0 @@ -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.FilterInputStream; -import java.io.InputStream; - -@JsonTypeName("stdin") -@SuperBuilder -@Jacksonized -public class StdinDataStore extends JacksonizedValue implements StreamDataStore { - - @Override - public boolean isContentExclusivelyAccessible() { - return true; - } - - @Override - public InputStream openInput() { - var in = System.in; - // Prevent closing the standard in when the returned input stream is closed - return new FilterInputStream(in) { - @Override - public void close() {} - }; - } -} diff --git a/core/src/main/java/io/xpipe/core/store/StdoutDataStore.java b/core/src/main/java/io/xpipe/core/store/StdoutDataStore.java deleted file mode 100644 index c39f29207..000000000 --- a/core/src/main/java/io/xpipe/core/store/StdoutDataStore.java +++ /dev/null @@ -1,34 +0,0 @@ -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.FilterOutputStream; -import java.io.OutputStream; - -@JsonTypeName("stdout") -@SuperBuilder -@Jacksonized -public class StdoutDataStore extends JacksonizedValue implements StreamDataStore { - - @Override - public boolean canOpen() { - return false; - } - - @Override - public boolean isContentExclusivelyAccessible() { - return true; - } - - @Override - public OutputStream openOutput() { - // Create an output stream that will write to standard out but will not close it - return new FilterOutputStream(System.out) { - @Override - public void close() {} - }; - } -} diff --git a/core/src/main/java/io/xpipe/core/store/StreamDataStore.java b/core/src/main/java/io/xpipe/core/store/StreamDataStore.java deleted file mode 100644 index defd88d75..000000000 --- a/core/src/main/java/io/xpipe/core/store/StreamDataStore.java +++ /dev/null @@ -1,60 +0,0 @@ -package io.xpipe.core.store; - -import java.io.BufferedInputStream; -import java.io.InputStream; -import java.io.OutputStream; - -/** - * A data store that can be accessed using InputStreams and/or OutputStreams. - */ -public interface StreamDataStore extends DataStore { - - default DataFlow getFlow() { - return DataFlow.INPUT_OUTPUT; - } - - /** - * Checks whether this store can be opened. - * This can be not the case for example if the underlying store does not exist. - */ - default boolean canOpen() { - 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. - * - * @see StdinDataStore - * @see StdoutDataStore - */ - default boolean isContentExclusivelyAccessible() { - return false; - } - - /** - * Opens an input stream that can be used to read its data. - */ - default InputStream openInput() { - throw new UnsupportedOperationException("Can't open store input"); - } - - /** - * Opens an input stream that is guaranteed to be buffered. - */ - default InputStream openBufferedInput() throws Exception { - var in = openInput(); - if (in.markSupported()) { - return in; - } - - return new BufferedInputStream(in); - } - - /** - * Opens an output stream that can be used to write data. - */ - default OutputStream openOutput() { - throw new UnsupportedOperationException("Can't open store output"); - } -} 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 a85295d62..a670255df 100644 --- a/core/src/main/java/io/xpipe/core/util/CoreJacksonModule.java +++ b/core/src/main/java/io/xpipe/core/util/CoreJacksonModule.java @@ -20,8 +20,6 @@ import io.xpipe.core.process.OsType; import io.xpipe.core.process.ShellDialect; import io.xpipe.core.process.ShellDialects; import io.xpipe.core.store.LocalStore; -import io.xpipe.core.store.StdinDataStore; -import io.xpipe.core.store.StdoutDataStore; import java.io.IOException; import java.lang.reflect.WildcardType; @@ -35,8 +33,6 @@ public class CoreJacksonModule extends SimpleModule { public void setupModule(SetupContext context) { context.registerSubtypes( new NamedType(InPlaceSecretValue.class), - new NamedType(StdinDataStore.class), - new NamedType(StdoutDataStore.class), new NamedType(LocalStore.class), new NamedType(ArrayType.class), new NamedType(WildcardType.class),