use of org.drools.compiler.kie.builder.impl.KieBuilderImpl in project drools by kiegroup.
the class KieBuilderTest method testSetPomModelReuse.
@Test
public void testSetPomModelReuse() throws IOException {
String namespace = "org.kie.test";
ReleaseId releaseId = KieServices.Factory.get().newReleaseId(namespace, "pomModelReuse", "1.0-SNAPSHOT");
String pom = KieBuilderImpl.generatePomXml(releaseId);
KieFileSystem kfs = KieServices.Factory.get().newKieFileSystem();
kfs.writePomXML(pom);
// Create a KieBuilder instance
KieBuilder kieBuilder1 = createKieBuilder(kfs);
kieBuilder1.buildAll();
// Get PomModel to re-use in second KieBuilder instance
PomModel pomModel = ((KieBuilderImpl) kieBuilder1).getPomModel();
kfs.writePomXML(pom);
// Create another KieBuilder instance with the same KieFileSystem, setting PomModel
KieBuilder kieBuilder2 = createKieBuilder(kfs);
((KieBuilderImpl) kieBuilder2).setPomModel(pomModel);
kieBuilder2.buildAll();
// Read pom.xml from first KieBuilder's KieModule
InternalKieModule kieModule1 = (InternalKieModule) ((KieBuilderImpl) kieBuilder1).getKieModuleIgnoringErrors();
final Reader reader1 = kieModule1.getResource("META-INF/maven/org.kie.test/pomModelReuse/pom.xml").getReader();
int charCode;
String readPom1 = "";
while ((charCode = reader1.read()) != -1) {
readPom1 = readPom1 + (char) charCode;
}
reader1.close();
assertEquals(pom, readPom1);
// Read pom.xml from second KieBuilder's KieModule
InternalKieModule kieModule2 = (InternalKieModule) ((KieBuilderImpl) kieBuilder2).getKieModuleIgnoringErrors();
final Reader reader2 = kieModule2.getResource("META-INF/maven/org.kie.test/pomModelReuse/pom.xml").getReader();
String readPom2 = "";
while ((charCode = reader2.read()) != -1) {
readPom2 = readPom2 + (char) charCode;
}
reader1.close();
assertEquals(pom, readPom2);
}
use of org.drools.compiler.kie.builder.impl.KieBuilderImpl in project drools by kiegroup.
the class BuildFromKJarTest method createKieModule.
private InternalKieModule createKieModule(KieServices ks, ReleaseId releaseId) {
KieFileSystem kfs = ks.newKieFileSystem();
kfs.writeKModuleXML(getDefaultKieModuleModel(ks).toXML());
kfs.writePomXML(KJARUtils.getPom(releaseId));
String javaSrc = Person.class.getCanonicalName().replace('.', '/') + ".java";
Resource javaResource = ks.getResources().newFileSystemResource("src/test/java/" + javaSrc);
kfs.write("src/main/java/" + javaSrc, javaResource);
kfs.write("src/main/resources/rule.drl", getRule());
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
List<Message> messages = ((KieBuilderImpl) kieBuilder).buildAll(ExecutableModelFlowProject.class).getResults().getMessages();
if (!messages.isEmpty()) {
fail(messages.toString());
}
return (InternalKieModule) kieBuilder.getKieModule();
}
Aggregations