Search in sources :

Example 16 with CompilationFailedException

use of org.codehaus.groovy.control.CompilationFailedException in project groovy-core by groovy.

the class Main method loadScript.

private Class loadScript(String name) {
    Class scriptClass = null;
    GroovyClassLoader gcl = new GroovyClassLoader(this.getClass().getClassLoader());
    name = "src/test/" + getClass().getPackage().getName().replace(".", "/") + "/" + name;
    try {
        scriptClass = gcl.parseClass(new File(name));
    } catch (CompilationFailedException e) {
        throw new RuntimeException("Script compilation failed: " + e.getMessage());
    } catch (IOException e) {
        throw new RuntimeException("Script file not found: " + name);
    }
    return scriptClass;
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) CompilationFailedException(org.codehaus.groovy.control.CompilationFailedException) IOException(java.io.IOException) File(java.io.File)

Example 17 with CompilationFailedException

use of org.codehaus.groovy.control.CompilationFailedException in project groovy-core by groovy.

the class Groovy method parseAndRunScript.

private void parseAndRunScript(GroovyShell shell, String txt, Object mavenPom, String scriptName, File scriptFile, AntBuilder builder) {
    try {
        final Script script;
        if (scriptFile != null) {
            script = shell.parse(scriptFile);
        } else {
            script = shell.parse(txt, scriptName);
        }
        final Project project = getProject();
        script.setProperty("ant", builder);
        script.setProperty("project", project);
        script.setProperty("properties", new AntProjectPropertiesDelegate(project));
        script.setProperty("target", getOwningTarget());
        script.setProperty("task", this);
        script.setProperty("args", cmdline.getCommandline());
        if (mavenPom != null) {
            script.setProperty("pom", mavenPom);
        }
        script.run();
    } catch (final MissingMethodException mme) {
        // not a script, try running through run method but properties will not be available
        if (scriptFile != null) {
            try {
                shell.run(scriptFile, cmdline.getCommandline());
            } catch (IOException e) {
                processError(e);
            }
        } else {
            shell.run(txt, scriptName, cmdline.getCommandline());
        }
    } catch (final CompilationFailedException e) {
        processError(e);
    } catch (IOException e) {
        processError(e);
    }
}
Also used : Script(groovy.lang.Script) Project(org.apache.tools.ant.Project) MissingMethodException(groovy.lang.MissingMethodException) CompilationFailedException(org.codehaus.groovy.control.CompilationFailedException) IOException(java.io.IOException)

Example 18 with CompilationFailedException

use of org.codehaus.groovy.control.CompilationFailedException in project groovy-core by groovy.

the class DependencyTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    cu = new CompilationUnit();
    cache = new StringSetMap();
    cu.addPhaseOperation(new CompilationUnit.PrimaryClassNodeOperation() {

        @Override
        public void call(final SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException {
            DependencyTracker dt = new DependencyTracker(source, cache);
            dt.visitClass(classNode);
        }
    }, Phases.CLASS_GENERATION);
}
Also used : CompilationUnit(org.codehaus.groovy.control.CompilationUnit) ClassNode(org.codehaus.groovy.ast.ClassNode) CompilationFailedException(org.codehaus.groovy.control.CompilationFailedException) SourceUnit(org.codehaus.groovy.control.SourceUnit) GeneratorContext(org.codehaus.groovy.classgen.GeneratorContext)

Example 19 with CompilationFailedException

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

the class DependencyTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    cu = new CompilationUnit();
    cache = new StringSetMap();
    cu.addPhaseOperation(new CompilationUnit.PrimaryClassNodeOperation() {

        @Override
        public void call(final SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException {
            DependencyTracker dt = new DependencyTracker(source, cache);
            dt.visitClass(classNode);
        }
    }, Phases.CLASS_GENERATION);
}
Also used : CompilationUnit(org.codehaus.groovy.control.CompilationUnit) ClassNode(org.codehaus.groovy.ast.ClassNode) CompilationFailedException(org.codehaus.groovy.control.CompilationFailedException) SourceUnit(org.codehaus.groovy.control.SourceUnit) GeneratorContext(org.codehaus.groovy.classgen.GeneratorContext)

Example 20 with CompilationFailedException

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

the class TraitASTTransformation method registerASTTranformations.

private void registerASTTranformations(final ClassNode helper) {
    ASTTransformationCollectorCodeVisitor collector = new ASTTransformationCollectorCodeVisitor(unit, compilationUnit.getTransformLoader());
    collector.visitClass(helper);
    // Perform an additional phase which has to be done *after* type checking
    compilationUnit.addPhaseOperation(new CompilationUnit.PrimaryClassNodeOperation() {

        @Override
        public void call(final SourceUnit source, final GeneratorContext context, final ClassNode classNode) throws CompilationFailedException {
            if (classNode == helper) {
                PostTypeCheckingExpressionReplacer replacer = new PostTypeCheckingExpressionReplacer(source);
                replacer.visitClass(helper);
            }
        }
    }, CompilePhase.INSTRUCTION_SELECTION.getPhaseNumber());
}
Also used : CompilationUnit(org.codehaus.groovy.control.CompilationUnit) InnerClassNode(org.codehaus.groovy.ast.InnerClassNode) ClassNode(org.codehaus.groovy.ast.ClassNode) CompilationFailedException(org.codehaus.groovy.control.CompilationFailedException) SourceUnit(org.codehaus.groovy.control.SourceUnit) GeneratorContext(org.codehaus.groovy.classgen.GeneratorContext) ASTTransformationCollectorCodeVisitor(org.codehaus.groovy.transform.ASTTransformationCollectorCodeVisitor)

Aggregations

CompilationFailedException (org.codehaus.groovy.control.CompilationFailedException)26 IOException (java.io.IOException)14 GroovyClassLoader (groovy.lang.GroovyClassLoader)7 Script (groovy.lang.Script)5 ClassNode (org.codehaus.groovy.ast.ClassNode)5 CompilationUnit (org.codehaus.groovy.control.CompilationUnit)5 File (java.io.File)4 GeneratorContext (org.codehaus.groovy.classgen.GeneratorContext)4 SourceUnit (org.codehaus.groovy.control.SourceUnit)4 GroovyShell (groovy.lang.GroovyShell)3 InputStream (java.io.InputStream)3 URL (java.net.URL)3 CompilerConfiguration (org.codehaus.groovy.control.CompilerConfiguration)3 Binding (groovy.lang.Binding)2 Closure (groovy.lang.Closure)2 GroovyObject (groovy.lang.GroovyObject)2 GroovyRuntimeException (groovy.lang.GroovyRuntimeException)2 MissingMethodException (groovy.lang.MissingMethodException)2 Node (groovy.util.Node)2 InputStreamReader (java.io.InputStreamReader)2