From 0d65db95f9a7788e8a3e8979b6a5905b49a9a3b8 Mon Sep 17 00:00:00 2001 From: Christopher Schnick Date: Fri, 2 Dec 2022 18:46:46 +0100 Subject: [PATCH] Small fixes and cleanup --- .../java/io/xpipe/beacon/BeaconClient.java | 2 +- .../io/xpipe/core/source/DataSourceInfo.java | 175 ------------------ .../io/xpipe/core/util/CoreJacksonModule.java | 6 - .../io/xpipe/core/util/XPipeInstallation.java | 4 +- 4 files changed, 3 insertions(+), 184 deletions(-) delete mode 100644 core/src/main/java/io/xpipe/core/source/DataSourceInfo.java diff --git a/beacon/src/main/java/io/xpipe/beacon/BeaconClient.java b/beacon/src/main/java/io/xpipe/beacon/BeaconClient.java index 0c8a0467..ccab7347 100644 --- a/beacon/src/main/java/io/xpipe/beacon/BeaconClient.java +++ b/beacon/src/main/java/io/xpipe/beacon/BeaconClient.java @@ -189,7 +189,7 @@ public class BeaconClient implements AutoCloseable { } public void sendRequest(T req) throws ClientException, ConnectorException { - ObjectNode json = JacksonMapper.newMapper().valueToTree(req); + ObjectNode json = JacksonMapper.getDefault().valueToTree(req); var prov = MessageExchanges.byRequest(req); if (prov.isEmpty()) { throw new ClientException("Unknown request class " + req.getClass()); diff --git a/core/src/main/java/io/xpipe/core/source/DataSourceInfo.java b/core/src/main/java/io/xpipe/core/source/DataSourceInfo.java deleted file mode 100644 index 7bea823f..00000000 --- a/core/src/main/java/io/xpipe/core/source/DataSourceInfo.java +++ /dev/null @@ -1,175 +0,0 @@ -package io.xpipe.core.source; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.fasterxml.jackson.annotation.JsonTypeName; -import io.xpipe.core.data.type.TupleType; -import lombok.EqualsAndHashCode; -import lombok.Value; - -import java.util.OptionalInt; - -/** - * A data source info instances contains all required - * essential information of a specific data source type. - * - * This information is usually determined only once on data - * source creation, as this process might be expensive. - * - * @see DataSourceType - */ -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") -public abstract class DataSourceInfo { - - public abstract DataSourceType getType(); - - /** - * Casts this instance to a table info. - */ - public Table asTable() { - if (!getType().equals(DataSourceType.TABLE)) { - throw new IllegalStateException("Not a table"); - } - - return (Table) this; - } - - /** - * Casts this instance to a structure info. - */ - public Structure asStructure() { - if (!getType().equals(DataSourceType.STRUCTURE)) { - throw new IllegalStateException("Not a structure"); - } - - return (Structure) this; - } - - /** - * Casts this instance to a text info. - */ - public Text asText() { - if (!getType().equals(DataSourceType.TEXT)) { - throw new IllegalStateException("Not a text"); - } - - return (Text) this; - } - - /** - * Casts this instance to a raw info. - */ - public Raw asRaw() { - if (!getType().equals(DataSourceType.RAW)) { - throw new IllegalStateException("Not raw"); - } - - return (Raw) this; - } - - /** - * Casts this instance to a collection info. - */ - public Collection asCollection() { - if (!getType().equals(DataSourceType.COLLECTION)) { - throw new IllegalStateException("Not a collection"); - } - - return (Collection) this; - } - - @EqualsAndHashCode(callSuper = false) - @Value - @JsonTypeName("table") - public static class Table extends DataSourceInfo { - TupleType dataType; - int rowCount; - - @JsonCreator - public Table(TupleType dataType, int rowCount) { - this.dataType = dataType; - this.rowCount = rowCount; - } - - public OptionalInt getRowCountIfPresent() { - return getRowCount() != -1 ? OptionalInt.of(getRowCount()) : OptionalInt.empty(); - } - - @Override - public DataSourceType getType() { - return DataSourceType.TABLE; - } - } - - @EqualsAndHashCode(callSuper = false) - @Value - @JsonTypeName("structure") - public static class Structure extends DataSourceInfo { - - int entries; - - @JsonCreator - public Structure(int entries) { - this.entries = entries; - } - - @Override - public DataSourceType getType() { - return DataSourceType.STRUCTURE; - } - } - - @EqualsAndHashCode(callSuper = false) - @Value - @JsonTypeName("collection") - public static class Collection extends DataSourceInfo { - - int entries; - - @JsonCreator - public Collection(int entries) { - this.entries = entries; - } - - @Override - public DataSourceType getType() { - return DataSourceType.COLLECTION; - } - } - - @EqualsAndHashCode(callSuper = false) - @Value - @JsonTypeName("text") - public static class Text extends DataSourceInfo { - int characters; - int lineCount; - - @JsonCreator - public Text(int characters, int lineCount) { - this.characters = characters; - this.lineCount = lineCount; - } - - @Override - public DataSourceType getType() { - return DataSourceType.TEXT; - } - } - - @EqualsAndHashCode(callSuper = false) - @Value - @JsonTypeName("raw") - public static class Raw extends DataSourceInfo { - int byteCount; - - @JsonCreator - public Raw(int byteCount) { - this.byteCount = byteCount; - } - - @Override - public DataSourceType getType() { - return DataSourceType.RAW; - } - } -} 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 6f7ac030..2f73771d 100644 --- a/core/src/main/java/io/xpipe/core/util/CoreJacksonModule.java +++ b/core/src/main/java/io/xpipe/core/util/CoreJacksonModule.java @@ -23,7 +23,6 @@ import io.xpipe.core.dialog.HeaderElement; import io.xpipe.core.impl.*; import io.xpipe.core.process.ShellTypes; import io.xpipe.core.source.DataSource; -import io.xpipe.core.source.DataSourceInfo; import io.xpipe.core.source.DataSourceReference; import java.io.IOException; @@ -48,11 +47,6 @@ public class CoreJacksonModule extends SimpleModule { new NamedType(ShellTypes.Cmd.class), new NamedType(ShellTypes.PowerShell.class), new NamedType(ShellTypes.Sh.class), - new NamedType(DataSourceInfo.Table.class), - new NamedType(DataSourceInfo.Structure.class), - new NamedType(DataSourceInfo.Text.class), - new NamedType(DataSourceInfo.Collection.class), - new NamedType(DataSourceInfo.Raw.class), new NamedType(BaseQueryElement.class), new NamedType(ChoiceElement.class), new NamedType(BusyElement.class), diff --git a/core/src/main/java/io/xpipe/core/util/XPipeInstallation.java b/core/src/main/java/io/xpipe/core/util/XPipeInstallation.java index 88e52ffe..721e544a 100644 --- a/core/src/main/java/io/xpipe/core/util/XPipeInstallation.java +++ b/core/src/main/java/io/xpipe/core/util/XPipeInstallation.java @@ -48,9 +48,9 @@ public class XPipeInstallation { public static String getDataBasePath(ShellProcessControl p) throws Exception { if (p.getOsType().equals(OsType.WINDOWS)) { var base = p.executeSimpleCommand(p.getShellType().getPrintVariableCommand("userprofile")); - return FileNames.join(base, "X-Pipe"); + return FileNames.join(base, ".xpipe"); } else { - return FileNames.join("~", "xpipe"); + return FileNames.join("~", ".xpipe"); } }