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;
}
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);
}
}
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);
}
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);
}
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());
}
Aggregations