protected String compileUnits(JRCompilationUnit[] units,
String classpath,
File tempDirFile) throws JRException {
CompilerConfiguration config = new CompilerConfiguration();
//config.setClasspath(classpath);
CompilationUnit unit = new CompilationUnit(config);
for (int i = 0; i < units.length; i++)
{
unit.addSource("calculator_" + units[i].getName(), new ByteArrayInputStream(units[i].getSourceCode().getBytes()));
}
ClassCollector collector = new ClassCollector();
unit.setClassgenCallback(collector);
try
{
unit.compile(Phases.CLASS_GENERATION);
}
catch (CompilationFailedException e)
{
throw new JRException(
"Errors were encountered when compiling report expressions class file:\n"
+ e.toString()
);
}
if (collector.classes.size() < units.length)
{
throw new JRException("Too few groovy class were generated.");
}
else if (collector.classCount > units.length)
{
throw new JRException(
"Too many groovy classes were generated.\n"
+ "Please make sure that you don't use Groovy features such as closures that are not supported by this report compiler.\n"
);
}
for (int i = 0; i < units.length; i++)
{
units[i].setCompileData((Serializable) collector.classes.get(units[i].getName()));
}
return null;
}
|