Search in sources :

Example 1 with KnowledgeBuilderError

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;
}
Also used : KnowledgeBuilderError(org.kie.internal.builder.KnowledgeBuilderError) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) KnowledgeBuilderErrors(org.kie.internal.builder.KnowledgeBuilderErrors) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase)

Example 2 with KnowledgeBuilderError

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");
    }
}
Also used : KnowledgeBuilderError(org.kie.internal.builder.KnowledgeBuilderError) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) KnowledgeBuilderErrors(org.kie.internal.builder.KnowledgeBuilderErrors) MVELDialectConfiguration(org.drools.compiler.rule.builder.dialect.mvel.MVELDialectConfiguration) Test(org.junit.Test)

Example 3 with KnowledgeBuilderError

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;
}
Also used : CompositeKnowledgeBuilder(org.kie.internal.builder.CompositeKnowledgeBuilder) KnowledgeBuilderError(org.kie.internal.builder.KnowledgeBuilderError) CompositeKnowledgeBuilder(org.kie.internal.builder.CompositeKnowledgeBuilder) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) HashSet(java.util.HashSet) KnowledgeBuilderResult(org.kie.internal.builder.KnowledgeBuilderResult)

Example 4 with KnowledgeBuilderError

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();
    }
}
Also used : KnowledgeBuilderError(org.kie.internal.builder.KnowledgeBuilderError) PackageBuilderErrors(org.drools.compiler.compiler.PackageBuilderErrors)

Example 5 with KnowledgeBuilderError

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.");
    }
}
Also used : KnowledgeBuilderError(org.kie.internal.builder.KnowledgeBuilderError) KnowledgeBuilderErrors(org.kie.internal.builder.KnowledgeBuilderErrors)

Aggregations

KnowledgeBuilderError (org.kie.internal.builder.KnowledgeBuilderError)31 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)23 KnowledgeBuilderErrors (org.kie.internal.builder.KnowledgeBuilderErrors)12 Test (org.junit.Test)9 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)7 KnowledgeBuilderConfigurationImpl (org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl)6 Resource (org.kie.api.io.Resource)5 ArrayList (java.util.ArrayList)4 ByteArrayResource (org.drools.core.io.impl.ByteArrayResource)4 StringReader (java.io.StringReader)3 HashMap (java.util.HashMap)3 ClassPathResource (org.drools.core.io.impl.ClassPathResource)3 InternalKnowledgeBase (org.drools.kiesession.rulebase.InternalKnowledgeBase)3 KiePackage (org.kie.api.definition.KiePackage)3 Process (org.kie.api.definition.process.Process)3 ResourceType (org.kie.api.io.ResourceType)3 KieSession (org.kie.api.runtime.KieSession)3 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)3 CompositeKnowledgeBuilder (org.kie.internal.builder.CompositeKnowledgeBuilder)3 KnowledgeBuilderResult (org.kie.internal.builder.KnowledgeBuilderResult)3