Search in sources :

Example 56 with KieModule

use of org.kie.api.builder.KieModule in project drools by kiegroup.

the class BuildFromKJarBenchmark method buildKnowledge.

@Benchmark
public KieBase buildKnowledge(final Blackhole eater) {
    final KieModule zipKieModule = type.useRuleModel ? new CanonicalKieModule(releaseId, kieModuleModel, kjarFiles.getJarFile(), kjarFiles.getKnowledgeFiles()) : new ZipKieModule(releaseId, kieModuleModel, kjarFiles.getJarFile());
    kieRepository.addKieModule(zipKieModule);
    if (eater != null) {
        eater.consume(zipKieModule);
    }
    return kieServices.newKieContainer(releaseId).getKieBase();
}
Also used : ZipKieModule(org.drools.compiler.kie.builder.impl.ZipKieModule) CanonicalKieModule(org.drools.modelcompiler.CanonicalKieModule) CanonicalKieModule(org.drools.modelcompiler.CanonicalKieModule) ZipKieModule(org.drools.compiler.kie.builder.impl.ZipKieModule) KieModule(org.kie.api.builder.KieModule) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 57 with KieModule

use of org.kie.api.builder.KieModule in project drools by kiegroup.

the class KieHelper method deployJarIntoRepository.

private static KieModule deployJarIntoRepository(KieServices ks, byte[] jar) {
    Resource jarRes = ks.getResources().newByteArrayResource(jar);
    KieModule km = ks.getRepository().addKieModule(jarRes);
    return km;
}
Also used : Resource(org.kie.api.io.Resource) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule)

Example 58 with KieModule

use of org.kie.api.builder.KieModule in project drools by kiegroup.

the class JavaBeansEventRoleTest method testImportBean.

@Test
public void testImportBean() throws Exception {
    String declaration = "package org.drools.compiler;\n" + "public class Bean {}";
    String drl = "package some.other.package;\n" + "import org.drools.compiler.Bean;\n" + "declare Bean\n" + "  @role(event)\n" + "end";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/java/org/drools/compiler/Bean.java", declaration).write("src/main/resources/bean1.drl", drl);
    final KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    final KieModule kieModule = kieBuilder.buildAll().getKieModule();
    final KieModuleMetaData kieModuleMetaData = KieModuleMetaData.Factory.newKieModuleMetaData(kieModule);
    final String packageName = "org.drools.compiler";
    final String className = "Bean";
    final Class clazz = kieModuleMetaData.getClass(packageName, className);
    final TypeMetaInfo typeMetaInfo = kieModuleMetaData.getTypeMetaInfo(clazz);
    assertTrue(typeMetaInfo.isEvent());
}
Also used : TypeMetaInfo(org.drools.core.rule.TypeMetaInfo) KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) KieModule(org.kie.api.builder.KieModule) KieModuleMetaData(org.kie.scanner.KieModuleMetaData) Test(org.junit.Test)

Example 59 with KieModule

use of org.kie.api.builder.KieModule in project drools by kiegroup.

the class JavaBeansEventRoleTest method testBeanAndDeclarativeTypeInSamePackage.

@Test
public void testBeanAndDeclarativeTypeInSamePackage() throws Exception {
    String declaration = "package org.drools.compiler;\n" + "public class Bean {}";
    String drl = "package org.drools.compiler;\n" + "declare Bean\n" + "  @role(event)\n" + "end";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/java/org/drools/compiler/Bean.java", declaration).write("src/main/resources/bean1.drl", drl);
    final KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    final KieModule kieModule = kieBuilder.buildAll().getKieModule();
    final KieModuleMetaData kieModuleMetaData = KieModuleMetaData.Factory.newKieModuleMetaData(kieModule);
    final String packageName = "org.drools.compiler";
    final String className = "Bean";
    final Class clazz = kieModuleMetaData.getClass(packageName, className);
    final TypeMetaInfo typeMetaInfo = kieModuleMetaData.getTypeMetaInfo(clazz);
    assertTrue(typeMetaInfo.isEvent());
}
Also used : TypeMetaInfo(org.drools.core.rule.TypeMetaInfo) KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) KieModule(org.kie.api.builder.KieModule) KieModuleMetaData(org.kie.scanner.KieModuleMetaData) Test(org.junit.Test)

Example 60 with KieModule

use of org.kie.api.builder.KieModule in project drools by kiegroup.

the class AbstractKieCiTest method deployJar.

public static KieModule deployJar(KieServices ks, byte[] jar) {
    // Deploy jar into the repository
    Resource jarRes = ks.getResources().newByteArrayResource(jar);
    KieModule km = ks.getRepository().addKieModule(jarRes);
    return km;
}
Also used : Resource(org.kie.api.io.Resource) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule)

Aggregations

KieModule (org.kie.api.builder.KieModule)124 KieServices (org.kie.api.KieServices)104 Test (org.junit.Test)94 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)84 ReleaseId (org.kie.api.builder.ReleaseId)84 KieContainer (org.kie.api.runtime.KieContainer)75 KieSession (org.kie.api.runtime.KieSession)64 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)53 Message (org.drools.compiler.Message)25 KieFileSystem (org.kie.api.builder.KieFileSystem)23 Resource (org.kie.api.io.Resource)20 ArrayList (java.util.ArrayList)15 KieModuleModel (org.kie.api.builder.model.KieModuleModel)15 KieBuilder (org.kie.api.builder.KieBuilder)13 KieRepository (org.kie.api.builder.KieRepository)10 MemoryFileSystem (org.drools.compiler.compiler.io.memory.MemoryFileSystem)7 KieBaseModel (org.kie.api.builder.model.KieBaseModel)7 KieBase (org.kie.api.KieBase)6 List (java.util.List)5 Results (org.kie.api.builder.Results)5