Search in sources :

Example 1 with KieBuilderImpl

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);
}
Also used : KieBuilderImpl(org.drools.compiler.kie.builder.impl.KieBuilderImpl) KieFileSystem(org.kie.api.builder.KieFileSystem) PomModel(org.appformer.maven.support.PomModel) Reader(java.io.Reader) ReleaseId(org.kie.api.builder.ReleaseId) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) Test(org.junit.Test)

Example 2 with KieBuilderImpl

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();
}
Also used : KieBuilderImpl(org.drools.compiler.kie.builder.impl.KieBuilderImpl) KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) Resource(org.kie.api.io.Resource) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Aggregations

InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)2 KieBuilderImpl (org.drools.compiler.kie.builder.impl.KieBuilderImpl)2 KieBuilder (org.kie.api.builder.KieBuilder)2 KieFileSystem (org.kie.api.builder.KieFileSystem)2 Reader (java.io.Reader)1 PomModel (org.appformer.maven.support.PomModel)1 Test (org.junit.Test)1 Message (org.kie.api.builder.Message)1 ReleaseId (org.kie.api.builder.ReleaseId)1 Resource (org.kie.api.io.Resource)1