Package org.codehaus.groovy.control

Examples of org.codehaus.groovy.control.CompilerConfiguration


                TClassLoader tClassLoader = new TClassLoader();

                // Let's compile the groovy source
                final List<GroovyClass> groovyClassesForThisTemplate = new ArrayList<GroovyClass>();
                // ~~~ Please !
                CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
                compilerConfiguration.setSourceEncoding("utf-8"); // ouf
                CompilationUnit compilationUnit = new CompilationUnit(compilerConfiguration);
                compilationUnit.addSource(new SourceUnit(name, compiledSource, compilerConfiguration, tClassLoader, compilationUnit.getErrorCollector()));
                Field phasesF = compilationUnit.getClass().getDeclaredField("phaseOperations");
                phasesF.setAccessible(true);
                LinkedList[] phases = (LinkedList[]) phasesF.get(compilationUnit);
View Full Code Here


         
          if (commandLine.hasOption("script")) {
              final String scriptName = commandLine.getOptionValue("script");
              final File scriptFile = getAbsoluteFile(scriptName);
             
              final CompilerConfiguration conf = new CompilerConfiguration(System.getProperties());
              final GroovyShell shell = new GroovyShell(binding, conf);
              shell.run(scriptFile, args);
          }
          else {
              final Groovysh shell = new Groovysh(binding, new IO());
View Full Code Here

      //
      String groovyText = script.toString();

      //
      CompilerConfiguration config = new CompilerConfiguration();

      //
      byte[] bytes;
      try
      {
         config.setScriptBaseClass(BaseScript.class.getName());
         bytes = groovyText.getBytes(config.getSourceEncoding());
      }
      catch (UnsupportedEncodingException e)
      {
         throw new TemplateCompilationException(e, groovyText);
      }
View Full Code Here

        }
    }

    protected void ensureInitializedOrReloaded() {
        if (groovyClassLoader == null) {
            compilerConfiguration = new CompilerConfiguration(getCompilerConfigurationFactory().getCompilerConfiguration());
            if (getScriptBaseClass() != null) {
                compilerConfiguration.setScriptBaseClass(getScriptBaseClass());
            }

            groovyClassLoader = AccessController.doPrivileged(new PrivilegedAction<GroovyClassLoader>() {
View Full Code Here

        }
    }

    public void testScriptWithDerivedBaseClass() throws Exception {
        Binding context = new Binding();
        CompilerConfiguration config = new CompilerConfiguration();
        config.setScriptBaseClass(DerivedScript.class.getName());
        GroovyShell shell = new GroovyShell(context, config);
        Object result = shell.evaluate("x = 'abc'; doSomething(cheese)");
        assertEquals("I like Cheddar", result);
        assertEquals("abc", context.getVariable("x"));
    }
View Full Code Here

     * Test for GROOVY-6615
     * @throws Exception
     */
    public void testScriptWithCustomBodyMethod() throws Exception {
        Binding context = new Binding();
        CompilerConfiguration config = new CompilerConfiguration();
        config.setScriptBaseClass(BaseScriptCustomBodyMethod.class.getName());
        GroovyShell shell = new GroovyShell(context, config);
        Object result = shell.evaluate("'I like ' + cheese");
        assertEquals("I like Cheddar", result);
    }
View Full Code Here

        assertEquals("I like Cheddar", result);
    }

    public void testClassLoader() {
        Binding context = new Binding();
        CompilerConfiguration config = new CompilerConfiguration();
        config.setScriptBaseClass(DerivedScript.class.getName());
        GroovyShell shell = new GroovyShell(context, config);
        String script = "evaluate '''\n"+
                        "class XXXX{}\n"+
                        "assert evaluate('XXXX') == XXXX\n"+
                        "'''";
View Full Code Here

     * This is a test specific subclass for AbstractReaderSource.
     */
    private static class AbstractReaderSourceSubclass extends AbstractReaderSource {

        private AbstractReaderSourceSubclass() {
            super(new CompilerConfiguration());
        }
View Full Code Here

    @SuppressWarnings("unchecked")
    private void setLoader(final BSFManager mgr, final ClassLoader finalParent) {
        this.loader =
                (GroovyClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
                    public Object run() {
                        CompilerConfiguration configuration = new CompilerConfiguration();
                        configuration.setClasspath(mgr.getClassPath());
                        return new GroovyClassLoader(finalParent, configuration);
                    }
                });
    }
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

TOP

Related Classes of org.codehaus.groovy.control.CompilerConfiguration

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.