Search in sources :

Example 41 with IncrementalResults

use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.

the class IncrementalCompilationNonExecModelTest method testCreateFileSetWithDeclaredModel.

@Test
public void testCreateFileSetWithDeclaredModel() throws InstantiationException, IllegalAccessException {
    final String drl1 = "package myPkg\n" + "declare StringWrapper\n" + " s : String\n" + "end\n";
    // Requires 3 AlphaNodes to enable hash index
    final String drl2_1 = DRL2_COMMON_SRC + "rule R2_C\n" + "when\n" + "  $s : StringWrapper( s == \"Hi Universe\" )\n" + "then\n" + "end\n";
    final String drl2_2 = DRL2_COMMON_SRC + "rule R2_C when\n" + "  $s : StringWrapper( s == \"Hello World\" )\n" + "then\n" + "  System.out.println(\"HIT\");\n" + "end\n";
    final KieServices ks = KieServices.Factory.get();
    final KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/myPkg/r1.drl", drl1).write("src/main/resources/myPkg/r2.drl", drl2_1);
    ReleaseId releaseId1 = ks.newReleaseId("org.default", "artifact", "1.1.0");
    kfs.generateAndWritePomXML(releaseId1);
    KieBuilder kieBuilder = KieUtil.getKieBuilderFromKieFileSystem(kieBaseTestConfiguration, kfs, true);
    final KieContainer kieContainer = ks.newKieContainer(releaseId1);
    runRules(kieContainer, 1);
    // ---------------------
    kfs.delete("src/main/resources/myPkg/r2.drl");
    kfs.write("src/main/resources/myPkg/r2.drl", drl2_2);
    ReleaseId releaseId2 = ks.newReleaseId("org.default", "artifact", "1.2.0");
    kfs.generateAndWritePomXML(releaseId2);
    // buildAll instead of createFileSet doesn't have the issue
    // if (kieBaseTestConfiguration.isExecutableModel()) {
    // kieBuilder = ks.newKieBuilder(kfs).buildAll(ExecutableModelProject.class);
    // } else {
    // kieBuilder = ks.newKieBuilder(kfs).buildAll(DrlProject.class);
    // }
    final IncrementalResults results = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/myPkg/r2.drl").build();
    assertEquals(0, results.getAddedMessages().size());
    assertEquals(0, results.getRemovedMessages().size());
    kieContainer.updateToVersion(releaseId2);
    runRules(kieContainer, 2);
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) IncrementalResults(org.kie.internal.builder.IncrementalResults) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 42 with IncrementalResults

use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.

the class MessageImplTest method testMessageWithIncrementalBuild.

@Test
public void testMessageWithIncrementalBuild() throws Exception {
    // Some suitably duff DSL to generate errors
    String dsl1 = "bananna\n";
    // Some suitably valid DRL
    String drl1 = "import org.drools.mvel.compiler.Person;\n" + "rule R1\n" + "when\n" + "There is a Person\n" + "then\n" + "end\n";
    // Some suitably valid DRL
    String drl2 = "rule R2\n" + "when\n" + "then\n" + "end\n";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/dsl.dsl", dsl1).write("src/main/resources/drl.dslr", drl1);
    final KieBuilder kieBuilder = KieUtil.getKieBuilderFromKieFileSystem(kieBaseTestConfiguration, kfs, false);
    Results fullBuildResults = kieBuilder.getResults();
    assertEquals(3, fullBuildResults.getMessages().size());
    kfs.write("src/main/resources/r2.drl", drl2);
    IncrementalResults incrementalBuildResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
    assertEquals(0, incrementalBuildResults.getAddedMessages().size());
    assertEquals(0, incrementalBuildResults.getRemovedMessages().size());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) IncrementalResults(org.kie.internal.builder.IncrementalResults) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) IncrementalResults(org.kie.internal.builder.IncrementalResults) Test(org.junit.Test)

Example 43 with IncrementalResults

use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.

the class KieModuleIncrementalCompilationTest method testIncrementalCompilationFirstBuildHasErrors.

@Test
public void testIncrementalCompilationFirstBuildHasErrors() throws Exception {
    KieServices ks = KieServices.Factory.get();
    // Malformed POM - No Version information
    ReleaseId releaseId = ks.newReleaseId("org.kie", "incremental-test-with-invalid pom", "");
    KieFileSystem kfs = createKieFileSystemWithKProject(ks);
    kfs.writePomXML(getPom(releaseId));
    // Valid
    String drl1 = "rule R1 when\n" + "   $s : String()\n" + "then\n" + "end\n";
    // Invalid
    String drl2 = "rule R2 when\n" + "   $s : Strin( )\n" + "then\n" + "end\n";
    // Write Rule 1 - No DRL errors, but POM is in error
    kfs.write("src/main/resources/KBase1/r1.drl", drl1);
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    assertEquals(1, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
    // Add file with error - expect 1 "added" error message
    kfs.write("src/main/resources/KBase1/r2.drl", drl2);
    IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/KBase1/r2.drl").build();
    assertEquals(1, addResults.getAddedMessages().size());
    assertEquals(0, addResults.getRemovedMessages().size());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) IncrementalResults(org.kie.internal.builder.IncrementalResults) Test(org.junit.Test)

Example 44 with IncrementalResults

use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.

the class KieModuleIncrementalCompilationTest method checkIncrementalCompilationWithFunctionThenRule.

@Test
public void checkIncrementalCompilationWithFunctionThenRule() throws Exception {
    String rule = "package org.kie.scanner\n" + "rule R1 when\n" + "   String()\n" + "then\n" + "   System.out.println(MyFunction());\n" + "end\n";
    String function = "package org.kie.scanner\n" + "function int MyFunction() {\n" + "   return 1;\n" + "}\n";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    kfs.write("src/main/resources/org/kie/scanner/function.drl", function);
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    assertEquals(0, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
    kfs.write("src/main/resources/org/kie/scanner/rule.drl", rule);
    IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/org/kie/scanner/rule.drl").build();
    assertEquals(0, addResults.getAddedMessages().size());
    assertEquals(0, addResults.getRemovedMessages().size());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) IncrementalResults(org.kie.internal.builder.IncrementalResults) Test(org.junit.Test)

Aggregations

IncrementalResults (org.kie.internal.builder.IncrementalResults)44 Test (org.junit.Test)42 KieServices (org.kie.api.KieServices)42 KieFileSystem (org.kie.api.builder.KieFileSystem)42 KieBuilder (org.kie.api.builder.KieBuilder)39 InternalKieBuilder (org.kie.internal.builder.InternalKieBuilder)39 KieContainer (org.kie.api.runtime.KieContainer)14 ReleaseId (org.kie.api.builder.ReleaseId)13 KieSession (org.kie.api.runtime.KieSession)10 Results (org.kie.api.builder.Results)8 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)8 Message (org.kie.api.builder.Message)5 ArrayList (java.util.ArrayList)4 StringReader (java.io.StringReader)3 Message (org.drools.testcoverage.common.model.Message)3 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)3 KieBuilderSetImpl (org.drools.compiler.kie.builder.impl.KieBuilderSetImpl)2 KieModuleModel (org.kie.api.builder.model.KieModuleModel)2 ClassObjectFilter (org.kie.api.runtime.ClassObjectFilter)2 InputStream (java.io.InputStream)1