Search in sources :

Example 86 with GroovyShell

use of groovy.lang.GroovyShell in project bamboobsc by billchen198318.

the class ScriptExpressionUtils method executeGroovy.

private static void executeGroovy(String scriptExpression, Map<String, Object> results, Map<String, Object> parameters) throws Exception {
    //GroovyShell groovyShell = new GroovyShell(groovyCompilerConfig);		
    GroovyShell groovyShell = buildGroovyShell(false);
    Binding binding = groovyShell.getContext();
    if (parameters != null) {
        for (Map.Entry<String, Object> entry : parameters.entrySet()) {
            //groovyShell.setProperty(entry.getKey(), entry.getValue());
            binding.setVariable(entry.getKey(), entry.getValue());
        }
    }
    groovyShell.evaluate(scriptExpression);
    if (results != null) {
        for (Map.Entry<String, Object> entry : results.entrySet()) {
            //entry.setValue( groovyShell.getVariable(entry.getKey()) );
            entry.setValue(binding.getVariable(entry.getKey()));
        }
    }
}
Also used : Binding(groovy.lang.Binding) PyObject(org.python.core.PyObject) Map(java.util.Map) GroovyShell(groovy.lang.GroovyShell)

Aggregations

GroovyShell (groovy.lang.GroovyShell)86 Binding (groovy.lang.Binding)43 File (java.io.File)15 CompilerConfiguration (org.codehaus.groovy.control.CompilerConfiguration)14 Script (groovy.lang.Script)10 ImportCustomizer (org.codehaus.groovy.control.customizers.ImportCustomizer)10 Closure (groovy.lang.Closure)9 IOException (java.io.IOException)8 List (java.util.List)6 GroovyClassLoader (groovy.lang.GroovyClassLoader)5 GroovyObject (groovy.lang.GroovyObject)4 GroovyRuntimeException (groovy.lang.GroovyRuntimeException)4 AntBuilder (groovy.util.AntBuilder)4 InputStreamReader (java.io.InputStreamReader)4 StringWriter (java.io.StringWriter)4 BuildException (org.apache.tools.ant.BuildException)4 CompilationFailedException (org.codehaus.groovy.control.CompilationFailedException)4 UrlMapping (grails.web.mapping.UrlMapping)3 InputStream (java.io.InputStream)3 PrintWriter (java.io.PrintWriter)3