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

How to use
run
method
in
groovy.lang.Script

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

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: org.codehaus.groovy/groovy

/**
 * Run a script identified by name with a given binding.
 *
 * @param scriptName name of the script to run
 * @param binding    the binding to pass to the script
 * @return an object
 * @throws ResourceException if there is a problem accessing the script
 * @throws ScriptException   if there is a problem parsing the script
 */
public Object run(String scriptName, Binding binding) throws ResourceException, ScriptException {
  return createScript(scriptName, binding).run();
}
origin: org.codehaus.groovy/groovy

/**
 * Evaluates some script against the current Binding and returns the result
 *
 * @param codeSource
 * @throws CompilationFailedException
 */
public Object evaluate(GroovyCodeSource codeSource) throws CompilationFailedException {
  Script script = parse(codeSource);
  return script.run();
}
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: spring-projects/spring-framework

return ((Script) goo).run();
origin: groovy/groovy-core

  public void run() {
    try {
      Script script = (Script) script1Class.newInstance();
      script.run();
      completed [0] = true;
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
};
origin: groovy/groovy-core

/**
 * Evaluate an expression.
 */
public Object eval(String source, int lineNo, int columnNo, Object script) throws BSFException {
  try {
    Class scriptClass = evalScripts.get(script);
    if (scriptClass == null) {
      scriptClass = loader.parseClass(script.toString(), source);
      evalScripts.put(script, scriptClass);
    } else {
      LOG.fine("eval() - Using cached script...");
    }
    //can't cache the script because the context may be different.
    //but don't bother loading parsing the class again
    Script s = InvokerHelper.createScript(scriptClass, context);
    return s.run();
  } catch (Exception e) {
    throw new BSFException(BSFException.REASON_EXECUTION_ERROR, "exception from Groovy: " + e, e);
  }
}
origin: org.codehaus.groovy/groovy

/**
 * Evaluates some script against the current Binding and returns the result
 *
 * @param in       the stream reading the script
 * @param fileName is the logical file name of the script (which is used to create the class name of the script)
 */
public Object evaluate(Reader in, String fileName) throws CompilationFailedException {
  Script script = null;
  try {
    script = parse(in, fileName);
    return script.run();
  } finally {
    if (script != null) {
      InvokerHelper.removeClass(script.getClass());
    }
  }
}
origin: org.springframework/spring-context

return ((Script) goo).run();
origin: groovy/groovy-core

  public void run() {
    try {
      Class cls = groovyLoader.loadClass("Script2", true, true);
      Script script = (Script) cls.newInstance();
      script.run();
      completed [1] = true;
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
};
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

 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: groovy/groovy-core

protected void assertScriptFile(String fileName) throws Exception {
  log.info("About to execute script: " + fileName);
  Class groovyClass = loader.parseClass(new GroovyCodeSource(new File(fileName)));
  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: 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: 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: 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: groovy/groovy-core

protected void executeScript(Class scriptClass, Permission missingPermission) {
  try {
    Script script = InvokerHelper.createScript(scriptClass, new Binding());
    script.run();
    //InvokerHelper.runScript(scriptClass, null);
  } catch (AccessControlException ace) {
    if (missingPermission != null && missingPermission.implies(ace.getPermission())) {
      return;
    } else {
      fail(ace.toString());
    }
  }
  if (missingPermission != null) {
    fail("Should catch an AccessControlException");
  }
}
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));
  }
}
groovy.langScriptrun

Javadoc

A helper method to allow scripts to be run taking command line arguments

Popular methods of Script

  • 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

  • Making http post requests using okhttp
  • scheduleAtFixedRate (ScheduledExecutorService)
  • getSystemService (Context)
  • getSharedPreferences (Context)
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • Kernel (java.awt.image)
  • 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
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • TreeMap (java.util)
    Walk the nodes of the tree left-to-right or right-to-left. Note that in descending iterations, next
  • 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