mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-25 00:50:31 +00:00
Cleanup
This commit is contained in:
parent
6e5f131658
commit
9154a28aca
16 changed files with 2 additions and 345 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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<ReadStreamExchange.Request, ReadStreamExchange.Response> {
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
|
@ -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<WriteStreamExchange.Request, WriteStreamExchange.Response> {
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
|
@ -150,8 +150,6 @@ open module io.xpipe.app {
|
|||
TerminalWaitExchangeImpl,
|
||||
TerminalLaunchExchangeImpl,
|
||||
QueryStoreExchangeImpl,
|
||||
WriteStreamExchangeImpl,
|
||||
ReadStreamExchangeImpl,
|
||||
InstanceExchangeImpl,
|
||||
VersionExchangeImpl;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 {}
|
||||
}
|
|
@ -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 {}
|
||||
}
|
|
@ -29,8 +29,6 @@ open module io.xpipe.beacon {
|
|||
LaunchExchange,
|
||||
InstanceExchange,
|
||||
EditStoreExchange,
|
||||
WriteStreamExchange,
|
||||
ReadStreamExchange,
|
||||
StoreProviderListExchange,
|
||||
ModeExchange,
|
||||
QueryStoreExchange,
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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() {}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -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() {}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
}
|
|
@ -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),
|
||||
|
|
Loading…
Reference in a new issue