Search in sources :

Example 1 with KieProject

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

the class DMNUpdateTest method test_as_kie_wb_common_services_backend_Builder2.

@Test
public void test_as_kie_wb_common_services_backend_Builder2() throws Exception {
    final KieServices ks = KieServices.Factory.get();
    final ReleaseId v100 = ks.newReleaseId("org.kie", "dmn-test", "1.0.0");
    final KieModule kieModule = KieHelper.createAndDeployJar(ks, v100, ks.getResources().newClassPathResource("v1_2/dmn-hotcold.dmn", this.getClass()));
    final KieContainer kieContainer = ks.newKieContainer(v100);
    final KieSession kieSession = kieContainer.newKieSession();
    final DMNRuntime runtime = kieSession.getKieRuntime(DMNRuntime.class);
    Assert.assertNotNull(runtime);
    assertThat(runtime.getModels(), hasSize(1));
    checkDMNHotColdDMN12WithNSScattered(runtime);
    // the below is performed by the WB at: https://github.com/kiegroup/kie-wb-common/blob/9e6b6da145e61ac8f5a9f7c0259d44aa9d090a2b/kie-wb-common-services/kie-wb-common-services-backend/src/main/java/org/kie/workbench/common/services/backend/builder/core/Builder.java#L592-L620
    final KieProject kieProject = new KieModuleKieProject((InternalKieModule) kieModule, null);
    final KieContainer kieContainer2 = new KieContainerImpl(kieProject, ks.getRepository(), v100);
    // exhibit the issue.
    final KieSession kieSession2 = kieContainer2.newKieSession();
    final DMNRuntime runtime2 = kieSession2.getKieRuntime(DMNRuntime.class);
    Assert.assertNotNull(runtime2);
    assertThat(runtime2.getModels(), hasSize(1));
    checkDMNHotColdDMN12WithNSScattered(runtime2);
}
Also used : KieModuleKieProject(org.drools.compiler.kie.builder.impl.KieModuleKieProject) KieProject(org.drools.compiler.kie.builder.impl.KieProject) KieContainerImpl(org.drools.compiler.kie.builder.impl.KieContainerImpl) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) KieModuleKieProject(org.drools.compiler.kie.builder.impl.KieModuleKieProject) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 2 with KieProject

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

the class WBCommonServicesBackendTest method testProfileWithKieWbCommonServicesBackendBuilder.

@Test
public void testProfileWithKieWbCommonServicesBackendBuilder() throws Exception {
    final KieServices ks = KieServices.Factory.get();
    final ReleaseId v100 = ks.newReleaseId("org.kie", "dmn-test-" + UUID.randomUUID(), "1.0.0");
    final KieModule kieModule = KieHelper.createAndDeployJar(ks, v100, ks.getResources().newClassPathResource("nowGT1970.dmn", this.getClass()));
    final KieContainer kieContainer = ks.newKieContainer(v100);
    final DMNRuntime runtime = KieRuntimeFactory.of(kieContainer.getKieBase()).get(DMNRuntime.class);
    Assert.assertNotNull(runtime);
    assertThat(runtime.getModels(), hasSize(1));
    check_nowGT1970(runtime);
    // the below is performed by the WB at: https://github.com/kiegroup/kie-wb-common/blob/9e6b6da145e61ac8f5a9f7c0259d44aa9d090a2b/kie-wb-common-services/kie-wb-common-services-backend/src/main/java/org/kie/workbench/common/services/backend/builder/core/Builder.java#L592-L620
    final KieProject kieProject = new KieModuleKieProject((InternalKieModule) kieModule, null);
    final KieContainer kieContainer2 = new KieContainerImpl(kieProject, ks.getRepository(), v100);
    final DMNRuntime runtime2 = KieRuntimeFactory.of(kieContainer2.getKieBase()).get(DMNRuntime.class);
    Assert.assertNotNull(runtime2);
    assertThat(runtime2.getModels(), hasSize(1));
    check_nowGT1970(runtime2);
}
Also used : KieModuleKieProject(org.drools.compiler.kie.builder.impl.KieModuleKieProject) KieProject(org.drools.compiler.kie.builder.impl.KieProject) KieContainerImpl(org.drools.compiler.kie.builder.impl.KieContainerImpl) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KieModuleKieProject(org.drools.compiler.kie.builder.impl.KieModuleKieProject) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 3 with KieProject

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

the class KieHelloWorldTest method testClassLoaderStore.

@Test
public void testClassLoaderStore() throws Exception {
    // DROOLS-1766
    String drl = "package org; declare Person name : String end";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl);
    KieUtil.getKieBuilderFromKieFileSystem(kieBaseTestConfiguration, kfs, false);
    KieContainer kcontainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
    KieProject kieProject = ((KieContainerImpl) kcontainer).getKieProject();
    ResultsImpl messages = kieProject.verify();
    assertSame(kieProject.getClassLoader(), kcontainer.getClassLoader());
    ProjectClassLoader pcl = ((ProjectClassLoader) kieProject.getClassLoader());
    assertNotNull(pcl.getStore().get("org/Person.class"));
}
Also used : ProjectClassLoader(org.drools.wiring.api.classloader.ProjectClassLoader) KieFileSystem(org.kie.api.builder.KieFileSystem) KieProject(org.drools.compiler.kie.builder.impl.KieProject) KieContainerImpl(org.drools.compiler.kie.builder.impl.KieContainerImpl) KieServices(org.kie.api.KieServices) ResultsImpl(org.drools.compiler.kie.builder.impl.ResultsImpl) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 4 with KieProject

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

