X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.jshell%2Fsrc%2Forg%2Fargeo%2Finternal%2Fcms%2Fjshell%2Fosgi%2FOsgiExecutionControlProvider.java;h=fbca085861759a1410b743555d8eb1d817db6367;hb=7a1298bb4b78713553a37fba483373eeaf738069;hp=80acd55517e9af81e2b7a990584603458877397c;hpb=9a975983b2f3509a287dfb5751799544ec97ce70;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms.jshell/src/org/argeo/internal/cms/jshell/osgi/OsgiExecutionControlProvider.java b/org.argeo.cms.jshell/src/org/argeo/internal/cms/jshell/osgi/OsgiExecutionControlProvider.java index 80acd5551..fbca08586 100644 --- a/org.argeo.cms.jshell/src/org/argeo/internal/cms/jshell/osgi/OsgiExecutionControlProvider.java +++ b/org.argeo.cms.jshell/src/org/argeo/internal/cms/jshell/osgi/OsgiExecutionControlProvider.java @@ -19,6 +19,7 @@ import java.util.TreeMap; import java.util.TreeSet; import org.argeo.api.cms.CmsLog; +import org.argeo.cms.jshell.CmsExecutionControl; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; @@ -28,7 +29,6 @@ import org.osgi.framework.wiring.BundleRevision; import org.osgi.framework.wiring.BundleWire; import org.osgi.framework.wiring.BundleWiring; -import jdk.jshell.execution.DirectExecutionControl; import jdk.jshell.spi.ExecutionControl; import jdk.jshell.spi.ExecutionControlProvider; import jdk.jshell.spi.ExecutionEnv; @@ -53,24 +53,15 @@ public class OsgiExecutionControlProvider implements ExecutionControlProvider { @Override public ExecutionControl generate(ExecutionEnv env, Map parameters) throws Throwable { - // TODO find a better way to get a default bundle context - // NOTE: the related default bundle has to be started - -// String symbolicName = parameters.get(BUNDLE_PARAMETER); -// Bundle fromBundle = getBundleFromSn(symbolicName); - Long bundleId = Long.parseLong(parameters.get(BUNDLE_PARAMETER)); Bundle fromBundle = getBundleFromId(bundleId); BundleWiring fromBundleWiring = fromBundle.adapt(BundleWiring.class); ClassLoader fromBundleClassLoader = fromBundleWiring.getClassLoader(); - // use the bundle classloade as context classloader - Thread.currentThread().setContextClassLoader(fromBundleClassLoader); - - ExecutionControl executionControl = new DirectExecutionControl( + ExecutionControl executionControl = new CmsExecutionControl(env, new WrappingLoaderDelegate(env, fromBundleClassLoader)); - log.debug("JShell from " + fromBundle.getSymbolicName() + "_" + fromBundle.getVersion() + " [" + log.trace(() -> "JShell from " + fromBundle.getSymbolicName() + "_" + fromBundle.getVersion() + " [" + fromBundle.getBundleId() + "]"); return executionControl; } @@ -121,9 +112,13 @@ public class OsgiExecutionControlProvider implements ExecutionControlProvider { } String std = """ + /open DEFAULT import jdk.jshell.spi.ExecutionEnv; + import java.util.function.*; - InputStream STDIN = new Supplier() { + /** Redirected standard IO. */ + public class Std { + final static InputStream in = new Supplier() { @Override public InputStream get() { @@ -131,7 +126,7 @@ public class OsgiExecutionControlProvider implements ExecutionControlProvider { } }.get(); - PrintStream STDOUT = new Supplier() { + final static PrintStream out = new Supplier() { @Override public PrintStream get() { @@ -139,7 +134,7 @@ public class OsgiExecutionControlProvider implements ExecutionControlProvider { } }.get(); - PrintStream STDERR = new Supplier() { + final static PrintStream err = new Supplier() { @Override public PrintStream get() { @@ -147,7 +142,9 @@ public class OsgiExecutionControlProvider implements ExecutionControlProvider { } }.get(); - """; + + } + """; writer.write(std); } catch (IOException e) { throw new RuntimeException("Cannot writer bundle startup script to " + bundleStartupScript, e);