Add canonical JShell direct execution provider
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 29 May 2023 08:27:16 +0000 (10:27 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 29 May 2023 08:27:16 +0000 (10:27 +0200)
org.argeo.init/src/META-INF/services/jdk.jshell.spi.ExecutionControlProvider [new file with mode: 0644]
org.argeo.init/src/org/argeo/init/jshell/DirectExecutionControlProvider.java [new file with mode: 0644]

diff --git a/org.argeo.init/src/META-INF/services/jdk.jshell.spi.ExecutionControlProvider b/org.argeo.init/src/META-INF/services/jdk.jshell.spi.ExecutionControlProvider
new file mode 100644 (file)
index 0000000..dc44974
--- /dev/null
@@ -0,0 +1 @@
+org.argeo.init.jshell.DirectExecutionControlProvider
\ No newline at end of file
diff --git a/org.argeo.init/src/org/argeo/init/jshell/DirectExecutionControlProvider.java b/org.argeo.init/src/org/argeo/init/jshell/DirectExecutionControlProvider.java
new file mode 100644 (file)
index 0000000..1ba8796
--- /dev/null
@@ -0,0 +1,28 @@
+package org.argeo.init.jshell;
+
+import java.util.Map;
+
+import jdk.jshell.execution.DirectExecutionControl;
+import jdk.jshell.spi.ExecutionControl;
+import jdk.jshell.spi.ExecutionControlProvider;
+import jdk.jshell.spi.ExecutionEnv;
+import jdk.jshell.tool.JavaShellToolBuilder;
+
+/**
+ * Canonical {@link ExecutionControlProvider} wrapping a
+ * {@link DirectExecutionControl}, so that {@link JavaShellToolBuilder} can run
+ * in the same VM.
+ */
+public class DirectExecutionControlProvider implements ExecutionControlProvider {
+
+       @Override
+       public String name() {
+               return "direct";
+       }
+
+       @Override
+       public ExecutionControl generate(ExecutionEnv env, Map<String, String> parameters) throws Throwable {
+               return new DirectExecutionControl();
+       }
+
+}