Migrate all actions, fix various bugs

This commit is contained in:
crschnick
2023-02-09 21:06:58 +00:00
parent 51bbf8ad67
commit 7be8087b19
19 changed files with 298 additions and 207 deletions

View File

@@ -41,7 +41,7 @@ public interface OsType {
@Override
public String getTempDirectory(ShellProcessControl pc) throws Exception {
return pc.executeStringSimpleCommand(ShellTypes.CMD, ShellTypes.CMD.getPrintVariableCommand("TEMP"));
return pc.executeStringSimpleCommand(pc.getShellType().getPrintEnvironmentVariableCommand("TEMP"));
}
@Override
@@ -52,7 +52,7 @@ public interface OsType {
@Override
public Map<String, String> getProperties(ShellProcessControl pc) throws Exception {
try (CommandProcessControl c =
pc.subShell(ShellTypes.CMD).command("systeminfo").start()) {
pc.command("systeminfo").start()) {
var text = c.readOrThrow();
return PropertiesFormatsParser.parse(text, ":");
}

View File

@@ -1,12 +1,12 @@
package io.xpipe.core.process;
import io.xpipe.core.util.FailableBiFunction;
import io.xpipe.core.util.FailableFunction;
import lombok.NonNull;
import java.util.List;
import java.util.Objects;
import java.util.ServiceLoader;
import java.util.function.BiFunction;
import java.util.function.Function;
public abstract class ProcessControlProvider {
@@ -18,21 +18,22 @@ public abstract class ProcessControlProvider {
}
public static ShellProcessControl createLocal() {
return INSTANCES.stream().map(localProcessControlProvider -> localProcessControlProvider.createLocalProcessControl()).findFirst().orElseThrow();
return INSTANCES.stream().map(localProcessControlProvider -> localProcessControlProvider.createLocalProcessControl()).filter(
Objects::nonNull).findFirst().orElseThrow();
}
public static ShellProcessControl createSub(
ShellProcessControl parent,
@NonNull Function<ShellProcessControl, String> commandFunction,
BiFunction<ShellProcessControl, String, String> terminalCommand) {
@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();
}
public static CommandProcessControl createCommand(
ShellProcessControl parent,
@NonNull Function<ShellProcessControl, String> command,
Function<ShellProcessControl, String> terminalCommand) {
@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();
}
@@ -44,13 +45,13 @@ public abstract class ProcessControlProvider {
public abstract ShellProcessControl sub(
ShellProcessControl parent,
@NonNull Function<ShellProcessControl, String> commandFunction,
BiFunction<ShellProcessControl, String, String> terminalCommand);
@NonNull FailableFunction<ShellProcessControl, String, Exception> commandFunction,
FailableBiFunction<ShellProcessControl, String, String, Exception> terminalCommand);
public abstract CommandProcessControl command(
ShellProcessControl parent,
@NonNull Function<ShellProcessControl, String> command,
Function<ShellProcessControl, String> terminalCommand);
@NonNull FailableFunction<ShellProcessControl, String, Exception> command,
FailableFunction<ShellProcessControl, String, Exception> terminalCommand);
public abstract ShellProcessControl createLocalProcessControl();

View File

@@ -1,13 +1,13 @@
package io.xpipe.core.process;
import io.xpipe.core.util.FailableBiFunction;
import io.xpipe.core.util.FailableFunction;
import io.xpipe.core.util.SecretValue;
import lombok.NonNull;
import java.io.IOException;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
public interface ShellProcessControl extends ProcessControl {
@@ -87,18 +87,18 @@ public interface ShellProcessControl extends ProcessControl {
}
ShellProcessControl subShell(
@NonNull Function<ShellProcessControl, String> command,
BiFunction<ShellProcessControl, String, String> terminalCommand);
FailableFunction<ShellProcessControl, String, Exception> command,
FailableBiFunction<ShellProcessControl, String, String, Exception> terminalCommand);
void executeLine(String command) throws Exception;
@Override
ShellProcessControl start() throws Exception;
CommandProcessControl command(Function<ShellProcessControl, String> command);
CommandProcessControl command(FailableFunction<ShellProcessControl, String, Exception> command);
CommandProcessControl command(
Function<ShellProcessControl, String> command, Function<ShellProcessControl, String> terminalCommand);
FailableFunction<ShellProcessControl, String, Exception> command, FailableFunction<ShellProcessControl, String, Exception> terminalCommand);
default CommandProcessControl command(String command) {
return command(shellProcessControl -> command);

View File

@@ -60,11 +60,9 @@ public interface ShellType {
String getEchoCommand(String s, boolean toErrorStream);
default String getPrintVariableCommand(String name) {
return getPrintVariableCommand("", name);
}
String getPrintVariableCommand(String name);
String getPrintVariableCommand(String prefix, String name);
String getPrintExitCodeCommand(String prefix);
default String getPrintEnvironmentVariableCommand(String name) {
return getPrintVariableCommand(name);

View File

@@ -0,0 +1,7 @@
package io.xpipe.core.util;
@FunctionalInterface
public interface FailableBiFunction<T1, T2, R, E extends Throwable> {
R apply(T1 var1, T2 var2) throws E;
}

View File

@@ -0,0 +1,7 @@
package io.xpipe.core.util;
@FunctionalInterface
public interface FailableFunction<T, R, E extends Throwable> {
R apply(T var1) throws E;
}