use of org.drools.compiler.kproject.models.KieBaseModelImpl in project drools by kiegroup.
the class CanonicalKieModule method createKiePackages.
private CanonicalKiePackages createKiePackages(KieProject kieProject, KieBaseModelImpl kBaseModel, BuildContext buildContext, KieBaseConfiguration conf) {
Set<String> includes = kieProject == null ? Collections.emptySet() : kieProject.getTransitiveIncludes(kBaseModel);
List<Process> processes = findProcesses(internalKieModule, kBaseModel);
Collection<Model> modelsForKBase;
if (includes.isEmpty()) {
modelsForKBase = getModelForKBase(kBaseModel);
} else {
modelsForKBase = new ArrayList<>(getModelForKBase(kBaseModel));
for (String include : includes) {
if (StringUtils.isEmpty(include)) {
continue;
}
InternalKieModule includeModule = kieProject.getKieModuleForKBase(include);
if (includeModule == null) {
String text = "Unable to build KieBase, could not find include: " + include;
buildContext.getMessages().addMessage(Message.Level.ERROR, KieModuleModelImpl.KMODULE_SRC_PATH.asString(), text).setKieBaseName(kBaseModel.getName());
continue;
}
if (!(includeModule instanceof CanonicalKieModule)) {
String text = "It is not possible to mix drl based and executable model based projects. Found a drl project: " + include;
buildContext.getMessages().addMessage(Message.Level.ERROR, KieModuleModelImpl.KMODULE_SRC_PATH.asString(), text).setKieBaseName(kBaseModel.getName());
continue;
}
KieBaseModelImpl includeKBaseModel = (KieBaseModelImpl) kieProject.getKieBaseModel(include);
CanonicalKieModule canonicalInclude = (CanonicalKieModule) includeModule;
canonicalInclude.setModuleClassLoader((ProjectClassLoader) kieProject.getClassLoader());
modelsForKBase.addAll(canonicalInclude.getModelForKBase(includeKBaseModel));
processes.addAll(findProcesses(includeModule, includeKBaseModel));
}
}
CanonicalKiePackages canonicalKiePkgs = new KiePackagesBuilder(conf, getBuilderConfiguration(kBaseModel), modelsForKBase).build();
CanonicalKiePackages canonicalKiePackages = mergeProcesses(processes, canonicalKiePkgs);
modelsForKBase.clear();
this.models.clear();
return canonicalKiePackages;
}
use of org.drools.compiler.kproject.models.KieBaseModelImpl in project drools by kiegroup.
the class KieBuilderTest method testKieModuleDependencies.
@Test
public void testKieModuleDependencies() throws ClassNotFoundException, InterruptedException, IOException {
KieServices ks = KieServices.Factory.get();
String namespace1 = "org.kie.test1";
ReleaseId releaseId1 = KieServices.Factory.get().newReleaseId(namespace1, "memory", "1.0");
KieModuleModel kProj1 = createKieProject(namespace1);
KieFileSystem kfs1 = KieServices.Factory.get().newKieFileSystem();
generateAll(kfs1, namespace1, releaseId1, kProj1);
KieBuilder kb1 = createKieBuilder(kfs1);
kb1.buildAll();
if (kb1.getResults().hasMessages(Level.ERROR)) {
fail("Unable to build KieJar\n" + kb1.getResults().toString());
}
KieRepository kr = ks.getRepository();
KieModule kModule1 = kr.getKieModule(releaseId1);
assertNotNull(kModule1);
String namespace2 = "org.kie.test2";
ReleaseId releaseId2 = KieServices.Factory.get().newReleaseId(namespace2, "memory", "1.0");
KieModuleModel kProj2 = createKieProject(namespace2);
KieBaseModelImpl kieBase2 = (KieBaseModelImpl) kProj2.getKieBaseModels().get(namespace2);
kieBase2.addInclude(namespace1);
KieFileSystem kfs2 = KieServices.Factory.get().newKieFileSystem();
generateAll(kfs2, namespace2, releaseId2, kProj2);
KieBuilder kb2 = createKieBuilder(kfs2);
kb2.setDependencies(kModule1);
kb2.buildAll();
if (kb2.getResults().hasMessages(Level.ERROR)) {
fail("Unable to build KieJar\n" + kb2.getResults().toString());
}
KieModule kModule2 = kr.getKieModule(releaseId2);
assertNotNull(kModule2);
KieContainer kContainer = ks.newKieContainer(releaseId2);
KieBase kBase = kContainer.getKieBase(namespace2);
KieSession kSession = kBase.newKieSession();
List list = new ArrayList();
kSession.setGlobal("list", list);
kSession.fireAllRules();
assertEquals(2, list.size());
if ("org.kie.test1.Message".equals(list.get(0).getClass().getName())) {
assertEquals("org.kie.test2.Message", list.get(1).getClass().getName());
} else {
assertEquals("org.kie.test2.Message", list.get(0).getClass().getName());
assertEquals("org.kie.test1.Message", list.get(1).getClass().getName());
}
}
use of org.drools.compiler.kproject.models.KieBaseModelImpl in project drools by kiegroup.
the class KBaseConverter method unmarshal.
public Object unmarshal(HierarchicalStreamReader reader, final UnmarshallingContext context) {
final KieBaseModelImpl kBase = new KieBaseModelImpl();
String kbaseName = reader.getAttribute("name");
kBase.setNameForUnmarshalling(kbaseName != null ? kbaseName : StringUtils.uuid());
kBase.setDefault("true".equals(reader.getAttribute("default")));
String eventMode = reader.getAttribute("eventProcessingMode");
if (eventMode != null) {
kBase.setEventProcessingMode(EventProcessingOption.determineEventProcessingMode(eventMode));
}
String equalsBehavior = reader.getAttribute("equalsBehavior");
if (equalsBehavior != null) {
kBase.setEqualsBehavior(EqualityBehaviorOption.determineEqualityBehavior(equalsBehavior));
}
String mutability = reader.getAttribute("mutability");
if (mutability != null) {
kBase.setMutability(KieBaseMutabilityOption.determineMutability(mutability));
}
String declarativeAgenda = reader.getAttribute("declarativeAgenda");
if (declarativeAgenda != null) {
kBase.setDeclarativeAgenda(DeclarativeAgendaOption.determineDeclarativeAgenda(declarativeAgenda));
}
String sequential = reader.getAttribute("sequential");
if (sequential != null) {
kBase.setSequential(SequentialOption.determineSequential(sequential));
}
String sessionsPool = reader.getAttribute("sessionsPool");
if (sessionsPool != null) {
kBase.setSessionsPool(SessionsPoolOption.get(Integer.parseInt(sessionsPool)));
}
String betaRangeIndex = reader.getAttribute("betaRangeIndex");
if (betaRangeIndex != null) {
kBase.setBetaRangeIndexOption(BetaRangeIndexOption.determineBetaRangeIndex(betaRangeIndex));
}
String scope = reader.getAttribute("scope");
if (scope != null) {
kBase.setScope(scope.trim());
}
String pkgs = reader.getAttribute("packages");
if (pkgs != null) {
for (String pkg : pkgs.split(",")) {
kBase.addPackage(pkg.trim());
}
}
String includes = reader.getAttribute("includes");
if (includes != null) {
for (String include : includes.split(",")) {
kBase.addInclude(include.trim());
}
}
readNodes(reader, new AbstractXStreamConverter.NodeReader() {
public void onNode(HierarchicalStreamReader reader, String name, String value) {
if ("ksession".equals(name)) {
KieSessionModelImpl kSession = readObject(reader, context, KieSessionModelImpl.class);
kBase.getRawKieSessionModels().put(kSession.getName(), kSession);
kSession.setKBase(kBase);
} else if ("ruleTemplate".equals(name)) {
RuleTemplateModelImpl ruleTemplate = readObject(reader, context, RuleTemplateModelImpl.class);
kBase.getRawRuleTemplates().add(ruleTemplate);
ruleTemplate.setKBase(kBase);
}
// @TODO we don't use support nested includes
// if ( "includes".equals( name ) ) {
// for ( String include : readList( reader ) ) {
// kBase.addInclude( include );
// }
// }
}
});
return kBase;
}
Aggregations