mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-04-25 08:59:25 -04:00
Merge branch 1.7.3-fixes into master
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package io.xpipe.core.charsetter;
|
||||
|
||||
import io.xpipe.core.store.FileStore;
|
||||
import io.xpipe.core.store.ShellStore;
|
||||
import io.xpipe.core.store.StreamDataStore;
|
||||
import io.xpipe.core.util.FailableConsumer;
|
||||
import io.xpipe.core.util.FailableSupplier;
|
||||
import lombok.Value;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@@ -76,7 +76,7 @@ public abstract class Charsetter {
|
||||
}
|
||||
|
||||
public abstract Result read(
|
||||
FailableSupplier<InputStream, Exception> in, FailableConsumer<InputStreamReader, Exception> con)
|
||||
FailableSupplier<InputStream> in, FailableConsumer<InputStreamReader, Exception> con)
|
||||
throws Exception;
|
||||
|
||||
public Result detect(StreamDataStore store) throws Exception {
|
||||
@@ -107,13 +107,13 @@ public abstract class Charsetter {
|
||||
}
|
||||
}
|
||||
|
||||
if (store instanceof FileStore fileStore && fileStore.getFileSystem() instanceof ShellStore m) {
|
||||
if (result.getNewLine() == null) {
|
||||
result = new Result(
|
||||
result.getCharset(),
|
||||
m.getShellType() != null ? m.getShellType().getNewLine() : null);
|
||||
}
|
||||
}
|
||||
// if (store instanceof FileStore fileStore && fileStore.getFileSystem() instanceof ShellStore m) {
|
||||
// if (result.getNewLine() == null) {
|
||||
// result = new Result(
|
||||
// result.getCharset(),
|
||||
// m.getShellType() != null ? m.getShellType().getNewLine() : null);
|
||||
// }
|
||||
// }
|
||||
|
||||
if (result.getCharset() == null) {
|
||||
result = new Result(StreamCharset.UTF8, result.getNewLine());
|
||||
@@ -167,17 +167,6 @@ public abstract class Charsetter {
|
||||
return StandardCharsets.UTF_8;
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface FailableSupplier<R, E extends Throwable> {
|
||||
R get() throws E;
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface FailableConsumer<T, E extends Throwable> {
|
||||
|
||||
void accept(T var1) throws E;
|
||||
}
|
||||
|
||||
@Value
|
||||
public static class Result {
|
||||
StreamCharset charset;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.xpipe.core.dialog;
|
||||
|
||||
import io.xpipe.core.charsetter.Charsetter;
|
||||
import io.xpipe.core.util.FailableConsumer;
|
||||
import io.xpipe.core.util.FailableSupplier;
|
||||
import io.xpipe.core.util.SecretValue;
|
||||
|
||||
@@ -27,7 +28,7 @@ import java.util.function.Supplier;
|
||||
*/
|
||||
public abstract class Dialog {
|
||||
|
||||
private final List<Charsetter.FailableConsumer<?, Exception>> completion = new ArrayList<>();
|
||||
private final List<FailableConsumer<?, Exception>> completion = new ArrayList<>();
|
||||
protected Object eval;
|
||||
private Supplier<?> evaluation;
|
||||
|
||||
@@ -416,7 +417,7 @@ public abstract class Dialog {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Dialog onCompletion(Charsetter.FailableConsumer<?, Exception> s) {
|
||||
public Dialog onCompletion(FailableConsumer<?, Exception> s) {
|
||||
completion.add(s);
|
||||
return this;
|
||||
}
|
||||
@@ -426,7 +427,7 @@ public abstract class Dialog {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Dialog onCompletion(List<Charsetter.FailableConsumer<?, Exception>> s) {
|
||||
public Dialog onCompletion(List<FailableConsumer<?, Exception>> s) {
|
||||
completion.addAll(s);
|
||||
return this;
|
||||
}
|
||||
@@ -440,8 +441,8 @@ public abstract class Dialog {
|
||||
public <T> void complete() throws Exception {
|
||||
if (evaluation != null) {
|
||||
eval = evaluation.get();
|
||||
for (Charsetter.FailableConsumer<?, Exception> c : completion) {
|
||||
Charsetter.FailableConsumer<T, Exception> ct = (Charsetter.FailableConsumer<T, Exception>) c;
|
||||
for (FailableConsumer<?, Exception> c : completion) {
|
||||
FailableConsumer<T, Exception> ct = (FailableConsumer<T, Exception>) c;
|
||||
ct.accept((T) eval);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package io.xpipe.core.process;
|
||||
|
||||
import io.xpipe.core.charsetter.Charsetter;
|
||||
import io.xpipe.core.util.FailableConsumer;
|
||||
import io.xpipe.core.util.FailableFunction;
|
||||
|
||||
import java.io.InputStream;
|
||||
@@ -12,10 +12,11 @@ import java.util.function.Function;
|
||||
|
||||
public interface CommandControl extends ProcessControl {
|
||||
|
||||
int UNASSIGNED_EXIT_CODE = -1;
|
||||
int EXIT_TIMEOUT_EXIT_CODE = -2;
|
||||
int START_FAILED_EXIT_CODE = -3;
|
||||
int INTERNAL_ERROR_EXIT_CODE = -4;
|
||||
// Keep these out of a normal exit code range
|
||||
int UNASSIGNED_EXIT_CODE = -80001;
|
||||
int EXIT_TIMEOUT_EXIT_CODE = -80002;
|
||||
int START_FAILED_EXIT_CODE = -80003;
|
||||
int INTERNAL_ERROR_EXIT_CODE = -80004;
|
||||
|
||||
enum TerminalExitMode {
|
||||
KEEP_OPEN,
|
||||
@@ -71,7 +72,7 @@ public interface CommandControl extends ProcessControl {
|
||||
|
||||
CommandControl exitTimeout(Integer timeout);
|
||||
|
||||
void withStdoutOrThrow(Charsetter.FailableConsumer<InputStreamReader, Exception> c);
|
||||
void withStdoutOrThrow(FailableConsumer<InputStreamReader, Exception> c);
|
||||
|
||||
String readStdoutDiscardErr() throws Exception;
|
||||
|
||||
@@ -85,6 +86,8 @@ public interface CommandControl extends ProcessControl {
|
||||
|
||||
String readStdoutOrThrow() throws Exception;
|
||||
|
||||
String readStdoutAndWait() throws Exception;
|
||||
|
||||
default boolean discardAndCheckExit() throws ProcessOutputException {
|
||||
try {
|
||||
discardOrThrow();
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package io.xpipe.core.process;
|
||||
|
||||
public interface OsNameState {
|
||||
|
||||
String getOsName();
|
||||
}
|
||||
@@ -6,9 +6,21 @@ import java.io.BufferedReader;
|
||||
import java.io.StringReader;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class PropertiesFormatsParser {
|
||||
|
||||
@SneakyThrows
|
||||
public static Map<String, String> parseLine(String line, String split, String quotes) {
|
||||
var map = new LinkedHashMap<String, String>();
|
||||
var pattern = Pattern.compile("(\\w+?)\\s*" + split + "\\s*" + quotes + "(.+?)" + quotes);
|
||||
var matcher = pattern.matcher(line);
|
||||
while (matcher.find()) {
|
||||
map.put(matcher.group(1), matcher.group(2));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static Map<String, String> parse(String text, String split) {
|
||||
var map = new LinkedHashMap<String, String>();
|
||||
|
||||
@@ -13,7 +13,7 @@ import lombok.extern.jackson.Jacksonized;
|
||||
@Getter
|
||||
@Jacksonized
|
||||
@SuperBuilder
|
||||
public class ShellStoreState extends DataStoreState {
|
||||
public class ShellStoreState extends DataStoreState implements OsNameState {
|
||||
|
||||
OsType osType;
|
||||
String osName;
|
||||
|
||||
@@ -21,7 +21,6 @@ public interface FileSystem extends Closeable, AutoCloseable {
|
||||
@Value
|
||||
@NonFinal
|
||||
class FileEntry {
|
||||
@NonNull
|
||||
FileSystem fileSystem;
|
||||
|
||||
@NonNull
|
||||
@@ -39,7 +38,7 @@ public interface FileSystem extends Closeable, AutoCloseable {
|
||||
FileKind kind;
|
||||
|
||||
public FileEntry(
|
||||
@NonNull FileSystem fileSystem,
|
||||
FileSystem fileSystem,
|
||||
@NonNull String path,
|
||||
Instant date,
|
||||
boolean hidden,
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
package io.xpipe.core.store;
|
||||
|
||||
import io.xpipe.core.process.OsType;
|
||||
import io.xpipe.core.process.ProcessControl;
|
||||
import io.xpipe.core.process.ShellControl;
|
||||
import io.xpipe.core.process.ShellDialect;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
public interface ShellStore extends DataStore, InternalCacheDataStore, LaunchableStore, FileSystemStore, ValidatableStore {
|
||||
public interface ShellStore extends DataStore, LaunchableStore, FileSystemStore, ValidatableStore {
|
||||
|
||||
static boolean isLocal(ShellStore s) {
|
||||
return s instanceof LocalStore;
|
||||
@@ -23,32 +19,8 @@ public interface ShellStore extends DataStore, InternalCacheDataStore, Launchabl
|
||||
return control();
|
||||
}
|
||||
|
||||
default ShellDialect getShellType() {
|
||||
return getCache("type", ShellDialect.class, null);
|
||||
}
|
||||
|
||||
default OsType getOsType() {
|
||||
return getOrCompute("os", OsType.class, () -> {
|
||||
try (var sc = control().start()) {
|
||||
return sc.getOsType();
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
default Charset getCharset() {
|
||||
return getCache("charset", Charset.class, null);
|
||||
}
|
||||
|
||||
ShellControl control();
|
||||
|
||||
default ShellDialect determineType() throws Exception {
|
||||
try (var pc = control().start()) {
|
||||
return pc.getShellDialect();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
default void validate() throws Exception {
|
||||
var c = control();
|
||||
@@ -58,11 +30,4 @@ public interface ShellStore extends DataStore, InternalCacheDataStore, Launchabl
|
||||
|
||||
try (ShellControl pc = c.start()) {}
|
||||
}
|
||||
|
||||
default String queryMachineName() throws Exception {
|
||||
try (var pc = control().start()) {
|
||||
var operatingSystem = pc.getOsType();
|
||||
return operatingSystem.determineOperatingSystemName(pc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user