Squash merge xpipe 13 feature branches into master

This commit is contained in:
crschnick
2024-11-16 07:13:24 +00:00
parent 6dabe53011
commit 5868fcfd33
482 changed files with 7425 additions and 5709 deletions

View File

@@ -8,7 +8,6 @@ import lombok.Getter;
import lombok.SneakyThrows;
import java.util.*;
import java.util.function.Function;
public class CommandBuilder {

View File

@@ -17,6 +17,8 @@ public interface ProcessControl extends AutoCloseable {
String prepareTerminalOpen(TerminalInitScriptConfig config, WorkingDirectoryFunction workingDirectory)
throws Exception;
void refreshRunningState();
void closeStdin() throws IOException;
boolean isStdinClosed();

View File

@@ -1,7 +1,7 @@
package io.xpipe.core.process;
import io.xpipe.core.store.DataStore;
import io.xpipe.core.store.FilePath;
import io.xpipe.core.store.ShellStore;
import io.xpipe.core.store.StatefulDataStore;
import io.xpipe.core.util.FailableConsumer;
import io.xpipe.core.util.FailableFunction;
@@ -18,6 +18,8 @@ import java.util.function.Function;
public interface ShellControl extends ProcessControl {
Optional<ShellControl> getParentControl();
ShellTtyState getTtyState();
void setNonInteractive();
@@ -32,9 +34,9 @@ public interface ShellControl extends ProcessControl {
void setWorkingDirectory(WorkingDirectoryFunction workingDirectory);
Optional<ShellStore> getSourceStore();
Optional<DataStore> getSourceStore();
ShellControl withSourceStore(ShellStore store);
ShellControl withSourceStore(DataStore store);
List<ShellInitCommand> getInitCommands();

View File

@@ -24,7 +24,7 @@ public interface ShellDumbMode {
default void prepareDumbInit(ShellControl shellControl) throws Exception {}
default void prepareDumbExit(ShellControl shellControl) throws IOException {
shellControl.writeLine("exit");
shellControl.writeLine(" exit");
}
class Unsupported implements ShellDumbMode {

View File

@@ -2,5 +2,5 @@ package io.xpipe.core.store;
public interface FileSystemStore extends DataStore {
FileSystem createFileSystem();
FileSystem createFileSystem() throws Exception;
}

View File

@@ -17,7 +17,7 @@ public interface NetworkTunnelStore extends DataStore {
interface TunnelFunction {
NetworkTunnelSession create(int localPort, int remotePort);
NetworkTunnelSession create(int localPort, int remotePort, String address) throws Exception;
}
DataStore getNetworkParent();
@@ -57,7 +57,7 @@ public interface NetworkTunnelStore extends DataStore {
}
}
default NetworkTunnelSession sessionChain(int local, int remotePort) throws Exception {
default NetworkTunnelSession sessionChain(int local, int remotePort, String address) throws Exception {
if (!isLocallyTunneable()) {
throw new IllegalStateException(
"Unable to create tunnel chain as one intermediate system does not support tunneling");
@@ -75,7 +75,7 @@ public interface NetworkTunnelStore extends DataStore {
var currentLocalPort = isLast(current) ? local : randomPort();
var currentRemotePort =
sessions.isEmpty() ? remotePort : sessions.getLast().getLocalPort();
var t = func.create(currentLocalPort, currentRemotePort);
var t = func.create(currentLocalPort, currentRemotePort, current == this ? address : "localhost");
t.start();
sessions.add(t);
counter.incrementAndGet();

View File

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

View File

@@ -1,24 +0,0 @@
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

@@ -38,7 +38,6 @@ public interface SingletonSessionStore<T extends Session>
default void startSessionIfNeeded() throws Exception {
synchronized (this) {
var s = getSession();
setSessionEnabled(true);
if (s != null) {
if (s.isRunning()) {
return;
@@ -50,9 +49,14 @@ public interface SingletonSessionStore<T extends Session>
try {
s = newSession();
s.start();
setCache("session", s);
onStateChange(true);
if (s != null) {
setSessionEnabled(true);
s.start();
setCache("session", s);
onStateChange(true);
} else {
setSessionEnabled(false);
}
} catch (Exception ex) {
onStateChange(false);
throw ex;
@@ -65,9 +69,12 @@ public interface SingletonSessionStore<T extends Session>
var ex = getSession();
setSessionEnabled(false);
if (ex != null) {
ex.stop();
setCache("session", null);
onStateChange(false);
try {
ex.stop();
} finally {
setCache("session", null);
onStateChange(false);
}
}
}
}

View File

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

View File

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

View File

@@ -1,8 +0,0 @@
package io.xpipe.core.util;
import io.xpipe.core.store.ShellStore;
public interface Proxyable {
ShellStore getProxy();
}