This commit is contained in:
crschnick
2023-02-09 21:30:07 +00:00
parent 7be8087b19
commit 131dec75ec
228 changed files with 800 additions and 942 deletions

View File

@@ -23,8 +23,7 @@ public abstract class Charsetter {
public static Charsetter INSTANCE;
private static CharsetterUniverse universe;
protected Charsetter() {
}
protected Charsetter() {}
protected static void checkInit() {
if (universe == null) {
@@ -78,8 +77,7 @@ 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 {
@@ -112,7 +110,9 @@ public abstract class Charsetter {
if (store instanceof FileStore fileStore && fileStore.getFileSystem() instanceof MachineStore m) {
if (result.getNewLine() == null) {
result = new Result(result.getCharset(), m.getShellType() != null ? m.getShellType().getNewLine() : null);
result = new Result(
result.getCharset(),
m.getShellType() != null ? m.getShellType().getNewLine() : null);
}
}

View File

@@ -19,13 +19,8 @@ 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
@@ -36,24 +31,16 @@ 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 = UTF16_LE;
@@ -67,8 +54,7 @@ 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,
@@ -76,20 +62,15 @@ 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"))));
// ======
// UTF-32
@@ -98,26 +79,16 @@ public class StreamCharset {
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")
);
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")
);
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);
@@ -130,19 +101,17 @@ 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();
public static final List<StreamCharset> ALL =
Stream.concat(COMMON.stream(), RARE.stream()).toList();
Charset charset;
byte[] byteOrderMark;
@@ -151,13 +120,15 @@ public class StreamCharset {
public static StreamCharset get(Charset charset, boolean byteOrderMark) {
return ALL.stream()
.filter(streamCharset ->
streamCharset.getCharset().equals(charset) && streamCharset.hasByteOrderMark() == byteOrderMark)
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();
var found = ALL.stream()
.filter(streamCharset -> streamCharset.getNames().contains(s.toLowerCase(Locale.ROOT)))
.findFirst();
if (found.isEmpty()) {
throw new IllegalArgumentException("Unknown charset name: " + s);
}

View File

@@ -17,8 +17,7 @@ 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,21 +4,15 @@ 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,8 +19,7 @@ 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,8 +8,7 @@ import java.util.stream.Collectors;
public abstract class ArrayNode extends DataStructureNode {
protected ArrayNode() {
}
protected ArrayNode() {}
public static ArrayNode empty() {
return of(List.of());
@@ -57,7 +56,6 @@ public abstract class ArrayNode extends DataStructureNode {
return "array node";
}
@Override
public final String toString(int indent) {
var content = getNodes().stream().map(n -> n.toString(indent)).collect(Collectors.joining(", "));

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,6 +242,5 @@ 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,8 +217,7 @@ 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,8 +86,7 @@ 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

@@ -116,9 +116,8 @@ 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,8 +13,7 @@ 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();
@@ -67,7 +66,8 @@ public abstract class ValueNode extends DataStructureNode {
public static ValueNode ofBytes(byte[] data) {
var created = of(data);
if (data != null) {
created.tag(IS_BINARY);}
created.tag(IS_BINARY);
}
return created;
}

View File

@@ -10,10 +10,7 @@ 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,15 +2,11 @@ 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,8 +41,7 @@ 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

@@ -65,7 +65,9 @@ public class TupleType extends DataType {
throw new UnsupportedOperationException();
}
return new TupleType(subNames, subNames.stream().map(s -> types.get(getNames().indexOf(s))).toList());
return new TupleType(
subNames,
subNames.stream().map(s -> types.get(getNames().indexOf(s))).toList());
}
@Override

View File

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

View File

@@ -7,27 +7,19 @@ 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

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

@@ -58,8 +58,11 @@ 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;
@@ -77,8 +80,7 @@ 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();
@@ -115,8 +117,7 @@ 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;
@@ -162,8 +163,7 @@ 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;
}
@@ -354,8 +354,7 @@ 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() {
@@ -468,7 +467,12 @@ public abstract class Dialog {
private final ChoiceElement element;
private Choice(String description, List<io.xpipe.core.dialog.Choice> elements, boolean required, boolean quiet, int selected) {
private Choice(
String description,
List<io.xpipe.core.dialog.Choice> elements,
boolean required,
boolean quiet,
int selected) {
this.element = new ChoiceElement(description, elements, required, quiet, selected);
}
@@ -502,8 +506,7 @@ 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,8 +5,7 @@ package io.xpipe.core.dialog;
*/
public class DialogCancelException extends Exception {
public DialogCancelException() {
}
public DialogCancelException() {}
public DialogCancelException(String message) {
super(message);
@@ -21,8 +20,7 @@ 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,10 +8,7 @@ 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

@@ -34,8 +34,7 @@ public class DialogMapper {
var newElement = dialog.next(response);
if (element.equals(newElement)) {
throw new IllegalStateException(
"Loop for key " + newElement.toDisplayString());
throw new IllegalStateException("Loop for key " + newElement.toDisplayString());
}
element = newElement;

View File

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

@@ -51,5 +51,4 @@ public class LocalStore extends JacksonizedValue implements FileSystemStore, Mac
public ShellProcessControl createControl() {
return ProcessControlProvider.createLocal();
}
}

View File

@@ -15,8 +15,7 @@ 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;
@@ -29,7 +28,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

@@ -9,7 +9,6 @@ import java.util.Optional;
public interface SimpleTableWriteConnection<T extends TableDataSource<?>> extends TableWriteConnection {
public T getSource();
public default Optional<TupleType> getType() throws Exception {

View File

@@ -94,7 +94,7 @@ public class SinkDrainStore extends JacksonizedValue implements KnownFormatStrea
if (getState() == State.NONE_CONNECTED) {
setState(State.CONSUMER_CONNECTED);
//waitForOpen();
// waitForOpen();
}
try {
@@ -121,11 +121,12 @@ public class SinkDrainStore extends JacksonizedValue implements KnownFormatStrea
if (getState() == State.NONE_CONNECTED) {
setState(State.PRODUCER_CONNECTED);
//waitForOpen();
// waitForOpen();
}
try {
return new FilterOutputStream(Channels.newOutputStream(getOrOpenPipe().sink())) {
return new FilterOutputStream(
Channels.newOutputStream(getOrOpenPipe().sink())) {
@Override
public void close() throws IOException {
super.close();

View File

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

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

View File

@@ -19,6 +19,7 @@ public class XpbtWriteConnection extends StreamWriteConnection implements Simple
@Getter
private final XpbtSource source;
private TupleType writtenDescriptor;
public XpbtWriteConnection(XpbtSource source) {
@@ -53,5 +54,4 @@ public class XpbtWriteConnection extends StreamWriteConnection implements Simple
}
writer.flush();
}
}

View File

@@ -11,6 +11,7 @@ public interface CommandProcessControl extends ProcessControl {
@Override
public CommandProcessControl sensitive();
CommandProcessControl complex();
default InputStream startExternalStdout() throws Exception {

View File

@@ -51,8 +51,7 @@ public interface OsType {
@Override
public Map<String, String> getProperties(ShellProcessControl pc) throws Exception {
try (CommandProcessControl c =
pc.command("systeminfo").start()) {
try (CommandProcessControl c = pc.command("systeminfo").start()) {
var text = c.readOrThrow();
return PropertiesFormatsParser.parse(text, ":");
}
@@ -144,7 +143,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, ":");
}
@@ -154,9 +153,9 @@ public interface OsType {
public String determineOperatingSystemName(ShellProcessControl pc) throws Exception {
var properties = getProperties(pc);
var name = pc.executeStringSimpleCommand(
"awk '/SOFTWARE LICENSE AGREEMENT FOR macOS/' '/System/Library/CoreServices/Setup " +
"Assistant.app/Contents/Resources/en.lproj/OSXSoftwareLicense.rtf' | " +
"awk -F 'macOS ' '{print $NF}' | awk '{print substr($0, 0, length($0)-1)}'");
"awk '/SOFTWARE LICENSE AGREEMENT FOR macOS/' '/System/Library/CoreServices/Setup "
+ "Assistant.app/Contents/Resources/en.lproj/OSXSoftwareLicense.rtf' | "
+ "awk -F 'macOS ' '{print $NF}' | awk '{print substr($0, 0, length($0)-1)}'");
return properties.get("ProductName") + " " + name + " " + properties.get("ProductVersion");
}
}

View File

@@ -13,34 +13,49 @@ public abstract class ProcessControlProvider {
private static List<ProcessControlProvider> INSTANCES;
public static void init(ModuleLayer layer) {
INSTANCES = ServiceLoader.load(layer, ProcessControlProvider.class)
.stream().map(localProcessControlProviderProvider -> localProcessControlProviderProvider.get()).toList();
INSTANCES = ServiceLoader.load(layer, ProcessControlProvider.class).stream()
.map(localProcessControlProviderProvider -> localProcessControlProviderProvider.get())
.toList();
}
public static ShellProcessControl createLocal() {
return INSTANCES.stream().map(localProcessControlProvider -> localProcessControlProvider.createLocalProcessControl()).filter(
Objects::nonNull).findFirst().orElseThrow();
return INSTANCES.stream()
.map(localProcessControlProvider -> localProcessControlProvider.createLocalProcessControl())
.filter(Objects::nonNull)
.findFirst()
.orElseThrow();
}
public static ShellProcessControl createSub(
ShellProcessControl parent,
@NonNull FailableFunction<ShellProcessControl, String, Exception> commandFunction,
FailableBiFunction<ShellProcessControl, String, String, Exception> terminalCommand) {
return INSTANCES.stream().map(localProcessControlProvider -> localProcessControlProvider.sub(parent, commandFunction, terminalCommand)).filter(
Objects::nonNull).findFirst().orElseThrow();
return INSTANCES.stream()
.map(localProcessControlProvider ->
localProcessControlProvider.sub(parent, commandFunction, terminalCommand))
.filter(Objects::nonNull)
.findFirst()
.orElseThrow();
}
public static CommandProcessControl createCommand(
ShellProcessControl parent,
@NonNull FailableFunction<ShellProcessControl, String, Exception> command,
FailableFunction<ShellProcessControl, String, Exception> terminalCommand) {
return INSTANCES.stream().map(localProcessControlProvider -> localProcessControlProvider.command(parent, command, terminalCommand)).filter(
Objects::nonNull).findFirst().orElseThrow();
return INSTANCES.stream()
.map(localProcessControlProvider ->
localProcessControlProvider.command(parent, command, terminalCommand))
.filter(Objects::nonNull)
.findFirst()
.orElseThrow();
}
public static ShellProcessControl createSsh(Object sshStore) {
return INSTANCES.stream().map(localProcessControlProvider -> localProcessControlProvider.createSshControl(sshStore)).filter(
Objects::nonNull).findFirst().orElseThrow();
return INSTANCES.stream()
.map(localProcessControlProvider -> localProcessControlProvider.createSshControl(sshStore))
.filter(Objects::nonNull)
.findFirst()
.orElseThrow();
}
public abstract ShellProcessControl sub(

View File

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

@@ -22,7 +22,6 @@ public interface ShellProcessControl extends ProcessControl {
public void checkRunning() throws Exception;
default String executeStringSimpleCommand(String command) throws Exception {
try (CommandProcessControl c = command(command).start()) {
return c.readOrThrow();
@@ -98,7 +97,8 @@ public interface ShellProcessControl extends ProcessControl {
CommandProcessControl command(FailableFunction<ShellProcessControl, String, Exception> command);
CommandProcessControl command(
FailableFunction<ShellProcessControl, String, Exception> command, FailableFunction<ShellProcessControl, String, Exception> terminalCommand);
FailableFunction<ShellProcessControl, String, Exception> command,
FailableFunction<ShellProcessControl, String, Exception> terminalCommand);
default CommandProcessControl command(String command) {
return command(shellProcessControl -> command);

View File

@@ -8,10 +8,7 @@ import java.util.List;
import java.util.Map;
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 +22,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(" "));
@@ -54,12 +51,10 @@ public interface ShellType {
return getEchoCommand(s, false);
}
String getSetEnvironmentVariableCommand(String variable, String value);
String getSetEnvironmentVariableCommand(String variable, String value);
String getEchoCommand(String s, boolean toErrorStream);
String getPrintVariableCommand(String name);
String getPrintExitCodeCommand(String prefix);

View File

@@ -23,10 +23,7 @@ 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;
@@ -42,7 +39,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) {

View File

@@ -9,9 +9,7 @@ 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

@@ -37,8 +37,7 @@ public interface TableReadConnection extends DataSourceReadConnection {
}
@Override
public void withRows(DataStructureNodeAcceptor<TupleNode> lineAcceptor) throws Exception {
}
public void withRows(DataStructureNodeAcceptor<TupleNode> lineAcceptor) throws Exception {}
@Override
public ArrayNode readRows(int maxLines) throws Exception {

View File

@@ -17,8 +17,8 @@ public class WriteMode extends JacksonizedValue {
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());
}
}
@@ -34,14 +34,11 @@ public class WriteMode extends JacksonizedValue {
}
@JsonTypeName("replace")
public static final class Replace extends WriteMode {
}
public static final class Replace extends WriteMode {}
@JsonTypeName("append")
public static final class Append extends WriteMode {
}
public static final class Append extends WriteMode {}
@JsonTypeName("prepend")
public static final class Prepend extends WriteMode {
}
public static final class Prepend extends WriteMode {}
}

View File

@@ -16,10 +16,7 @@ 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() {
@@ -78,11 +75,9 @@ public interface DataStore {
*
* @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

@@ -11,8 +11,8 @@ public interface MachineStore extends FileSystemStore, ShellStore {
@Override
public default InputStream openInput(String file) throws Exception {
return create().command(proc -> proc.getShellType()
.getFileReadCommand(proc.getOsType().normalizeFileName(file)))
return create().command(proc ->
proc.getShellType().getFileReadCommand(proc.getOsType().normalizeFileName(file)))
.startExternalStdout();
}
@@ -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()
.getMkdirsCommand(proc.getOsType().normalizeFileName(file))))
.getMkdirsCommand(proc.getOsType().normalizeFileName(file))))
.start()) {
return pc.discardAndCheckExit();
}

View File

@@ -8,8 +8,7 @@ import io.xpipe.core.process.ShellType;
import java.nio.charset.Charset;
public interface ShellStore extends DataStore, StatefulDataStore
{
public interface ShellStore extends DataStore, StatefulDataStore {
public static MachineStore local() {
return new LocalStore();
@@ -42,6 +41,7 @@ public interface ShellStore extends DataStore, StatefulDataStore
default OsType getOsType() {
return getState("os", OsType.class, null);
}
default Charset getCharset() {
return getState("charset", Charset.class, null);
}
@@ -56,8 +56,7 @@ public interface ShellStore extends DataStore, StatefulDataStore
@Override
default void validate() throws Exception {
try (ShellProcessControl pc = create().start()) {
}
try (ShellProcessControl pc = create().start()) {}
}
public default String queryMachineName() throws Exception {

View File

@@ -50,8 +50,7 @@ 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));
for (ShellType t : ShellTypes.getAllShellTypes()) {
context.registerSubtypes(new NamedType(t.getClass()));
@@ -200,16 +199,12 @@ 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

@@ -106,6 +106,8 @@ public class Deobfuscator {
}
var t = ShellTypes.getPlatformDefault();
return ShellStore.local().create().executeBooleanSimpleCommand(t.getWhichCommand("retrace." + t.getScriptFileEnding()));
return ShellStore.local()
.create()
.executeBooleanSimpleCommand(t.getWhichCommand("retrace." + t.getScriptFileEnding()));
}
}

View File

@@ -17,10 +17,6 @@ public class Identifiers {
private static List<String> nameAlternatives(List<String> split) {
return List.of(
String.join("", split),
String.join(" ", split),
String.join("_", split),
String.join("-", split)
);
String.join("", split), String.join(" ", split), String.join("_", split), String.join("-", split));
}
}

View File

@@ -32,13 +32,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,14 +5,10 @@ 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 String toString() {

View File

@@ -29,12 +29,10 @@ public abstract class ProxyProvider {
public abstract boolean isRemote(Object base);
public abstract <T extends DataSourceReadConnection> T createRemoteReadConnection(
DataSource<?> source, ShellStore proxy
) throws Exception;
DataSource<?> source, ShellStore proxy) throws Exception;
public abstract <T extends DataSourceConnection> T createRemoteWriteConnection(
DataSource<?> source, WriteMode mode, ShellStore proxy
) throws Exception;
DataSource<?> source, WriteMode mode, ShellStore proxy) throws Exception;
public abstract ProxyFunction call(ProxyFunction func, ShellStore proxy);
}

View File

@@ -12,7 +12,9 @@ public abstract class SecretProvider {
public static SecretProvider get() {
if (INSTANCE == null) {
INSTANCE = ServiceLoader.load(ModuleLayer.boot(), SecretProvider.class).findFirst().orElseThrow();
INSTANCE = ServiceLoader.load(ModuleLayer.boot(), SecretProvider.class)
.findFirst()
.orElseThrow();
}
return INSTANCE;

View File

@@ -19,5 +19,4 @@ public abstract class SimpleProxyFunction<T> extends ProxyFunction {
var result = callAndCopy();
return ((SimpleProxyFunction<T>) result).getResult();
}
}

View File

@@ -9,7 +9,7 @@ public class UuidHelper {
public static Optional<UUID> parse(String s) {
try {
return Optional.of(UUID.fromString(s));
return Optional.of(UUID.fromString(s));
} catch (IllegalArgumentException ex) {
return Optional.empty();
}

View File

@@ -3,5 +3,4 @@ package io.xpipe.core.util;
import lombok.experimental.StandardException;
@StandardException
public class ValidationException extends Exception {
}
public class ValidationException extends Exception {}

View File

@@ -196,9 +196,7 @@ public class XPipeInstallation {
} else if (OsType.getLocal().equals(OsType.LINUX)) {
return path.resolve("logo.png");
} else {
return path.resolve("Contents")
.resolve("Resources")
.resolve("logo.icns");
return path.resolve("Contents").resolve("Resources").resolve("logo.icns");
}
}

View File

@@ -24,7 +24,9 @@ public class XPipeTempDirectory {
var dir = FileNames.join(base, "xpipe");
if (!proc.executeBooleanSimpleCommand(proc.getShellType().getFileExistsCommand(dir))) {
proc.executeSimpleCommand(proc.getShellType().flatten(proc.getShellType().getMkdirsCommand(dir)), "Unable to access or create temporary directory " + dir);
proc.executeSimpleCommand(
proc.getShellType().flatten(proc.getShellType().getMkdirsCommand(dir)),
"Unable to access or create temporary directory " + dir);
if (proc.getOsType().equals(OsType.LINUX) || proc.getOsType().equals(OsType.MACOS)) {
proc.executeSimpleCommand("chmod -f 777 \"" + dir + "\"");

View File

@@ -30,7 +30,10 @@ open module io.xpipe.core {
uses io.xpipe.core.util.DataStateProvider;
uses io.xpipe.core.util.SecretProvider;
provides WriteMode with WriteMode.Replace, WriteMode.Append, WriteMode.Prepend;
provides WriteMode with
WriteMode.Replace,
WriteMode.Append,
WriteMode.Prepend;
provides com.fasterxml.jackson.databind.Module with
CoreJacksonModule;
}