public interface Script { public int computeResult(int value); }
ScriptWrapper<Script> wrapper = new GroovyScriptWrapper<Script>() { };with
Script being the interface you want to implement in the scripting language.
ScriptWrapper<Script> wrapper = new GroovyScriptWrapper<Script>() { }; Script Script = wrapper.getScript();And install the script:
File file = new File(<our script file>); wrapper.installScript(file);and:
int value = script.computeResult(10);Note that the ScriptWrapper.getScript() method will return a non null and valid result even before the script is installed because the proxy object is a wrapper around the effective script object.
public int computeResult(int value) { return value * 10; }You don't need to specify that this groovy script implements the
Script interface. The framework will take care of that.
ScriptWrapper if you want to change to script you use. Just call again the ScriptWrapper.installScript(File) method. For example this will work:ScriptWrapper<Script> wrapper = new GroovyScriptWrapper<Script>() { }; Script Script = wrapper.getScript(); File file = new File(<our first script file>); wrapper.installScript(file); int value = script.execute(10); file = new File(<our second script file>); value = script.execute(10);
logger field.wrapper.logExceptions(true);
context field in your script. For example:public void apply() { context.echo("Hello World"); }
logger field in your script. For example:public void apply() { logger.append("Hello World"); }
helper field in your script. For example:public void apply() { helper.doSomeComputation(); }
Copyright 2019-2020 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence