congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
Script
Code IndexAdd Tabnine to your IDE (free)

How to use
Script
in
groovy.lang

Best Java code snippets using groovy.lang.Script (Showing top 20 results out of 909)

Refine searchRefine arrow

  • Binding
origin: groovy/groovy-core

protected void assertScript(final String text, final String scriptName) throws Exception {
  log.info("About to execute script");
  log.info(text);
  GroovyCodeSource gcs = (GroovyCodeSource) AccessController.doPrivileged(new PrivilegedAction() {
    public Object run() {
      return new GroovyCodeSource(text, scriptName, "/groovy/testSupport");
    }
  });
  Class groovyClass = loader.parseClass(gcs);
  Script script = InvokerHelper.createScript(groovyClass, new Binding());
  script.run();
}
origin: twosigma/beakerx

private Object runScript(Script script) {
 groovyEvaluator.getScriptBinding().setVariable(Evaluator.BEAKER_VARIABLE_NAME, groovyEvaluator.getBeakerX());
 script.setBinding(groovyEvaluator.getScriptBinding());
 return script.run();
}
origin: org.codehaus.groovy/groovy

String line;
String lineCountName = "count";
s.setProperty(lineCountName, BigInteger.ZERO);
String autoSplitName = "split";
s.setProperty("out", pw);
  s.setProperty("line", line);
  s.setProperty(lineCountName, ((BigInteger)s.getProperty(lineCountName)).add(BigInteger.ONE));
    s.setProperty(autoSplitName, line.split(splitPattern));
  Object o = s.run();
origin: org.codehaus.groovy/groovy

public void setProperty(String property, Object newValue) {
  if ("binding".equals(property))
    setBinding((Binding) newValue);
  else if("metaClass".equals(property))
    setMetaClass((MetaClass)newValue);
  else
    binding.setVariable(property, newValue);
}
origin: groovy/groovy-core

public Writer writeTo(Writer out) {
  Script scriptObject = InvokerHelper.createScript(script.getClass(), binding);
  PrintWriter pw = new PrintWriter(out);
  scriptObject.setProperty("out", pw);
  scriptObject.run();
  pw.flush();
  return out;
}
origin: groovy/groovy-core

/**
 * Write the template document with the set binding applied to the writer.
 *
 * @see groovy.lang.Writable#writeTo(java.io.Writer)
 */
public Writer writeTo(Writer writer) {
  Binding binding;
  if (map == null)
    binding = new Binding();
  else
    binding = new Binding(map);
  Script scriptObject = InvokerHelper.createScript(script.getClass(), binding);
  PrintWriter pw = new PrintWriter(writer);
  scriptObject.setProperty("out", pw);
  scriptObject.run();
  pw.flush();
  return writer;
}
origin: org.carewebframework/org.carewebframework.web.script.groovy

@Override
public Object run(Map<String, Object> variables) {
  script.setBinding(variables == null ? null : new Binding(variables));
  return script.run();
}
origin: groovy/groovy-core

/**
 * When a method is not found in the current script, checks that it's possible to call a method closure from the binding.
 *
 * @throws IOException
 * @throws CompilationFailedException
 * @throws IllegalAccessException
 * @throws InstantiationException
 */
public void testInvokeMethodFallsThroughToMethodClosureInBinding() throws IOException, CompilationFailedException, IllegalAccessException, InstantiationException {
  String text = "if (method() == 3) { println 'succeeded' }";
  GroovyCodeSource codeSource = new GroovyCodeSource(text, "groovy.script", "groovy.script");
  GroovyClassLoader loader = new GroovyClassLoader(Thread.currentThread().getContextClassLoader());
  Class clazz = loader.parseClass(codeSource);
  Script script = ((Script) clazz.newInstance());
  Binding binding = new Binding();
  binding.setVariable("method", new MethodClosure(new Dummy(), "method"));
  script.setBinding(binding);
  script.run();
}
origin: org.codehaus.groovy/groovy

  public void set(Object value) {
    script.getBinding().setVariable(variable, value);
  }
}
origin: groovy/groovy-core

  public void run()
  {
    final long id = Thread.currentThread().getId();

    // run the script numIter times
    for (int i = 0; i < numIter; i++)
    {
      Builder builder = new Builder();

      Binding binding = new Binding();
      binding.setVariable("builder", builder);

      script = InvokerHelper.createScript(scriptClass, binding);

      script.run();
    }

    latch.countDown();
  }
}
origin: groovy/groovy-core

  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));
  }
}
origin: io.vertx/vertx-lang-groovy-gen

