Class GroovyEngineFactory

  • All Implemented Interfaces:
    ScriptEngineFactory

    public class GroovyEngineFactory
    extends org.codehaus.groovy.jsr223.GroovyScriptEngineFactory
    This factory overrides the default getScriptEngine implementation, and ensures that we use the AST Transformation Customizer to provide interruption checks at the beginning of closures, loops, etc. in the executed script. This allows us to monitor the thread running the script and trigger an interrupt if the script's allowed running time is up.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ScriptEngine getScriptEngine()
      Instantiates and returns an instance of GroovyScriptEngineImpl passing in a new GroovyClassLoader with an AST transformation customizer that will ensure that interrupt checks are inserted into the compiled code (at the start of closures, loops, etc.).
      void setSandbox​(org.kohsuke.groovy.sandbox.GroovyValueFilter sandbox)
      Sets the Groovy value filter to use for sandboxing scripts.
      • Methods inherited from class org.codehaus.groovy.jsr223.GroovyScriptEngineFactory

        getEngineName, getEngineVersion, getExtensions, getLanguageName, getLanguageVersion, getMethodCallSyntax, getMimeTypes, getNames, getOutputStatement, getParameter, getProgram
    • Constructor Detail

      • GroovyEngineFactory

        public GroovyEngineFactory()
    • Method Detail

      • getScriptEngine

        public ScriptEngine getScriptEngine()
        Instantiates and returns an instance of GroovyScriptEngineImpl passing in a new GroovyClassLoader with an AST transformation customizer that will ensure that interrupt checks are inserted into the compiled code (at the start of closures, loops, etc.). Scripts run through engines provided by this function will be interruptable.
        Specified by:
        getScriptEngine in interface ScriptEngineFactory
        Overrides:
        getScriptEngine in class org.codehaus.groovy.jsr223.GroovyScriptEngineFactory
        Returns:
        an interruptable groovy script engine implementation.
      • setSandbox

        public void setSandbox​(org.kohsuke.groovy.sandbox.GroovyValueFilter sandbox)
        Sets the Groovy value filter to use for sandboxing scripts. The filter is called every time an object is accessed by the script to verify that the access is allowed.
        Parameters:
        sandbox - the new sandbox to use.