use of org.drools.compiler.builder.impl.errors.ErrorHandler in project drools by kiegroup.
the class ProjectJavaCompiler method compileAll.
public List<KnowledgeBuilderResult> compileAll(ProjectClassLoader projectClassLoader, List<String> classList, MemoryResourceReader src) {
List<KnowledgeBuilderResult> results = new ArrayList<KnowledgeBuilderResult>();
if (classList.isEmpty()) {
return results;
}
final String[] classes = new String[classList.size()];
classList.toArray(classes);
CompilationResult result = compiler.compile(classes, src, new ProjectResourceStore(projectClassLoader), projectClassLoader);
if (result.getErrors().length > 0) {
Map<String, ErrorHandler> errorHandlerMap = new HashMap<String, ErrorHandler>();
for (int i = 0; i < result.getErrors().length; i++) {
final CompilationProblem err = result.getErrors()[i];
ErrorHandler handler = errorHandlerMap.get(err.getFileName());
if (handler == null) {
handler = new SrcErrorHandler("Src compile error");
errorHandlerMap.put(err.getFileName(), handler);
}
handler.addError(err);
}
for (ErrorHandler handler : errorHandlerMap.values()) {
if (handler.isInError()) {
results.add(handler.getError());
}
}
}
return results;
}
use of org.drools.compiler.builder.impl.errors.ErrorHandler in project drools by kiegroup.
the class JavaDialect method compileAll.
/**
* This actually triggers the compiling of all the resources.
* Errors are mapped back to the element that originally generated the semantic
* code.
*/
public void compileAll() {
if (this.generatedClassList.isEmpty()) {
this.errorHandlers.clear();
return;
}
final String[] classes = new String[this.generatedClassList.size()];
this.generatedClassList.toArray(classes);
File dumpDir = this.configuration.getPackageBuilderConfiguration().getDumpDir();
if (dumpDir != null) {
dumpResources(classes, dumpDir);
}
final CompilationResult result = this.compiler.compile(classes, this.src, this.packageStoreWrapper, rootClassLoader);
// this will sort out the errors based on what class/file they happened in
if (result.getErrors().length > 0) {
for (int i = 0; i < result.getErrors().length; i++) {
final CompilationProblem err = result.getErrors()[i];
final ErrorHandler handler = this.errorHandlers.get(err.getFileName());
handler.addError(err);
}
final Collection errors = this.errorHandlers.values();
for (Object error : errors) {
final ErrorHandler handler = (ErrorHandler) error;
if (handler.isInError()) {
this.results.add(handler.getError());
}
}
}
// We've compiled everthing, so clear it for the next set of additions
this.generatedClassList.clear();
this.errorHandlers.clear();
}
Aggregations