// where the transform class is loaded from)
for (File file : spec.getClasspath()) {
astTransformClassLoader.addClasspath(file.getPath());
}
JavaAwareCompilationUnit unit = new JavaAwareCompilationUnit(configuration, compileClasspathClassLoader) {
@Override
public GroovyClassLoader getTransformLoader() {
return astTransformClassLoader;
}
};
unit.addSources(Iterables.toArray(spec.getSource(), File.class));
unit.setCompilerFactory(new org.codehaus.groovy.tools.javac.JavaCompilerFactory() {
public JavaCompiler createCompiler(final CompilerConfiguration config) {
return new JavaCompiler() {
public void compile(List<String> files, CompilationUnit cu) {
spec.setSource(spec.getSource().filter(new Spec<File>() {
public boolean isSatisfiedBy(File file) {
return file.getName().endsWith(".java");
}
}));
spec.getCompileOptions().getCompilerArgs().add("-sourcepath");
spec.getCompileOptions().getCompilerArgs().add(((File) config.getJointCompilationOptions().get("stubDir")).getAbsolutePath());
try {
javaCompiler.execute(spec);
} catch (CompilationFailedException e) {
cu.getErrorCollector().addFatalError(new SimpleMessage(e.getMessage(), cu));
}
}
};
}
});
try {
unit.compile();
} catch (org.codehaus.groovy.control.CompilationFailedException e) {
System.err.println(e.getMessage());
throw new CompilationFailedException();
}