mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-10-05 14:41:33 +00:00
Refactor and cleanup
This commit is contained in:
1 parent
6af56c451a
commit
0274ade547
299 files changed
+1634
-1335
No files matched your search
@@ -69,7 +69,7 @@ public abstract class Charsetter {
|
||||
if (charset.hasByteOrderMark()) {
|
||||
var bom = stream.readNBytes(charset.getByteOrderMark().length);
|
||||
if (bom.length != 0 && !Arrays.equals(bom, charset.getByteOrderMark())) {
|
||||
throw new IllegalStateException("Charset does not match: " + charset.toString());
|
||||
throw new IllegalStateException("Charset does not match: " + charset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ public abstract class Dialog {
|
||||
.toList();
|
||||
var index = Arrays.asList(vals).indexOf(def);
|
||||
if (def != null && index == -1) {
|
||||
throw new IllegalArgumentException("Default value " + def.toString() + " is not in possible values");
|
||||
throw new IllegalArgumentException("Default value " + def + " is not in possible values");
|
||||
}
|
||||
|
||||
var c = choice(description, elements, required, quiet, index);
|
||||
@@ -164,7 +164,6 @@ public abstract class Dialog {
|
||||
if (currentElement == null) {
|
||||
DialogElement next = null;
|
||||
while (current < ds.length - 1 && (next = ds[++current].start()) == null) {}
|
||||
;
|
||||
return next;
|
||||
}
|
||||
|
||||
@@ -213,13 +212,13 @@ public abstract class Dialog {
|
||||
final String[] msgEval = {null};
|
||||
return new Dialog() {
|
||||
@Override
|
||||
public DialogElement start() throws Exception {
|
||||
public DialogElement start() {
|
||||
msgEval[0] = msg.get();
|
||||
return new HeaderElement(msgEval[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DialogElement next(String answer) throws Exception {
|
||||
protected DialogElement next(String answer) {
|
||||
return null;
|
||||
}
|
||||
}.evaluateTo(() -> msgEval[0]);
|
||||
@@ -264,13 +263,13 @@ public abstract class Dialog {
|
||||
return new Dialog() {
|
||||
|
||||
@Override
|
||||
public DialogElement start() throws Exception {
|
||||
public DialogElement start() {
|
||||
eval = null;
|
||||
return e;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DialogElement next(String answer) throws Exception {
|
||||
protected DialogElement next(String answer) {
|
||||
if (e.apply(answer)) {
|
||||
return null;
|
||||
}
|
||||
@@ -365,7 +364,7 @@ public abstract class Dialog {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DialogElement start() throws Exception {
|
||||
public DialogElement start() {
|
||||
choiceMade = null;
|
||||
eval = null;
|
||||
return choice;
|
||||
@@ -458,7 +457,7 @@ public abstract class Dialog {
|
||||
|
||||
protected abstract DialogElement next(String answer) throws Exception;
|
||||
|
||||
public static interface FailableSupplier<T> {
|
||||
public interface FailableSupplier<T> {
|
||||
|
||||
T get() throws Exception;
|
||||
}
|
||||
@@ -477,12 +476,12 @@ public abstract class Dialog {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DialogElement start() throws Exception {
|
||||
public DialogElement start() {
|
||||
return element;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DialogElement next(String answer) throws Exception {
|
||||
protected DialogElement next(String answer) {
|
||||
if (element.apply(answer)) {
|
||||
return null;
|
||||
}
|
||||
@@ -511,12 +510,12 @@ public abstract class Dialog {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DialogElement start() throws Exception {
|
||||
public DialogElement start() {
|
||||
return element;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DialogElement next(String answer) throws Exception {
|
||||
protected DialogElement next(String answer) {
|
||||
if (element.requiresExplicitUserInput()
|
||||
&& (answer == null || answer.trim().length() == 0)) {
|
||||
return element;
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.UUID;
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
|
||||
public abstract class DialogElement {
|
||||
|
||||
protected String id;
|
||||
protected final String id;
|
||||
|
||||
public DialogElement() {
|
||||
this.id = UUID.randomUUID().toString();
|
||||
|
||||
@@ -10,7 +10,7 @@ import lombok.ToString;
|
||||
@ToString
|
||||
public class HeaderElement extends DialogElement {
|
||||
|
||||
protected String header;
|
||||
protected final String header;
|
||||
|
||||
@JsonCreator
|
||||
public HeaderElement(String header) {
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.Map;
|
||||
|
||||
public abstract class QueryConverter<T> {
|
||||
|
||||
public static final QueryConverter<NewLine> NEW_LINE = new QueryConverter<NewLine>() {
|
||||
public static final QueryConverter<NewLine> NEW_LINE = new QueryConverter<>() {
|
||||
@Override
|
||||
protected NewLine fromString(String s) {
|
||||
return NewLine.byId(s);
|
||||
@@ -23,7 +23,7 @@ public abstract class QueryConverter<T> {
|
||||
}
|
||||
};
|
||||
|
||||
public static final QueryConverter<StreamCharset> CHARSET = new QueryConverter<StreamCharset>() {
|
||||
public static final QueryConverter<StreamCharset> CHARSET = new QueryConverter<>() {
|
||||
@Override
|
||||
protected StreamCharset fromString(String s) {
|
||||
return StreamCharset.get(s);
|
||||
@@ -35,7 +35,7 @@ public abstract class QueryConverter<T> {
|
||||
}
|
||||
};
|
||||
|
||||
public static final QueryConverter<String> STRING = new QueryConverter<String>() {
|
||||
public static final QueryConverter<String> STRING = new QueryConverter<>() {
|
||||
@Override
|
||||
protected String fromString(String s) {
|
||||
return s;
|
||||
@@ -47,10 +47,10 @@ public abstract class QueryConverter<T> {
|
||||
}
|
||||
};
|
||||
|
||||
public static final QueryConverter<SecretValue> SECRET = new QueryConverter<SecretValue>() {
|
||||
public static final QueryConverter<SecretValue> SECRET = new QueryConverter<>() {
|
||||
@Override
|
||||
protected SecretValue fromString(String s) {
|
||||
//TODO
|
||||
// TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -60,29 +60,28 @@ public abstract class QueryConverter<T> {
|
||||
}
|
||||
};
|
||||
|
||||
public static final QueryConverter<Map.Entry<String, String>> HTTP_HEADER =
|
||||
new QueryConverter<Map.Entry<String, String>>() {
|
||||
@Override
|
||||
protected Map.Entry<String, String> fromString(String s) {
|
||||
if (!s.contains(":")) {
|
||||
throw new IllegalArgumentException("Missing colon");
|
||||
}
|
||||
public static final QueryConverter<Map.Entry<String, String>> HTTP_HEADER = new QueryConverter<>() {
|
||||
@Override
|
||||
protected Map.Entry<String, String> fromString(String s) {
|
||||
if (!s.contains(":")) {
|
||||
throw new IllegalArgumentException("Missing colon");
|
||||
}
|
||||
|
||||
var split = s.split(":");
|
||||
if (split.length != 2) {
|
||||
throw new IllegalArgumentException("Too many colons");
|
||||
}
|
||||
var split = s.split(":");
|
||||
if (split.length != 2) {
|
||||
throw new IllegalArgumentException("Too many colons");
|
||||
}
|
||||
|
||||
return new AbstractMap.SimpleEntry<>(split[0].trim(), split[1].trim());
|
||||
}
|
||||
return new AbstractMap.SimpleEntry<>(split[0].trim(), split[1].trim());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toString(Map.Entry<String, String> value) {
|
||||
return value.getKey() + ": " + value.getValue();
|
||||
}
|
||||
};
|
||||
@Override
|
||||
protected String toString(Map.Entry<String, String> value) {
|
||||
return value.getKey() + ": " + value.getValue();
|
||||
}
|
||||
};
|
||||
|
||||
public static final QueryConverter<URI> URI = new QueryConverter<URI>() {
|
||||
public static final QueryConverter<URI> URI = new QueryConverter<>() {
|
||||
@Override
|
||||
protected URI fromString(String s) {
|
||||
try {
|
||||
@@ -98,7 +97,7 @@ public abstract class QueryConverter<T> {
|
||||
}
|
||||
};
|
||||
|
||||
public static final QueryConverter<Integer> INTEGER = new QueryConverter<Integer>() {
|
||||
public static final QueryConverter<Integer> INTEGER = new QueryConverter<>() {
|
||||
@Override
|
||||
protected Integer fromString(String s) {
|
||||
return Integer.parseInt(s);
|
||||
@@ -110,7 +109,7 @@ public abstract class QueryConverter<T> {
|
||||
}
|
||||
};
|
||||
|
||||
public static final QueryConverter<Character> CHARACTER = new QueryConverter<Character>() {
|
||||
public static final QueryConverter<Character> CHARACTER = new QueryConverter<>() {
|
||||
@Override
|
||||
protected Character fromString(String s) {
|
||||
if (s.length() != 1) {
|
||||
@@ -126,7 +125,7 @@ public abstract class QueryConverter<T> {
|
||||
}
|
||||
};
|
||||
|
||||
public static final QueryConverter<Boolean> BOOLEAN = new QueryConverter<Boolean>() {
|
||||
public static final QueryConverter<Boolean> BOOLEAN = new QueryConverter<>() {
|
||||
@Override
|
||||
protected Boolean fromString(String s) {
|
||||
if (s.equalsIgnoreCase("y") || s.equalsIgnoreCase("yes") || s.equalsIgnoreCase("true")) {
|
||||
|
||||
@@ -46,7 +46,7 @@ public class FileNames {
|
||||
if (split.length == 0) {
|
||||
return "";
|
||||
}
|
||||
var components = Arrays.stream(split).filter(s -> !s.isEmpty()).toList();
|
||||
var components = Arrays.stream(split).filter(s -> !s.isEmpty()).toList();
|
||||
if (components.size() == 0) {
|
||||
return "";
|
||||
}
|
||||
@@ -134,7 +134,7 @@ public class FileNames {
|
||||
}
|
||||
|
||||
public static String relativize(String from, String to) {
|
||||
return normalize(to).substring(normalize(from).length());
|
||||
return normalize(to).substring(normalize(from).length());
|
||||
}
|
||||
|
||||
public static String normalize(String file) {
|
||||
@@ -149,7 +149,7 @@ public class FileNames {
|
||||
|
||||
public static String toUnix(String file) {
|
||||
var joined = String.join("/", split(file));
|
||||
var prefix = file.startsWith("/") ? "/" : "";
|
||||
var prefix = file.startsWith("/") ? "/" : "";
|
||||
var suffix = file.endsWith("/") || file.endsWith("\\") ? "/" : "";
|
||||
return prefix + joined + suffix;
|
||||
}
|
||||
|
||||
@@ -35,12 +35,12 @@ public class InMemoryStore extends JacksonizedValue implements StreamDataStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream openInput() throws Exception {
|
||||
public InputStream openInput() {
|
||||
return value != null ? new ByteArrayInputStream(value) : InputStream.nullInputStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream openOutput() throws Exception {
|
||||
public OutputStream openOutput() {
|
||||
return new ByteArrayOutputStream() {
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
|
||||
@@ -17,7 +17,7 @@ public class InputStreamStore implements StreamDataStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream openInput() throws Exception {
|
||||
public InputStream openInput() {
|
||||
return in;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,12 +22,12 @@ public final class NamedStore implements DataStore {
|
||||
private final String name;
|
||||
|
||||
@Override
|
||||
public void validate() throws Exception {
|
||||
public void validate() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete() throws Exception {
|
||||
public boolean delete() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,12 +25,12 @@ public class OutputStreamStore implements StreamDataStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream openInput() throws Exception {
|
||||
public InputStream openInput() {
|
||||
throw new UnsupportedOperationException("No input available");
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream openOutput() throws Exception {
|
||||
public OutputStream openOutput() {
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,13 +9,13 @@ import java.util.Optional;
|
||||
|
||||
public interface SimpleTableWriteConnection<T extends TableDataSource<?>> extends TableWriteConnection {
|
||||
|
||||
public T getSource();
|
||||
T getSource();
|
||||
|
||||
public default Optional<TupleType> getType() throws Exception {
|
||||
default Optional<TupleType> getType() throws Exception {
|
||||
return getSource().determineDataType();
|
||||
}
|
||||
|
||||
public default Optional<TableMapping> createMapping(TupleType inputType) throws Exception {
|
||||
default Optional<TableMapping> createMapping(TupleType inputType) throws Exception {
|
||||
var outputType = getType();
|
||||
if (outputType.isEmpty() || outputType.get().getSize() == 0) {
|
||||
return Optional.of(TableMapping.createIdentity(inputType));
|
||||
|
||||
@@ -80,12 +80,12 @@ public class SinkDrainStore extends JacksonizedValue implements KnownFormatStrea
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canOpen() throws Exception {
|
||||
public boolean canOpen() {
|
||||
return getState() == State.PRODUCER_CONNECTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream openInput() throws Exception {
|
||||
public InputStream openInput() {
|
||||
checkState(false);
|
||||
|
||||
if (getState() == State.PRODUCER_CONNECTED) {
|
||||
@@ -112,7 +112,7 @@ public class SinkDrainStore extends JacksonizedValue implements KnownFormatStrea
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream openOutput() throws Exception {
|
||||
public OutputStream openOutput() {
|
||||
checkState(true);
|
||||
|
||||
if (getState() == State.CONSUMER_CONNECTED) {
|
||||
@@ -157,7 +157,7 @@ public class SinkDrainStore extends JacksonizedValue implements KnownFormatStrea
|
||||
}
|
||||
}
|
||||
|
||||
public static enum State {
|
||||
public enum State {
|
||||
NONE_CONNECTED,
|
||||
PRODUCER_CONNECTED,
|
||||
CONSUMER_CONNECTED,
|
||||
|
||||
@@ -7,7 +7,6 @@ import lombok.experimental.SuperBuilder;
|
||||
import lombok.extern.jackson.Jacksonized;
|
||||
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
@JsonTypeName("stdin")
|
||||
@@ -21,12 +20,12 @@ public class StdinDataStore extends JacksonizedValue implements StreamDataStore
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream openInput() throws Exception {
|
||||
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() throws IOException {}
|
||||
public void close() {}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import lombok.experimental.SuperBuilder;
|
||||
import lombok.extern.jackson.Jacksonized;
|
||||
|
||||
import java.io.FilterOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
@JsonTypeName("stdout")
|
||||
@@ -16,7 +15,7 @@ import java.io.OutputStream;
|
||||
public class StdoutDataStore extends JacksonizedValue implements StreamDataStore {
|
||||
|
||||
@Override
|
||||
public boolean canOpen() throws Exception {
|
||||
public boolean canOpen() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -26,11 +25,11 @@ public class StdoutDataStore extends JacksonizedValue implements StreamDataStore
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream openOutput() throws Exception {
|
||||
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() throws IOException {}
|
||||
public void close() {}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public class TextReadConnection extends StreamReadConnection implements io.xpipe
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> lines() throws Exception {
|
||||
public Stream<String> lines() {
|
||||
return bufferedReader.lines();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,11 +12,11 @@ import java.util.function.Function;
|
||||
|
||||
public interface CommandControl extends ProcessControl {
|
||||
|
||||
public static final int UNASSIGNED_EXIT_CODE = -1;
|
||||
public static final int EXIT_TIMEOUT_EXIT_CODE = -2;
|
||||
public static final int START_FAILED_EXIT_CODE = -3;
|
||||
int UNASSIGNED_EXIT_CODE = -1;
|
||||
int EXIT_TIMEOUT_EXIT_CODE = -2;
|
||||
int START_FAILED_EXIT_CODE = -3;
|
||||
|
||||
static enum TerminalExitMode {
|
||||
enum TerminalExitMode {
|
||||
KEEP_OPEN,
|
||||
CLOSE
|
||||
}
|
||||
@@ -25,10 +25,10 @@ public interface CommandControl extends ProcessControl {
|
||||
|
||||
CommandControl terminalExitMode(TerminalExitMode mode);
|
||||
|
||||
public CommandControl doesNotObeyReturnValueConvention();
|
||||
CommandControl doesNotObeyReturnValueConvention();
|
||||
|
||||
@Override
|
||||
public CommandControl sensitive();
|
||||
CommandControl sensitive();
|
||||
|
||||
CommandControl complex();
|
||||
|
||||
@@ -54,7 +54,7 @@ public interface CommandControl extends ProcessControl {
|
||||
|
||||
OutputStream startExternalStdin() throws Exception;
|
||||
|
||||
public boolean waitFor();
|
||||
boolean waitFor();
|
||||
|
||||
CommandControl withCustomCharset(Charset charset);
|
||||
|
||||
@@ -71,24 +71,25 @@ public interface CommandControl extends ProcessControl {
|
||||
|
||||
CommandControl exitTimeout(Integer timeout);
|
||||
|
||||
public void withStdoutOrThrow(Charsetter.FailableConsumer<InputStreamReader, Exception> c) throws Exception;
|
||||
void withStdoutOrThrow(Charsetter.FailableConsumer<InputStreamReader, Exception> c);
|
||||
|
||||
String readStdoutDiscardErr() throws Exception;
|
||||
|
||||
public void discardOrThrow() throws Exception;
|
||||
void discardOrThrow() throws Exception;
|
||||
|
||||
void accumulateStdout(Consumer<String> con);
|
||||
|
||||
void accumulateStderr(Consumer<String> con);
|
||||
|
||||
public byte[] readRawBytesOrThrow() throws Exception;
|
||||
byte[] readRawBytesOrThrow() throws Exception;
|
||||
|
||||
public String readStdoutOrThrow() throws Exception;
|
||||
String readStdoutOrThrow() throws Exception;
|
||||
|
||||
public default boolean discardAndCheckExit() throws ProcessOutputException {
|
||||
default boolean discardAndCheckExit() throws ProcessOutputException {
|
||||
try {
|
||||
discardOrThrow();
|
||||
return true;
|
||||
} catch (ProcessOutputException ex) {
|
||||
} catch (ProcessOutputException ex) {
|
||||
if (ex.isTimeOut()) {
|
||||
throw ex;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public sealed interface OsType permits OsType.Windows, OsType.Linux, OsType.MacO
|
||||
Linux LINUX = new Linux();
|
||||
MacOs MACOS = new MacOs();
|
||||
|
||||
public static OsType getLocal() {
|
||||
static OsType getLocal() {
|
||||
String osName = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
|
||||
if ((osName.contains("mac")) || (osName.contains("darwin"))) {
|
||||
return MACOS;
|
||||
@@ -48,7 +48,7 @@ public sealed interface OsType permits OsType.Windows, OsType.Linux, OsType.MacO
|
||||
|
||||
String determineOperatingSystemName(ShellControl pc) throws Exception;
|
||||
|
||||
static final class Windows implements OsType {
|
||||
final class Windows implements OsType {
|
||||
|
||||
@Override
|
||||
public List<String> determineInterestingPaths(ShellControl pc) throws Exception {
|
||||
@@ -90,7 +90,7 @@ public sealed interface OsType permits OsType.Windows, OsType.Linux, OsType.MacO
|
||||
}
|
||||
|
||||
@Override
|
||||
public String determineOperatingSystemName(ShellControl pc) throws Exception {
|
||||
public String determineOperatingSystemName(ShellControl pc) {
|
||||
try {
|
||||
return pc.executeSimpleStringCommand("wmic os get Caption")
|
||||
.lines()
|
||||
@@ -110,7 +110,7 @@ public sealed interface OsType permits OsType.Windows, OsType.Linux, OsType.MacO
|
||||
}
|
||||
}
|
||||
|
||||
static final class Linux implements OsType {
|
||||
final class Linux implements OsType {
|
||||
|
||||
@Override
|
||||
public List<String> determineInterestingPaths(ShellControl pc) throws Exception {
|
||||
@@ -130,7 +130,7 @@ public sealed interface OsType permits OsType.Windows, OsType.Linux, OsType.MacO
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTempDirectory(ShellControl pc) throws Exception {
|
||||
public String getTempDirectory(ShellControl pc) {
|
||||
return "/tmp/";
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ public sealed interface OsType permits OsType.Windows, OsType.Linux, OsType.MacO
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getProperties(ShellControl pc) throws Exception {
|
||||
public Map<String, String> getProperties(ShellControl pc) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ public sealed interface OsType permits OsType.Windows, OsType.Linux, OsType.MacO
|
||||
}
|
||||
}
|
||||
|
||||
static final class MacOs implements OsType {
|
||||
final class MacOs implements OsType {
|
||||
|
||||
@Override
|
||||
public List<String> determineInterestingPaths(ShellControl pc) throws Exception {
|
||||
@@ -193,8 +193,7 @@ public sealed interface OsType permits OsType.Windows, OsType.Linux, OsType.MacO
|
||||
"/Applications",
|
||||
"/Library",
|
||||
"/System",
|
||||
"/etc"
|
||||
);
|
||||
"/etc");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,10 +17,10 @@ public class PropertiesFormatsParser {
|
||||
String line;
|
||||
|
||||
String currentKey = null;
|
||||
String currentValue = "";
|
||||
StringBuilder currentValue = new StringBuilder();
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.startsWith("\s") || line.startsWith("\t")) {
|
||||
currentValue += line;
|
||||
if (line.startsWith(" ") || line.startsWith("\t")) {
|
||||
currentValue.append(line);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -35,15 +35,15 @@ public class PropertiesFormatsParser {
|
||||
}
|
||||
|
||||
if (currentKey != null) {
|
||||
map.put(currentKey, currentValue);
|
||||
map.put(currentKey, currentValue.toString());
|
||||
}
|
||||
|
||||
currentKey = keyName;
|
||||
currentValue = value;
|
||||
currentValue = new StringBuilder(value);
|
||||
}
|
||||
|
||||
if (currentKey != null) {
|
||||
map.put(currentKey, currentValue);
|
||||
map.put(currentKey, currentValue.toString());
|
||||
}
|
||||
|
||||
return map;
|
||||
|
||||
@@ -37,7 +37,7 @@ public interface ShellControl extends ProcessControl {
|
||||
|
||||
String getSubTemporaryDirectory();
|
||||
|
||||
public void checkRunning();
|
||||
void checkRunning();
|
||||
|
||||
default CommandControl osascriptCommand(String script) {
|
||||
return command(String.format(
|
||||
@@ -45,7 +45,8 @@ public interface ShellControl extends ProcessControl {
|
||||
osascript - "$@" <<EOF
|
||||
%s
|
||||
EOF
|
||||
""", script));
|
||||
""",
|
||||
script));
|
||||
}
|
||||
|
||||
default byte[] executeSimpleRawBytesCommand(String command) throws Exception {
|
||||
@@ -112,7 +113,7 @@ public interface ShellControl extends ProcessControl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String prepare(ShellControl sc, String command) throws Exception {
|
||||
public String prepare(ShellControl sc, String command) {
|
||||
return command;
|
||||
}
|
||||
})
|
||||
@@ -134,7 +135,7 @@ public interface ShellControl extends ProcessControl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String prepare(ShellControl sc, String command) throws Exception {
|
||||
public String prepare(ShellControl sc, String command) {
|
||||
return command;
|
||||
}
|
||||
})
|
||||
@@ -149,7 +150,7 @@ public interface ShellControl extends ProcessControl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String prepare(ShellControl sc, String command) throws Exception {
|
||||
public String prepare(ShellControl sc, String command) {
|
||||
return command;
|
||||
}
|
||||
});
|
||||
@@ -196,8 +197,7 @@ public interface ShellControl extends ProcessControl {
|
||||
}
|
||||
|
||||
default CommandControl command(List<String> command) {
|
||||
return command(
|
||||
shellProcessControl -> ShellDialect.flatten(command));
|
||||
return command(shellProcessControl -> ShellDialect.flatten(command));
|
||||
}
|
||||
|
||||
void exitAndWait() throws IOException;
|
||||
|
||||
@@ -15,23 +15,23 @@ import java.util.stream.Stream;
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
|
||||
public interface ShellDialect {
|
||||
|
||||
public static String flatten(List<String> command) {
|
||||
static 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(" "));
|
||||
}
|
||||
|
||||
CommandControl prepareTempDirectory(ShellControl shellControl, String directory);
|
||||
CommandControl prepareTempDirectory(ShellControl shellControl, String directory);
|
||||
|
||||
String initFileName(ShellControl sc) throws Exception;
|
||||
|
||||
CommandControl directoryExists(ShellControl shellControl, String directory);
|
||||
CommandControl directoryExists(ShellControl shellControl, String directory);
|
||||
|
||||
CommandControl normalizeDirectory(ShellControl shellControl, String directory);
|
||||
CommandControl normalizeDirectory(ShellControl shellControl, String directory);
|
||||
|
||||
String fileArgument(String s);
|
||||
|
||||
@@ -53,15 +53,15 @@ public interface ShellDialect {
|
||||
|
||||
CommandControl createStreamFileWriteCommand(ShellControl shellControl, String file);
|
||||
|
||||
default String getCdCommand(String directory){
|
||||
default String getCdCommand(String directory) {
|
||||
return "cd \"" + directory + "\"";
|
||||
}
|
||||
|
||||
default String getPushdCommand(String directory){
|
||||
default String getPushdCommand(String directory) {
|
||||
return "pushd \"" + directory + "\"";
|
||||
}
|
||||
|
||||
default String getPopdCommand(){
|
||||
default String getPopdCommand() {
|
||||
return "popd";
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ public interface ShellDialect {
|
||||
|
||||
String getOpenCommand();
|
||||
|
||||
String prepareTerminalInitFileOpenCommand(ShellDialect parentDialect, ShellControl sc, String file) throws Exception;
|
||||
String prepareTerminalInitFileOpenCommand(ShellDialect parentDialect, ShellControl sc, String file);
|
||||
|
||||
String runScript(ShellControl parent, String file);
|
||||
|
||||
@@ -149,7 +149,7 @@ public interface ShellDialect {
|
||||
|
||||
String getWhichCommand(String executable);
|
||||
|
||||
Charset determineCharset(ShellControl control) throws Exception;
|
||||
Charset determineCharset(ShellControl control);
|
||||
|
||||
NewLine getNewLine();
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ public abstract class CollectionDataSource<DS extends DataStore> extends DataSou
|
||||
return DataSourceType.COLLECTION;
|
||||
}
|
||||
|
||||
public final CollectionReadConnection openReadConnection() throws Exception {
|
||||
public final CollectionReadConnection openReadConnection() {
|
||||
if (!isComplete()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@@ -19,7 +19,7 @@ public abstract class CollectionDataSource<DS extends DataStore> extends DataSou
|
||||
return newReadConnection();
|
||||
}
|
||||
|
||||
public final CollectionWriteConnection openWriteConnection(WriteMode mode) throws Exception {
|
||||
public final CollectionWriteConnection openWriteConnection(WriteMode mode) {
|
||||
var con = newWriteConnection(mode);
|
||||
if (con == null) {
|
||||
throw new UnsupportedOperationException(mode.getId());
|
||||
@@ -30,5 +30,5 @@ public abstract class CollectionDataSource<DS extends DataStore> extends DataSou
|
||||
|
||||
protected abstract CollectionWriteConnection newWriteConnection(WriteMode mode);
|
||||
|
||||
protected abstract CollectionReadConnection newReadConnection() throws Exception;
|
||||
protected abstract CollectionReadConnection newReadConnection();
|
||||
}
|
||||
@@ -9,7 +9,7 @@ public interface CollectionReadConnection extends DataSourceReadConnection {
|
||||
Stream<DataSource<?>> listEntries() throws Exception;
|
||||
|
||||
@SneakyThrows
|
||||
default void forward(DataSourceConnection con) throws Exception {
|
||||
default void forward(DataSourceConnection con) {
|
||||
try (var tCon = (CollectionWriteConnection) con) {
|
||||
tCon.init();
|
||||
listEntries().forEach(s -> {
|
||||
|
||||
@@ -4,5 +4,5 @@ import java.io.InputStream;
|
||||
|
||||
public interface CollectionWriteConnection extends DataSourceConnection {
|
||||
|
||||
void write(String entry, InputStream content) throws Exception;
|
||||
void write(String entry, InputStream content);
|
||||
}
|
||||
@@ -89,7 +89,7 @@ public interface DataSourceReference {
|
||||
*/
|
||||
@Value
|
||||
@AllArgsConstructor
|
||||
static class Id implements DataSourceReference {
|
||||
class Id implements DataSourceReference {
|
||||
@NonNull
|
||||
DataSourceId value;
|
||||
|
||||
@@ -143,7 +143,7 @@ public interface DataSourceReference {
|
||||
*/
|
||||
@Value
|
||||
@AllArgsConstructor
|
||||
static class Name implements DataSourceReference {
|
||||
class Name implements DataSourceReference {
|
||||
@NonNull
|
||||
String value;
|
||||
|
||||
@@ -195,7 +195,7 @@ public interface DataSourceReference {
|
||||
* Data source referral this way is unstable however as adding or
|
||||
* removing data sources might change the referral behaviour and is therefore not recommended.
|
||||
*/
|
||||
static class Latest implements DataSourceReference {
|
||||
class Latest implements DataSourceReference {
|
||||
|
||||
@Override
|
||||
public String toRefString() {
|
||||
|
||||
@@ -14,7 +14,7 @@ public abstract class RawDataSource<DS extends DataStore> extends DataSource<DS>
|
||||
}
|
||||
|
||||
@Override
|
||||
public final RawReadConnection openReadConnection() throws Exception {
|
||||
public final RawReadConnection openReadConnection() {
|
||||
if (!isComplete()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@@ -23,7 +23,7 @@ public abstract class RawDataSource<DS extends DataStore> extends DataSource<DS>
|
||||
}
|
||||
|
||||
@Override
|
||||
public final RawWriteConnection openWriteConnection(WriteMode mode) throws Exception {
|
||||
public final RawWriteConnection openWriteConnection(WriteMode mode) {
|
||||
var con = newWriteConnection(mode);
|
||||
if (con == null) {
|
||||
throw new UnsupportedOperationException(mode.getId());
|
||||
|
||||
@@ -24,7 +24,7 @@ public abstract class StructureDataSource<DS extends DataStore> extends DataSour
|
||||
return c;
|
||||
}
|
||||
|
||||
public final StructureReadConnection openReadConnection() throws Exception {
|
||||
public final StructureReadConnection openReadConnection() {
|
||||
if (!isComplete()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@@ -32,7 +32,7 @@ public abstract class StructureDataSource<DS extends DataStore> extends DataSour
|
||||
return newReadConnection();
|
||||
}
|
||||
|
||||
public final StructureWriteConnection openWriteConnection(WriteMode mode) throws Exception {
|
||||
public final StructureWriteConnection openWriteConnection(WriteMode mode) {
|
||||
var con = newWriteConnection(mode);
|
||||
if (con == null) {
|
||||
throw new UnsupportedOperationException(mode.getId());
|
||||
|
||||
@@ -45,7 +45,7 @@ public abstract class TableDataSource<DS extends DataStore> extends DataSource<D
|
||||
return newReadConnection();
|
||||
}
|
||||
|
||||
public final Optional<TableMapping> createMapping(TupleType inputType) throws Exception {
|
||||
public final Optional<TableMapping> createMapping(TupleType inputType) {
|
||||
return Optional.ofNullable(new CreateMappingFunction(this, inputType).callAndGet());
|
||||
}
|
||||
|
||||
|
||||
@@ -19,10 +19,10 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
*/
|
||||
public interface TableReadConnection extends DataSourceReadConnection {
|
||||
|
||||
public static TableReadConnection empty() {
|
||||
static TableReadConnection empty() {
|
||||
return new TableReadConnection() {
|
||||
@Override
|
||||
public boolean canRead() throws Exception {
|
||||
public boolean canRead() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -32,15 +32,15 @@ public interface TableReadConnection extends DataSourceReadConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalInt getRowCount() throws Exception {
|
||||
public OptionalInt getRowCount() {
|
||||
return OptionalInt.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void withRows(DataStructureNodeAcceptor<TupleNode> lineAcceptor) throws Exception {}
|
||||
public void withRows(DataStructureNodeAcceptor<TupleNode> lineAcceptor) {}
|
||||
|
||||
@Override
|
||||
public ArrayNode readRows(int maxLines) throws Exception {
|
||||
public ArrayNode readRows(int maxLines) {
|
||||
return ArrayNode.of();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -11,10 +11,10 @@ import java.util.Optional;
|
||||
*/
|
||||
public interface TableWriteConnection extends DataSourceConnection {
|
||||
|
||||
public static TableWriteConnection empty() {
|
||||
static TableWriteConnection empty() {
|
||||
return new TableWriteConnection() {
|
||||
@Override
|
||||
public Optional<TableMapping> createMapping(TupleType inputType) throws Exception {
|
||||
public Optional<TableMapping> createMapping(TupleType inputType) {
|
||||
return Optional.of(TableMapping.empty(inputType));
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ public abstract class TextDataSource<DS extends DataStore> extends DataSource<DS
|
||||
}
|
||||
|
||||
@Override
|
||||
public final TextReadConnection openReadConnection() throws Exception {
|
||||
public final TextReadConnection openReadConnection() {
|
||||
if (!isComplete()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@@ -24,7 +24,7 @@ public abstract class TextDataSource<DS extends DataStore> extends DataSource<DS
|
||||
}
|
||||
|
||||
@Override
|
||||
public final TextWriteConnection openWriteConnection(WriteMode mode) throws Exception {
|
||||
public final TextWriteConnection openWriteConnection(WriteMode mode) {
|
||||
var con = newWriteConnection(mode);
|
||||
if (con == null) {
|
||||
throw new UnsupportedOperationException(mode.getId());
|
||||
|
||||
@@ -9,5 +9,5 @@ public interface CommandExecutionStore extends DataStore, LaunchableStore {
|
||||
return create().prepareTerminalOpen(displayName);
|
||||
}
|
||||
|
||||
CommandControl create() throws Exception;
|
||||
CommandControl create();
|
||||
}
|
||||
@@ -31,8 +31,11 @@ public class ConnectionFileSystem implements FileSystem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean directoryExists(String file) throws Exception{
|
||||
return shellControl.getShellDialect().directoryExists(shellControl, file).executeAndCheck();
|
||||
public boolean directoryExists(String file) throws Exception {
|
||||
return shellControl
|
||||
.getShellDialect()
|
||||
.directoryExists(shellControl, file)
|
||||
.executeAndCheck();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,22 +66,25 @@ public class ConnectionFileSystem implements FileSystem {
|
||||
|
||||
@Override
|
||||
public InputStream openInput(String file) throws Exception {
|
||||
return shellControl.command(proc ->
|
||||
proc.getShellDialect().getFileReadCommand(file))
|
||||
return shellControl
|
||||
.command(proc -> proc.getShellDialect().getFileReadCommand(file))
|
||||
.startExternalStdout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream openOutput(String file) throws Exception {
|
||||
return shellControl.getShellDialect()
|
||||
.createStreamFileWriteCommand(shellControl, file)
|
||||
return shellControl
|
||||
.getShellDialect()
|
||||
.createStreamFileWriteCommand(shellControl, file)
|
||||
.startExternalStdin();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fileExists(String file) throws Exception {
|
||||
try (var pc = shellControl.getShellDialect()
|
||||
.createFileExistsCommand(shellControl, file).complex()
|
||||
try (var pc = shellControl
|
||||
.getShellDialect()
|
||||
.createFileExistsCommand(shellControl, file)
|
||||
.complex()
|
||||
.start()) {
|
||||
return pc.discardAndCheckExit();
|
||||
}
|
||||
@@ -86,8 +92,9 @@ public class ConnectionFileSystem implements FileSystem {
|
||||
|
||||
@Override
|
||||
public void delete(String file) throws Exception {
|
||||
try (var pc = shellControl.command(proc -> proc.getShellDialect()
|
||||
.getFileDeleteCommand(file)).complex()
|
||||
try (var pc = shellControl
|
||||
.command(proc -> proc.getShellDialect().getFileDeleteCommand(file))
|
||||
.complex()
|
||||
.start()) {
|
||||
pc.discardOrThrow();
|
||||
}
|
||||
@@ -95,8 +102,9 @@ public class ConnectionFileSystem implements FileSystem {
|
||||
|
||||
@Override
|
||||
public void copy(String file, String newFile) throws Exception {
|
||||
try (var pc = shellControl.command(proc -> proc.getShellDialect()
|
||||
.getFileCopyCommand(file, newFile)).complex()
|
||||
try (var pc = shellControl
|
||||
.command(proc -> proc.getShellDialect().getFileCopyCommand(file, newFile))
|
||||
.complex()
|
||||
.start()) {
|
||||
pc.discardOrThrow();
|
||||
}
|
||||
@@ -104,8 +112,9 @@ public class ConnectionFileSystem implements FileSystem {
|
||||
|
||||
@Override
|
||||
public void move(String file, String newFile) throws Exception {
|
||||
try (var pc = shellControl.command(proc -> proc.getShellDialect()
|
||||
.getFileMoveCommand(file, newFile)).complex()
|
||||
try (var pc = shellControl
|
||||
.command(proc -> proc.getShellDialect().getFileMoveCommand(file, newFile))
|
||||
.complex()
|
||||
.start()) {
|
||||
pc.discardOrThrow();
|
||||
}
|
||||
@@ -113,8 +122,9 @@ public class ConnectionFileSystem implements FileSystem {
|
||||
|
||||
@Override
|
||||
public void mkdirs(String file) throws Exception {
|
||||
try (var pc = shellControl.command(proc -> proc.getShellDialect()
|
||||
.getMkdirsCommand(file)).complex()
|
||||
try (var pc = shellControl
|
||||
.command(proc -> proc.getShellDialect().getMkdirsCommand(file))
|
||||
.complex()
|
||||
.start()) {
|
||||
pc.discardOrThrow();
|
||||
}
|
||||
@@ -122,8 +132,9 @@ public class ConnectionFileSystem implements FileSystem {
|
||||
|
||||
@Override
|
||||
public void touch(String file) throws Exception {
|
||||
try (var pc = shellControl.command(proc -> proc.getShellDialect()
|
||||
.getFileTouchCommand(file)).complex()
|
||||
try (var pc = shellControl
|
||||
.command(proc -> proc.getShellDialect().getFileTouchCommand(file))
|
||||
.complex()
|
||||
.start()) {
|
||||
pc.discardOrThrow();
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public interface DataStore {
|
||||
|
||||
default void checkComplete() throws Exception {}
|
||||
|
||||
default boolean delete() throws Exception {
|
||||
default boolean delete() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package io.xpipe.core.store;
|
||||
|
||||
import io.xpipe.core.process.ShellControl;
|
||||
|
||||
public interface DelegateShellStore extends ShellStore {
|
||||
public interface DelegateShellStore extends ShellStore {
|
||||
|
||||
@Override
|
||||
default ShellControl createBasicControl() {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package io.xpipe.core.store;
|
||||
|
||||
public enum FileKind {
|
||||
|
||||
FILE,
|
||||
DIRECTORY,
|
||||
LINK,
|
||||
OTHER;
|
||||
OTHER
|
||||
}
|
||||
@@ -17,25 +17,31 @@ import java.util.stream.Stream;
|
||||
public interface FileSystem extends Closeable, AutoCloseable {
|
||||
|
||||
@Value
|
||||
static class FileEntry {
|
||||
class FileEntry {
|
||||
@NonNull
|
||||
FileSystem fileSystem;
|
||||
|
||||
@NonNull
|
||||
String path;
|
||||
|
||||
Instant date;
|
||||
boolean hidden;
|
||||
Boolean executable;
|
||||
long size;
|
||||
String mode;
|
||||
|
||||
@NonNull
|
||||
FileKind kind;
|
||||
|
||||
public FileEntry(
|
||||
@NonNull FileSystem fileSystem, @NonNull String path, Instant date, boolean hidden, Boolean executable,
|
||||
@NonNull FileSystem fileSystem,
|
||||
@NonNull String path,
|
||||
Instant date,
|
||||
boolean hidden,
|
||||
Boolean executable,
|
||||
long size,
|
||||
String mode,
|
||||
@NonNull FileKind kind
|
||||
) {
|
||||
@NonNull FileKind kind) {
|
||||
this.fileSystem = fileSystem;
|
||||
this.mode = mode;
|
||||
this.kind = kind;
|
||||
@@ -49,7 +55,6 @@ public interface FileSystem extends Closeable, AutoCloseable {
|
||||
public static FileEntry ofDirectory(FileSystem fileSystem, String path) {
|
||||
return new FileEntry(fileSystem, path, Instant.now(), true, false, 0, null, FileKind.DIRECTORY);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
FileSystemStore getStore();
|
||||
@@ -62,9 +67,9 @@ public interface FileSystem extends Closeable, AutoCloseable {
|
||||
|
||||
OutputStream openOutput(String file) throws Exception;
|
||||
|
||||
public boolean fileExists(String file) throws Exception;
|
||||
boolean fileExists(String file) throws Exception;
|
||||
|
||||
public void delete(String file) throws Exception;
|
||||
void delete(String file) throws Exception;
|
||||
|
||||
void copy(String file, String newFile) throws Exception;
|
||||
|
||||
@@ -82,20 +87,22 @@ public interface FileSystem extends Closeable, AutoCloseable {
|
||||
|
||||
default List<FileEntry> listFilesRecursively(String file) throws Exception {
|
||||
var base = listFiles(file).toList();
|
||||
return base.stream().flatMap(fileEntry -> {
|
||||
if (fileEntry.getKind() != FileKind.DIRECTORY) {
|
||||
return Stream.of(fileEntry);
|
||||
}
|
||||
return base.stream()
|
||||
.flatMap(fileEntry -> {
|
||||
if (fileEntry.getKind() != FileKind.DIRECTORY) {
|
||||
return Stream.of(fileEntry);
|
||||
}
|
||||
|
||||
try {
|
||||
var list = new ArrayList<FileEntry>();
|
||||
list.add(fileEntry);
|
||||
list.addAll(listFilesRecursively(fileEntry.getPath()));
|
||||
return list.stream();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}).toList();
|
||||
try {
|
||||
var list = new ArrayList<FileEntry>();
|
||||
list.add(fileEntry);
|
||||
list.addAll(listFilesRecursively(fileEntry.getPath()));
|
||||
return list.stream();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
})
|
||||
.toList();
|
||||
}
|
||||
|
||||
List<String> listRoots() throws Exception;
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
package io.xpipe.core.store;
|
||||
|
||||
public interface LeafShellStore extends DataStore {
|
||||
|
||||
}
|
||||
public interface LeafShellStore extends DataStore {}
|
||||
@@ -2,14 +2,14 @@ package io.xpipe.core.store;
|
||||
|
||||
import io.xpipe.core.impl.LocalStore;
|
||||
import io.xpipe.core.process.OsType;
|
||||
import io.xpipe.core.process.ShellDialect;
|
||||
import io.xpipe.core.process.ShellControl;
|
||||
import io.xpipe.core.process.ShellDialect;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
public interface ShellStore extends DataStore, StatefulDataStore, LaunchableStore, FileSystemStore {
|
||||
|
||||
public static ShellStore createLocal() {
|
||||
static ShellStore createLocal() {
|
||||
return new LocalStore();
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public interface ShellStore extends DataStore, StatefulDataStore, LaunchableStor
|
||||
|
||||
ShellControl createBasicControl();
|
||||
|
||||
public default ShellDialect determineType() throws Exception {
|
||||
default ShellDialect determineType() throws Exception {
|
||||
try (var pc = control().start()) {
|
||||
return pc.getShellDialect();
|
||||
}
|
||||
@@ -68,7 +68,7 @@ public interface ShellStore extends DataStore, StatefulDataStore, LaunchableStor
|
||||
try (ShellControl pc = control().start()) {}
|
||||
}
|
||||
|
||||
public default String queryMachineName() throws Exception {
|
||||
default String queryMachineName() throws Exception {
|
||||
try (var pc = control().start()) {
|
||||
var operatingSystem = pc.getOsType();
|
||||
return operatingSystem.determineOperatingSystemName(pc);
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
@@ -87,10 +86,11 @@ public class CoreJacksonModule extends SimpleModule {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static class NullDeserializer extends JsonDeserializer<DataSource> {
|
||||
|
||||
@Override
|
||||
public DataSource deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
public DataSource deserialize(JsonParser p, DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -186,9 +186,8 @@ public class CoreJacksonModule extends SimpleModule {
|
||||
@JsonSerialize(as = DataSourceReference.class)
|
||||
public abstract static class DataSourceReferenceTypeMixIn {}
|
||||
|
||||
public class NullSerializer extends JsonSerializer<Object> {
|
||||
public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider)
|
||||
throws IOException, JsonProcessingException {
|
||||
public static class NullSerializer extends JsonSerializer<Object> {
|
||||
public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
|
||||
jgen.writeNull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public class Deobfuscator {
|
||||
System.err.println(s);
|
||||
}
|
||||
|
||||
private static boolean canDeobfuscate() throws Exception {
|
||||
private static boolean canDeobfuscate() {
|
||||
if (!System.getenv().containsKey("XPIPE_MAPPING")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class JacksonMapper {
|
||||
}
|
||||
|
||||
private static List<Module> findModules(ModuleLayer layer) {
|
||||
ArrayList<Module> modules = new ArrayList<Module>();
|
||||
ArrayList<Module> modules = new ArrayList<>();
|
||||
ServiceLoader<Module> loader =
|
||||
layer != null ? ServiceLoader.load(layer, Module.class) : ServiceLoader.load(Module.class);
|
||||
for (Module module : loader) {
|
||||
@@ -81,7 +81,7 @@ public class JacksonMapper {
|
||||
if (!JacksonMapper.isInit()) {
|
||||
return BASE;
|
||||
}
|
||||
|
||||
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package io.xpipe.core.util;
|
||||
|
||||
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface ModuleLayerLoader {
|
||||
|
||||
public static void loadAll(ModuleLayer layer, boolean hasDaemon, boolean prioritization, Consumer<Throwable> errorHandler) {
|
||||
static void loadAll(
|
||||
ModuleLayer layer, boolean hasDaemon, boolean prioritization, Consumer<Throwable> errorHandler) {
|
||||
ServiceLoader.load(layer, ModuleLayerLoader.class).stream().forEach(moduleLayerLoaderProvider -> {
|
||||
var instance = moduleLayerLoaderProvider.get();
|
||||
try {
|
||||
@@ -25,7 +25,7 @@ public interface ModuleLayerLoader {
|
||||
});
|
||||
}
|
||||
|
||||
public void init(ModuleLayer layer);
|
||||
void init(ModuleLayer layer);
|
||||
|
||||
boolean requiresFullDaemon();
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.xpipe.core.util;
|
||||
|
||||
import com.fasterxml.jackson.core.JacksonException;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
@@ -67,8 +66,7 @@ public abstract class ProxyFunction {
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public ProxyFunction deserialize(JsonParser p, DeserializationContext ctxt)
|
||||
throws IOException, JacksonException {
|
||||
public ProxyFunction deserialize(JsonParser p, DeserializationContext ctxt) {
|
||||
var tree = (ObjectNode) JacksonMapper.getDefault().readTree(p);
|
||||
var moduleReference = tree.remove("module").asText();
|
||||
var classReference = tree.remove("class").asText();
|
||||
|
||||
@@ -9,25 +9,25 @@ import java.util.function.Consumer;
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
|
||||
public interface SecretValue {
|
||||
|
||||
public static String toBase64e(byte[] b) {
|
||||
static String toBase64e(byte[] b) {
|
||||
var base64 = Base64.getEncoder().encodeToString(b);
|
||||
return base64.replace("/", "-");
|
||||
}
|
||||
|
||||
public static byte[] fromBase64e(String s) {
|
||||
static byte[] fromBase64e(String s) {
|
||||
var bytes = Base64.getDecoder().decode(s.replace("-", "/"));
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public default void withSecretValue(Consumer<char[]> con) {
|
||||
default void withSecretValue(Consumer<char[]> con) {
|
||||
var chars = getSecret();
|
||||
con.accept(chars);
|
||||
Arrays.fill(chars, (char) 0);
|
||||
}
|
||||
|
||||
public abstract char[] getSecret();
|
||||
char[] getSecret();
|
||||
|
||||
public default String getSecretValue() {
|
||||
default String getSecretValue() {
|
||||
return new String(getSecret());
|
||||
}
|
||||
}
|
||||
@@ -44,12 +44,13 @@ public class XPipeExecTempDirectory {
|
||||
|
||||
public static String getSubDirectory(ShellControl proc, String... sub) throws Exception {
|
||||
var base = proc.getOsType().getTempDirectory(proc);
|
||||
var arr = Stream.concat(Stream.of(base, "xpipe", "exec"), Arrays.stream(sub)).toArray(String[]::new);
|
||||
var arr = Stream.concat(Stream.of(base, "xpipe", "exec"), Arrays.stream(sub))
|
||||
.toArray(String[]::new);
|
||||
var dir = FileNames.join(arr);
|
||||
|
||||
var existsCommand = proc.getShellDialect().createFileExistsCommand(proc, dir);
|
||||
if (!existsCommand.executeAndCheck()) {
|
||||
proc.getShellDialect().prepareTempDirectory(proc,dir).execute();
|
||||
proc.getShellDialect().prepareTempDirectory(proc, dir).execute();
|
||||
}
|
||||
|
||||
return dir;
|
||||
|
||||
@@ -123,7 +123,7 @@ public class XPipeInstallation {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getLocalInstallationBasePathForCLI(String cliExecutable) throws Exception {
|
||||
public static String getLocalInstallationBasePathForCLI(String cliExecutable) {
|
||||
var defaultInstallation = getLocalDefaultInstallationBasePath(true);
|
||||
|
||||
// Can be empty in development mode
|
||||
@@ -162,7 +162,7 @@ public class XPipeInstallation {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getInstallationExecutable(ShellControl p, String installation) throws Exception {
|
||||
public static String getInstallationExecutable(ShellControl p, String installation) {
|
||||
var executable = getDaemonExecutablePath(p.getOsType());
|
||||
var file = FileNames.join(installation, executable);
|
||||
return file;
|
||||
@@ -206,7 +206,7 @@ public class XPipeInstallation {
|
||||
return customHome;
|
||||
}
|
||||
|
||||
String path = null;
|
||||
String path;
|
||||
if (OsType.getLocal().equals(OsType.WINDOWS)) {
|
||||
var base = System.getenv("LOCALAPPDATA");
|
||||
path = FileNames.join(base, "XPipe");
|
||||
@@ -219,8 +219,7 @@ public class XPipeInstallation {
|
||||
return path;
|
||||
}
|
||||
|
||||
public static String getDefaultInstallationBasePath(ShellControl p, boolean acceptPortable)
|
||||
throws Exception {
|
||||
public static String getDefaultInstallationBasePath(ShellControl p, boolean acceptPortable) throws Exception {
|
||||
if (acceptPortable) {
|
||||
var customHome = p.executeSimpleStringCommand(p.getShellDialect().getPrintVariableCommand("XPIPE_HOME"));
|
||||
if (!customHome.isEmpty()) {
|
||||
@@ -228,7 +227,7 @@ public class XPipeInstallation {
|
||||
}
|
||||
}
|
||||
|
||||
String path = null;
|
||||
String path;
|
||||
if (p.getOsType().equals(OsType.WINDOWS)) {
|
||||
var base = p.executeSimpleStringCommand(p.getShellDialect().getPrintVariableCommand("LOCALAPPDATA"));
|
||||
path = FileNames.join(base, "XPipe");
|
||||
|
||||
@@ -35,8 +35,8 @@ open module io.xpipe.core {
|
||||
uses ModuleLayerLoader;
|
||||
uses ShellDialect;
|
||||
|
||||
provides ModuleLayerLoader with ShellDialects.Loader;
|
||||
|
||||
provides ModuleLayerLoader with
|
||||
ShellDialects.Loader;
|
||||
provides WriteMode with
|
||||
WriteMode.Replace,
|
||||
WriteMode.Append,
|
||||
|
||||
Reference in new issue
Block a user