From aa07f88e1d77df136fda0ca7385962bfe12cddac Mon Sep 17 00:00:00 2001 From: Christopher Schnick Date: Thu, 20 Oct 2022 09:11:45 +0200 Subject: [PATCH] Small fixes --- .../io/xpipe/beacon/BeaconConnection.java | 6 +-- .../java/io/xpipe/beacon/BeaconServer.java | 14 ++--- .../exchange/QueryDataSourceExchange.java | 4 +- .../java/io/xpipe/core/dialog/Choice.java | 7 +-- .../java/io/xpipe/core/dialog/Dialog.java | 7 +++ .../io/xpipe/core/dialog/DialogMapper.java | 52 +++++++++++++++++++ .../xpipe/core/store/StandardShellStore.java | 7 ++- .../io/xpipe/core/util/CoreJacksonModule.java | 6 --- .../extension/comp/FancyTooltipAugment.java | 11 ---- 9 files changed, 80 insertions(+), 34 deletions(-) create mode 100644 core/src/main/java/io/xpipe/core/dialog/DialogMapper.java diff --git a/beacon/src/main/java/io/xpipe/beacon/BeaconConnection.java b/beacon/src/main/java/io/xpipe/beacon/BeaconConnection.java index f6c36b490..141c13e41 100644 --- a/beacon/src/main/java/io/xpipe/beacon/BeaconConnection.java +++ b/beacon/src/main/java/io/xpipe/beacon/BeaconConnection.java @@ -171,15 +171,15 @@ public abstract class BeaconConnection implements AutoCloseable { private BeaconException unwrapException(Exception exception) { if (exception instanceof ServerException s) { - return new BeaconException("An internal server error occurred", s.getCause()); + return new BeaconException("An internal server error occurred", s); } if (exception instanceof ClientException s) { - return new BeaconException("A client error occurred", s.getCause()); + return new BeaconException("A client error occurred", s); } if (exception instanceof ConnectorException s) { - return new BeaconException("A beacon connection error occurred", s.getCause()); + return new BeaconException("A beacon connection error occurred", s); } return new BeaconException("An unexpected error occurred", exception); diff --git a/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java b/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java index da43b4673..c4398d323 100644 --- a/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java +++ b/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java @@ -63,7 +63,7 @@ public class BeaconServer { System.out.println("Starting daemon: " + command); } - new Thread( + var out = new Thread( null, () -> { try { @@ -79,10 +79,11 @@ public class BeaconServer { ioe.printStackTrace(); } }, - "daemon sysout") - .start(); + "daemon sysout"); + out.setDaemon(true); + out.start(); - new Thread( + var err = new Thread( null, () -> { try { @@ -98,8 +99,9 @@ public class BeaconServer { ioe.printStackTrace(); } }, - "daemon syserr") - .start(); + "daemon syserr"); + err.setDaemon(true); + err.start(); } public static boolean tryStop(BeaconClient client) throws Exception { diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/QueryDataSourceExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/QueryDataSourceExchange.java index 9f1293a69..3505b3c26 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/QueryDataSourceExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/QueryDataSourceExchange.java @@ -11,7 +11,7 @@ import lombok.NonNull; import lombok.Value; import lombok.extern.jackson.Jacksonized; -import java.util.Map; +import java.util.LinkedHashMap; /** * Queries general information about a data source. @@ -50,7 +50,7 @@ public class QueryDataSourceExchange implements MessageExchange { String provider; @NonNull - Map config; + LinkedHashMap config; DataSource internalSource; } diff --git a/core/src/main/java/io/xpipe/core/dialog/Choice.java b/core/src/main/java/io/xpipe/core/dialog/Choice.java index e6d6bec27..53ca11b68 100644 --- a/core/src/main/java/io/xpipe/core/dialog/Choice.java +++ b/core/src/main/java/io/xpipe/core/dialog/Choice.java @@ -1,14 +1,11 @@ package io.xpipe.core.dialog; +import com.fasterxml.jackson.annotation.JsonCreator; import lombok.AllArgsConstructor; -import lombok.Builder; import lombok.Value; -import lombok.extern.jackson.Jacksonized; @Value -@Builder -@Jacksonized -@AllArgsConstructor +@AllArgsConstructor(onConstructor_ = @JsonCreator) public class Choice { /** diff --git a/core/src/main/java/io/xpipe/core/dialog/Dialog.java b/core/src/main/java/io/xpipe/core/dialog/Dialog.java index 90812732a..10b9fadf4 100644 --- a/core/src/main/java/io/xpipe/core/dialog/Dialog.java +++ b/core/src/main/java/io/xpipe/core/dialog/Dialog.java @@ -30,6 +30,13 @@ 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. */ diff --git a/core/src/main/java/io/xpipe/core/dialog/DialogMapper.java b/core/src/main/java/io/xpipe/core/dialog/DialogMapper.java new file mode 100644 index 000000000..a870addf3 --- /dev/null +++ b/core/src/main/java/io/xpipe/core/dialog/DialogMapper.java @@ -0,0 +1,52 @@ +package io.xpipe.core.dialog; + +import java.util.LinkedHashMap; + +public class DialogMapper { + + private final Dialog dialog; + private final LinkedHashMap map = new LinkedHashMap<>(); + + public DialogMapper(Dialog dialog) { + this.dialog = dialog; + dialog.clearCompletion(); + } + + public LinkedHashMap handle() throws Exception { + var element = dialog.start(); + handle(element); + return map; + } + + private void handle(DialogElement element) throws Exception { + String response = null; + if (element instanceof ChoiceElement c) { + response = handleChoice(c); + } + + if (element instanceof BaseQueryElement q) { + response = handleQuery(q); + } + + var newElement = dialog.next(response); + if (element.equals(newElement)) { + throw new IllegalStateException( + "Loop for key " + newElement.toDisplayString()); + } + + element = newElement; + if (element != null) { + handle(element); + } + } + + private String handleQuery(BaseQueryElement q) { + map.put(q.getDescription(), q.getValue()); + return q.getValue(); + } + + private String handleChoice(ChoiceElement c) { + map.put(c.getDescription(), c.getElements().get(c.getSelected()).getDescription()); + return String.valueOf(c.getSelected() + 1); + } +} diff --git a/core/src/main/java/io/xpipe/core/store/StandardShellStore.java b/core/src/main/java/io/xpipe/core/store/StandardShellStore.java index 907ca76d4..876729d1d 100644 --- a/core/src/main/java/io/xpipe/core/store/StandardShellStore.java +++ b/core/src/main/java/io/xpipe/core/store/StandardShellStore.java @@ -11,6 +11,11 @@ import java.util.List; public interface StandardShellStore extends MachineFileStore, ShellStore { + public default ProcessControl prepareLocalCommand(List input, List cmd, Integer timeout) + throws Exception { + return prepareCommand(input, cmd, timeout, determineType().determineCharset(this)); + } + public default boolean isLocal() { return false; } @@ -19,7 +24,7 @@ public interface StandardShellStore extends MachineFileStore, ShellStore { return determineType().getNewLine(); } - public abstract ShellType determineType() throws Exception; + ShellType determineType() throws Exception; public default String querySystemName() throws Exception { var result = prepareCommand( 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 4a9561389..e038b0974 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.dialog.BaseQueryElement; import io.xpipe.core.dialog.BusyElement; import io.xpipe.core.dialog.ChoiceElement; import io.xpipe.core.dialog.HeaderElement; -import io.xpipe.core.impl.TextSource; -import io.xpipe.core.impl.XpbtSource; import io.xpipe.core.source.DataSource; import io.xpipe.core.source.DataSourceInfo; import io.xpipe.core.source.DataSourceReference; @@ -36,14 +34,10 @@ public class CoreJacksonModule extends SimpleModule { @Override public void setupModule(SetupContext context) { context.registerSubtypes( - new NamedType(TextSource.class), - new NamedType(XpbtSource.class), - new NamedType(FileStore.class), new NamedType(StdinDataStore.class), new NamedType(StdoutDataStore.class), new NamedType(LocalDirectoryDataStore.class), new NamedType(CollectionEntryDataStore.class), - new NamedType(InMemoryStore.class), new NamedType(LocalStore.class), new NamedType(NamedStore.class), new NamedType(ValueType.class), diff --git a/extension/src/main/java/io/xpipe/extension/comp/FancyTooltipAugment.java b/extension/src/main/java/io/xpipe/extension/comp/FancyTooltipAugment.java index 5a02587ca..3ca11eec7 100644 --- a/extension/src/main/java/io/xpipe/extension/comp/FancyTooltipAugment.java +++ b/extension/src/main/java/io/xpipe/extension/comp/FancyTooltipAugment.java @@ -75,17 +75,6 @@ public class FancyTooltipAugment> implements Augment< } } - @Override - public void hide() { - Window owner = getOwnerWindow(); - if (owner == null || owner.isFocused()) { - try { - super.hide(); - } catch (Exception e) { - } - } - } - @Override public void show(Node ownerNode, double anchorX, double anchorY) { Window owner = getOwnerWindow();