mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-04-24 00:21:11 -04:00
Squash merge xpipe 13 feature branches into master
This commit is contained in:
@@ -8,7 +8,6 @@ import lombok.Getter;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class CommandBuilder {
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -2,5 +2,5 @@ package io.xpipe.core.store;
|
||||
|
||||
public interface FileSystemStore extends DataStore {
|
||||
|
||||
FileSystem createFileSystem();
|
||||
FileSystem createFileSystem() throws Exception;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package io.xpipe.core.store;
|
||||
|
||||
public interface ValidationContext<T> {
|
||||
|
||||
T get();
|
||||
|
||||
void close();
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package io.xpipe.core.util;
|
||||
|
||||
import io.xpipe.core.store.ShellStore;
|
||||
|
||||
public interface Proxyable {
|
||||
|
||||
ShellStore getProxy();
|
||||
}
|
||||
Reference in New Issue
Block a user