Package org.jruby.embed.osgi
Class OSGiScriptingContainer
java.lang.Object
org.jruby.embed.ScriptingContainer
org.jruby.embed.osgi.OSGiScriptingContainer
- All Implemented Interfaces:
EmbedRubyInstanceConfigAdapter
Helpers to create a ScriptingContainer and set it up so it lives as well
as possible in the OSGi world.
Currently:
- Access to the java classes and resources provided by the osgi bundle.
- Setup of jruby home pointing at the jruby bundle by default. Supporting unzipped jruby bundle for now.
TODO: look into using the LoadService of jruby. Look if it would be possible to reuse the base runtime and minimize the cost of new jruby runtimes.
- Author:
- hmalphettes
-
Constructor Summary
ConstructorsConstructorDescriptionOSGiScriptingContainer
(org.osgi.framework.Bundle creator) A scripting container where the classloader can find classes in the osgi creator bundle and where the jruby home is set to point to the one in the jruby's bundle home folder.OSGiScriptingContainer
(org.osgi.framework.Bundle creator, LocalContextScope scope, LocalVariableBehavior behavior) A scripting container where the classloader can find classes in the osgi creator bundle and where the jruby home is set to point to the one in the jruby's bundle home folder. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addToClassPath
(org.osgi.framework.Bundle bundle) Parses a script given by a input stream and return an object which can be run().runScriptlet
(String bundleSymbolicName, String path) runScriptlet
(org.osgi.framework.Bundle bundle, String path) Methods inherited from class org.jruby.embed.ScriptingContainer
addClassLoader, addGemPath, addGemPath, addLoadPath, addLoadPath, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callSuper, callSuper, clear, finalize, get, get, getArgv, getAttribute, getAttributeMap, getClassLoader, getClassloaderDelegate, getCompileMode, getCurrentDirectory, getEnvironment, getErr, getError, getErrorWriter, getHomeDirectory, getIn, getInput, getInstance, getJitLogEvery, getJitMax, getJitMaxSize, getJitThreshold, getKCode, getLoadPaths, getLoadServiceCreator, getOut, getOutput, getProfile, getProfileOutput, getProfilingMode, getProperty, getProvider, getReader, getRecordSeparator, getRuntime, getScriptFilename, getSupportedRubyVersion, getVarMap, getWriter, isNativeEnabled, isObjectSpaceEnabled, isRunRubyInProcess, newObjectAdapter, newRuntimeAdapter, parse, parse, parse, parse, put, put, remove, remove, removeAttribute, resetErrorWriter, resetWriter, runRubyMethod, runRubyMethod, runScriptlet, runScriptlet, runScriptlet, runScriptlet, setArgv, setAttribute, setClassLoader, setClassloaderDelegate, setCompileMode, setCurrentDirectory, setEnvironment, setError, setError, setErrorWriter, setHomeDirectory, setInput, setInput, setJitLogEvery, setJitMax, setJitMaxSize, setJitThreshold, setKCode, setLoadPaths, setLoadServiceCreator, setNativeEnabled, setObjectSpaceEnabled, setOutput, setOutput, setProfile, setProfile, setProfileOutput, setProfilingMode, setReader, setRecordSeparator, setRunRubyInProcess, setScriptFilename, setWriter, terminate
-
Constructor Details
-
OSGiScriptingContainer
public OSGiScriptingContainer(org.osgi.framework.Bundle creator) A scripting container where the classloader can find classes in the osgi creator bundle and where the jruby home is set to point to the one in the jruby's bundle home folder.scope: LocalContextScope.SINGLETHREAD; behavior: LocalVariableBehavior.TRANSIENT
- Parameters:
creator
-
-
OSGiScriptingContainer
public OSGiScriptingContainer(org.osgi.framework.Bundle creator, LocalContextScope scope, LocalVariableBehavior behavior) A scripting container where the classloader can find classes in the osgi creator bundle and where the jruby home is set to point to the one in the jruby's bundle home folder.- Parameters:
creator
-scope
- if null, LocalContextScope.SINGLETHREADbehavior
- if null, LocalVariableBehavior.TRANSIENT
-
-
Method Details
-
runScriptlet
- Parameters:
bundleSymbolicName
- The bundle where the script is located. Lazily added to the loader of the OSGiScriptingContainer. (require bundle:/... is implicitly done here)path
- The entry in the bundle- Returns:
-
runScriptlet
- Parameters:
bundle
- The bundle where the script is located. Lazily added to the loader of the OSGiScriptingContainer. (require bundle:/... is implicitly done here)path
- The entry in the bundle- Returns:
-
parse
public EmbedEvalUnit parse(org.osgi.framework.Bundle bundle, String path, int... lines) throws IOException Parses a script given by a input stream and return an object which can be run(). This allows the script to be parsed once and evaluated many times.- Parameters:
bundle
- is where the script is locatedpath
- is the entry in the bundle.lines
- are linenumbers to display for parse errors and backtraces. This field is optional. Only the first argument is used for parsing. When no line number is specified, 0 is applied to.- Returns:
- an object which can be run
- Throws:
IOException
-
addToClassPath
public void addToClassPath(org.osgi.framework.Bundle bundle) - Parameters:
bundle
- Add a bundle to the jruby classloader. Equivalent to require"bundle:/#{bundle.symbolic.name}"
-
getOSGiBundleClassLoader
- Returns:
- The ScriptingContainer's classloader casted to a JRubyOSGiBundleClassLoader. It is the parent classloader of the actual's runtime's JRubyClassLoader. It enables finding classes and resources in the OSGi environment.
-