Skip to content

Commit

Permalink
[DROOLS-527] attempt drl compilation even if parsing fail in order to…
Browse files Browse the repository at this point in the history
… give a complete error reporting
  • Loading branch information
mariofusco committed Jun 18, 2014
1 parent e945673 commit 789b4e2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 34 deletions.
Expand Up @@ -837,10 +837,7 @@ public void addPackage(final PackageDescr packageDescr) {
void compileAllRules(PackageDescr packageDescr, PackageRegistry pkgRegistry) {
pkgRegistry.setDialect(getPackageDialect(packageDescr));

// only try to compile if there are no parse errors
if (!hasErrors()) {
compileRules(packageDescr, pkgRegistry);
}
compileRules(packageDescr, pkgRegistry);

compileAll();
try {
Expand Down
Expand Up @@ -895,7 +895,7 @@ public void testDuplicateRuleNames() throws Exception {

builder.addPackage( packageDescr );

assertLength( 1,
assertLength( 2,
builder.getErrors().getErrors() );
final ParserError err = (ParserError) builder.getErrors().getErrors()[0];
assertEquals( 42,
Expand Down
@@ -1,20 +1,11 @@
package org.drools.compiler.integrationtests;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.drools.compiler.CommonTestMethodBase;
import org.drools.compiler.Message;
import org.drools.compiler.kie.builder.impl.KieContainerImpl;
import org.drools.core.definitions.rule.impl.RuleImpl;
import org.drools.core.impl.KnowledgeBaseImpl;
import org.drools.core.reteoo.RuleTerminalNode;
import org.junit.Ignore;
import org.junit.Test;
import org.kie.api.KieServices;
import org.kie.api.builder.KieBuilder;
Expand All @@ -32,7 +23,15 @@
import org.kie.internal.builder.IncrementalResults;
import org.kie.internal.builder.InternalKieBuilder;

import static java.util.Arrays.*;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static java.util.Arrays.asList;

public class IncrementalCompilationTest extends CommonTestMethodBase {

Expand Down Expand Up @@ -484,7 +483,7 @@ public void testIncrementalCompilationWithDuplicatedRuleInSameDRL() throws Excep
.write( "src/main/resources/r1.drl", drl1 );

KieBuilder kieBuilder = ks.newKieBuilder( kfs ).buildAll();
assertEquals( 1, kieBuilder.getResults().getMessages( org.kie.api.builder.Message.Level.ERROR ).size() );
assertEquals( 2, kieBuilder.getResults().getMessages( org.kie.api.builder.Message.Level.ERROR ).size() );
}

@Test
Expand Down Expand Up @@ -1069,7 +1068,6 @@ public void testIncrementalCompilationWithIncludes() throws Exception {
}

@Test
@Ignore("https://issues.jboss.org/browse/DROOLS-527")
public void testIncrementalCompilationWithInvalidDRL() throws Exception {
String drl1 = "Smurf";

Expand All @@ -1091,17 +1089,15 @@ public void testIncrementalCompilationWithInvalidDRL() throws Exception {
KieFileSystem kfs = ks.newKieFileSystem();

//First file contains errors
kfs.write( "src/main/resources/r1.drl",
drl1 );
kfs.write( "src/main/resources/r1.drl", drl1 );

KieBuilder kieBuilder = ks.newKieBuilder( kfs ).buildAll();
Results results1 = kieBuilder.getResults();
assertEquals( 2,
results1.getMessages().size() );

//Second file also contains errors.. expect some added messages
kfs.write( "src/main/resources/r2.drl",
drl2_1 );
kfs.write( "src/main/resources/r2.drl", drl2_1 );
IncrementalResults results2 = ( (InternalKieBuilder) kieBuilder ).createFileSet( "src/main/resources/r2.drl" ).build();

assertEquals( 1,
Expand All @@ -1110,8 +1106,7 @@ public void testIncrementalCompilationWithInvalidDRL() throws Exception {
results2.getRemovedMessages().size() );

//Correct second file... expect original errors relating to the file to be removed
kfs.write( "src/main/resources/r2.drl",
drl2_2 );
kfs.write( "src/main/resources/r2.drl", drl2_2 );
IncrementalResults results3 = ( (InternalKieBuilder) kieBuilder ).createFileSet( "src/main/resources/r2.drl" ).build();

assertEquals( 0,
Expand All @@ -1125,9 +1120,8 @@ public void testIncrementalCompilationWithInvalidDRL() throws Exception {

assertEquals( 0,
results4.getAddedMessages().size() );
assertEquals( 1,
assertEquals( 2,
results4.getRemovedMessages().size() );

}

}
}
@@ -1,16 +1,15 @@
package org.drools.decisiontable.integrationtests;

import java.io.InputStream;

import org.junit.Ignore;
import org.junit.Test;
import org.kie.api.KieServices;
import org.kie.internal.builder.IncrementalResults;
import org.kie.internal.builder.InternalKieBuilder;
import org.kie.api.builder.KieBuilder;
import org.kie.api.builder.KieFileSystem;
import org.kie.internal.builder.IncrementalResults;
import org.kie.internal.builder.InternalKieBuilder;

import java.io.InputStream;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

public class IncrementalCompilationTest {

Expand All @@ -37,7 +36,7 @@ public void testDuplicateXLSResources() throws Exception {
KieServices.Factory.get().getResources().newInputStreamResource( in2 ) );

//Check errors on a full build
assertEquals( 1, ks.newKieBuilder( kfs ).buildAll().getResults().getMessages().size() );
assertEquals( 2, ks.newKieBuilder( kfs ).buildAll().getResults().getMessages().size() );

} finally {
if ( in1 != null ) {
Expand Down Expand Up @@ -82,7 +81,7 @@ public void testIncrementalCompilationDuplicateXLSResources() throws Exception {
assertEquals( 0, addResults.getRemovedMessages().size() );

//Check errors on a full build
assertEquals( 1, ks.newKieBuilder( kfs ).buildAll().getResults().getMessages().size() );
assertEquals( 2, ks.newKieBuilder( kfs ).buildAll().getResults().getMessages().size() );

} finally {
if ( in1 != null ) {
Expand Down

0 comments on commit 789b4e2

Please sign in to comment.