Search in sources :

Example 41 with Results

use of org.kie.api.builder.Results in project drools by kiegroup.

the class KieRepositoryScannerImpl method updateKieModule.

private boolean updateKieModule(DependencyDescriptor oldDependency, Artifact artifact) {
    org.appformer.maven.support.AFReleaseId newReleaseId = new DependencyDescriptor(artifact).getReleaseId();
    InternalKieModule kieModule = createKieModule(newReleaseId, artifact.getFile());
    if (kieModule != null) {
        addDependencies(kieModule, artifactResolver, artifactResolver.getArtifactDependecies(newReleaseId.toString()));
        ResultsImpl messages = kieModule.build();
        if (messages.filterMessages(Message.Level.ERROR).isEmpty()) {
            Results updateMessages = kieContainer.updateDependencyToVersion(adapt(oldDependency.getArtifactReleaseId()), adapt(newReleaseId));
            oldDependency.setArtifactVersion(artifact.getVersion());
            // append all update Results into build Results to notify listeners
            messages.getMessages().addAll(updateMessages.getMessages());
        }
        listeners.fireKieScannerUpdateResultsEventImpl(messages);
        return !messages.hasMessages(Message.Level.ERROR);
    }
    return false;
}
Also used : DependencyDescriptor(org.appformer.maven.integration.DependencyDescriptor) Results(org.kie.api.builder.Results) ResultsImpl(org.drools.compiler.kie.builder.impl.ResultsImpl) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 42 with Results

use of org.kie.api.builder.Results in project drools by kiegroup.

the class KieBuilderTest method checkKModule.

private void checkKModule(final String kmodule, final int expectedErrors) {
    final KieServices ks = KieServices.Factory.get();
    final ReleaseId releaseId = ks.newReleaseId("org.kie", "test-kie-builder", "1.0.0");
    final KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId).writeKModuleXML(kmodule);
    final KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    kieBuilder.buildAll();
    final Results results = kieBuilder.getResults();
    assertEquals(expectedErrors, results.getMessages(org.kie.api.builder.Message.Level.ERROR).size());
    assertNotNull(((InternalKieBuilder) kieBuilder).getKieModuleIgnoringErrors());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) KieBuilder(org.kie.api.builder.KieBuilder)

Example 43 with Results

use of org.kie.api.builder.Results in project drools by kiegroup.

the class KieBuilderTest method testReportKBuilderErrorWhenUsingAJavaClassWithNoPkg.

@Test
public void testReportKBuilderErrorWhenUsingAJavaClassWithNoPkg() {
    // BZ-995018
    final String java = "public class JavaClass { }\n";
    final KieServices ks = KieServices.Factory.get();
    final KieFileSystem kfs = ks.newKieFileSystem().write("src/main/java/JavaClass.java", java);
    final Results results = ks.newKieBuilder(kfs).buildAll().getResults();
    System.out.println(results.getMessages());
    assertEquals(1, results.getMessages().size());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) KieServices(org.kie.api.KieServices) Test(org.junit.Test)

Example 44 with Results

use of org.kie.api.builder.Results in project drools by kiegroup.

the class AccumulateTest method testAccumulateWithoutSeparator.

@Test
public void testAccumulateWithoutSeparator() throws Exception {
    // DROOLS-602
    String str = "package org.drools.compiler\n" + "\n" + "rule \"Constraints everywhere\" \n" + "    when\n" + "        $person : Person( $likes : likes )\n" + "        accumulate( Cheese( type == $likes, $price : price )\n" + "                    $sum : sum( $price ),\n" + "                    $avg : average( $price ),\n" + "                    $min : min( $price );\n" + "                    $min == 3,\n" + "                    $sum > 10 )\n" + "    then\n" + "        // do something\n" + "end  ";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", str);
    Results results = ks.newKieBuilder(kfs).buildAll().getResults();
    assertFalse(results.getMessages().isEmpty());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) QueryResults(org.kie.api.runtime.rule.QueryResults) Results(org.kie.api.builder.Results) KieServices(org.kie.api.KieServices) Test(org.junit.Test)

Example 45 with Results

use of org.kie.api.builder.Results in project drools by kiegroup.

the class AccumulateTest method testIncompatibleListOnAccumulateFunction.

@Test
public void testIncompatibleListOnAccumulateFunction() {
    // DROOLS-1243
    String drl = "import " + MyPerson.class.getCanonicalName() + ";\n" + "import " + BigDecimal.class.getCanonicalName() + ";\n" + "global java.util.List list;\n" + "rule R when\n" + "  $theFrom : String() from accumulate(MyPerson( $val : age ); \n" + "                                          collectList( $val ) )\n" + "then\n" + "  list.add($theFrom);\n" + "end\n";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl);
    Results results = ks.newKieBuilder(kfs).buildAll().getResults();
    assertFalse(results.getMessages().isEmpty());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) QueryResults(org.kie.api.runtime.rule.QueryResults) Results(org.kie.api.builder.Results) KieServices(org.kie.api.KieServices) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

Results (org.kie.api.builder.Results)92 Test (org.junit.Test)81 KieServices (org.kie.api.KieServices)72 KieFileSystem (org.kie.api.builder.KieFileSystem)60 KieContainer (org.kie.api.runtime.KieContainer)36 KieBuilder (org.kie.api.builder.KieBuilder)32 KieSession (org.kie.api.runtime.KieSession)25 IncrementalResults (org.kie.internal.builder.IncrementalResults)20 ReleaseId (org.kie.api.builder.ReleaseId)19 QueryResults (org.kie.api.runtime.rule.QueryResults)17 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)15 KieBase (org.kie.api.KieBase)14 InternalKieBuilder (org.kie.internal.builder.InternalKieBuilder)13 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)11 KieHelper (org.kie.internal.utils.KieHelper)11 KieModuleModel (org.kie.api.builder.model.KieModuleModel)10 FactType (org.kie.api.definition.type.FactType)10 ArrayList (java.util.ArrayList)9 FlatQueryResults (org.drools.core.runtime.rule.impl.FlatQueryResults)9 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)7