use of org.drools.compiler.kie.builder.impl.KieContainerImpl in project drools by kiegroup.
the class KieProjectRuntimeModulesTest method createMultipleJarAndFileResources.
@Test
public void createMultipleJarAndFileResources() 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 = ((RuleBase) 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");
}
use of org.drools.compiler.kie.builder.impl.KieContainerImpl 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);
}
use of org.drools.compiler.kie.builder.impl.KieContainerImpl in project drools by kiegroup.
the class KieCDIExtension method addKContainerBean.
public void addKContainerBean(AfterBeanDiscovery abd, KieCDIEntry entry) {
ReleaseId releaseId = entry.getReleaseId();
// default to classpath, but allow it to be overriden
KieContainerImpl kieContainer = classpathKContainer;
if (releaseId != null) {
kieContainer = (KieContainerImpl) gavs.get(releaseId);
if (kieContainer == null) {
log.error("Could not retrieve KieContainer for ReleaseId {}", entry.getValue(), releaseId.toString());
return;
}
}
KContainerBean bean = new KContainerBean(kieContainer, entry.getKReleaseId(), entry.getName(), entry.getInjectionPoints());
if (log.isDebugEnabled()) {
log.debug("Added Bean for @KContainer({})", releaseId);
}
abd.addBean(bean);
}
use of org.drools.compiler.kie.builder.impl.KieContainerImpl 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");
}
use of org.drools.compiler.kie.builder.impl.KieContainerImpl 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"));
}
Aggregations