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);
}
}
}
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);
}
}
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);
}
}
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);
}
}
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();
}
Aggregations