Class GroovyClosureScript

  • All Implemented Interfaces:
    groovy.lang.GroovyObject
    Direct Known Subclasses:
    StaplerClosureScript

    public abstract class GroovyClosureScript
    extends groovy.lang.Script
    Script that performs method invocations and property access like Closure does.

    For example, when the script is:

    
     a = 1;
     b(2);
     
    Using GroovyClosureScript as the base class would run it as:
    
     delegate.a = 1;
     delegate.b(2);
     
    ... whereas in plain Script, this will be run as:
    
     binding.setProperty("a",1);
     ((Closure)binding.getProperty("b")).call(2);
     
    This is convenient for building DSL as you can use an external object to define methods and properties.
    Author:
    Kohsuke Kawaguchi
    • Constructor Detail

      • GroovyClosureScript

        protected GroovyClosureScript()
      • GroovyClosureScript

        protected GroovyClosureScript​(groovy.lang.Binding binding)
    • Method Detail

      • setDelegate

        public void setDelegate​(groovy.lang.GroovyObject delegate)
        Sets the delegation target.
      • getDelegate

        public groovy.lang.GroovyObject getDelegate()
      • invokeMethod

        public Object invokeMethod​(String name,
                                   Object args)
        Specified by:
        invokeMethod in interface groovy.lang.GroovyObject
        Overrides:
        invokeMethod in class groovy.lang.Script
      • getProperty

        public Object getProperty​(String property)
        Specified by:
        getProperty in interface groovy.lang.GroovyObject
        Overrides:
        getProperty in class groovy.lang.Script
      • setProperty

        public void setProperty​(String property,
                                Object newValue)
        Specified by:
        setProperty in interface groovy.lang.GroovyObject
        Overrides:
        setProperty in class groovy.lang.Script