Package groovy.lang

Examples of groovy.lang.GroovyShell


        String message = writer.toString();
        throw new BuildException("Script Failed: " + message, e, getLocation());
    }

    public static void main(String[] args) {
        final GroovyShell shell = new GroovyShell(new Binding());
        final Groovy groovy = new Groovy();
        for (int i = 1; i < args.length; i++) {
            final Commandline.Argument argument = groovy.createArg();
            argument.setValue(args[i]);
        }
View Full Code Here


    StringBuffer sb = new StringBuffer();
    String fullFile = readTemplate();
    int fullFileIndex = 0;
   
    try {
      GroovyShell shell = bindContextVariables(context);
      Binding b = shell.getContext();
      if (m_verbose) dumpBinding(b);
     
      while (fullFileIndex < fullFile.length()) {
        int startIndex = fullFile.indexOf(MARKER_START, fullFileIndex);
        if (-1 != startIndex) {
View Full Code Here

 
  private GroovyShell bindContextVariables(Context context)
    throws SyntaxException, ClassNotFoundException, IOException
  {
    Binding binding = new Binding();
    GroovyShell result = new GroovyShell(binding);
   
    for (Iterator it = context.keySet().iterator(); it.hasNext(); ) {
      Object oVariable = it.next();
      Object oValue = context.get(oVariable);
      if (null != oValue) {
View Full Code Here

 
  static public void main(String[] argv) {
  //call groovy expressions from Java code
    Binding binding = new Binding();
    binding.setVariable("foo", new Integer(2));
    GroovyShell shell = new GroovyShell(binding);
 
    try {
      Object value =
        shell.evaluate("println 'Hello World!'; x = 123; return foo * 10", "TestScript");
      assert value.equals(new Integer(20));
      assert binding.getVariable("x").equals(new Integer(123));
      System.out.println("value:" + value);
    }
    catch (SyntaxException e) {
View Full Code Here

    classLoader = new GroovyClassLoader( parentClassLoader );
    binding = new Binding();
    CompilerConfiguration config = new CompilerConfiguration();
    config.setDebug( true );
    config.setVerbose( true );
    shell = new GroovyShell( classLoader, binding, config );
  }
View Full Code Here

  }

  @SuppressWarnings({ "rawtypes", "unchecked" })
  protected void resolveVariables(List arg) {
    List temp = new ArrayList();
    GroovyShell gs = new GroovyShell(getBinding());
    for(Object obj:arg) {
      Script scr = gs.parse("\""+(String)obj+"\"");
      try {
        temp.add(scr.run().toString());
      }
      catch(MissingPropertyException e) {
        throw new SqoopException(ClientError.CLIENT_0004, e.getMessage(), e);
View Full Code Here

        init();
    }

    private void init() {
        ClassLoader loader = getClass().getClassLoader();
        GroovyShell shell = new GroovyShell(loader);
        shell.evaluate(new InputStreamReader(loader.getResourceAsStream("org/apache/camel/language/groovy/ConfigureCamel.groovy")));

        // TODO compile Groovy as part of build!
        //new ConfigureCamel().run();
    }
View Full Code Here

    GroovyObject go = GroovyParser.parse("class Test { \n String doStuff() { return \"Do stuff\" } }");
    String result = (String) go.invokeMethod("doStuff", null);
    assertEquals("Do stuff", result);
   
    //GroovyEngine ge = new GroovyEngine();
    GroovyShell sh = new GroovyShell();
    List<?> evaluate = (List<?>) sh.evaluate("[1, 2, 3]");
    System.out.println(evaluate);
  }
View Full Code Here

public class ClassicGroovyTestGeneratorHelper implements TestGeneratorHelper {

    /** evaluate the source text against the classic AST with the JSR parser implementation*/
    public Object evaluate(String theSrcText, String testName) throws Exception {
        parse(theSrcText, testName); // fail early with a direct message if possible')
        GroovyShell groovy = new GroovyShell(new CompilerConfiguration());
        return groovy.run(theSrcText, "main", new ArrayList());
    }
View Full Code Here

        assertEquals("extends MockObjectTestCase", classProps[Inspector.CLASS_SUPERCLASS_IDX]);
        assertEquals("is Primitive: false, is Array: false, is Groovy: false", classProps[Inspector.CLASS_OTHER_IDX]);
    }

    public void testClassPropsGroovy() {
        Object testObject = new GroovyShell().evaluate("class Test {def meth1(a,b){}}\nreturn new Test()");
        Inspector insp = new Inspector(testObject);
        String[] classProps = insp.getClassProps();
        assertEquals("package n/a", classProps[Inspector.CLASS_PACKAGE_IDX]);
        assertEquals("public class Test", classProps[Inspector.CLASS_CLASS_IDX]);
        assertEquals("implements GroovyObject ", classProps[Inspector.CLASS_INTERFACE_IDX]);
View Full Code Here

TOP

Related Classes of groovy.lang.GroovyShell

Copyright © 2018 www.massapicom. 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.