[jboss-svn-commits] JBL Code SVN: r31452 - in labs/jbossrules/trunk/drools-guvnor/src: test/java/org/drools/guvnor/server and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Feb 5 08:03:29 EST 2010


Author: Rikkola
Date: 2010-02-05 08:03:29 -0500 (Fri, 05 Feb 2010)
New Revision: 31452

Modified:
   labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/builder/ContentPackageAssembler.java
   labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/ServiceImplementationTest.java
Log:
GUVNOR-501 : Can't call function in another function that is declared 'above'

Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/builder/ContentPackageAssembler.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/builder/ContentPackageAssembler.java	2010-02-05 12:49:36 UTC (rev 31451)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/builder/ContentPackageAssembler.java	2010-02-05 13:03:29 UTC (rev 31452)
@@ -261,18 +261,33 @@
 		// finally, any functions we will load at this point.
 		AssetItemIterator it = this.pkg
 				.listAssetsByFormat(new String[] { AssetFormats.FUNCTION });
-		while (it.hasNext()) {
-			AssetItem func = it.next();
-            if (!func.getDisabled()) {
-                addDrl(func.getContent());
-                if (builder.hasErrors()) {
-                    recordBuilderErrors(func);
-                    builder.clearErrors();
+		
+        // Adds the function DRLs as one string because they might be calling each others.
+        StringBuilder stringBuilder = new StringBuilder();
+        while ( it.hasNext() ) {
+            AssetItem func = it.next();
+            if ( !func.getDisabled() ) {
+                stringBuilder.append( func.getContent() );
+            }
+        }
+        addDrl( stringBuilder.toString() );
+        // If the function part had errors we need to add them one by one to find out which one is bad.
+        if ( builder.hasErrors() ) {
+            builder.clearErrors();
+            it = this.pkg.listAssetsByFormat( new String[]{AssetFormats.FUNCTION} );
+            while ( it.hasNext() ) {
+                AssetItem func = it.next();
+                if ( !func.getDisabled() ) {
+                    addDrl( func.getContent() );
+                    if ( builder.hasErrors() ) {
+                        recordBuilderErrors( func );
+                        builder.clearErrors();
+                    }
                 }
             }
-		}
+        }
 
-		return errors.size() == 0;
+        return errors.size() == 0;
 	}
 
 	private void loadDeclaredTypes() {

Modified: labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/ServiceImplementationTest.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/ServiceImplementationTest.java	2010-02-05 12:49:36 UTC (rev 31451)
+++ labs/jbossrules/trunk/drools-guvnor/src/test/java/org/drools/guvnor/server/ServiceImplementationTest.java	2010-02-05 13:03:29 UTC (rev 31452)
@@ -1951,6 +1951,47 @@
 
 	}
 
+    public void testBuildAssetMultipleFunctionsCallingEachOther() throws Exception {
+
+        ServiceImplementation impl = getService();
+        impl.createPackage( "testBuildAssetMultipleFunctionsCallingEachOther",
+                            "" );
+        impl.createCategory( "/",
+                             "funkytest",
+                             "" );
+
+        String uuidt1 = impl.createNewRule( "t1",
+                                            "",
+                                            "funkytest",
+                                            "testBuildAssetMultipleFunctionsCallingEachOther",
+                                            AssetFormats.FUNCTION );
+        RuleAsset t1 = impl.loadRuleAsset( uuidt1 );
+        RuleContentText t1Content = new RuleContentText();
+        t1Content.content = "function void t1(){\n";
+        t1Content.content += " t2();\n";
+        t1Content.content += "}\n";
+        t1.content = t1Content;    
+        impl.checkinVersion( t1 );
+
+        String uuidt2 = impl.createNewRule( "t2",
+                                            "",
+                                            "funkytest",
+                                            "testBuildAssetMultipleFunctionsCallingEachOther",
+                                            AssetFormats.FUNCTION );
+        RuleAsset t2 = impl.loadRuleAsset( uuidt2 );
+        RuleContentText t2Content = new RuleContentText();
+        t2Content.content = "function void t2(){\n";
+        t2Content.content += " t1();\n";
+        t2Content.content += "}\n";
+        t2.content = t2Content;
+        impl.checkinVersion( t2 );
+
+        BuilderResult[] result = impl.buildAsset( t1 );
+
+        assertNull( result );
+        
+    }
+
 	public void testBuildAssetBRXMLAndCopy() throws Exception {
 		ServiceImplementation impl = getService();
 		RulesRepository repo = impl.repository;



More information about the jboss-svn-commits mailing list