Merge branch icons into master [release]

This commit is contained in:
crschnick
2024-10-01 10:29:31 +00:00
parent 19b341d848
commit dbea577662
5425 changed files with 52433 additions and 1535 deletions

View File

@@ -254,12 +254,7 @@ public class CommandBuilder {
return list;
}
public String buildFull(ShellControl sc) throws Exception {
if (sc == null) {
return buildSimple();
}
var s = buildBase(sc);
public Map<String, String> buildEnvironmentVariables(ShellControl sc) throws Exception {
LinkedHashMap<String, String> map = new LinkedHashMap<>();
for (var e : environmentVariables.entrySet()) {
var v = e.getValue().evaluate(sc);
@@ -267,6 +262,16 @@ public class CommandBuilder {
map.put(e.getKey(), v);
}
}
return map;
}
public String buildFull(ShellControl sc) throws Exception {
if (sc == null) {
return buildSimple();
}
var s = buildBase(sc);
Map<String, String> map = buildEnvironmentVariables(sc);
return sc.getShellDialect().assembleCommand(s, map);
}

View File

@@ -34,6 +34,8 @@ public interface ProcessControl extends AutoCloseable {
@Override
void close() throws Exception;
void shutdown() throws Exception;
void kill();
ProcessControl start() throws Exception;

View File

@@ -29,6 +29,12 @@ public class ProcessOutputException extends Exception {
return new ProcessOutputException(message, ex.getExitCode(), ex.getOutput());
}
public static ProcessOutputException withSuffix(String customSuffix, ProcessOutputException ex) {
var messagePrefix = ex.getOutput() != null && !ex.getOutput().isBlank() ? ex.getOutput() + "\n" : "";
var message = messagePrefix + customSuffix;
return new ProcessOutputException(message, ex.getExitCode(), ex.getOutput());
}
public static ProcessOutputException of(long exitCode, String... messages) {
var combinedError = Arrays.stream(messages)
.filter(s -> s != null && !s.isBlank())

View File

@@ -19,6 +19,8 @@ public interface ShellDumbMode {
return function.prepareWithoutInitCommand();
}
default void prepareInlineShellSwitch(ShellControl shellControl) throws Exception {}
default void prepareDumbInit(ShellControl shellControl) throws Exception {}
default void prepareDumbExit(ShellControl shellControl) throws IOException {

View File

@@ -21,6 +21,8 @@ public class ShellEnvironmentStoreState extends ShellStoreState {
var n = (ShellEnvironmentStoreState) newer;
var b = toBuilder();
mergeBuilder(n, b);
return b.shellName(useNewer(shellName, n.shellName)).setDefault(useNewer(setDefault,n.setDefault)).build();
return b.shellName(useNewer(shellName, n.shellName))
.setDefault(useNewer(setDefault, n.setDefault))
.build();
}
}

View File

@@ -18,21 +18,7 @@ public interface ShellOpenFunction {
};
}
static ShellOpenFunction of(String b) {
return new ShellOpenFunction() {
@Override
public CommandBuilder prepareWithoutInitCommand() {
return CommandBuilder.of().add(b);
}
@Override
public CommandBuilder prepareWithInitCommand(@NonNull String command) {
return CommandBuilder.of().add(command);
}
};
}
static ShellOpenFunction of(CommandBuilder b) {
static ShellOpenFunction of(CommandBuilder b, boolean append) {
return new ShellOpenFunction() {
@Override
public CommandBuilder prepareWithoutInitCommand() {
@@ -41,7 +27,7 @@ public interface ShellOpenFunction {
@Override
public CommandBuilder prepareWithInitCommand(@NonNull String command) {
return CommandBuilder.ofString(command);
return CommandBuilder.ofFunction(sc -> (append ? b.buildFull(sc) + " " : "") + command);
}
};
}

View File

@@ -56,7 +56,7 @@ public interface FileSystem extends Closeable, AutoCloseable {
try {
var list = new ArrayList<FileEntry>();
list.add(fileEntry);
list.addAll(listFilesRecursively(fileEntry.getPath().toString()));
list.addAll(listFilesRecursively(fileEntry.getPath()));
return list.stream();
} catch (Exception e) {
throw new RuntimeException(e);

View File

@@ -1,28 +1,33 @@
package io.xpipe.core.store;
import io.xpipe.core.process.ProcessControl;
import io.xpipe.core.process.ShellControl;
public interface ShellStore extends DataStore, FileSystemStore, ValidatableStore {
public interface ShellStore extends DataStore, FileSystemStore, ValidatableStore<ShellValidationContext> {
@Override
default FileSystem createFileSystem() {
return new ConnectionFileSystem(control());
}
default ProcessControl prepareLaunchCommand() {
return control();
ShellControl parentControl();
ShellControl control(ShellControl parent);
default ShellControl control() {
return control(parentControl());
}
ShellControl control();
@Override
default void validate() throws Exception {
var c = control();
default ShellValidationContext validate(ShellValidationContext context) throws Exception {
var c = control(context.get());
if (!isInStorage()) {
c.withoutLicenseCheck();
}
return new ShellValidationContext(c.start());
}
try (ShellControl pc = c.start()) {}
@Override
default ShellValidationContext createContext() throws Exception {
return new ShellValidationContext(parentControl().start());
}
}

View File

@@ -0,0 +1,24 @@
package io.xpipe.core.store;
import io.xpipe.core.process.ShellControl;
import lombok.Value;
@Value
public class ShellValidationContext implements ValidationContext<ShellControl> {
ShellControl shellControl;
@Override
public ShellControl get() {
return shellControl;
}
@Override
public void close() {
try {
shellControl.shutdown();
} catch (Exception ignored) {
}
}
}

View File

@@ -1,6 +1,6 @@
package io.xpipe.core.store;
public interface ValidatableStore extends DataStore {
public interface ValidatableStore<T extends ValidationContext<?>> extends DataStore {
/**
* Performs a validation of this data store.
@@ -18,5 +18,7 @@ public interface ValidatableStore extends DataStore {
*
* @throws Exception if any part of the validation went wrong
*/
default void validate() throws Exception {}
T validate(T context) throws Exception;
T createContext() throws Exception;
}

View File

@@ -0,0 +1,8 @@
package io.xpipe.core.store;
public interface ValidationContext<T> {
T get();
void close();
}

View File

@@ -1,13 +1,5 @@
package io.xpipe.core.util;
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.databind.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.module.SimpleModule;
import io.xpipe.core.dialog.BaseQueryElement;
import io.xpipe.core.dialog.BusyElement;
import io.xpipe.core.dialog.ChoiceElement;
@@ -18,6 +10,15 @@ import io.xpipe.core.process.ShellDialects;
import io.xpipe.core.store.FilePath;
import io.xpipe.core.store.StorePath;
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.databind.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.module.SimpleModule;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Path;