use of groovy.lang.Binding in project LogHub by fbacchella.
the class TestGroovy method testGroovy2.
@SuppressWarnings("unchecked")
@Test
public void testGroovy2() throws InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException, IOException {
String script = "event.a.b * 2";
try (GroovyClassLoader groovyClassLoader = new GroovyClassLoader()) {
Class<Script> theParsedClass = groovyClassLoader.parseClass(script);
Script groovyScript = theParsedClass.newInstance();
Binding groovyBinding = new Binding();
Event event = new EventInstance(ConnectionContext.EMPTY);
event.put("a", Collections.singletonMap("b", 1));
groovyBinding.setVariable("event", event);
groovyScript.setBinding(groovyBinding);
System.out.println(groovyScript.run().getClass());
}
}
use of groovy.lang.Binding in project LogHub by fbacchella.
the class TestGroovy method testGroovy1.
@Test
public void testGroovy1() {
GroovyShell groovyShell = new GroovyShell(getClass().getClassLoader());
Script groovyScript = groovyShell.parse("event.a * 2");
Binding groovyBinding = new Binding();
Event event = new EventInstance(ConnectionContext.EMPTY);
event.put("a", 1);
groovyBinding.setVariable("event", event);
groovyScript.setBinding(groovyBinding);
System.out.println(groovyScript.run().getClass());
}
use of groovy.lang.Binding in project freeplane by freeplane.
the class GroovyScript method createBindingForCompilation.
private Binding createBindingForCompilation() {
final Binding binding = new Binding();
binding.setVariable("c", null);
binding.setVariable("node", null);
return binding;
}
use of groovy.lang.Binding in project freeplane by freeplane.
the class GroovyScript method compileAndCache.
private Script compileAndCache(final ScriptingSecurityManager scriptingSecurityManager) throws Throwable {
if (!groovyPatched) {
GroovyPatcher.apply(GroovyObject.class);
groovyPatched = true;
}
if (compileTimeStrategy.canUseOldCompiledScript()) {
scriptClassLoader.setSecurityManager(scriptingSecurityManager);
return compiledScript;
}
removeOldScript();
errorsInScript = null;
if (script instanceof Script) {
return (Script) script;
} else {
try {
final Binding binding = createBindingForCompilation();
scriptClassLoader = ScriptClassLoader.createClassLoader();
scriptClassLoader.setSecurityManager(scriptingSecurityManager);
final GroovyShell shell = new GroovyShell(scriptClassLoader, binding, createCompilerConfiguration());
compileTimeStrategy.scriptCompileStart();
if (script instanceof String) {
compiledScript = shell.parse((String) script);
} else if (script instanceof File) {
compiledScript = shell.parse((File) script);
} else {
throw new IllegalArgumentException();
}
compileTimeStrategy.scriptCompiled();
return compiledScript;
} catch (Throwable e) {
errorsInScript = e;
throw e;
}
}
}
use of groovy.lang.Binding in project beakerx by twosigma.
the class GroovyEvaluator method reloadClassloader.
private void reloadClassloader() {
this.beakerxUrlClassLoader = newParentClassLoader(getClasspath());
this.icz = new ImportCustomizer();
this.groovyClassLoader = newEvaluator(getImports(), getClasspath(), getOutDir(), icz, beakerxUrlClassLoader);
this.scriptBinding = new Binding();
}
Aggregations