Search in sources :

Example 1 with KieRepository

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

the class KieBuilderImpl method buildKieProject.

private static void buildKieProject(ResultsImpl messages, KieModuleKieProject kProject, MemoryFileSystem trgMfs) {
    kProject.init();
    kProject.verify(messages);
    if (messages.filterMessages(Level.ERROR).isEmpty()) {
        InternalKieModule kModule = kProject.getInternalKieModule();
        if (trgMfs != null) {
            new KieMetaInfoBuilder(kModule).writeKieModuleMetaInfo(trgMfs);
            kProject.writeProjectOutput(trgMfs, messages);
        }
        KieRepository kieRepository = KieServices.Factory.get().getRepository();
        kieRepository.addKieModule(kModule);
        for (InternalKieModule kDep : kModule.getKieDependencies().values()) {
            kieRepository.addKieModule(kDep);
        }
    }
}
Also used : KieRepository(org.kie.api.builder.KieRepository)

Example 2 with KieRepository

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

the class KieRepositoryTest method testLoadingNotAKJar.

@Test
public void testLoadingNotAKJar() {
    // DROOLS-1351
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { this.getClass().getResource("/only-jar-pojo-not-kjar-no-kmodule-1.0.0.jar") });
    Thread.currentThread().setContextClassLoader(urlClassLoader);
    try {
        KieServices ks = KieServices.Factory.get();
        KieRepository kieRepository = ks.getRepository();
        ReleaseId releaseId = ks.newReleaseId("org.test", "only-jar-pojo-not-kjar-no-kmodule", "1.0.0");
        KieModule kieModule = kieRepository.getKieModule(releaseId);
        assertNull(kieModule);
    } finally {
        Thread.currentThread().setContextClassLoader(cl);
    }
}
Also used : KieRepository(org.kie.api.builder.KieRepository) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KieModule(org.kie.api.builder.KieModule) Test(org.junit.Test)

Example 3 with KieRepository

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

the class KieRepositoryTest method testLoadKjarFromClasspath.

@Test
public void testLoadKjarFromClasspath() {
    // DROOLS-1335
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { this.getClass().getResource("/kie-project-simple-1.0.0.jar") });
    Thread.currentThread().setContextClassLoader(urlClassLoader);
    try {
        KieServices ks = KieServices.Factory.get();
        KieRepository kieRepository = ks.getRepository();
        ReleaseId releaseId = ks.newReleaseId("org.test", "kie-project-simple", "1.0.0");
        KieModule kieModule = kieRepository.getKieModule(releaseId);
        assertNotNull(kieModule);
        assertEquals(releaseId, kieModule.getReleaseId());
    } finally {
        Thread.currentThread().setContextClassLoader(cl);
    }
}
Also used : KieRepository(org.kie.api.builder.KieRepository) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KieModule(org.kie.api.builder.KieModule) Test(org.junit.Test)

Example 4 with KieRepository

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

the class KieRepositoryTest method testTryLoadNotExistingKjarFromClasspath.

@Test
public void testTryLoadNotExistingKjarFromClasspath() {
    // DROOLS-1335
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { this.getClass().getResource("/kie-project-simple-1.0.0.jar") });
    Thread.currentThread().setContextClassLoader(urlClassLoader);
    try {
        KieServices ks = KieServices.Factory.get();
        KieRepository kieRepository = ks.getRepository();
        ReleaseId releaseId = ks.newReleaseId("org.test", "kie-project-simple", "1.0.1");
        KieModule kieModule = kieRepository.getKieModule(releaseId);
        assertNull(kieModule);
    } finally {
        Thread.currentThread().setContextClassLoader(cl);
    }
}
Also used : KieRepository(org.kie.api.builder.KieRepository) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KieModule(org.kie.api.builder.KieModule) Test(org.junit.Test)

Example 5 with KieRepository

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

the class DroolsAbstractPMMLTest method readKnowledgeBase.

private static KieBase readKnowledgeBase(List<InputStream> theory) {
    KieServices ks = KieServices.Factory.get();
    KieRepository kr = ks.getRepository();
    KieFileSystem kfs = ks.newKieFileSystem();
    for (int j = 0; j < theory.size(); j++) {
        Resource res = ks.getResources().newInputStreamResource(theory.get(j));
        kfs.write(RESOURCE_PATH + "source_" + j + ".drl", res);
    }
    KieModuleModel model = ks.newKieModuleModel();
    KieBaseModel kbModel = model.newKieBaseModel(DEFAULT_KIEBASE).setDefault(true).addPackage(BASE_PACK).setEventProcessingMode(EventProcessingOption.STREAM);
    kfs.writeKModuleXML(model.toXML());
    KieBuilder kb = ks.newKieBuilder(kfs);
    kb.buildAll();
    if (kb.getResults().hasMessages(Message.Level.ERROR)) {
        throw new RuntimeException("Build Errors:\n" + kb.getResults().toString());
    }
    KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId());
    return kContainer.getKieBase();
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieRepository(org.kie.api.builder.KieRepository) KieFileSystem(org.kie.api.builder.KieFileSystem) KieModuleModel(org.kie.api.builder.model.KieModuleModel) Resource(org.kie.api.io.Resource) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) KieContainer(org.kie.api.runtime.KieContainer)

Aggregations

KieRepository (org.kie.api.builder.KieRepository)28 KieServices (org.kie.api.KieServices)23 KieContainer (org.kie.api.runtime.KieContainer)18 KieBuilder (org.kie.api.builder.KieBuilder)11 KieFileSystem (org.kie.api.builder.KieFileSystem)10 KieModule (org.kie.api.builder.KieModule)10 Resource (org.kie.api.io.Resource)8 Test (org.junit.Test)7 KieBase (org.kie.api.KieBase)7 ReleaseId (org.kie.api.builder.ReleaseId)7 KieSession (org.kie.api.runtime.KieSession)7 KieBaseModel (org.kie.api.builder.model.KieBaseModel)6 KieModuleModel (org.kie.api.builder.model.KieModuleModel)6 URLClassLoader (java.net.URLClassLoader)4 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)4 ArrayList (java.util.ArrayList)3 FileOutputStream (java.io.FileOutputStream)2 List (java.util.List)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1