Class OSGiScriptingContainer

java.lang.Object
org.jruby.embed.ScriptingContainer
org.jruby.embed.osgi.OSGiScriptingContainer
All Implemented Interfaces:
EmbedRubyInstanceConfigAdapter

public class OSGiScriptingContainer extends ScriptingContainer
Helpers to create a ScriptingContainer and set it up so it lives as well as possible in the OSGi world.

Currently:

  1. Access to the java classes and resources provided by the osgi bundle.
  2. 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.

  • Constructor Details

    • OSGiScriptingContainer

      public OSGiScriptingContainer(org.osgi.framework.Bundle creator)
    • OSGiScriptingContainer

      public OSGiScriptingContainer(org.osgi.framework.Bundle creator, LocalContextScope scope, LocalVariableBehavior behavior)
      Parameters:
      scope - if null, LocalContextScope.SINGLETHREAD
      behavior - if null, LocalVariableBehavior.TRANSIENT
  • Method Details

    • runScriptlet

      public Object runScriptlet(String bundleSymbolicName, String path)
      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

      public Object runScriptlet(org.osgi.framework.Bundle bundle, String path)
      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 located
      path - 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
    • getFilename

      private String getFilename(org.osgi.framework.Bundle bundle, String path)
      Parameters:
      bundle -
      path -
      Returns:
      a nice debugging string for the stack traces that is passed as the 'filename' of this script to jruby.
    • 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

      public JRubyOSGiBundleClassLoader 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.