mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-21 15:10:23 +00:00
Rework beacon to support more cli features
This commit is contained in:
parent
40f9de1dc3
commit
a9ee9c1bdc
11 changed files with 147 additions and 19 deletions
|
@ -33,7 +33,8 @@ public interface DataSource {
|
|||
* @return a reference to the data source that can be used to access the underlying data source
|
||||
*/
|
||||
static DataSource get(DataSourceId id) {
|
||||
return DataSourceImpl.get(id);
|
||||
return null;
|
||||
//return DataSourceImpl.get(id);
|
||||
}
|
||||
|
||||
static DataSource wrap(InputStream in, String type, Map<String, String> configOptions) {
|
||||
|
|
|
@ -11,6 +11,7 @@ import io.xpipe.beacon.exchange.StoreResourceExchange;
|
|||
import io.xpipe.beacon.exchange.StoreStreamExchange;
|
||||
import io.xpipe.core.source.DataSourceConfig;
|
||||
import io.xpipe.core.source.DataSourceId;
|
||||
import io.xpipe.core.source.DataSourceReference;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
@ -18,7 +19,7 @@ import java.util.Map;
|
|||
|
||||
public abstract class DataSourceImpl implements DataSource {
|
||||
|
||||
public static DataSource get(DataSourceId ds) {
|
||||
public static DataSource get(DataSourceReference ds) {
|
||||
final DataSource[] source = new DataSource[1];
|
||||
new XPipeApiConnector() {
|
||||
@Override
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package io.xpipe.api.test;
|
||||
|
||||
import io.xpipe.beacon.BeaconClient;
|
||||
import io.xpipe.beacon.BeaconServer;
|
||||
import org.junit.jupiter.api.extension.BeforeAllCallback;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
|
||||
import static org.junit.jupiter.api.extension.ExtensionContext.Namespace.GLOBAL;
|
||||
|
||||
public class XPipeConfig implements BeforeAllCallback, ExtensionContext.Store.CloseableResource {
|
||||
|
||||
private static boolean started = false;
|
||||
|
@ -13,15 +13,17 @@ public class XPipeConfig implements BeforeAllCallback, ExtensionContext.Store.Cl
|
|||
public void beforeAll(ExtensionContext context) throws Exception {
|
||||
if (!started) {
|
||||
started = true;
|
||||
// Your "before all tests" startup logic goes here
|
||||
// The following line registers a callback hook when the root test context is shut down
|
||||
context.getRoot().getStore(GLOBAL).put("any unique name", this);
|
||||
//BeaconServer.start();
|
||||
if (BeaconServer.tryStart()) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
// Your "after all tests" logic goes here
|
||||
public void close() throws Exception {
|
||||
var client = new BeaconClient();
|
||||
if (BeaconServer.tryStop(client)) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package io.xpipe.beacon;
|
||||
|
||||
import io.xpipe.beacon.exchange.StopExchange;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.ServerSocket;
|
||||
|
@ -42,6 +44,11 @@ public class BeaconServer {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static boolean tryStop(BeaconClient client) throws Exception {
|
||||
StopExchange.Response res = client.simpleExchange(StopExchange.Request.builder().build());
|
||||
return res.isSuccess();
|
||||
}
|
||||
|
||||
private static Optional<Path> getPortableLauncherExecutable() {
|
||||
var env = System.getenv("XPIPE_HOME");
|
||||
Path file = null;
|
||||
|
@ -49,9 +56,9 @@ public class BeaconServer {
|
|||
// Prepare for invalid XPIPE_HOME path value
|
||||
try {
|
||||
if (System.getProperty("os.name").startsWith("Windows")) {
|
||||
file = Path.of(env, "xpipe-launcher.exe");
|
||||
file = Path.of(env, "xpipe_launcher.exe");
|
||||
} else {
|
||||
file = Path.of(env, "xpipe-launcher");
|
||||
file = Path.of(env, "xpipe_launcher");
|
||||
}
|
||||
return Files.exists(file) ? Optional.of(file) : Optional.empty();
|
||||
} catch (Exception ex) {
|
||||
|
@ -68,9 +75,9 @@ public class BeaconServer {
|
|||
try {
|
||||
Path file = null;
|
||||
if (System.getProperty("os.name").startsWith("Windows")) {
|
||||
file = Path.of(System.getenv("LOCALAPPDATA"), "X-Pipe", "xpipe-launcher.exe");
|
||||
file = Path.of(System.getenv("LOCALAPPDATA"), "X-Pipe", "xpipe_launcher.exe");
|
||||
} else {
|
||||
file = Path.of("/opt/xpipe/xpipe-launcher");
|
||||
file = Path.of("/opt/xpipe/xpipe_launcher");
|
||||
}
|
||||
return Files.exists(file) ? Optional.of(file) : Optional.empty();
|
||||
} catch (Exception ex) {
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package io.xpipe.beacon.exchange;
|
||||
|
||||
import io.xpipe.beacon.message.RequestMessage;
|
||||
import io.xpipe.beacon.message.ResponseMessage;
|
||||
import io.xpipe.core.source.DataSourceConfigInstance;
|
||||
import io.xpipe.core.source.DataSourceReference;
|
||||
import lombok.Builder;
|
||||
import lombok.NonNull;
|
||||
import lombok.Value;
|
||||
import lombok.extern.jackson.Jacksonized;
|
||||
|
||||
public class EditExecuteExchange implements MessageExchange<EditExecuteExchange.Request, EditExecuteExchange.Response> {
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "editExecute";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<EditExecuteExchange.Request> getRequestClass() {
|
||||
return EditExecuteExchange.Request.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<EditExecuteExchange.Response> getResponseClass() {
|
||||
return EditExecuteExchange.Response.class;
|
||||
}
|
||||
|
||||
@Jacksonized
|
||||
@Builder
|
||||
@Value
|
||||
public static class Request implements RequestMessage {
|
||||
@NonNull DataSourceReference ref;
|
||||
@NonNull
|
||||
DataSourceConfigInstance config;
|
||||
}
|
||||
|
||||
@Jacksonized
|
||||
@Builder
|
||||
@Value
|
||||
public static class Response implements ResponseMessage {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package io.xpipe.beacon.exchange;
|
||||
|
||||
import io.xpipe.beacon.message.RequestMessage;
|
||||
import io.xpipe.beacon.message.ResponseMessage;
|
||||
import io.xpipe.core.source.DataSourceConfigInstance;
|
||||
import io.xpipe.core.source.DataSourceReference;
|
||||
import lombok.Builder;
|
||||
import lombok.NonNull;
|
||||
import lombok.Value;
|
||||
import lombok.extern.jackson.Jacksonized;
|
||||
|
||||
public class EditPreparationExchange implements MessageExchange<EditPreparationExchange.Request, EditPreparationExchange.Response> {
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "editPreparation";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<EditPreparationExchange.Request> getRequestClass() {
|
||||
return EditPreparationExchange.Request.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<EditPreparationExchange.Response> getResponseClass() {
|
||||
return EditPreparationExchange.Response.class;
|
||||
}
|
||||
|
||||
@Jacksonized
|
||||
@Builder
|
||||
@Value
|
||||
public static class Request implements RequestMessage {
|
||||
@NonNull
|
||||
DataSourceReference ref;
|
||||
}
|
||||
|
||||
@Jacksonized
|
||||
@Builder
|
||||
@Value
|
||||
public static class Response implements ResponseMessage {
|
||||
DataSourceConfigInstance config;
|
||||
}
|
||||
}
|
|
@ -33,5 +33,7 @@ module io.xpipe.beacon {
|
|||
DialogExchange,
|
||||
InfoExchange,
|
||||
PreStoreExchange,
|
||||
EditPreparationExchange,
|
||||
EditExecuteExchange,
|
||||
VersionExchange;
|
||||
}
|
|
@ -8,6 +8,7 @@ plugins {
|
|||
apply from: "$rootDir/deps/java.gradle"
|
||||
apply from: "$rootDir/deps/jackson.gradle"
|
||||
apply from: "$rootDir/deps/lombok.gradle"
|
||||
apply from: "$rootDir/deps/junit.gradle"
|
||||
apply from: 'publish.gradle'
|
||||
apply from: "$rootDir/deps/publish-base.gradle"
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ public interface DataSourceReference {
|
|||
return new Id(DataSourceId.fromString(s));
|
||||
}
|
||||
|
||||
return new Name(s);
|
||||
return new Name(s.trim());
|
||||
}
|
||||
|
||||
enum Type {
|
||||
|
|
|
@ -10,9 +10,6 @@ public class DataSourceIdTest {
|
|||
|
||||
@Test
|
||||
public void testCreateInvalidParameters() {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
DataSourceId.create(null, "abc");
|
||||
});
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
DataSourceId.create("a:bc", "abc");
|
||||
});
|
||||
|
@ -46,7 +43,7 @@ public class DataSourceIdTest {
|
|||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"abc", "abc:", "ab::c", ":abc", " :ab", "::::", "", " "})
|
||||
@ValueSource(strings = {"abc", "abc:", "ab::c", "::abc", " ab", "::::", "", " "})
|
||||
public void testFromStringInvalidParameters(String arg) {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
DataSourceId.fromString(arg);
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package io.xpipe.core.test;
|
||||
|
||||
import io.xpipe.core.source.DataSourceId;
|
||||
import io.xpipe.core.source.DataSourceReference;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
public class DataSourceReferenceTest {
|
||||
|
||||
@Test
|
||||
public void parseValidParameters() {
|
||||
Assertions.assertEquals(DataSourceReference.parse(" ").getType(), DataSourceReference.Type.EMPTY);
|
||||
Assertions.assertEquals(DataSourceReference.parse(null).getType(), DataSourceReference.Type.EMPTY);
|
||||
|
||||
Assertions.assertEquals(DataSourceReference.parse("abc").getType(), DataSourceReference.Type.NAME);
|
||||
Assertions.assertEquals(DataSourceReference.parse(" abc_ d e").getName(), "abc_ d e");
|
||||
|
||||
Assertions.assertEquals(DataSourceReference.parse("ab:c").getId(), DataSourceId.fromString(" AB: C "));
|
||||
Assertions.assertEquals(DataSourceReference.parse(" ab:c ").getId(), DataSourceId.fromString("ab:c "));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"abc:", "ab::c", "::abc"})
|
||||
public void parseInvalidParameters(String arg) {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
DataSourceReference.parse(arg);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue