public void set(Object value) { script.getBinding().setVariable(variable, value); } }
public Object get() { return script.getBinding().getVariable(variable); }
private Object invokePropertyOrMissing(Object object, String methodName, Object[] originalArguments, boolean fromInsideClass, boolean isCallToSuper) { // if no method was found, try to find a closure defined as a field of the class and run it Object value = null; final MetaProperty metaProperty = this.getMetaProperty(methodName, false); if (metaProperty != null) value = metaProperty.getProperty(object); else { if (object instanceof Map) value = ((Map)object).get(methodName); } if (value instanceof Closure) { // This test ensures that value != this If you ever change this ensure that value != this Closure closure = (Closure) value; MetaClass delegateMetaClass = closure.getMetaClass(); return delegateMetaClass.invokeMethod(closure.getClass(), closure, CLOSURE_DO_CALL_METHOD, originalArguments, false, fromInsideClass); } if (object instanceof Script) { Object bindingVar = ((Script) object).getBinding().getVariables().get(methodName); if (bindingVar != null) { MetaClass bindingVarMC = ((MetaClassRegistryImpl) registry).getMetaClass(bindingVar); return bindingVarMC.invokeMethod(bindingVar, CLOSURE_CALL_METHOD, originalArguments); } } return invokeMissingMethod(object, methodName, originalArguments, null, isCallToSuper); }
public void testCreateScriptWithNullClass() { Script script = InvokerHelper.createScript(null, new Binding(bindingVariables)); assertEquals(bindingVariables, script.getBinding().getVariables()); }
Map bindings = script.getBinding().getVariables();
public void testCreateScriptWithScriptClass() { GroovyClassLoader classLoader = new GroovyClassLoader(); String controlProperty = "text"; String controlValue = "I am a script"; String code = controlProperty + " = '" + controlValue + "'"; GroovyCodeSource codeSource = new GroovyCodeSource(code, "testscript", "/groovy/shell"); Class scriptClass = classLoader.parseClass(codeSource, false); Script script = InvokerHelper.createScript(scriptClass, new Binding(bindingVariables)); assertEquals(bindingVariables, script.getBinding().getVariables()); script.run(); assertEquals(controlValue, script.getProperty(controlProperty)); } }
/** * Note on the System.setSecurityManager call: * * The main method of the Groovysh class initializes a SecurityManager to * prevent the use of System.exit. The SecurityManager is not actually * necessary for Groovysh, so this change removes it to allow JDBC * access (removes the need for users to create an explicit ~/.java.policy * file). */ public static void callback(Script script, boolean mutationsEnabled) throws CompilationFailedException, IOException { System.setSecurityManager(null); setupBinding(script.getBinding(), mutationsEnabled); }
public void customize(GroovyObject goo) { Assert.state(goo instanceof Script, "Expected a Script"); if (this.variables != null) { Binding binding = ((Script) goo).getBinding(); for (Map.Entry<String, ?> entry : this.variables.entrySet()) { binding.setVariable(entry.getKey(), entry.getValue()); } } if (this.customizer != null) { this.customizer.customize(goo); } }
@SuppressWarnings({"unchecked"}) @Override public void setNextScore(float score) { script.getBinding().getVariables().put("_score", score); }
@SuppressWarnings({"unchecked"}) @Override public void setNextVar(String name, Object value) { script.getBinding().getVariables().put(name, value); }
@SuppressWarnings({"unchecked"}) @Override public void setNextVar(String name, Object value) { script.getBinding().getVariables().put(name, value); }
public void set(Object value) { script.getBinding().setVariable(variable, value); } }
public void set(Object value) { script.getBinding().setVariable(variable, value); } }
public void set(Object value) { script.getBinding().setVariable(variable, value); } }
public void set(Object value) { script.getBinding().setVariable(variable, value); } }
/** * Note on the System.setSecurityManager call: * * The main method of the Groovysh class initializes a SecurityManager to * prevent the use of System.exit. The SecurityManager is not actually * necessary for Groovysh, so this change removes it to allow JDBC * access (removes the need for users to create an explicit ~/.java.policy * file). */ public static void callback(Script script, boolean mutationsEnabled) throws CompilationFailedException, IOException { System.setSecurityManager(null); setupBinding(script.getBinding(), mutationsEnabled); }
public void customize(GroovyObject goo) { Assert.state(goo instanceof Script, "Expected a Script"); if (this.variables != null) { Binding binding = ((Script) goo).getBinding(); for (Map.Entry<String, ?> entry : this.variables.entrySet()) { binding.setVariable(entry.getKey(), entry.getValue()); } } if (this.customizer != null) { this.customizer.customize(goo); } }
public void startRun(final Script script){ final Binding oldBinding = THREAD_BINDING.get(); final Binding scriptBinding = script.getBinding(); if(oldBinding != scriptBinding){ if(oldBinding!=null){ scriptBinding.setVariable(THREAD_BINDING_PREVIOUS, oldBinding); } scriptBinding.setVariable(THREAD_BINDING_OWNER, script); THREAD_BINDING.set(scriptBinding); } }
public void startRun(final Script script){ final Binding oldBinding = THREAD_BINDING.get(); final Binding scriptBinding = script.getBinding(); if(oldBinding != scriptBinding){ if(oldBinding!=null){ scriptBinding.setVariable(THREAD_BINDING_PREVIOUS, oldBinding); } scriptBinding.setVariable(THREAD_BINDING_OWNER, script); THREAD_BINDING.set(scriptBinding); } }
@SuppressWarnings("unchecked") public GroovyScript(CompiledScript compiledScript, Script script, @Nullable LeafSearchLookup lookup, ESLogger logger) { this.compiledScript = compiledScript; this.script = script; this.lookup = lookup; this.logger = logger; this.variables = script.getBinding().getVariables(); }