AbstractKieModule kModule = (AbstractKieModule) kieProject.getKieModuleForKBase(kBaseModel.getName());
PackageBuilderConfiguration pconf = new PackageBuilderConfiguration(kieProject.getClonedClassLoader());
pconf.setCompilationCache(kModule.getCompilationCache(kBaseModel.getName()));
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(pconf);
CompositeKnowledgeBuilder ckbuilder = kbuilder.batch();
Map<String, InternalKieModule> assets = new HashMap<String, InternalKieModule>();
boolean allIncludesAreValid = true;
for (String include : getTransitiveIncludes(kieProject, kBaseModel)) {
if (StringUtils.isEmpty(include)) {
continue;
}
InternalKieModule includeModule = kieProject.getKieModuleForKBase(include);
if (includeModule == null) {
String text = "Unable to build KieBase, could not find include: " + include;
log.error(text);
messages.addMessage(Message.Level.ERROR, KieModuleModelImpl.KMODULE_SRC_PATH, text);
allIncludesAreValid = false;
continue;
}
addFiles( assets, kieProject.getKieBaseModel(include), includeModule );
}
if (!allIncludesAreValid) {
return null;
}
addFiles( assets, kBaseModel, kModule );
if (assets.isEmpty()) {
if (kModule instanceof FileKieModule) {
log.warn("No files found for KieBase " + kBaseModel.getName() + ", searching folder " + kModule.getFile());
} else {
log.warn("No files found for KieBase " + kBaseModel.getName());
}
} else {
for (Map.Entry<String, InternalKieModule> entry : assets.entrySet()) {
entry.getValue().addResourceToCompiler(ckbuilder, entry.getKey());
}
}
ckbuilder.build();
if (kbuilder.hasErrors()) {
for (KnowledgeBuilderError error : kbuilder.getErrors()) {
messages.addMessage(error);
}
log.error("Unable to build KieBaseModel:" + kBaseModel.getName() + "\n" + kbuilder.getErrors().toString());
}
// cache KnowledgeBuilder and results
kModule.cacheKnowledgeBuilderForKieBase(kBaseModel.getName(), kbuilder);
kModule.cacheResultsForKieBase(kBaseModel.getName(), messages);