Examples of GroovyShell


Examples of groovy.lang.GroovyShell

   * @throws InstantiationException
   */
  public static void main(final String[] args) throws InstantiationException, Exception {
    Binding binding = new Binding();
    binding.setVariable("foo", new Integer(2));
    GroovyShell shell = new GroovyShell(binding);
    Script script = shell.parse("service.with{sru()} ;x = 123; return foo * 10;");
    MetaClass metaClass = script.getMetaClass();
    Binding binding2 = script.getBinding();
    // Object property = script.getProperty("service");
    script.setProperty("service", new CustomerService() {

View Full Code Here

Examples of groovy.lang.GroovyShell

   * @param args
   */
  public static void main(final String[] args) {
    Binding binding = new Binding();
    binding.setVariable("foo", new Integer(2));
    GroovyShell shell = new GroovyShell(binding);
    long start = System.currentTimeMillis();
    Script script = shell.parse("x = 123; return foo * 10");
    MetaClass metaClass = script.getMetaClass();
    Binding binding2 = script.getBinding();
    for (int i = 0; i < 1000; i++) {
      script.run();
    }
    long end = System.currentTimeMillis() - start;
    System.out.println("Parsowenie " + end);

    start = System.currentTimeMillis();
    for (int i = 0; i < 1000; i++) {
      Object value = shell.evaluate("x = 123; return foo * 10");
    }
    end = System.currentTimeMillis() - start;
    System.out.println("Evolution " + end);

    // assert value.equals(new Integer(20));
View Full Code Here

Examples of groovy.lang.GroovyShell

        String handler;
        DefaultBenchmarkHandler() {
            String handler = System.getProperty("gbench.defaultHandler");
            if (null != handler) {
                this.handler = handler;
                shell = new GroovyShell();
            }
        }
View Full Code Here

Examples of groovy.lang.GroovyShell

            return (T)object;
         ResourceResolver resolver = context.getResourceResolver(value);
         InputStream is = resolver.getInputStream(value);
         //TODO if is == null throw an exception saying the it's impossible to find the file
         Binding binding = new Binding();
         GroovyShell shell = new GroovyShell(Thread.currentThread().getContextClassLoader(), binding);
         object = shell.evaluate(is);
         is.close();
         return (T)object;
      }
      catch (Exception ex)
      {
View Full Code Here

Examples of groovy.lang.GroovyShell

      try
      {
         ResourceResolver resolver = context.getResourceResolver(value);
         InputStream is = resolver.getInputStream(value);
         Binding binding = new Binding();
         GroovyShell shell = new GroovyShell(Thread.currentThread().getContextClassLoader(), binding);
         object = shell.evaluate(is);
         is.close();
         return (T)object;
      }
      catch (Exception ex)
      {
View Full Code Here

Examples of groovy.lang.GroovyShell

        if (Debug.verboseOn()) {
            Debug.logVerbose("Evaluating -- " + expression, module);
            Debug.logVerbose("Using Context -- " + context, module);
        }
        try {
            GroovyShell shell = new GroovyShell(getBinding(context));
            o = shell.evaluate(StringUtil.convertOperatorSubstitutions(expression));
            if (Debug.verboseOn()) {
                Debug.logVerbose("Evaluated to -- " + o, module);
            }
            // read back the context info
            Binding binding = shell.getContext();
            context.putAll(binding.getVariables());
        } catch (CompilationFailedException e) {
            Debug.logError(e, "Groovy Evaluation error.", module);
            throw e;
        }
View Full Code Here

Examples of groovy.lang.GroovyShell

                loader = childFirstLoader;
            }

            Binding binding = new Binding( globalVariables );

            GroovyShell interpreter = new GroovyShell( loader, binding, config );

            try
            {
                return interpreter.evaluate( script );
            }
            catch ( ThreadDeath e )
            {
                throw e;
            }
View Full Code Here

Examples of groovy.lang.GroovyShell

    }

    public <T> T evaluate(Exchange exchange, Class<T> type) {
        // use application classloader if given
        ClassLoader cl = exchange.getContext().getApplicationContextClassLoader();
        GroovyShell shell = cl != null ? new GroovyShell(cl) : new GroovyShell();

        // need to re-parse script due thread-safe with binding
        Script script = shell.parse(text);
        configure(exchange, script.getBinding());
        Object value = script.evaluate(text);

        return exchange.getContext().getTypeConverter().convertTo(type, value);
    }
View Full Code Here

Examples of groovy.lang.GroovyShell

     */
    public void parse(InputStream script, Binding binding) {
        setBinding(binding);
        CompilerConfiguration cc = new CompilerConfiguration();
        cc.setScriptBaseClass(ClosureScript.class.getName());
        GroovyShell shell = new GroovyShell(classLoader,binding,cc);

        ClosureScript s = (ClosureScript)shell.parse(script);
        s.setDelegate(this);
        s.run();
    }
View Full Code Here

Examples of groovy.lang.GroovyShell

      }
    };
    Binding b = new Binding();
    b.setVariable("beans", beans);

    GroovyShell shell = classLoader != null ? new GroovyShell(classLoader,b) : new GroovyShell(b);
        for (Resource resource : resources) {
            shell.evaluate(resource.getInputStream());
        }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.