the class KieCDIExtension method addKBaseBean.

public void addKBaseBean(AfterBeanDiscovery abd, KieCDIEntry entry) {
    ReleaseId releaseId = entry.getReleaseId();
    // default to classpath, but allow it to be overridden
    KieContainerImpl kieContainer = classpathKContainer;
    if (releaseId != null) {
        kieContainer = (KieContainerImpl) gavs.get(releaseId);
        if (kieContainer == null) {
            log.error("Unable to create @KBase({}), could not retrieve KieContainer for ReleaseId {}", entry.getValue(), releaseId.toString());
            return;
        }
    }
    KieProject kProject = kieContainer.getKieProject();
    KieBaseModel kBaseModel = null;
    String kBaseQName = entry.getValue();
    if (StringUtils.isEmpty(kBaseQName)) {
        kBaseModel = kProject.getDefaultKieBaseModel();
    } else {
        kBaseModel = kProject.getKieBaseModel(kBaseQName);
    }
    if (kBaseModel == null) {
        log.error("Annotation @KBase({}) found, but no KieBaseModel exists.\nEither the required kmodule.xml does not exist, is corrupted, or is missing the KieBase entry", kBaseQName);
        return;
    }
    if (!kBaseModel.getScope().trim().equals(entry.getScope().getClass().getName())) {
        try {
            if (kBaseModel.getScope().indexOf('.') >= 0) {
                entry.setScope((Class<? extends Annotation>) Class.forName(kBaseModel.getScope()));
            } else {
                entry.setScope((Class<? extends Annotation>) Class.forName("javax.enterprise.context." + kBaseModel.getScope()));
            }
        } catch (ClassNotFoundException e) {
            log.error("KieBaseModule {} overrides default annotation, but it was not able to find it {}\n{}", new String[] { kBaseQName, kBaseModel.getScope(), e.getMessage() });
        }
    }
    KBaseBean bean = new KBaseBean(kBaseQName, kBaseModel, kieContainer, entry.getKReleaseId(), entry.getScope(), entry.getName(), entry.getInjectionPoints());
    if (log.isDebugEnabled()) {
        InternalKieModule kModule = kProject.getKieModuleForKBase(kBaseQName);
        log.debug("Added Bean for @KBase({})", kBaseQName, kModule);
    }
    abd.addBean(bean);
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieProject(org.drools.compiler.kie.builder.impl.KieProject) KieContainerImpl(org.drools.compiler.kie.builder.impl.KieContainerImpl) KReleaseId(org.kie.api.cdi.KReleaseId) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 5 with KieProject

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

the class KieHelloWorldTest method testClassLoaderStore.

@Test
public void testClassLoaderStore() throws Exception {
    // DROOLS-1766
    String drl = "package org; declare Person name : String end";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl);
    ks.newKieBuilder(kfs).buildAll();
    KieContainer kcontainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
    KieProject kieProject = ((KieContainerImpl) kcontainer).getKieProject();
    ResultsImpl messages = kieProject.verify();
    assertSame(kieProject.getClassLoader(), kcontainer.getClassLoader());
    ProjectClassLoader pcl = ((ProjectClassLoader) kieProject.getClassLoader());
    assertNotNull(pcl.getStore().get("org/Person.class"));
}
Also used : ProjectClassLoader(org.drools.core.common.ProjectClassLoader) KieFileSystem(org.kie.api.builder.KieFileSystem) KieProject(org.drools.compiler.kie.builder.impl.KieProject) KieContainerImpl(org.drools.compiler.kie.builder.impl.KieContainerImpl) KieServices(org.kie.api.KieServices) ResultsImpl(org.drools.compiler.kie.builder.impl.ResultsImpl) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Aggregations

KieContainerImpl (org.drools.compiler.kie.builder.impl.KieContainerImpl)9 KieProject (org.drools.compiler.kie.builder.impl.KieProject)9 Test (org.junit.Test)7 KieServices (org.kie.api.KieServices)7 ReleaseId (org.kie.api.builder.ReleaseId)7 KieContainer (org.kie.api.runtime.KieContainer)7 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)6 KieModule (org.kie.api.builder.KieModule)5 KieModuleKieProject (org.drools.compiler.kie.builder.impl.KieModuleKieProject)4 KieSession (org.kie.api.runtime.KieSession)4 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)4 KieFileSystem (org.kie.api.builder.KieFileSystem)3 ResultsImpl (org.drools.compiler.kie.builder.impl.ResultsImpl)2 ProjectClassLoader (org.drools.wiring.api.classloader.ProjectClassLoader)2 KReleaseId (org.kie.api.cdi.KReleaseId)2 KieSessionModelImpl (org.drools.compiler.kproject.models.KieSessionModelImpl)1 ProjectClassLoader (org.drools.core.common.ProjectClassLoader)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 KieBuilder (org.kie.api.builder.KieBuilder)1 KieRepository (org.kie.api.builder.KieRepository)1