Search in sources :

Example 1 with ZipKieModule

use of org.drools.compiler.kie.builder.impl.ZipKieModule in project drools by kiegroup.

the class BuildtimeUtil method generateKJarFromKieBuilder.

public static void generateKJarFromKieBuilder(final KieBuilder kieBuilder, final boolean useCanonicalModel) throws IOException {
    final ReleaseId releaseId = kieBuilder.getKieModule().getReleaseId();
    final InternalKieModule kieModule = (InternalKieModule) kieBuilder.getKieModule();
    final File kjarFile = bytesToTempFile(releaseId, kieModule.getBytes(), ".jar");
    final KieModule zipKieModule;
    if (useCanonicalModel) {
        zipKieModule = new CanonicalKieModule(releaseId, kieModule.getKieModuleModel(), kjarFile);
    } else {
        zipKieModule = new ZipKieModule(releaseId, kieModule.getKieModuleModel(), kjarFile);
    }
    KieServices.get().getRepository().addKieModule(zipKieModule);
}
Also used : ZipKieModule(org.drools.compiler.kie.builder.impl.ZipKieModule) CanonicalKieModule(org.drools.modelcompiler.CanonicalKieModule) ReleaseId(org.kie.api.builder.ReleaseId) File(java.io.File) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) CanonicalKieModule(org.drools.modelcompiler.CanonicalKieModule) ZipKieModule(org.drools.compiler.kie.builder.impl.ZipKieModule) KieModule(org.kie.api.builder.KieModule) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 2 with ZipKieModule

use of org.drools.compiler.kie.builder.impl.ZipKieModule 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 3 with ZipKieModule

use of org.drools.compiler.kie.builder.impl.ZipKieModule in project drools by kiegroup.

the class KieProjectRuntimeModulesTest method createMultpleJarAndFileResources.

@Test
public void createMultpleJarAndFileResources() throws IOException, ClassNotFoundException, InterruptedException {
    KieModuleModel kProjModel1 = createKieModule("jar1", true);
    KieModuleModel kProjModel2 = createKieModule("jar2", true);
    KieModuleModel kProjModel3 = createKieModule("jar3", true);
    KieModuleModel kProjModel4 = createKieModule("fol4", false);
    ReleaseId releaseId1 = KieServices.Factory.get().newReleaseId("jar1", "art1", "1.0-SNAPSHOT");
    ReleaseId releaseId2 = KieServices.Factory.get().newReleaseId("jar2", "art1", "1.0-SNAPSHOT");
    ReleaseId releaseId3 = KieServices.Factory.get().newReleaseId("jar3", "art1", "1.0-SNAPSHOT");
    ReleaseId releaseId4 = KieServices.Factory.get().newReleaseId("fol4", "art1", "1.0-SNAPSHOT");
    java.io.File file1 = fileManager.newFile("jar1-1.0-SNAPSHOT.jar");
    java.io.File file2 = fileManager.newFile("jar2-1.0-SNAPSHOT.jar");
    java.io.File file3 = fileManager.newFile("jar3-1.0-SNAPSHOT.jar");
    java.io.File fol4 = fileManager.newFile("fol4-1.0-SNAPSHOT");
    ZipKieModule mod1 = new ZipKieModule(releaseId1, kProjModel1, file1);
    ZipKieModule mod2 = new ZipKieModule(releaseId2, kProjModel2, file2);
    ZipKieModule mod3 = new ZipKieModule(releaseId3, kProjModel3, file3);
    FileKieModule mod4 = new FileKieModule(releaseId4, kProjModel4, fol4);
    mod1.addKieDependency(mod2);
    mod1.addKieDependency(mod3);
    mod1.addKieDependency(mod4);
    KieModuleKieProject kProject = new KieModuleKieProject(mod1);
    KieContainer kContainer = new KieContainerImpl(kProject, null);
    KieBase kBase = kContainer.getKieBase("jar1.KBase1");
    ClassLoader cl = ((KnowledgeBaseImpl) kBase).getRootClassLoader();
    Class cls = cl.loadClass("org.drools.compiler.cdi.test.KProjectTestClassjar1");
    assertNotNull(cls);
    cls = cl.loadClass("org.drools.compiler.cdi.test.KProjectTestClassjar2");
    assertNotNull(cls);
    cls = cl.loadClass("org.drools.compiler.cdi.test.KProjectTestClassjar3");
    assertNotNull(cls);
    testEntry(new KProjectTestClassImpl("jar1", kContainer), "jar1");
    testEntry(new KProjectTestClassImpl("jar2", kContainer), "jar2");
    testEntry(new KProjectTestClassImpl("jar3", kContainer), "jar3");
    testEntry(new KProjectTestClassImpl("fol4", kContainer), "fol4");
}
Also used : ZipKieModule(org.drools.compiler.kie.builder.impl.ZipKieModule) FileKieModule(org.drools.compiler.kie.builder.impl.FileKieModule) KieContainerImpl(org.drools.compiler.kie.builder.impl.KieContainerImpl) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) ReleaseId(org.kie.api.builder.ReleaseId) KieModuleKieProject(org.drools.compiler.kie.builder.impl.KieModuleKieProject) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieBase(org.kie.api.KieBase) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Aggregations

ZipKieModule (org.drools.compiler.kie.builder.impl.ZipKieModule)3 CanonicalKieModule (org.drools.modelcompiler.CanonicalKieModule)2 KieModule (org.kie.api.builder.KieModule)2 ReleaseId (org.kie.api.builder.ReleaseId)2 File (java.io.File)1 FileKieModule (org.drools.compiler.kie.builder.impl.FileKieModule)1 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)1 KieContainerImpl (org.drools.compiler.kie.builder.impl.KieContainerImpl)1 KieModuleKieProject (org.drools.compiler.kie.builder.impl.KieModuleKieProject)1 KnowledgeBaseImpl (org.drools.core.impl.KnowledgeBaseImpl)1 Test (org.junit.Test)1 KieBase (org.kie.api.KieBase)1 KieModuleModel (org.kie.api.builder.model.KieModuleModel)1 KieContainer (org.kie.api.runtime.KieContainer)1 Benchmark (org.openjdk.jmh.annotations.Benchmark)1