This commit is contained in:
Christopher Schnick 2022-12-30 12:54:40 +01:00
parent b9501bad43
commit 661ad8a79c
116 changed files with 715 additions and 491 deletions

View file

@ -15,10 +15,10 @@ import java.nio.file.Path;
/**
* Represents a reference to a data source that is managed by X-Pipe.
*
* <p>
* The actual data is only queried when required and is not cached.
* Therefore, the queried data is always up-to-date at the point of calling a method that queries the data.
*
* <p>
* As soon a data source reference is created, the data source is locked
* within X-Pipe to prevent concurrent modification and the problems that can arise from it.
* By default, the lock is held until the calling program terminates and prevents
@ -29,14 +29,14 @@ public interface DataSource {
/**
* NOT YET IMPLEMENTED!
*
* <p>
* Creates a new supplier data source that will be interpreted as the generated data source.
* In case this program should be a data source generator, this method has to be called at
* least once to register that it actually generates a data source.
*
* <p>
* All content that is written to this data source until the generator program terminates is
* will be available later on when the data source is used as a supplier later on.
*
* <p>
* In case this method is called multiple times, the same data source is returned.
*
* @return the generator data source
@ -132,9 +132,9 @@ public interface DataSource {
/**
* Creates a new data source from an input stream.
*
* @param id the data source id
* @param id the data source id
* @param type the data source type
* @param in the input stream to read
* @param in the input stream to read
* @return a {@link DataSource} instances that can be used to access the underlying data
*/
public static DataSource create(DataSourceId id, String type, InputStream in) {
@ -153,10 +153,11 @@ public interface DataSource {
/**
* Creates a new data source from an input stream.
*1
* @param id the data source id
* 1
*
* @param id the data source id
* @param type the data source type
* @param in the data store to add
* @param in the data store to add
* @return a {@link DataSource} instances that can be used to access the underlying data
*/
public static DataSource create(DataSourceId id, String type, DataStore in) {

View file

@ -1,8 +1,8 @@
package io.xpipe.api;
import io.xpipe.api.connector.XPipeApiConnection;
import io.xpipe.beacon.util.QuietDialogHandler;
import io.xpipe.beacon.exchange.cli.StoreAddExchange;
import io.xpipe.beacon.util.QuietDialogHandler;
import io.xpipe.core.store.DataStore;
import java.util.Map;

View file

@ -8,7 +8,7 @@ import io.xpipe.core.source.DataSourceId;
/**
* An accumulator for table data.
*
* <p>
* This class can be used to construct new table data sources by
* accumulating the rows using {@link #add(DataStructureNode)} or {@link #acceptor()} and then calling
* {@link #finish(DataSourceId)} to complete the construction process and create a new data source.

View file

@ -12,7 +12,8 @@ import java.util.Optional;
public final class XPipeApiConnection extends BeaconConnection {
private XPipeApiConnection() {}
private XPipeApiConnection() {
}
public static XPipeApiConnection open() {
var con = new XPipeApiConnection();
@ -30,8 +31,8 @@ public final class XPipeApiConnection extends BeaconConnection {
}
DialogExchange.Response response = con.performSimpleExchange(DialogExchange.Request.builder()
.dialogKey(reference.getDialogId())
.build());
.dialogKey(reference.getDialogId())
.build());
element = response.getElement();
if (response.getElement() == null) {
break;
@ -78,9 +79,9 @@ public final class XPipeApiConnection extends BeaconConnection {
}
var s = BeaconClient.tryConnect(BeaconClient.ApiClientInformation.builder()
.version("?")
.language("Java")
.build());
.version("?")
.language("Java")
.build());
if (s.isPresent()) {
return s;
}
@ -122,9 +123,9 @@ public final class XPipeApiConnection extends BeaconConnection {
try {
beaconClient = BeaconClient.connect(BeaconClient.ApiClientInformation.builder()
.version("?")
.language("Java")
.build());
.version("?")
.language("Java")
.build());
} catch (Exception ex) {
throw new BeaconException("Unable to connect to running xpipe daemon", ex);
}

View file

@ -12,7 +12,8 @@ public class DataRawImpl extends DataSourceImpl implements DataRaw {
public DataRawImpl(
DataSourceId sourceId,
DataSourceConfig sourceConfig,
io.xpipe.core.source.DataSource<?> internalSource) {
io.xpipe.core.source.DataSource<?> internalSource
) {
super(sourceId, sourceConfig, internalSource);
}

View file

@ -18,7 +18,8 @@ public abstract class DataSourceImpl implements DataSource {
private final io.xpipe.core.source.DataSource<?> internalSource;
public DataSourceImpl(
DataSourceId sourceId, DataSourceConfig config, io.xpipe.core.source.DataSource<?> internalSource) {
DataSourceId sourceId, DataSourceConfig config, io.xpipe.core.source.DataSource<?> internalSource
) {
this.sourceId = sourceId;
this.config = config;
this.internalSource = internalSource;

View file

@ -11,7 +11,8 @@ public class DataStructureImpl extends DataSourceImpl implements DataStructure {
DataStructureImpl(
DataSourceId sourceId,
DataSourceConfig sourceConfig,
io.xpipe.core.source.DataSource<?> internalSource) {
io.xpipe.core.source.DataSource<?> internalSource
) {
super(sourceId, sourceConfig, internalSource);
}

View file

@ -27,7 +27,8 @@ public class DataTableImpl extends DataSourceImpl implements DataTable {
DataTableImpl(
DataSourceId id,
DataSourceConfig sourceConfig,
io.xpipe.core.source.DataSource<?> internalSource) {
io.xpipe.core.source.DataSource<?> internalSource
) {
super(id, sourceConfig, internalSource);
}
@ -73,6 +74,7 @@ public class DataTableImpl extends DataSourceImpl implements DataTable {
public Iterator<TupleNode> iterator() {
return new TableIterator();
}
;
private class TableIterator implements Iterator<TupleNode> {

View file

@ -24,10 +24,11 @@ import java.util.stream.StreamSupport;
public class DataTextImpl extends DataSourceImpl implements DataText {
DataTextImpl(
DataTextImpl(
DataSourceId sourceId,
DataSourceConfig sourceConfig,
io.xpipe.core.source.DataSource<?> internalSource) {
io.xpipe.core.source.DataSource<?> internalSource
) {
super(sourceId, sourceConfig, internalSource);
}

View file

@ -5,11 +5,9 @@ import io.xpipe.core.data.node.TupleNode;
import io.xpipe.core.data.node.ValueNode;
import io.xpipe.core.data.type.TupleType;
import io.xpipe.core.data.type.ValueType;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.OptionalInt;
public class DataTableAccumulatorTest extends ApiTest {

View file

@ -33,78 +33,8 @@ import static io.xpipe.beacon.BeaconConfig.BODY_SEPARATOR;
public class BeaconClient implements AutoCloseable {
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
public abstract static class ClientInformation {
public final CliClientInformation cli() {
return (CliClientInformation) this;
}
public abstract String toDisplayString();
}
@JsonTypeName("cli")
@Value
@Builder
@Jacksonized
@EqualsAndHashCode(callSuper = false)
public static class CliClientInformation extends ClientInformation {
int consoleWidth;
@Override
public String toDisplayString() {
return "X-Pipe CLI";
}
}
@JsonTypeName("reachableCheck")
@Value
@Builder
@Jacksonized
@EqualsAndHashCode(callSuper = false)
public static class ReachableCheckInformation extends ClientInformation {
@Override
public String toDisplayString() {
return "Reachable check";
}
}
@JsonTypeName("gateway")
@Value
@Builder
@Jacksonized
@EqualsAndHashCode(callSuper = false)
public static class GatewayClientInformation extends ClientInformation {
String version;
@Override
public String toDisplayString() {
return "X-Pipe Gateway " + version;
}
}
@JsonTypeName("api")
@Value
@Builder
@Jacksonized
@EqualsAndHashCode(callSuper = false)
public static class ApiClientInformation extends ClientInformation {
String version;
String language;
@Override
public String toDisplayString() {
return String.format("X-Pipe %s API v%s", language, version);
}
}
@Getter
private final Closeable base;
private final InputStream in;
private final OutputStream out;
@ -130,15 +60,15 @@ public class BeaconClient implements AutoCloseable {
command.discardErr();
return new BeaconClient(command, command.getStdout(), command.getStdin()) {
// {
// new Thread(() -> {
// while (true) {
// if (!control.isRunning()) {
// close();
// }
// }
// })
// }
// {
// new Thread(() -> {
// while (true) {
// if (!control.isRunning()) {
// close();
// }
// }
// })
// }
@Override
public <T extends ResponseMessage> T receiveResponse()
@ -365,4 +295,76 @@ public class BeaconClient implements AutoCloseable {
void run() throws E;
}
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
property = "type"
)
public abstract static class ClientInformation {
public final CliClientInformation cli() {
return (CliClientInformation) this;
}
public abstract String toDisplayString();
}
@JsonTypeName("cli")
@Value
@Builder
@Jacksonized
@EqualsAndHashCode(callSuper = false)
public static class CliClientInformation extends ClientInformation {
int consoleWidth;
@Override
public String toDisplayString() {
return "X-Pipe CLI";
}
}
@JsonTypeName("reachableCheck")
@Value
@Builder
@Jacksonized
@EqualsAndHashCode(callSuper = false)
public static class ReachableCheckInformation extends ClientInformation {
@Override
public String toDisplayString() {
return "Reachable check";
}
}
@JsonTypeName("gateway")
@Value
@Builder
@Jacksonized
@EqualsAndHashCode(callSuper = false)
public static class GatewayClientInformation extends ClientInformation {
String version;
@Override
public String toDisplayString() {
return "X-Pipe Gateway " + version;
}
}
@JsonTypeName("api")
@Value
@Builder
@Jacksonized
@EqualsAndHashCode(callSuper = false)
public static class ApiClientInformation extends ClientInformation {
String version;
String language;
@Override
public String toDisplayString() {
return String.format("X-Pipe %s API v%s", language, version);
}
}
}

View file

@ -78,7 +78,8 @@ public abstract class BeaconConnection implements AutoCloseable {
}
public <REQ extends RequestMessage, RES extends ResponseMessage> void performInputExchange(
REQ req, BeaconClient.FailableBiConsumer<RES, InputStream, Exception> responseConsumer) {
REQ req, BeaconClient.FailableBiConsumer<RES, InputStream, Exception> responseConsumer
) {
checkClosed();
performInputOutputExchange(req, null, responseConsumer);
@ -87,7 +88,8 @@ public abstract class BeaconConnection implements AutoCloseable {
public <REQ extends RequestMessage, RES extends ResponseMessage> void performInputOutputExchange(
REQ req,
BeaconClient.FailableConsumer<OutputStream, IOException> reqWriter,
BeaconClient.FailableBiConsumer<RES, InputStream, Exception> responseConsumer) {
BeaconClient.FailableBiConsumer<RES, InputStream, Exception> responseConsumer
) {
checkClosed();
try {
@ -149,7 +151,8 @@ public abstract class BeaconConnection implements AutoCloseable {
}
public <REQ extends RequestMessage, RES extends ResponseMessage> RES performOutputExchange(
REQ req, BeaconClient.FailableConsumer<OutputStream, Exception> reqWriter) {
REQ req, BeaconClient.FailableConsumer<OutputStream, Exception> reqWriter
) {
checkClosed();
try {

View file

@ -72,7 +72,7 @@ public class BeaconDaemonController {
throw new IOException("Wait for daemon start up timed out");
}
private static void waitForShutdown() {
private static void waitForShutdown() {
for (int i = 0; i < 40; i++) {
try {
Thread.sleep(500);

View file

@ -5,7 +5,8 @@ package io.xpipe.beacon;
*/
public class BeaconException extends RuntimeException {
public BeaconException() {}
public BeaconException() {
}
public BeaconException(String message) {
super(message);

View file

@ -10,6 +10,7 @@ public class BeaconJacksonModule extends SimpleModule {
context.registerSubtypes(
new NamedType(BeaconClient.ApiClientInformation.class),
new NamedType(BeaconClient.CliClientInformation.class),
new NamedType(BeaconClient.ReachableCheckInformation.class));
new NamedType(BeaconClient.ReachableCheckInformation.class)
);
}
}

View file

@ -81,8 +81,8 @@ public class BeaconProxyImpl extends ProxyProvider {
try {
client = BeaconClient.connectProxy(proxy);
client.sendRequest(ProxyReadConnectionExchange.Request.builder()
.source(downstream)
.build());
.source(downstream)
.build());
client.receiveResponse();
BeaconClient finalClient = client;
var inputStream = new FilterInputStream(finalClient.receiveBody()) {
@ -96,22 +96,24 @@ public class BeaconProxyImpl extends ProxyProvider {
var inputSource = DataSource.createInternalDataSource(source.getType(), new InputStreamStore(inputStream));
return (T) inputSource.openReadConnection();
} catch (Exception ex) {
if (client != null) client.close();
if (client != null) {
client.close();
}
throw ex;
}
}
@Override
@SuppressWarnings("unchecked")
public <T extends DataSourceConnection> T createRemoteWriteConnection(DataSource<?> source, WriteMode mode, ShellStore proxy) throws Exception {
public <T extends DataSourceConnection> T createRemoteWriteConnection(DataSource<?> source, WriteMode mode, ShellStore proxy) throws Exception {
var downstream = downstreamTransform(source, proxy);
BeaconClient client = null;
try {
client = BeaconClient.connectProxy(proxy);
client.sendRequest(ProxyWriteConnectionExchange.Request.builder()
.source(downstream)
.build());
.source(downstream)
.build());
BeaconClient finalClient = client;
var outputStream = new FilterOutputStream(client.sendBody()) {
@Override
@ -125,7 +127,9 @@ public class BeaconProxyImpl extends ProxyProvider {
var outputSource = DataSource.createInternalDataSource(source.getType(), new OutputStreamStore(outputStream));
return (T) outputSource.openWriteConnection(mode);
} catch (Exception ex) {
if (client != null) client.close();
if (client != null) {
client.close();
}
throw ex;
}
}

View file

@ -30,9 +30,9 @@ public class BeaconServer {
if (custom != null) {
var command = ShellTypes.getPlatformDefault()
.executeCommandListWithShell(custom
+ (BeaconConfig.getDaemonArguments() != null
? " " + BeaconConfig.getDaemonArguments()
: ""));
+ (BeaconConfig.getDaemonArguments() != null
? " " + BeaconConfig.getDaemonArguments()
: ""));
Process process = Runtime.getRuntime().exec(command.toArray(String[]::new));
printDaemonOutput(process, command);
return process;
@ -77,7 +77,8 @@ public class BeaconServer {
ioe.printStackTrace();
}
},
"daemon sysout");
"daemon sysout"
);
out.setDaemon(true);
out.start();
@ -97,7 +98,8 @@ public class BeaconServer {
ioe.printStackTrace();
}
},
"daemon syserr");
"daemon syserr"
);
err.setDaemon(true);
err.start();
}