@Test
public void testReuseBindingInScript() throws Exception {
 Class clazz = assertScript("ReuseBindingVerticleScript");
 Script script = (Script) clazz.newInstance();
 Binding binding = new Binding();
 binding.setVariable("myobject", new Object());
 script.setBinding(binding);
 ScriptVerticle verticle = new ScriptVerticle(script);
 assertDeploy((vertx, onDeploy) ->
   vertx.deployVerticle(verticle, onDeploy));
 assertTrue(isStarted());
}
origin: com.disney.groovity/groovity-portal

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
  if(request instanceof HttpServletRequest){
    HttpServletRequest hr = (HttpServletRequest) request;
    HttpSession session = hr.getSession(false);
    if(session!=null){
      Object userId = session.getAttribute("userId");
      if(userId != null){
        Groovity groovity = (Groovity) servletContext.getAttribute(GroovityServlet.SERVLET_CONTEXT_GROOVITY_INSTANCE);
        Script factory;
        try {
          factory = groovity.load("/data/factory", new Binding());
        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
          throw new ServletException(e);
        }
        Object user = factory.invokeMethod("call", new String[]{"person",userId.toString()});
        if(user!=null && user instanceof Principal){
          request = new AuthenticatedRequestWrapper(hr, (Principal)user);
        }
      }
    }
  }
  chain.doFilter(request, response);
}
origin: groovy/groovy-core

public void testCreateScriptWithNullClass() {
  Script script = InvokerHelper.createScript(null, new Binding(bindingVariables));
  assertEquals(bindingVariables, script.getBinding().getVariables());
}
origin: org.elasticsearch.module/lang-groovy

/**
 * Return a script object with the given vars from the compiled script object
 */
@SuppressWarnings("unchecked")
private Script createScript(Object compiledScript, Map<String, Object> vars) throws InstantiationException, IllegalAccessException {
  Class scriptClass = (Class) compiledScript;
  Script scriptObject = (Script) scriptClass.newInstance();
  Binding binding = new Binding();
  binding.getVariables().putAll(vars);
  scriptObject.setBinding(binding);
  return scriptObject;
}
origin: apache/incubator-shardingsphere

private Object evaluate(final String expression) {
  Script script;
  if (SCRIPTS.containsKey(expression)) {
    script = SCRIPTS.get(expression);
  } else {
    script = SHELL.parse(expression);
    SCRIPTS.put(expression, script);
  }
  return script.run();
}

origin: twosigma/beakerx

 public Object parseClassFromScript(String script) {
  Class<?> parsedClass = groovyClassLoader.parseClass(script);
  Script instance = null;
  try {
   instance = (Script) parsedClass.newInstance();
   instance.setBinding(scriptBinding);
  } catch (InstantiationException e) {
   e.printStackTrace();
  } catch (IllegalAccessException e) {
   e.printStackTrace();
  }
  return instance.run();
 }
}
origin: org.codehaus.groovy/groovy

public Object build(Script script) {
  // this used to be synchronized, but we also used to remove the
  // metaclass.  Since adding the metaclass is now a side effect, we
  // don't need to ensure the meta-class won't be observed and don't
  // need to hide the side effect.
  MetaClass scriptMetaClass = script.getMetaClass();
  script.setMetaClass(new FactoryInterceptorMetaClass(scriptMetaClass, this));
  script.setBinding(this);
  Object oldScriptName = getProxyBuilder().getVariables().get(SCRIPT_CLASS_NAME);
  try {
    getProxyBuilder().setVariable(SCRIPT_CLASS_NAME, script.getClass().getName());
    return script.run();
  } finally {
    if(oldScriptName != null) {
      getProxyBuilder().setVariable(SCRIPT_CLASS_NAME, oldScriptName);
    } else {
      getProxyBuilder().getVariables().remove(SCRIPT_CLASS_NAME);
    }
  }
}
origin: apache/nifi

Map bindings = script.getBinding().getVariables();
bindings.put("SQL", SQL);
script.run();
bindings.clear();
origin: org.codehaus.groovy/groovy

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);
}
groovy.langScript

Javadoc

This object represents a Groovy script

Most used methods

  • run
    A helper method to allow scripts to be run taking command line arguments
  • setBinding
  • getProperty
  • getBinding
  • setProperty
  • invokeMethod
    Invoke a method (or closure in the binding) defined.
  • getMetaClass
  • setMetaClass
  • evaluate
    A helper method to allow the dynamic evaluation of groovy expressions using this scripts binding as

Popular in Java

  • Reactive rest calls using spring rest template
  • findViewById (Activity)
  • getSystemService (Context)
  • scheduleAtFixedRate (Timer)
  • Menu (java.awt)
  • InputStreamReader (java.io)
    A class for turning a byte stream into a character stream. Data read from the source input stream is
  • String (java.lang)
  • InetAddress (java.net)
    An Internet Protocol (IP) address. This can be either an IPv4 address or an IPv6 address, and in pra
  • Selector (java.nio.channels)
    A controller for the selection of SelectableChannel objects. Selectable channels can be registered w
  • Timer (java.util)
    Timers schedule one-shot or recurring TimerTask for execution. Prefer java.util.concurrent.Scheduled
  • 14 Best Plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now