[jboss-svn-commits] JBL Code SVN: r14453 - in labs/jbossrules/trunk/drools-ant: src/main/java/org/drools/contrib and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Aug 22 16:24:49 EDT 2007
Author: fmeyer
Date: 2007-08-22 16:24:49 -0400 (Wed, 22 Aug 2007)
New Revision: 14453
Added:
labs/jbossrules/trunk/drools-ant/src/test/resources/rules/Person.brl
labs/jbossrules/trunk/drools-ant/src/test/resources/rules/rule.package
Modified:
labs/jbossrules/trunk/drools-ant/.classpath
labs/jbossrules/trunk/drools-ant/src/main/java/org/drools/contrib/DroolsAntTask.java
labs/jbossrules/trunk/drools-ant/src/test/resources/DroolsAntTask.xml
Log:
JBRULES-1028 - added support for brl in ant task
Modified: labs/jbossrules/trunk/drools-ant/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-ant/.classpath 2007-08-22 19:24:58 UTC (rev 14452)
+++ labs/jbossrules/trunk/drools-ant/.classpath 2007-08-22 20:24:49 UTC (rev 14453)
@@ -1,20 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry kind="src" path="src/test/java" output="target/test-classes"/>
- <classpathentry kind="src" path="src/test/resources" output="target/test-classes" excluding="**/*.java"/>
- <classpathentry kind="output" path="target/classes"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="var" path="M2_REPO/ant/ant/1.6.5/ant-1.6.5.jar"/>
- <classpathentry kind="var" path="M2_REPO/janino/janino/2.5.7/janino-2.5.7.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/drools/drools-compiler/4.0.1.SNAPSHOT/drools-compiler-4.0.1.SNAPSHOT.jar" sourcepath="M2_REPO/org/drools/drools-compiler/4.0.1.SNAPSHOT/drools-compiler-4.0.1.SNAPSHOT-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/drools/drools-core/4.0.1.SNAPSHOT/drools-core-4.0.1.SNAPSHOT.jar" sourcepath="M2_REPO/org/drools/drools-core/4.0.1.SNAPSHOT/drools-core-4.0.1.SNAPSHOT-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/ant/ant-nodeps/1.6.5/ant-nodeps-1.6.5.jar"/>
- <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
- <classpathentry kind="var" path="M2_REPO/xpp3/xpp3/1.1.3.4.O/xpp3-1.1.3.4.O.jar"/>
- <classpathentry kind="var" path="M2_REPO/xstream/xstream/1.1.3/xstream-1.1.3.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/antlr/antlr-runtime/3.0/antlr-runtime-3.0.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/eclipse/jdt/core/3.2.3.v_686_R32x/core-3.2.3.v_686_R32x.jar"/>
- <classpathentry kind="var" path="M2_REPO/xerces/xercesImpl/2.4.0/xercesImpl-2.4.0.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2rc1rv805/mvel14-1.2rc1rv805.jar"/>
- <classpathentry kind="var" path="M2_REPO/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar"/>
-</classpath>
\ No newline at end of file
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+ <classpathentry excluding="**/*.java" kind="src" output="target/test-classes" path="src/test/resources"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="var" path="M2_REPO/ant/ant/1.6.5/ant-1.6.5.jar"/>
+ <classpathentry kind="var" path="M2_REPO/janino/janino/2.5.7/janino-2.5.7.jar"/>
+ <classpathentry kind="var" path="M2_REPO/ant/ant-nodeps/1.6.5/ant-nodeps-1.6.5.jar"/>
+ <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/xpp3/xpp3/1.1.3.4.O/xpp3-1.1.3.4.O.jar"/>
+ <classpathentry kind="var" path="M2_REPO/xstream/xstream/1.1.3/xstream-1.1.3.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/antlr/antlr-runtime/3.0/antlr-runtime-3.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/eclipse/jdt/core/3.2.3.v_686_R32x/core-3.2.3.v_686_R32x.jar"/>
+ <classpathentry kind="var" path="M2_REPO/xerces/xercesImpl/2.4.0/xercesImpl-2.4.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2rc1rv805/mvel14-1.2rc1rv805.jar"/>
+ <classpathentry kind="var" path="M2_REPO/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/drools-compiler"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/drools-core"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Modified: labs/jbossrules/trunk/drools-ant/src/main/java/org/drools/contrib/DroolsAntTask.java
===================================================================
--- labs/jbossrules/trunk/drools-ant/src/main/java/org/drools/contrib/DroolsAntTask.java 2007-08-22 19:24:58 UTC (rev 14452)
+++ labs/jbossrules/trunk/drools-ant/src/main/java/org/drools/contrib/DroolsAntTask.java 2007-08-22 20:24:49 UTC (rev 14453)
@@ -16,13 +16,16 @@
package org.drools.contrib;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
+import java.io.Reader;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildException;
@@ -32,6 +35,9 @@
import org.apache.tools.ant.types.Reference;
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
+import org.drools.brms.client.modeldriven.brl.RuleModel;
+import org.drools.brms.server.util.BRDRLPersistence;
+import org.drools.brms.server.util.BRXMLPersistence;
import org.drools.compiler.DroolsParserException;
import org.drools.compiler.PackageBuilder;
import org.drools.compiler.PackageBuilderConfiguration;
@@ -74,24 +80,24 @@
public void setClasspath(Path classpath) {
createClasspath().append( classpath );
}
-
+
/**
* Classpath to use, by reference, when compiling the rulebase
*
* @param r a reference to an existing classpath
*/
public void setClasspathref(Reference r) {
- createClasspath().setRefid(r);
+ createClasspath().setRefid( r );
}
-
+
/**
* Adds a path to the classpath.
*
* @return created classpath
*/
public Path createClasspath() {
- if( this.classpath == null) {
- this.classpath = new Path(getProject());
+ if ( this.classpath == null ) {
+ this.classpath = new Path( getProject() );
}
return this.classpath.createPath();
}
@@ -108,10 +114,14 @@
}
// checking parameters are set
- if ( srcdir == null || !srcdir.exists() ) {
- throw new BuildException( "Source directory not specified or does not exists." );
+ if ( srcdir == null ) {
+ throw new BuildException( "Source directory not specified." );
}
+ if ( !srcdir.exists() ) {
+ throw new BuildException( "Source directory does not exists." + srcdir.getAbsolutePath() );
+ }
+
try {
// create a specialized classloader
AntClassLoader loader = getClassLoader();
@@ -179,17 +189,45 @@
DroolsParserException,
IOException {
InputStreamReader instream = null;
+
try {
- File file = new File( this.srcdir,
- fileName );
- instream = new InputStreamReader( new FileInputStream( file ) );
+ if ( fileName.endsWith( BRXMLPersistence.FILEEXTENSION ) ) {
+ RuleModel model = BRXMLPersistence.getInstance().unmarshal( loadResource( fileName ) );
+ String packagefile = loadResource( "rule.package" );
+ model.name = fileName.replace( BRXMLPersistence.FILEEXTENSION, "" );
+ ByteArrayInputStream istream = new ByteArrayInputStream( (packagefile + BRDRLPersistence.getInstance().marshal( model )).getBytes() );
+ instream = new InputStreamReader( istream );
+ } else {
+
+ File file = new File( this.srcdir,
+ fileName );
+
+ instream = new InputStreamReader( new FileInputStream( file ) );
+ }
+
builder.addPackageFromDrl( instream );
} finally {
if ( instream != null ) {
instream.close();
}
}
+ }
+ private String loadResource(final String name) throws IOException {
+
+ final InputStream in = new FileInputStream( this.srcdir + "/" + name );
+ final Reader reader = new InputStreamReader( in );
+ final StringBuffer text = new StringBuffer();
+ final char[] buf = new char[1024];
+ int len = 0;
+
+ while ( (len = reader.read( buf )) >= 0 ) {
+ text.append( buf,
+ 0,
+ len );
+ }
+
+ return text.toString();
}
/**
@@ -237,4 +275,5 @@
}
return fileNames;
}
+
}
Modified: labs/jbossrules/trunk/drools-ant/src/test/resources/DroolsAntTask.xml
===================================================================
--- labs/jbossrules/trunk/drools-ant/src/test/resources/DroolsAntTask.xml 2007-08-22 19:24:58 UTC (rev 14452)
+++ labs/jbossrules/trunk/drools-ant/src/test/resources/DroolsAntTask.xml 2007-08-22 20:24:49 UTC (rev 14453)
@@ -1,27 +1,28 @@
<project default="rules">
+ <property name="eclipsepath" value=""/>
+ <!-- enable for eclipse test runner <property name="eclipsepath" value="../../../"/> -->
+
<path id="cheese.classpath">
- <pathelement location="lib/cheese.jar"/>
+ <pathelement location="${eclipsepath}lib/cheese.jar"/>
</path>
<path id="drools.classpath">
- <fileset dir="../m2_repo">
+ <fileset dir="${eclipsepath}../m2_repo">
<include name="**/*.jar"/>
</fileset>
<pathelement location="target"/>
</path>
- <taskdef name="rulebase"
- classname="org.drools.contrib.DroolsAntTask"
- classpathref="drools.classpath" />
+ <taskdef name="rulebase" classname="org.drools.contrib.DroolsAntTask" classpathref="drools.classpath" />
-
<target name="rules" >
<rulebase
- srcdir="src/test/resources/rules"
- tofile="target/cheese.rules"
+ srcdir="${eclipsepath}src/test/resources/rules"
+ tofile="${eclipsepath}target/cheese.rules"
classpathref="cheese.classpath" >
<include name="*.drl" />
+ <include name="*.brl" />
</rulebase>
</target>
Added: labs/jbossrules/trunk/drools-ant/src/test/resources/rules/Person.brl
===================================================================
--- labs/jbossrules/trunk/drools-ant/src/test/resources/rules/Person.brl (rev 0)
+++ labs/jbossrules/trunk/drools-ant/src/test/resources/rules/Person.brl 2007-08-22 20:24:49 UTC (rev 14453)
@@ -0,0 +1,49 @@
+<rule>
+ <modelVersion>1.0</modelVersion>
+ <attributes>
+ <attribute>
+ <attributeName>no-loop</attributeName>
+ <value>true</value>
+ </attribute>
+ </attributes>
+ <lhs>
+ <fact>
+ <constraintList>
+ <constraints>
+ <fieldConstraint>
+ <fieldBinding>f1</fieldBinding>
+ <fieldName>age</fieldName>
+ <operator><</operator>
+ <value>42</value>
+ <constraintValueType>0</constraintValueType>
+ </fieldConstraint>
+ </constraints>
+ </constraintList>
+ <factType>Person</factType>
+ <boundName>p1</boundName>
+ </fact>
+ <compositePattern>
+ <type>not</type>
+ <patterns>
+ <fact>
+ <factType>Cheese</factType>
+ </fact>
+ </patterns>
+ </compositePattern>
+ </lhs>
+ <rhs>
+ <modify>
+ <variable>p1</variable>
+ <fieldValues>
+ <fieldValue>
+ <field>status</field>
+ <value>rejected</value>
+ <type>String</type>
+ </fieldValue>
+ </fieldValues>
+ </modify>
+ <retract>
+ <variableName>p1</variableName>
+ </retract>
+ </rhs>
+</rule>
Added: labs/jbossrules/trunk/drools-ant/src/test/resources/rules/rule.package
===================================================================
--- labs/jbossrules/trunk/drools-ant/src/test/resources/rules/rule.package (rev 0)
+++ labs/jbossrules/trunk/drools-ant/src/test/resources/rules/rule.package 2007-08-22 20:24:49 UTC (rev 14453)
@@ -0,0 +1,8 @@
+//This is a package configuration file
+//Add imports, globals etc here which will be used by all the rule assets in thise folder.
+
+package org.drools.test;
+
+import org.drools.Person;
+import org.drools.contrib.Cheese;
+
More information about the jboss-svn-commits
mailing list