View file

@ -5,7 +5,8 @@ package io.xpipe.beacon;
*/
public class ClientException extends Exception {
public ClientException() {}
public ClientException() {
}
public ClientException(String message) {
super(message);

View file

@ -5,7 +5,8 @@ package io.xpipe.beacon;
*/
public class ConnectorException extends Exception {
public ConnectorException() {}
public ConnectorException() {
}
public ConnectorException(String message) {
super(message);

View file

@ -1,3 +1,4 @@
package io.xpipe.beacon;
public interface RequestMessage {}
public interface RequestMessage {
}

View file

@ -1,3 +1,4 @@
package io.xpipe.beacon;
public interface ResponseMessage {}
public interface ResponseMessage {
}

View file

@ -5,7 +5,8 @@ package io.xpipe.beacon;
*/
public class ServerException extends Exception {
public ServerException() {}
public ServerException() {
}
public ServerException(String message) {
super(message);

View file

@ -31,5 +31,6 @@ public class ForwardExchange implements MessageExchange {
@Jacksonized
@Builder
@Value
public static class Response implements ResponseMessage {}
public static class Response implements ResponseMessage {
}
}

View file

@ -2,9 +2,9 @@ package io.xpipe.beacon.exchange;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.xpipe.core.util.ProxyFunction;
import io.xpipe.beacon.RequestMessage;
import io.xpipe.beacon.ResponseMessage;
import io.xpipe.core.util.ProxyFunction;
import lombok.Builder;
import lombok.Value;
import lombok.extern.jackson.Jacksonized;
@ -21,8 +21,14 @@ public class ProxyFunctionExchange implements MessageExchange {
@Value
public static class Request implements RequestMessage {
@JsonSerialize(using = ProxyFunction.Serializer.class, as = ProxyFunction.class)
@JsonDeserialize(using = ProxyFunction.Deserializer.class, as = ProxyFunction.class)
@JsonSerialize(
using = ProxyFunction.Serializer.class,
as = ProxyFunction.class
)
@JsonDeserialize(
using = ProxyFunction.Deserializer.class,
as = ProxyFunction.class
)
ProxyFunction function;
}
@ -31,8 +37,14 @@ public class ProxyFunctionExchange implements MessageExchange {
@Value
public static class Response implements ResponseMessage {
@JsonSerialize(using = ProxyFunction.Serializer.class, as = ProxyFunction.class)
@JsonDeserialize(using = ProxyFunction.Deserializer.class, as = ProxyFunction.class)
@JsonSerialize(
using = ProxyFunction.Serializer.class,
as = ProxyFunction.class
)
@JsonDeserialize(
using = ProxyFunction.Deserializer.class,
as = ProxyFunction.class
)
ProxyFunction function;
}
}

View file

@ -19,7 +19,8 @@ public class StopExchange implements MessageExchange {
@Jacksonized
@Builder
@Value
public static class Request implements RequestMessage {}
public static class Request implements RequestMessage {
}
@Jacksonized
@Builder

View file

@ -29,5 +29,6 @@ public class QueryRawDataExchange implements MessageExchange {
@Jacksonized
@Builder
@Value
public static class Response implements ResponseMessage {}
public static class Response implements ResponseMessage {
}
}

View file

@ -30,5 +30,6 @@ public class QueryTextDataExchange implements MessageExchange {
@Jacksonized
@Builder
@Value
public static class Response implements ResponseMessage {}
public static class Response implements ResponseMessage {
}
}

View file

@ -19,7 +19,8 @@ public class InstanceExchange implements MessageExchange {
@Jacksonized
@Builder
@Value
public static class Request implements RequestMessage {}
public static class Request implements RequestMessage {
}
@Jacksonized
@Builder

View file

@ -20,7 +20,8 @@ public class ListCollectionsExchange implements MessageExchange {
@Jacksonized
@Builder
@Value
public static class Request implements RequestMessage {}
public static class Request implements RequestMessage {
}
@Jacksonized
@Builder

View file

@ -20,7 +20,8 @@ public class ListStoresExchange implements MessageExchange {
@Jacksonized
@Builder
@Value
public static class Request implements RequestMessage {}
public static class Request implements RequestMessage {
}
@Jacksonized
@Builder

View file

@ -26,5 +26,6 @@ public class ModeExchange implements MessageExchange {
@Jacksonized
@Builder
@Value
public static class Response implements ResponseMessage {}
public static class Response implements ResponseMessage {
}
}

View file

@ -30,5 +30,6 @@ public class ReadDrainExchange implements MessageExchange {
@Jacksonized
@Builder
@Value
public static class Response implements ResponseMessage {}
public static class Response implements ResponseMessage {
}
}

View file

@ -26,5 +26,6 @@ public class RemoveCollectionExchange implements MessageExchange {
@Jacksonized
@Builder
@Value
public static class Response implements ResponseMessage {}
public static class Response implements ResponseMessage {
}
}

View file

@ -26,5 +26,6 @@ public class RemoveStoreExchange implements MessageExchange {
@Jacksonized
@Builder
@Value
public static class Response implements ResponseMessage {}
public static class Response implements ResponseMessage {
}
}

View file

@ -29,5 +29,6 @@ public class RenameCollectionExchange implements MessageExchange {
@Jacksonized
@Builder
@Value
public static class Response implements ResponseMessage {}
public static class Response implements ResponseMessage {
}
}

View file

@ -29,5 +29,6 @@ public class RenameStoreExchange implements MessageExchange {
@Jacksonized
@Builder
@Value
public static class Response implements ResponseMessage {}
public static class Response implements ResponseMessage {
}
}

View file

@ -27,5 +27,6 @@ public class SelectExchange implements MessageExchange {
@Jacksonized
@Builder
@Value
public static class Response implements ResponseMessage {}
public static class Response implements ResponseMessage {
}
}

View file

@ -23,7 +23,8 @@ public class SourceProviderListExchange implements MessageExchange {
@Jacksonized
@Builder
@Value
public static class Request implements RequestMessage {}
public static class Request implements RequestMessage {
}
@Jacksonized
@Builder

View file

@ -17,7 +17,8 @@ public class StatusExchange implements MessageExchange {
@Jacksonized
@Builder
@Value
public static class Request implements RequestMessage {}
public static class Request implements RequestMessage {
}
@Jacksonized
@Builder

View file

@ -22,7 +22,8 @@ public class StoreProviderListExchange implements MessageExchange {
@Jacksonized
@Builder
@Value
public static class Request implements RequestMessage {}
public static class Request implements RequestMessage {
}
@Jacksonized
@Builder

View file

@ -17,7 +17,8 @@ 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

View file

@ -13,15 +13,10 @@ import java.util.UUID;
public class QuietDialogHandler {
public static void handle(DialogReference ref, BeaconConnection connection) {
new QuietDialogHandler(ref, connection, Map.of()).handle();
}
private final UUID dialogKey;
private final BeaconConnection connection;
private final Map<String, String> overrides;
private DialogElement element;
public QuietDialogHandler(DialogReference ref, BeaconConnection connection, Map<String, String> overrides) {
this.dialogKey = ref.getDialogId();
this.element = ref.getStart();
@ -29,6 +24,10 @@ public class QuietDialogHandler {
this.overrides = overrides;
}
public static void handle(DialogReference ref, BeaconConnection connection) {
new QuietDialogHandler(ref, connection, Map.of()).handle();
}
public void handle() {
String response = null;
@ -41,9 +40,9 @@ public class QuietDialogHandler {
}
DialogExchange.Response res = connection.performSimpleExchange(DialogExchange.Request.builder()
.dialogKey(dialogKey)
.value(response)
.build());
.dialogKey(dialogKey)
.value(response)
.build());
if (res.getElement() != null && element.equals(res.getElement())) {
throw new BeaconException(
"Invalid value for key " + res.getElement().toDisplayString());

View file

@ -23,7 +23,8 @@ public abstract class Charsetter {
public static Charsetter INSTANCE;
private static CharsetterUniverse universe;
protected Charsetter() {}
protected Charsetter() {
}
protected static void checkInit() {
if (universe == null) {
@ -77,7 +78,8 @@ public abstract class Charsetter {
}
public abstract Result read(
FailableSupplier<InputStream, Exception> in, FailableConsumer<InputStreamReader, Exception> con)
FailableSupplier<InputStream, Exception> in, FailableConsumer<InputStreamReader, Exception> con
)
throws Exception;
public Result detect(StreamDataStore store) throws Exception {

View file

@ -20,8 +20,13 @@ public class StreamCharset {
public static final StreamCharset UTF8_BOM = new StreamCharset(
StandardCharsets.UTF_8,
new byte[] {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF},
Identifiers.get("utf", "8", "bom"));
new byte[]{
(byte) 0xEF,
(byte) 0xBB,
(byte) 0xBF
},
Identifiers.get("utf", "8", "bom")
);
// ======
// UTF-16
@ -32,16 +37,24 @@ public class StreamCharset {
public static final StreamCharset UTF16_BE_BOM = new StreamCharset(
StandardCharsets.UTF_16BE,
new byte[] {(byte) 0xFE, (byte) 0xFF},
Identifiers.get("utf", "16", "be", "bom"));
new byte[]{
(byte) 0xFE,
(byte) 0xFF
},
Identifiers.get("utf", "16", "be", "bom")
);
public static final StreamCharset UTF16_LE =
new StreamCharset(StandardCharsets.UTF_16LE, null, Identifiers.get("utf", "16", "le"));
public static final StreamCharset UTF16_LE_BOM = new StreamCharset(
StandardCharsets.UTF_16LE,
new byte[] {(byte) 0xFF, (byte) 0xFE},
Identifiers.get("utf", "16", "le", "bom"));
new byte[]{
(byte) 0xFF,
(byte) 0xFE
},
Identifiers.get("utf", "16", "le", "bom")
);
public static final StreamCharset UTF16 =
new StreamCharset(StandardCharsets.UTF_16, null, Identifiers.get("utf", "16"));
@ -51,30 +64,12 @@ public class StreamCharset {
ByteOrder.nativeOrder().equals(ByteOrder.BIG_ENDIAN)
? UTF16_BE_BOM.getByteOrderMark()
: UTF16_LE_BOM.getByteOrderMark(),
Identifiers.get("utf", "16", "bom"));
Identifiers.get("utf", "16", "bom")
);
// ======
// UTF-32
// ======
public static final StreamCharset UTF32_LE =
new StreamCharset(Charset.forName("utf-32le"), null, Identifiers.get("utf", "32", "le"));
public static final StreamCharset UTF32_LE_BOM = new StreamCharset(
Charset.forName("utf-32le"),
new byte[] {0x00, 0x00, (byte) 0xFE, (byte) 0xFF},
Identifiers.get("utf", "32", "le", "bom"));
public static final StreamCharset UTF32_BE =
new StreamCharset(Charset.forName("utf-32be"), null, Identifiers.get("utf", "32", "be"));
public static final StreamCharset UTF32_BE_BOM = new StreamCharset(
Charset.forName("utf-32be"),
new byte[] {
(byte) 0xFF, (byte) 0xFE, 0x00, 0x00,
},
Identifiers.get("utf", "32", "be", "bom"));
public static final List<StreamCharset> COMMON = List.of(
UTF8,
UTF8_BOM,
@ -83,7 +78,8 @@ public class StreamCharset {
new StreamCharset(
StandardCharsets.US_ASCII,
null,
Identifiers.join(Identifiers.get("ascii"), Identifiers.get("us", "ascii"))),
Identifiers.join(Identifiers.get("ascii"), Identifiers.get("us", "ascii"))
),
new StreamCharset(
StandardCharsets.ISO_8859_1,
null,
@ -91,16 +87,44 @@ public class StreamCharset {
Identifiers.get("iso", "8859"),
Identifiers.get("iso", "8859", "1"),
Identifiers.get("8859"),
Identifiers.get("8859", "1"))),
Identifiers.get("8859", "1")
)
),
new StreamCharset(
Charset.forName("Windows-1251"),
null,
Identifiers.join(Identifiers.get("windows", "1251"), Identifiers.get("1251"))),
Identifiers.join(Identifiers.get("windows", "1251"), Identifiers.get("1251"))
),
new StreamCharset(
Charset.forName("Windows-1252"),
null,
Identifiers.join(Identifiers.get("windows", "1252"), Identifiers.get("1252"))));
Identifiers.join(Identifiers.get("windows", "1252"), Identifiers.get("1252"))
)
);
public static final StreamCharset UTF32_LE =
new StreamCharset(Charset.forName("utf-32le"), null, Identifiers.get("utf", "32", "le"));
public static final StreamCharset UTF32_LE_BOM = new StreamCharset(
Charset.forName("utf-32le"),
new byte[]{
0x00,
0x00,
(byte) 0xFE,
(byte) 0xFF
},
Identifiers.get("utf", "32", "le", "bom")
);
public static final StreamCharset UTF32_BE =
new StreamCharset(Charset.forName("utf-32be"), null, Identifiers.get("utf", "32", "be"));
public static final StreamCharset UTF32_BE_BOM = new StreamCharset(
Charset.forName("utf-32be"),
new byte[]{
(byte) 0xFF,
(byte) 0xFE,
0x00,
0x00,
},
Identifiers.get("utf", "32", "be", "bom")
);
private static final List<StreamCharset> RARE_NAMED =
List.of(UTF16_LE, UTF16_LE_BOM, UTF16_BE, UTF16_BE_BOM, UTF32_LE, UTF32_LE_BOM, UTF32_BE, UTF32_BE_BOM);
@ -113,23 +137,41 @@ public class StreamCharset {
&& !charset.displayName().startsWith("X-")
&& !charset.displayName().endsWith("-BOM")
&& COMMON.stream()
.noneMatch(c -> c.getCharset().equals(charset))
.noneMatch(c -> c.getCharset().equals(charset))
&& RARE_NAMED.stream()
.noneMatch(c -> c.getCharset().equals(charset)))
.noneMatch(c -> c.getCharset().equals(charset)))
.map(charset -> new StreamCharset(
charset,
null,
Identifiers.get(charset.name().split("-")))))
Identifiers.get(charset.name().split("-"))
))
)
.toList();
public static final List<StreamCharset> ALL = Stream.concat(COMMON.stream(), RARE.stream()).toList();
Charset charset;
byte[] byteOrderMark;
List<String> names;
public static StreamCharset get(Charset charset, boolean byteOrderMark) {
return ALL.stream()
.filter(streamCharset ->
streamCharset.getCharset().equals(charset) && streamCharset.hasByteOrderMark() == byteOrderMark)
.findFirst()
.orElseThrow();
}
public static StreamCharset get(String s) {
var found = ALL.stream().filter(streamCharset -> streamCharset.getNames().contains(s.toLowerCase(Locale.ROOT))).findFirst();
if (found.isEmpty()) {
throw new IllegalArgumentException("Unknown charset name: " + s);
}
return found.get();
}
@Override
public boolean equals(Object o) {
if (this == o) {
@ -148,23 +190,6 @@ public class StreamCharset {
return result;
}
public static StreamCharset get(Charset charset, boolean byteOrderMark) {
return ALL.stream()
.filter(streamCharset ->
streamCharset.getCharset().equals(charset) && streamCharset.hasByteOrderMark() == byteOrderMark)
.findFirst()
.orElseThrow();
}
public static StreamCharset get(String s) {
var found = ALL.stream().filter(streamCharset -> streamCharset.getNames().contains(s.toLowerCase(Locale.ROOT))).findFirst();
if (found.isEmpty()) {
throw new IllegalArgumentException("Unknown charset name: " + s);
}
return found.get();
}
public String toString() {
return getNames().get(0);
}

View file

@ -17,7 +17,8 @@ public class GenericArrayReader implements GenericAbstractReader {
private GenericAbstractReader currentReader;
private DataStructureNode created;
public GenericArrayReader() {}
public GenericArrayReader() {
}
public static GenericArrayReader newReader(int length) {
var ar = new GenericArrayReader();

View file

@ -4,15 +4,21 @@ 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<Integer, String> metaAttributes) {}
default void onArrayEnd(Map<Integer, String> metaAttributes) {
}
default void onTupleStart(int length) {}
default void onTupleStart(int length) {
}
default void onTupleEnd(Map<Integer, String> metaAttributes) {}
default void onTupleEnd(Map<Integer, String> metaAttributes) {
}
default void onValue(byte[] value, Map<Integer, String> metaAttributes) {}
default void onValue(byte[] value, Map<Integer, String> metaAttributes) {
}
}

View file

@ -19,7 +19,8 @@ public class GenericTupleReader implements GenericAbstractReader {
private GenericAbstractReader currentReader;
private DataStructureNode created;
public GenericTupleReader() {}
public GenericTupleReader() {
}
public static GenericTupleReader newReader(int length) {
var tr = new GenericTupleReader();

View file

@ -8,7 +8,8 @@ import java.util.stream.Collectors;
public abstract class ArrayNode extends DataStructureNode {
protected ArrayNode() {}
protected ArrayNode() {
}
public static ArrayNode empty() {
return of(List.of());

View file

@ -129,13 +129,13 @@ public abstract class DataStructureNode implements Iterable<DataStructureNode> {
public String metaToString() {
return "("
+ (metaAttributes != null
? metaAttributes.entrySet().stream()
.sorted(Comparator.comparingInt(entry -> entry.getKey()))
.map(e -> e.getValue() != null
? e.getKey() + ":" + e.getValue()
: e.getKey().toString())
.collect(Collectors.joining("|"))
: "")
? metaAttributes.entrySet().stream()
.sorted(Comparator.comparingInt(entry -> entry.getKey()))
.map(e -> e.getValue() != null
? e.getKey() + ":" + e.getValue()
: e.getKey().toString())
.collect(Collectors.joining("|"))
: "")
+ ")";
}
@ -242,5 +242,6 @@ public abstract class DataStructureNode implements Iterable<DataStructureNode> {
throw unsupported("iterator creation");
}
public record KeyValue(String key, DataStructureNode value) {}
public record KeyValue(String key, DataStructureNode value) {
}
}

View file

@ -217,7 +217,8 @@ public class DataStructureNodePointer {
}
public Builder pointerEvaluation(
DataStructureNodePointer pointer, Function<DataStructureNode, String> converter) {
DataStructureNodePointer pointer, Function<DataStructureNode, String> converter
) {
path.add(new FunctionElement((current) -> {
var res = pointer.get(current);
if (res != null) {

View file

@ -86,7 +86,8 @@ public class LinkedTupleNode extends TupleNode {
public DataType determineDataType() {
return TupleType.of(
getKeyNames(),
getNodes().stream().map(DataStructureNode::determineDataType).toList());
getNodes().stream().map(DataStructureNode::determineDataType).toList()
);
}
@Override

View file

@ -67,7 +67,9 @@ public class SimpleTupleNode extends TupleNode {
@Override
public DataStructureNode clear() {
nodes.clear();
if (names != null) names.clear();
if (names != null) {
names.clear();
}
return this;
}

View file

@ -102,8 +102,9 @@ public abstract class TupleNode extends DataStructureNode {
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())
entries.stream().map(KeyValue::key).toList(),
entries.stream().map(KeyValue::value).toList()
)
: TupleNode.of(entries.stream().map(KeyValue::value).toList());
}
}

View file

@ -13,7 +13,8 @@ import java.util.Objects;
public abstract class ValueNode extends DataStructureNode {
protected ValueNode() {}
protected ValueNode() {
}
public static ValueNode nullValue() {
return new SimpleValueNode(new byte[0]).tag(IS_NULL).asValue();

View file

@ -10,7 +10,10 @@ import java.util.Optional;
* To check whether a {@link DataStructureNode} instance conforms to the specified type,
* the method {@link #matches(DataStructureNode)} can be used.
*/
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
property = "type"
)
public abstract class DataType {
/**

View file

@ -2,11 +2,15 @@ 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) {
}
}

View file

@ -41,7 +41,8 @@ public class DataTypeVisitors {
* Creates a visitor that allows for visiting possible recursive columns of table.
*/
public static DataTypeVisitor table(
Consumer<String> newTuple, Runnable endTuple, BiConsumer<String, DataStructureNodePointer> newValue) {
Consumer<String> newTuple, Runnable endTuple, BiConsumer<String, DataStructureNodePointer> newValue
) {
return new DataTypeVisitor() {
private final Stack<TupleType> tuples = new Stack<>();
private final Stack<Integer> keyIndices = new Stack<>();

View file

@ -17,7 +17,8 @@ import java.util.Optional;
@Value
public class WildcardType extends DataType {
private WildcardType() {}
private WildcardType() {
}
/**
* Creates a new instance.

View file

@ -7,19 +7,27 @@ import java.util.Map;
public interface TypedDataStreamCallback {
default void onValue(byte[] data, Map<Integer, String> metaAttributes) {}
default void onValue(byte[] data, Map<Integer, String> 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<Integer, String> metaAttributes) {}
default void onTupleEnd(Map<Integer, String> metaAttributes) {
}
default void onArrayBegin(int size) {}
default void onArrayBegin(int size) {
}
default void onArrayEnd(Map<Integer, String> metaAttributes) {}
default void onArrayEnd(Map<Integer, String> metaAttributes) {
}
default void onNodeBegin() {}
default void onNodeBegin() {
}
default void onNodeEnd() {}
default void onNodeEnd() {
}
}

View file

@ -19,6 +19,7 @@ public class TypedDataStructureNodeReader implements TypedAbstractReader {
private int arrayDepth;
private DataType expectedType;
private int currentExpectedTypeIndex;
private TypedDataStructureNodeReader(DataType type) {
flattened = new ArrayList<>();
type.visit(DataTypeVisitors.flatten(flattened::add));

View file

@ -21,7 +21,8 @@ public class BaseQueryElement extends DialogElement {
@JsonCreator
public BaseQueryElement(
String description, boolean newLine, boolean required, boolean secret, boolean quiet, String value) {
String description, boolean newLine, boolean required, boolean secret, boolean quiet, String value
) {
this.description = description;
this.newLine = newLine;
this.required = required;

View file

@ -30,13 +30,6 @@ public abstract class Dialog {
protected Object eval;
private Supplier<?> evaluation;
/**
* Removes all completion listeners. Intended for internal use only.
*/
public void clearCompletion() {
completion.clear();
}
/**
* Creates an empty dialogue. This dialogue completes immediately and does not handle any questions or answers.
*/
@ -65,7 +58,8 @@ public abstract class Dialog {
* @param selected the selected element index
*/
public static Dialog.Choice choice(
String description, List<io.xpipe.core.dialog.Choice> elements, boolean required, boolean quiet, int selected) {
String description, List<io.xpipe.core.dialog.Choice> elements, boolean required, boolean quiet, int selected
) {
Dialog.Choice c = new Dialog.Choice(description, elements, required, quiet, selected);
c.evaluateTo(c::getSelected);
return c;
@ -83,7 +77,8 @@ public abstract class Dialog {
*/
@SafeVarargs
public static <T> Dialog.Choice choice(
String description, Function<T, String> toString, boolean required, boolean quiet, T def, T... vals) {
String description, Function<T, String> toString, boolean required, boolean quiet, T def, T... vals
) {
var elements = Arrays.stream(vals)
.map(v -> new io.xpipe.core.dialog.Choice(null, toString.apply(v)))
.toList();
@ -120,7 +115,8 @@ public abstract class Dialog {
boolean required,
boolean quiet,
T value,
QueryConverter<T> converter) {
QueryConverter<T> converter
) {
var q = new <T>Dialog.Query(description, newLine, required, quiet, value, converter, false);
q.evaluateTo(q::getConvertedValue);
return q;
@ -166,7 +162,8 @@ 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;
}
@ -357,7 +354,8 @@ public abstract class Dialog {
List<io.xpipe.core.dialog.Choice> elements,
boolean required,
int selected,
Function<Integer, Dialog> c) {
Function<Integer, Dialog> c
) {
var choice = new ChoiceElement(description, elements, required, false, selected);
return new Dialog() {
@ -391,6 +389,13 @@ public abstract class Dialog {
};
}
/**
* Removes all completion listeners. Intended for internal use only.
*/
public void clearCompletion() {
completion.clear();
}
/* TODO: Implement automatic completion mechanism for start as well
* In case start returns null, the completion is not automatically done.
* */
@ -497,7 +502,8 @@ public abstract class Dialog {
boolean quiet,
T value,
QueryConverter<T> converter,
boolean hidden) {
boolean hidden
) {
this.element = new QueryElement(description, newLine, required, quiet, value, converter, hidden);
}

View file

@ -5,7 +5,8 @@ package io.xpipe.core.dialog;
*/
public class DialogCancelException extends Exception {
public DialogCancelException() {}
public DialogCancelException() {
}
public DialogCancelException(String message) {
super(message);
@ -20,7 +21,8 @@ public class DialogCancelException extends Exception {
}
public DialogCancelException(
String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace
) {
super(message, cause, enableSuppression, writableStackTrace);
}
}

View file

@ -8,7 +8,10 @@ import java.util.UUID;
@EqualsAndHashCode
@ToString
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
property = "type"
)
public abstract class DialogElement {
protected String id;

View file

@ -22,7 +22,7 @@ public class DialogMapper {
return map;
}
private void handle(DialogElement element) throws Exception {
private void handle(DialogElement element) throws Exception {
String response = null;
if (element instanceof ChoiceElement c) {
response = handleChoice(c);
@ -45,8 +45,8 @@ public class DialogMapper {
}
private String handleQuery(BaseQueryElement q) {
map.put(q.getDescription(), q.getValue());
return q.getValue();
map.put(q.getDescription(), q.getValue());
return q.getValue();
}
private String handleChoice(ChoiceElement c) {

View file

@ -14,7 +14,8 @@ public class QueryElement extends BaseQueryElement {
boolean quiet,
T value,
QueryConverter<T> converter,
boolean hidden) {
boolean hidden
) {
super(description, newLine, required, hidden, quiet, value != null ? converter.toString(value) : null);
this.converter = converter;
}

View file

@ -44,13 +44,13 @@ public class BinarySource extends RawDataSource<StreamDataStore> {
protected RawReadConnection newReadConnection() {
return new RawReadConnection() {
private InputStream inputStream;
@Override
public boolean canRead() throws Exception {
return getStore().canOpen();
}
private InputStream inputStream;
@Override
public void init() throws Exception {
if (inputStream != null) {

View file

@ -43,7 +43,7 @@ public class FileNames {
return backslash ? toWindows(file) : toUnix(file);
}
private static List<String> split(String file) {
private static List<String> split(String file) {
var split = file.split("[\\\\/]");
return Arrays.stream(split).filter(s -> !s.isEmpty()).toList();
}

View file

@ -32,7 +32,18 @@ public class FileStore extends JacksonizedValue implements FilenameStore, Stream
this.file = file;
}
public String getParent() {
public static FileStore local(Path p) {
return new FileStore(new LocalStore(), p.toString());
}
/**
* Creates a file store for a file that is local to the callers machine.
*/
public static FileStore local(String p) {
return new FileStore(new LocalStore(), p);
}
public String getParent() {
var matcher = Pattern.compile("^(.+?)[^\\\\/]+$").matcher(file);
if (!matcher.matches()) {
throw new IllegalArgumentException("Unable to determine parent of " + file);
@ -45,17 +56,6 @@ public class FileStore extends JacksonizedValue implements FilenameStore, Stream
return fileSystem instanceof LocalStore;
}
public static FileStore local(Path p) {
return new FileStore(new LocalStore(), p.toString());
}
/**
* Creates a file store for a file that is local to the callers machine.
*/
public static FileStore local(String p) {
return new FileStore(new LocalStore(), p);
}
@Override
public void checkComplete() throws Exception {
if (fileSystem == null) {

View file

@ -6,20 +6,20 @@ import java.util.ServiceLoader;
public abstract class LocalProcessControlProvider {
private static LocalProcessControlProvider INSTANCE;
public static LocalProcessControlProvider get() {
return INSTANCE;
}
private static LocalProcessControlProvider INSTANCE;
public static void init(ModuleLayer layer) {
INSTANCE = layer != null
? ServiceLoader.load(layer, LocalProcessControlProvider.class)
.findFirst()
.orElse(null)
.findFirst()
.orElse(null)
: ServiceLoader.load(LocalProcessControlProvider.class)
.findFirst()
.orElse(null);
.findFirst()
.orElse(null);
}
public static ShellProcessControl create() {

View file

@ -45,6 +45,7 @@ public class LocalStore extends JacksonizedValue implements FileSystemStore, Mac
var p = Path.of(file);
return Files.newOutputStream(p);
}
@Override
public ShellProcessControl create() {
return LocalProcessControlProvider.create();

View file

@ -12,6 +12,7 @@ public class PreservingTableWriteConnection extends PreservingWriteConnection im
public PreservingTableWriteConnection(DataSource<?> source, DataSourceConnection connection, boolean append) {
super(DataSourceType.TABLE, source, append, connection);
}
@Override
public Optional<TableMapping> createMapping(TupleType inputType) throws Exception {
return ((TableWriteConnection) connection).createMapping(inputType);

View file

@ -15,7 +15,8 @@ public class PreservingWriteConnection implements DataSourceConnection {
private final boolean append;
public PreservingWriteConnection(
DataSourceType type, DataSource<?> source, boolean append, DataSourceConnection connection) {
DataSourceType type, DataSource<?> source, boolean append, DataSourceConnection connection
) {
this.type = type;
this.source = source;
this.append = append;
@ -28,7 +29,7 @@ public class PreservingWriteConnection implements DataSourceConnection {
var nativeSource = DataSource.createInternalDataSource(type, nativeStore);
if (source.getStore().canOpen()) {
try (var in = source.openReadConnection();
var out = nativeSource.openWriteConnection(WriteMode.REPLACE)) {
var out = nativeSource.openWriteConnection(WriteMode.REPLACE)) {
in.init();
out.init();
in.forward(out);

View file

@ -7,7 +7,7 @@ import io.xpipe.core.source.TableWriteConnection;
import java.util.Optional;
public interface SimpleTableWriteConnection<T extends TableDataSource<?>> extends TableWriteConnection {
public interface SimpleTableWriteConnection<T extends TableDataSource<?>> extends TableWriteConnection {
public T getSource();
@ -18,7 +18,7 @@ public interface SimpleTableWriteConnection<T extends TableDataSource<?>> exten
public default Optional<TableMapping> createMapping(TupleType inputType) throws Exception {
var outputType = getType();
if (outputType.isEmpty() || outputType.get().getSize() == 0){
if (outputType.isEmpty() || outputType.get().getSize() == 0) {
return Optional.of(TableMapping.createIdentity(inputType));
}

View file

@ -21,14 +21,6 @@ import java.nio.channels.Pipe;
@Getter
public class SinkDrainStore extends JacksonizedValue implements KnownFormatStreamDataStore, StatefulDataStore {
public static enum State {
NONE_CONNECTED,
PRODUCER_CONNECTED,
CONSUMER_CONNECTED,
OPEN,
CLOSED
}
private final StreamCharset charset;
private final NewLine newLine;
@ -163,4 +155,12 @@ public class SinkDrainStore extends JacksonizedValue implements KnownFormatStrea
throw new IllegalStateException("Consumer is already connected");
}
}
public static enum State {
NONE_CONNECTED,
PRODUCER_CONNECTED,
CONSUMER_CONNECTED,
OPEN,
CLOSED
}
}

View file

@ -26,7 +26,8 @@ public class StdinDataStore extends JacksonizedValue implements StreamDataStore
// Prevent closing the standard in when the returned input stream is closed
return new FilterInputStream(in) {
@Override
public void close() throws IOException {}
public void close() throws IOException {
}
};
}
}

View file

@ -30,7 +30,8 @@ public class StdoutDataStore extends JacksonizedValue implements StreamDataStore
// Create an output stream that will write to standard out but will not close it
return new FilterOutputStream(System.out) {
@Override
public void close() throws IOException {}
public void close() throws IOException {
}
};
}
}

View file

@ -24,6 +24,7 @@ public class XpbtReadConnection extends StreamReadConnection implements TableRea
private TupleType dataType;
private TypedDataStreamParser parser;
private boolean empty;
protected XpbtReadConnection(XpbtSource source) {
super(source.getStore(), null);
this.store = source.getStore();
@ -46,13 +47,14 @@ public class XpbtReadConnection extends StreamReadConnection implements TableRea
this.inputStream.skip(headerLength + 1);
List<String> names = JacksonMapper.newMapper()
.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE)
.readerFor(new TypeReference<List<String>>() {})
.readerFor(new TypeReference<List<String>>() {
})
.readValue(header);
TupleType dataType = TupleType.tableType(names);
this.dataType = dataType;
this.parser = new TypedDataStreamParser(dataType);
}
@Override
public TupleType getDataType() {
return dataType;

View file

@ -9,16 +9,6 @@ public interface OsType {
Linux LINUX = new Linux();
Mac MAC = new Mac();
String getName();
String getTempDirectory(ShellProcessControl pc) throws Exception;
String normalizeFileName(String file);
Map<String, String> getProperties(ShellProcessControl pc) throws Exception;
String determineOperatingSystemName(ShellProcessControl pc) throws Exception;
public static OsType getLocal() {
String osName = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
if ((osName.contains("mac")) || (osName.contains("darwin"))) {
@ -32,6 +22,16 @@ public interface OsType {
}
}
String getName();
String getTempDirectory(ShellProcessControl pc) throws Exception;
String normalizeFileName(String file);
Map<String, String> getProperties(ShellProcessControl pc) throws Exception;
String determineOperatingSystemName(ShellProcessControl pc) throws Exception;
static class Windows implements OsType {
@Override
@ -52,7 +52,7 @@ public interface OsType {
@Override
public Map<String, String> getProperties(ShellProcessControl pc) throws Exception {
try (CommandProcessControl c =
pc.subShell(ShellTypes.CMD).command("systeminfo").start()) {
pc.subShell(ShellTypes.CMD).command("systeminfo").start()) {
var text = c.readOrThrow();
return PropertiesFormatsParser.parse(text, ":");
}
@ -144,7 +144,7 @@ public interface OsType {
@Override
public Map<String, String> getProperties(ShellProcessControl pc) throws Exception {
try (CommandProcessControl c =
pc.subShell(ShellTypes.BASH).command("sw_vers").start()) {
pc.subShell(ShellTypes.BASH).command("sw_vers").start()) {
var text = c.readOrThrow();
return PropertiesFormatsParser.parse(text, ":");
}

View file

@ -8,7 +8,7 @@ import java.nio.charset.Charset;
public interface ProcessControl extends Closeable, AutoCloseable {
String prepareTerminalOpen() throws Exception;
String prepareTerminalOpen() throws Exception;
void closeStdin() throws IOException;
@ -24,6 +24,7 @@ public interface ProcessControl extends Closeable, AutoCloseable {
@Override
void close() throws IOException;
void kill() throws Exception;
ProcessControl start() throws Exception;

View file

@ -18,7 +18,8 @@ public class ProcessOutputException extends Exception {
}
protected ProcessOutputException(
String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace
) {
super(message, cause, enableSuppression, writableStackTrace);
}
}

View file

@ -55,8 +55,8 @@ public interface ShellProcessControl extends ProcessControl {
default ShellProcessControl subShell(@NonNull ShellType type) {
return subShell(p -> type.getNormalOpenCommand(), (shellProcessControl, s) -> {
return s == null ? type.getNormalOpenCommand() : type.executeCommandWithShell(s);
})
return s == null ? type.getNormalOpenCommand() : type.executeCommandWithShell(s);
})
.elevation(getElevationPassword());
}
@ -71,7 +71,8 @@ public interface ShellProcessControl extends ProcessControl {
ShellProcessControl subShell(
@NonNull Function<ShellProcessControl, String> command,
BiFunction<ShellProcessControl, String, String> terminalCommand);
BiFunction<ShellProcessControl, String, String> terminalCommand
);
void executeCommand(String command) throws Exception;
@ -81,7 +82,8 @@ public interface ShellProcessControl extends ProcessControl {
CommandProcessControl command(Function<ShellProcessControl, String> command);
CommandProcessControl command(
Function<ShellProcessControl, String> command, Function<ShellProcessControl, String> terminalCommand);
Function<ShellProcessControl, String> command, Function<ShellProcessControl, String> terminalCommand
);
default CommandProcessControl command(String command) {
return command(shellProcessControl -> command);

View file

@ -7,7 +7,10 @@ import java.nio.charset.Charset;
import java.util.List;
import java.util.stream.Collectors;
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
property = "type"
)
public interface ShellType {
String getScriptFileEnding();
@ -25,8 +28,8 @@ public interface ShellType {
default String flatten(List<String> command) {
return command.stream()
.map(s -> s.contains(" ")
&& !(s.startsWith("\"") && s.endsWith("\""))
&& !(s.startsWith("'") && s.endsWith("'"))
&& !(s.startsWith("\"") && s.endsWith("\""))
&& !(s.startsWith("'") && s.endsWith("'"))
? "\"" + s + "\""
: s)
.collect(Collectors.joining(" "));

View file

@ -23,7 +23,10 @@ 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<DS extends DataStore> extends JacksonizedValue {
protected DS store;
@ -39,7 +42,7 @@ public abstract class DataSource<DS extends DataStore> extends JacksonizedValue
.charset(StreamCharset.UTF8)
.build();
case RAW -> null;
// TODO
// TODO
case COLLECTION -> null;
};
} catch (Exception ex) {
@ -47,7 +50,7 @@ public abstract class DataSource<DS extends DataStore> extends JacksonizedValue
}
}
public boolean isComplete() {
public boolean isComplete() {
try {
checkComplete();
return true;

View file

@ -9,7 +9,9 @@ public interface DataSourceConnection extends AutoCloseable {
* Initializes this connection. Required to be called
* exactly once prior to attempting to use this connection.
*/
default void init() throws Exception {}
default void init() throws Exception {
}
default void close() throws Exception {}
default void close() throws Exception {
}
}

View file

@ -11,7 +11,7 @@ import lombok.Getter;
* To allow for a simple usage of data source ids, the collection and entry names are trimmed and
* converted to lower case names when creating them.
* The two names are separated by a colon and are therefore not allowed to contain colons themselves.
*
* <p>
* A missing collection name indicates that the data source exists only temporarily.
*
* @see #create(String, String)

View file

@ -10,7 +10,7 @@ import java.util.Objects;
* Represents a reference to an X-Pipe data source.
* Using {@link DataSourceReference} instances instead of {@link DataSourceId}
* instances is mainly done for user convenience purposes.
*
* <p>
* While a {@link DataSourceId} represents a unique and canonical identifier for an X-Pipe data source,
* there also exist easier and shorter ways to address a data source.
* This convenience comes at the price of ambiguity and instability for other types of references.
@ -105,8 +105,12 @@ public interface DataSourceReference {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Id id = (Id) o;
return value.equals(id.value);
}
@ -155,8 +159,12 @@ public interface DataSourceReference {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Name n = (Name) o;
return value.equals(n.value);
}
@ -201,7 +209,9 @@ public interface DataSourceReference {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (this == o) {
return true;
}
return o != null && getClass() == o.getClass();
}

View file

@ -45,28 +45,6 @@ public abstract class TableDataSource<DS extends DataStore> extends DataSource<D
return newReadConnection();
}
@NoArgsConstructor
private static class CreateMappingFunction extends SimpleProxyFunction<TableMapping> {
private TableDataSource<?> source;
private TupleType type;
public CreateMappingFunction(TableDataSource<?> source, TupleType type) {
this.source = source;
this.type = type;
}
private TableMapping mapping;
@SneakyThrows
public void callLocal() {
try (TableWriteConnection w = source.openWriteConnection(WriteMode.REPLACE)) {
w.init();
mapping = w.createMapping(type).orElse(null);
}
}
}
public final Optional<TableMapping> createMapping(TupleType inputType) throws Exception {
return Optional.ofNullable(new CreateMappingFunction(this, inputType).callAndGet());
}
@ -100,4 +78,25 @@ public abstract class TableDataSource<DS extends DataStore> extends DataSource<D
protected TableReadConnection newReadConnection() {
throw new UnsupportedOperationException();
}
@NoArgsConstructor
private static class CreateMappingFunction extends SimpleProxyFunction<TableMapping> {
private TableDataSource<?> source;
private TupleType type;
private TableMapping mapping;
public CreateMappingFunction(TableDataSource<?> source, TupleType type) {
this.source = source;
this.type = type;
}
@SneakyThrows
public void callLocal() {
try (TableWriteConnection w = source.openWriteConnection(WriteMode.REPLACE)) {
w.init();
mapping = w.createMapping(type).orElse(null);
}
}
}
}

View file

@ -13,6 +13,17 @@ import java.util.stream.IntStream;
@Getter
public class TableMapping {
protected final Integer[] columMap;
private final TupleType inputType;
private final TupleType outputType;
@JsonCreator
public TableMapping(TupleType inputType, TupleType outputType, Integer[] columMap) {
this.inputType = inputType;
this.outputType = outputType;
this.columMap = columMap;
}
private static Integer[] range(int size) {
var array = new Integer[size];
for (int i = 0; i < size; i++) {
@ -58,19 +69,6 @@ public class TableMapping {
return OptionalInt.empty();
}
private final TupleType inputType;
private final TupleType outputType;
protected final Integer[] columMap;
@JsonCreator
public TableMapping(TupleType inputType, TupleType outputType, Integer[] columMap) {
this.inputType = inputType;
this.outputType = outputType;
this.columMap = columMap;
}
public boolean isIdentity() {
return inputType.equals(outputType)
&& Arrays.equals(columMap, range(getInputType().getSize()));

View file

@ -9,37 +9,39 @@ import java.util.ServiceLoader;
public class WriteMode extends JacksonizedValue {
public static final Replace REPLACE = new Replace();
public static final Append APPEND = new Append();
public static final Prepend PREPEND = new Prepend();
private static final List<WriteMode> ALL = new ArrayList<>();
public static void init(ModuleLayer layer) {
if (ALL.size() == 0) {
ALL.addAll(ServiceLoader.load(layer, WriteMode.class).stream()
.map(p -> p.get())
.toList());
.map(p -> p.get())
.toList());
}
}
@JsonTypeName("replace")
public static final class Replace extends WriteMode {}
@JsonTypeName("append")
public static final class Append extends WriteMode {}
@JsonTypeName("prepend")
public static final class Prepend extends WriteMode {}
public static final Replace REPLACE = new Replace();
public static final Append APPEND = new Append();
public static final Prepend PREPEND = new Prepend();
public final String getId() {
return getClass().getAnnotation(JsonTypeName.class).value();
}
public static WriteMode byId(String id) {
return ALL.stream()
.filter(writeMode -> writeMode.getId().equalsIgnoreCase(id))
.findFirst()
.orElseThrow();
}
public final String getId() {
return getClass().getAnnotation(JsonTypeName.class).value();
}
@JsonTypeName("replace")
public static final class Replace extends WriteMode {
}
@JsonTypeName("append")
public static final class Append extends WriteMode {
}
@JsonTypeName("prepend")
public static final class Prepend extends WriteMode {
}
}

View file

@ -16,7 +16,10 @@ import java.util.Optional;
*
* @see DataSource
*/
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
property = "type"
)
public interface DataStore {
default boolean shouldPersist() {
@ -61,23 +64,25 @@ public interface DataStore {
/**
* Performs a validation of this data store.
*
* <p>
* This validation can include one of multiple things:
* - Sanity checks of individual properties
* - Existence checks
* - Connection checks
*
* <p>
* All in all, a successful execution of this method should almost guarantee
* that the data store can be successfully accessed in the near future.
*
* <p>
* Note that some checks may take a long time, for example if a connection has to be validated.
* The caller should therefore expect a runtime of multiple seconds when calling this method.
*
* @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;

View file

@ -36,7 +36,7 @@ public interface MachineStore extends FileSystemStore, ShellStore {
public default boolean mkdirs(String file) throws Exception {
try (var pc = create().command(proc -> proc.getShellType()
.flatten(proc.getShellType()
.createMkdirsCommand(proc.getOsType().normalizeFileName(file))))
.createMkdirsCommand(proc.getOsType().normalizeFileName(file))))
.start()) {
return pc.discardAndCheckExit();
}

View file

@ -28,9 +28,11 @@ public interface ShellStore extends DataStore {
return pc.getShellType();
}
}
@Override
default void validate() throws Exception {
try (ShellProcessControl pc = create().start()) {}
try (ShellProcessControl pc = create().start()) {
}
}
public default String queryMachineName() throws Exception {

View file

@ -4,11 +4,12 @@ import io.xpipe.core.util.DataStateProvider;
import java.util.function.Supplier;
public interface StatefulDataStore extends DataStore {
public interface StatefulDataStore extends DataStore {
default <T> T getState(String key, Class<T> c, T def) {
default <T> T getState(String key, Class<T> c, T def) {
return DataStateProvider.get().getState(this, key, c, () -> def);
}
default <T> T getOrComputeState(String key, Class<T> c, Supplier<T> def) {
return DataStateProvider.get().getState(this, key, c, def);
}

View file

@ -52,7 +52,8 @@ public class CoreJacksonModule extends SimpleModule {
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());
@ -197,12 +198,16 @@ 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<Object> {
public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider)

View file

@ -14,8 +14,8 @@ public abstract class DataStateProvider {
public static DataStateProvider get() {
if (INSTANCE == null) {
INSTANCE = ServiceLoader.load(ModuleLayer.boot(), DataStateProvider.class)
.findFirst()
.orElseThrow();
.findFirst()
.orElseThrow();
}
return INSTANCE;

View file

@ -42,7 +42,9 @@ public class Deobfuscator {
deobfuscate(throwable.getCause());
}
for (Throwable suppressed : throwable.getSuppressed()) {
if (suppressed != throwable) deobfuscate(suppressed);
if (suppressed != throwable) {
deobfuscate(suppressed);
}
}
} catch (Throwable ex) {
System.err.println("Deobfuscation failed");
@ -65,9 +67,10 @@ public class Deobfuscator {
var file = Files.createTempFile("xpipe_stracktrace", null);
Files.writeString(file, stackTrace);
var proc = new ProcessBuilder(
"retrace." + (OsType.getLocal().equals(OsType.WINDOWS) ? "bat" : "sh"),
System.getenv("XPIPE_MAPPING"),
file.toString())
"retrace." + (OsType.getLocal().equals(OsType.WINDOWS) ? "bat" : "sh"),
System.getenv("XPIPE_MAPPING"),
file.toString()
)
.redirectErrorStream(true);
var active = proc.start();
var out = new String(active.getInputStream().readAllBytes()).replaceAll("\r\n", NewLine.LF.getNewLineString());
@ -91,7 +94,7 @@ public class Deobfuscator {
System.err.println(s);
}
private static boolean canDeobfuscate() throws Exception {
private static boolean canDeobfuscate() throws Exception {
if (!System.getenv().containsKey("XPIPE_MAPPING")) {
return false;
}

View file

@ -20,6 +20,7 @@ public class Identifiers {
String.join("", split),
String.join(" ", split),
String.join("_", split),
String.join("-", split));
String.join("-", split)
);
}
}

View file

@ -25,13 +25,13 @@ public class JacksonMapper {
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));
.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);

View file

@ -5,10 +5,14 @@ import lombok.SneakyThrows;
import lombok.experimental.SuperBuilder;
@SuperBuilder
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
property = "type"
)
public class JacksonizedValue {
public JacksonizedValue() {}
public JacksonizedValue() {
}
@SneakyThrows
public final String toString() {

Some files were not shown because too many files have changed in this diff Show more