Search in sources :

Example 1 with CompilerConfiguration

use of org.codehaus.groovy.control.CompilerConfiguration in project groovy by apache.

the class ScriptCompilationExecuter method execute.

public long execute() throws Exception {
    ClassLoader cl = new URLClassLoader(classpath, ClassLoader.getSystemClassLoader().getParent());
    GroovyClassLoader gcl = new GroovyClassLoader(cl);
    CompilationUnit cu = new CompilationUnit(new CompilerConfiguration(), null, gcl, new GroovyClassLoader(this.getClass().getClassLoader()));
    for (File source : sources) {
        cu.addSource(source);
    }
    long sd = System.nanoTime();
    cu.compile(CompilePhase.CLASS_GENERATION.getPhaseNumber());
    long dur = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - sd);
    return dur;
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) CompilationUnit(org.codehaus.groovy.control.CompilationUnit) URLClassLoader(java.net.URLClassLoader) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) URLClassLoader(java.net.URLClassLoader) GroovyClassLoader(groovy.lang.GroovyClassLoader) File(java.io.File)

Example 2 with CompilerConfiguration

use of org.codehaus.groovy.control.CompilerConfiguration in project groovy by apache.

the class CompilerTest method setUp.

protected void setUp() throws Exception {
    File dir = new File("target/test-generated-classes");
    dir.mkdirs();
    CompilerConfiguration config = new CompilerConfiguration();
    config.setTargetDirectory(dir);
    config.setDebug(dumpClass);
    compiler = new Compiler(config);
}
Also used : CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) File(java.io.File)

Example 3 with CompilerConfiguration

use of org.codehaus.groovy.control.CompilerConfiguration in project groovy by apache.

the class FileSystemCompilerTest method setUp.

protected void setUp() throws Exception {
    File dir = new File("target/test-generated-classes");
    dir.mkdirs();
    Map options = new HashMap();
    options.put("stubDir", dir);
    CompilerConfiguration configuration = new CompilerConfiguration();
    configuration.setTargetDirectory(dir);
    configuration.setVerbose(dumpClass);
    configuration.setJointCompilationOptions(options);
    compiler = new FileSystemCompiler(configuration);
}
Also used : HashMap(java.util.HashMap) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with CompilerConfiguration

use of org.codehaus.groovy.control.CompilerConfiguration in project groovy by apache.

the class Groovy7826Bug method testComplexTypeArguments.

public void testComplexTypeArguments() throws Exception {
    String script = "def f(org.codehaus.groovy.ast.Groovy7826Bug.C1 c1) { }";
    CompilerConfiguration config = new CompilerConfiguration();
    config.getOptimizationOptions().put("asmResolving", false);
    GroovyShell shell = new GroovyShell(config);
    shell.evaluate(script, "bug7826.groovy");
}
Also used : CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) GroovyShell(groovy.lang.GroovyShell)

Example 5 with CompilerConfiguration

use of org.codehaus.groovy.control.CompilerConfiguration in project groovy by apache.

the class GroovyShellTest method testScriptWithDerivedBaseClass.

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"));
}
Also used : CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration)

Aggregations

CompilerConfiguration (org.codehaus.groovy.control.CompilerConfiguration)40 GroovyShell (groovy.lang.GroovyShell)14 Binding (groovy.lang.Binding)10 File (java.io.File)10 ImportCustomizer (org.codehaus.groovy.control.customizers.ImportCustomizer)9 CompilationUnit (org.codehaus.groovy.control.CompilationUnit)8 ArrayList (java.util.ArrayList)6 GroovyClassLoader (groovy.lang.GroovyClassLoader)5 List (java.util.List)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 HashMap (java.util.HashMap)4 GroovyBugError (org.codehaus.groovy.GroovyBugError)4 ClassNode (org.codehaus.groovy.ast.ClassNode)4 GroovyClass (org.codehaus.groovy.tools.GroovyClass)4 ParseException (org.apache.commons.cli.ParseException)3 CompilationFailedException (org.codehaus.groovy.control.CompilationFailedException)3 SimpleMessage (org.codehaus.groovy.control.messages.SimpleMessage)3 Closure (groovy.lang.Closure)2 GroovyObject (groovy.lang.GroovyObject)2 GroovyRuntimeException (groovy.lang.GroovyRuntimeException)2