final ClassLoader pClassLoader,
final JavaCompilerSettings pSettings
) {
final CompilerConfiguration configuration = ((GroovyJavaCompilerSettings) pSettings).getCompilerConfiguration();
final ErrorCollector collector = new ErrorCollector(configuration);
final GroovyClassLoader groovyClassLoader = new GroovyClassLoader(pClassLoader);
final CompilationUnit unit = new CompilationUnit(configuration, null, groovyClassLoader);
final SourceUnit[] source = new SourceUnit[pResourceNames.length];
for (int i = 0; i < source.length; i++) {
final String resourceName = pResourceNames[i];
source[i] = new SourceUnit(
ConversionUtils.convertResourceToClassName(resourceName),
new String(pReader.getBytes(resourceName)), // FIXME delay the read
configuration,
groovyClassLoader,
collector
);
unit.addSource(source[i]);
}
final Collection<CompilationProblem> problems = new ArrayList<CompilationProblem>();
try {
log.debug("compiling");
unit.compile(Phases.CLASS_GENERATION);
@SuppressWarnings("unchecked") // Groovy library is not yet generic
final List<GroovyClass> classes = unit.getClasses();
for (GroovyClass clazz : classes) {
final byte[] bytes = clazz.getBytes();
pStore.write(ConversionUtils.convertClassToResourcePath(clazz.getName()), bytes);
}
} catch (final MultipleCompilationErrorsException e) {
final ErrorCollector col = e.getErrorCollector();
@SuppressWarnings("unchecked") // Groovy library is not yet generic
final Collection<WarningMessage> warnings = col.getWarnings();
if (warnings != null) {
for (WarningMessage warning : warnings) {
final CompilationProblem problem = new GroovyCompilationProblem(warning);
if (problemHandler != null) {
problemHandler.handle(problem);
}
problems.add(problem);
}
}
@SuppressWarnings("unchecked") // Groovy library is not yet generic
final Collection<Message> errors = col.getErrors();
if (errors != null) {
for (Message message : errors) {
final CompilationProblem problem = new GroovyCompilationProblem(message);
if (problemHandler != null) {
problemHandler.handle(problem);