mirror of
https://github.com/xpipe-io/xpipe.git
synced 2025-04-17 01:33:36 +00:00
Fixes for shells
This commit is contained in:
parent
936095aa24
commit
c15c1204f0
5 changed files with 41 additions and 35 deletions
|
@ -71,6 +71,7 @@ public class BeaconProxyImpl extends ProxyProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends DataSourceReadConnection> T createRemoteReadConnection(DataSource<?> source, ShellStore proxy) throws Exception {
|
||||
var downstream = downstreamTransform(source, proxy);
|
||||
|
||||
|
@ -99,6 +100,7 @@ public class BeaconProxyImpl extends ProxyProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends DataSourceConnection> T createRemoteWriteConnection(DataSource<?> source, WriteMode mode, ShellStore proxy) throws Exception {
|
||||
var downstream = downstreamTransform(source, proxy);
|
||||
|
||||
|
|
|
@ -11,8 +11,6 @@ public interface OsType {
|
|||
Linux LINUX = new Linux();
|
||||
Mac MAC = new Mac();
|
||||
|
||||
String getScriptFileEnding();
|
||||
|
||||
String getName();
|
||||
|
||||
String getTempDirectory(ShellProcessControl pc) throws Exception;
|
||||
|
@ -42,11 +40,6 @@ public interface OsType {
|
|||
|
||||
static class Windows implements OsType {
|
||||
|
||||
@Override
|
||||
public String getScriptFileEnding() {
|
||||
return "bat";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Windows";
|
||||
|
@ -54,7 +47,7 @@ public interface OsType {
|
|||
|
||||
@Override
|
||||
public String getTempDirectory(ShellProcessControl pc) throws Exception {
|
||||
return pc.executeSimpleCommand(pc.getShellType().getPrintVariableCommand("TEMP"));
|
||||
return pc.executeSimpleCommand(ShellTypes.CMD, pc.getShellType().getPrintVariableCommand("TEMP"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,7 +58,7 @@ public interface OsType {
|
|||
@Override
|
||||
public Map<String, String> getProperties(ShellProcessControl pc) throws Exception {
|
||||
try (CommandProcessControl c =
|
||||
pc.shell(ShellTypes.CMD).command("systeminfo").start()) {
|
||||
pc.subShell(ShellTypes.CMD).command("systeminfo").start()) {
|
||||
var text = c.readOrThrow();
|
||||
return PropertiesFormatsParser.parse(text, ":");
|
||||
}
|
||||
|
@ -105,11 +98,6 @@ public interface OsType {
|
|||
return String.join("/", file.split("[\\\\/]+"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getScriptFileEnding() {
|
||||
return "sh";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Linux";
|
||||
|
@ -180,11 +168,6 @@ public interface OsType {
|
|||
return String.join("/", file.split("[\\\\/]+"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getScriptFileEnding() {
|
||||
return "sh";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Mac";
|
||||
|
|
|
@ -8,6 +8,8 @@ import java.nio.charset.Charset;
|
|||
|
||||
public interface ProcessControl extends Closeable, AutoCloseable {
|
||||
|
||||
String prepareConsoleOpen(boolean keepOpen) throws Exception;
|
||||
|
||||
void closeStdin() throws IOException;
|
||||
|
||||
boolean isStdinClosed();
|
||||
|
|
|
@ -11,11 +11,11 @@ import java.util.stream.Collectors;
|
|||
|
||||
public interface ShellProcessControl extends ProcessControl {
|
||||
|
||||
default String prepareOpen() throws Exception {
|
||||
return prepareOpen(null);
|
||||
default String prepareConsoleOpen(boolean keepOpen) throws Exception {
|
||||
return prepareConsoleOpen(null, keepOpen);
|
||||
}
|
||||
|
||||
String prepareOpen(String content) throws Exception;
|
||||
String prepareConsoleOpen(String content, boolean keepOpen) throws Exception;
|
||||
|
||||
default String executeSimpleCommand(String command) throws Exception {
|
||||
try (CommandProcessControl c = command(command).start()) {
|
||||
|
@ -33,10 +33,7 @@ public interface ShellProcessControl extends ProcessControl {
|
|||
return executeSimpleCommand(type.switchTo(command));
|
||||
}
|
||||
|
||||
default void restart() throws Exception {
|
||||
exitAndWait();
|
||||
start();
|
||||
}
|
||||
void restart() throws Exception;
|
||||
|
||||
boolean isLocal();
|
||||
|
||||
|
@ -52,24 +49,30 @@ public interface ShellProcessControl extends ProcessControl {
|
|||
|
||||
SecretValue getElevationPassword();
|
||||
|
||||
default ShellProcessControl shell(@NonNull ShellType type) {
|
||||
return shell(type.openCommand()).elevation(getElevationPassword());
|
||||
default ShellProcessControl subShell(@NonNull ShellType type) {
|
||||
return subShell(type.openCommand()).elevation(getElevationPassword());
|
||||
}
|
||||
|
||||
default CommandProcessControl command(@NonNull ShellType type, String command) {
|
||||
return command(type.switchTo(command));
|
||||
}
|
||||
|
||||
default ShellProcessControl shell(@NonNull List<String> command) {
|
||||
return shell(
|
||||
default ShellProcessControl subShell(@NonNull List<String> command) {
|
||||
return subShell(
|
||||
command.stream().map(s -> s.contains(" ") ? "\"" + s + "\"" : s).collect(Collectors.joining(" ")));
|
||||
}
|
||||
|
||||
default ShellProcessControl shell(@NonNull String command) {
|
||||
return shell(processControl -> command);
|
||||
default ShellProcessControl subShell(@NonNull String command) {
|
||||
return subShell(processControl -> command);
|
||||
}
|
||||
|
||||
ShellProcessControl shell(@NonNull Function<ShellProcessControl, String> command);
|
||||
ShellProcessControl subShell(@NonNull Function<ShellProcessControl, String> command);
|
||||
|
||||
default ShellProcessControl consoleCommand(@NonNull String command) {
|
||||
return consoleCommand(shellProcessControl -> command);
|
||||
}
|
||||
|
||||
ShellProcessControl consoleCommand(@NonNull Function<ShellProcessControl, String> command);
|
||||
|
||||
void executeCommand(String command) throws Exception;
|
||||
|
||||
|
|
|
@ -10,12 +10,20 @@ import java.util.stream.Collectors;
|
|||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
|
||||
public interface ShellType {
|
||||
|
||||
String getScriptFileEnding();
|
||||
|
||||
default String commandWithVariable(String key, String value, String command) {
|
||||
return joinCommands(getSetVariableCommand(key, value), command);
|
||||
}
|
||||
|
||||
String getPauseCommand();
|
||||
|
||||
String createInitFileContent(String command);
|
||||
|
||||
List<String> getOpenWithInitFileCommand(String file);
|
||||
String getOpenWithInitFileCommand(String file);
|
||||
|
||||
default String flatten(List<String> command) {
|
||||
return command.stream().map(s -> s.contains(" ") ? "\"" + s + "\"" : s).collect(Collectors.joining(" "));
|
||||
return command.stream().map(s -> s.contains(" ") && !(s.startsWith("\"") && s.endsWith("\"")) ? "\"" + s + "\"" : s).collect(Collectors.joining(" "));
|
||||
}
|
||||
|
||||
|
||||
|
@ -41,6 +49,14 @@ public interface ShellType {
|
|||
return "&&";
|
||||
}
|
||||
|
||||
default String getOrConcatenationOperator() {
|
||||
return "||";
|
||||
}
|
||||
|
||||
String getMakeExecutableCommand(String file);
|
||||
|
||||
String elevateConsoleCommand(ShellProcessControl control, String command);
|
||||
|
||||
String getEchoCommand(String s, boolean toErrorStream);
|
||||
|
||||
String queryShellProcessId(ShellProcessControl control) throws Exception;
|
||||
|
|
Loading…
Add table
Reference in a new issue