use of org.kie.internal.builder.KnowledgeBuilderError in project drools by kiegroup.
the class StrEvaluatorTest method readKnowledgeBase.
private KieBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newInputStreamResource(getClass().getResourceAsStream("strevaluator_test.drl")), ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge." + errors.toArray());
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
return kbase;
}
use of org.kie.internal.builder.KnowledgeBuilderError in project drools by kiegroup.
the class RHSTest method testRHSClone.
@Test
public void testRHSClone() {
// JBRULES-3539
final String str = "import java.util.Map;\n" + "dialect \"mvel\"\n" + "rule \"RHSClone\"\n" + "when\n" + " Map($valOne : this['keyOne'] !=null)\n" + "then\n" + " System.out.println( $valOne.clone() );\n" + "end\n";
final KnowledgeBuilderConfigurationImpl pkgBuilderCfg = new KnowledgeBuilderConfigurationImpl();
final MVELDialectConfiguration mvelConf = (MVELDialectConfiguration) pkgBuilderCfg.getDialectConfiguration("mvel");
mvelConf.setStrict(false);
mvelConf.setLangLevel(5);
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(pkgBuilderCfg);
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
final KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (final KnowledgeBuilderError error : errors) {
System.err.println(error);
}
fail("Could not parse knowledge");
}
}
use of org.kie.internal.builder.KnowledgeBuilderError in project drools by kiegroup.
the class AbstractKieProject method buildKnowledgePackages.
public KnowledgeBuilder buildKnowledgePackages(KieBaseModelImpl kBaseModel, ResultsImpl messages) {
InternalKieModule kModule = getKieModuleForKBase(kBaseModel.getName());
KnowledgeBuilder kbuilder = createKnowledgeBuilder(kBaseModel, kModule);
CompositeKnowledgeBuilder ckbuilder = kbuilder.batch();
Set<Asset> assets = new HashSet<>();
boolean allIncludesAreValid = true;
for (String include : getTransitiveIncludes(kBaseModel)) {
if (StringUtils.isEmpty(include)) {
continue;
}
InternalKieModule includeModule = 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).setKieBaseName(kBaseModel.getName());
allIncludesAreValid = false;
continue;
}
addFiles(assets, 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 (Asset asset : assets) {
asset.kmodule.addResourceToCompiler(ckbuilder, kBaseModel, asset.name);
}
}
ckbuilder.build();
if (kbuilder.hasErrors()) {
for (KnowledgeBuilderError error : kbuilder.getErrors()) {
messages.addMessage(error).setKieBaseName(kBaseModel.getName());
}
log.error("Unable to build KieBaseModel:" + kBaseModel.getName() + "\n" + kbuilder.getErrors().toString());
}
if (kbuilder.hasResults(ResultSeverity.WARNING)) {
for (KnowledgeBuilderResult warn : kbuilder.getResults(ResultSeverity.WARNING)) {
messages.addMessage(warn).setKieBaseName(kBaseModel.getName());
}
log.warn("Warning : " + kBaseModel.getName() + "\n" + kbuilder.getResults(ResultSeverity.WARNING).toString());
}
// cache KnowledgeBuilder and results
kModule.cacheKnowledgeBuilderForKieBase(kBaseModel.getName(), kbuilder);
kModule.cacheResultsForKieBase(kBaseModel.getName(), messages);
return kbuilder;
}
use of org.kie.internal.builder.KnowledgeBuilderError in project drools by kiegroup.
the class KieBaseUpdater method rebuildAll.
private void rebuildAll(KnowledgeBuilderImpl kbuilder, CompositeKnowledgeBuilder ckbuilder) {
ckbuilder.build();
PackageBuilderErrors errors = kbuilder.getErrors();
if (!errors.isEmpty()) {
for (KnowledgeBuilderError error : errors.getErrors()) {
ctx.results.addMessage(error).setKieBaseName(ctx.newKieBaseModel.getName());
}
log.error("Unable to update KieBase: " + ctx.newKieBaseModel.getName() + " to release " + ctx.newReleaseId + "\n" + errors.toString());
}
if (ctx.modifyingUsedClass) {
kbuilder.rewireAllClassObjectTypes();
}
}
use of org.kie.internal.builder.KnowledgeBuilderError in project drools by kiegroup.
the class DynamicEvalTest method loadPackages.
public void loadPackages(Resource res, ResourceType type) {
kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(res, type);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
}
}
Aggregations