[jboss-svn-commits] JBL Code SVN: r15384 - in labs/jbossrules/trunk/drools-ant: src/main/java/org/drools/contrib and 5 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Sep 26 14:28:58 EDT 2007


Author: fmeyer
Date: 2007-09-26 14:28:57 -0400 (Wed, 26 Sep 2007)
New Revision: 15384

Added:
   labs/jbossrules/trunk/drools-ant/src/main/java/org/drools/contrib/DroolsAnalyticsAntTask.java
   labs/jbossrules/trunk/drools-ant/src/main/java/org/drools/contrib/DroolsCompilerAntTask.java
   labs/jbossrules/trunk/drools-ant/src/test/resources/org/
   labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/
   labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/
   labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/Misc.drl
   labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/Misc2.drl
   labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/Misc3.drl
   labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/MissingRangesForDates.drl
   labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/MissingRangesForDoubles.drl
   labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/MissingRangesForInts.drl
   labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/MissingRangesForVariables.drl
Removed:
   labs/jbossrules/trunk/drools-ant/src/main/java/org/drools/contrib/DroolsAntTask.java
Modified:
   labs/jbossrules/trunk/drools-ant/.classpath
   labs/jbossrules/trunk/drools-ant/pom.xml
   labs/jbossrules/trunk/drools-ant/src/test/java/org/drools/contrib/DroolsAntTaskTest.java
   labs/jbossrules/trunk/drools-ant/src/test/resources/DroolsAntTask.xml
Log:
JBRULES-1227 Added drools-analytics support to drools-ant 

Modified: labs/jbossrules/trunk/drools-ant/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-ant/.classpath	2007-09-26 17:11:44 UTC (rev 15383)
+++ labs/jbossrules/trunk/drools-ant/.classpath	2007-09-26 18:28:57 UTC (rev 15384)
@@ -1,20 +1,22 @@
+<?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/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/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="src" path="/drools-compiler"/>
-  <classpathentry kind="var" path="M2_REPO/com/thoughtworks/xstream/xstream/1.2.2/xstream-1.2.2.jar"/>
-  <classpathentry kind="var" path="M2_REPO/ant/ant/1.6.5/ant-1.6.5.jar"/>
-  <classpathentry kind="var" path="M2_REPO/xpp3/xpp3_min/1.1.3.4.O/xpp3_min-1.1.3.4.O.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2.6/mvel14-1.2.6.jar"/>
-  <classpathentry kind="var" path="M2_REPO/janino/janino/2.5.10/janino-2.5.10.jar"/>
-  <classpathentry kind="var" path="M2_REPO/xerces/xercesImpl/2.4.0/xercesImpl-2.4.0.jar"/>
-  <classpathentry kind="src" path="/drools-core"/>
-  <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/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/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="src" path="/drools-compiler"/>
+	<classpathentry kind="var" path="M2_REPO/com/thoughtworks/xstream/xstream/1.2.2/xstream-1.2.2.jar"/>
+	<classpathentry kind="var" path="M2_REPO/ant/ant/1.6.5/ant-1.6.5.jar"/>
+	<classpathentry kind="var" path="M2_REPO/xpp3/xpp3_min/1.1.3.4.O/xpp3_min-1.1.3.4.O.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2.6/mvel14-1.2.6.jar"/>
+	<classpathentry kind="var" path="M2_REPO/janino/janino/2.5.10/janino-2.5.10.jar"/>
+	<classpathentry kind="var" path="M2_REPO/xerces/xercesImpl/2.4.0/xercesImpl-2.4.0.jar"/>
+	<classpathentry kind="src" path="/drools-core"/>
+	<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-analytics"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

Modified: labs/jbossrules/trunk/drools-ant/pom.xml
===================================================================
--- labs/jbossrules/trunk/drools-ant/pom.xml	2007-09-26 17:11:44 UTC (rev 15383)
+++ labs/jbossrules/trunk/drools-ant/pom.xml	2007-09-26 18:28:57 UTC (rev 15384)
@@ -25,11 +25,17 @@
 
     <dependency>
       <groupId>org.drools</groupId>
-      <artifactId>drools-compiler</artifactId>
+      <artifactId>drools-analytics</artifactId>
       <version>${project.version}</version>
     </dependency>
 
     <dependency>
+      <groupId>org.drools</groupId>
+      <artifactId>drools-compiler</artifactId>
+
+    </dependency>
+
+    <dependency>
       <groupId>ant</groupId>
       <artifactId>ant</artifactId>
       <version>1.6.5</version>

Added: labs/jbossrules/trunk/drools-ant/src/main/java/org/drools/contrib/DroolsAnalyticsAntTask.java
===================================================================
--- labs/jbossrules/trunk/drools-ant/src/main/java/org/drools/contrib/DroolsAnalyticsAntTask.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-ant/src/main/java/org/drools/contrib/DroolsAnalyticsAntTask.java	2007-09-26 18:28:57 UTC (rev 15384)
@@ -0,0 +1,168 @@
+package org.drools.contrib;
+
+import java.io.File;
+import java.io.InputStreamReader;
+
+import org.apache.tools.ant.AntClassLoader;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.taskdefs.MatchingTask;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.Reference;
+import org.drools.analytics.Analyzer;
+import org.drools.compiler.DrlParser;
+import org.drools.compiler.DroolsParserException;
+import org.drools.compiler.PackageBuilder;
+import org.drools.lang.descr.PackageDescr;
+
+public class DroolsAnalyticsAntTask extends MatchingTask {
+
+	public static String BRLFILEEXTENSION = ".brl";
+	public static String XMLFILEEXTENSION = ".xml";
+	public static String RULEFLOWFILEEXTENSION = ".rfm";
+	public static String DSLFILEEXTENSION = ".dslr";
+
+	private File srcdir;
+	private File toFile;
+	private Path classpath;
+
+	/**
+	 * Source directory to read DRL files from
+	 * 
+	 * @param directory
+	 */
+	public void setSrcDir(File directory) {
+		this.srcdir = directory;
+	}
+
+	/**
+	 * File to serialize the rulebase to
+	 * 
+	 * @param toFile
+	 */
+	public void setToFile(File toFile) {
+		this.toFile = toFile;
+	}
+
+	/**
+	 * The classpath to use when compiling the rulebase
+	 * 
+	 * @param classpath
+	 */
+	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);
+	}
+
+	/**
+	 * Adds a path to the classpath.
+	 * 
+	 * @return created classpath
+	 */
+	public Path createClasspath() {
+		if (this.classpath == null) {
+			this.classpath = new Path(getProject());
+		}
+		return this.classpath.createPath();
+	}
+
+	/**
+	 * Task's main method
+	 */
+	public void execute() throws BuildException {
+		super.execute();
+
+		// checking parameters are set
+		if (toFile == null) {
+			throw new BuildException(
+					"Destination rulebase file does not specified.");
+		}
+
+		// checking parameters are set
+		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();
+
+			Analyzer droolsanalyzer = new Analyzer();
+
+			// get the list of files to be added to the rulebase
+			String[] fileNames = getFileList();
+
+			for (int i = 0; i < fileNames.length; i++) {
+				compileAndAnalyzeFile(droolsanalyzer, fileNames[i]);
+			}
+			
+			droolsanalyzer.fireAnalysis();
+			droolsanalyzer.writeComponentsHTML(toFile.getAbsolutePath() + "/");
+			
+			System.out.println("Writing analytics report to " + toFile.getAbsolutePath() + "/report");
+			
+		} catch (Exception e) {
+			throw new BuildException("RuleBaseTask failed: " + e.getMessage(),
+					e);
+		}
+	}
+
+	private void compileAndAnalyzeFile(Analyzer droolsanalyzer, String filename) throws DroolsParserException {
+		PackageDescr descr = new DrlParser()
+				.parse(new InputStreamReader(Analyzer.class
+						.getResourceAsStream(filename)));
+		
+		droolsanalyzer.addPackageDescr(descr);
+	}
+
+
+	/**
+	 * @return
+	 */
+	private AntClassLoader getClassLoader() {
+		// defining a new specialized classloader and setting it as the thread
+		// context classloader
+		AntClassLoader loader = null;
+		if (classpath != null) {
+			loader = new AntClassLoader(PackageBuilder.class.getClassLoader(),
+					getProject(), classpath, false);
+		} else {
+			loader = new AntClassLoader(PackageBuilder.class.getClassLoader(),
+					false);
+		}
+		loader.setThreadContextLoader();
+		return loader;
+	}
+
+
+	/**
+	 * Returns the list of files to be added into the rulebase
+	 * 
+	 * @return
+	 */
+	private String[] getFileList() {
+		// scan source directory for rule files
+		DirectoryScanner directoryScanner = getDirectoryScanner(srcdir);
+		String[] fileNames = directoryScanner.getIncludedFiles();
+
+		if (fileNames == null || fileNames.length <= 0) {
+			throw new BuildException(
+					"No rule files found in include directory.");
+		}
+		return fileNames;
+	}
+}


Property changes on: labs/jbossrules/trunk/drools-ant/src/main/java/org/drools/contrib/DroolsAnalyticsAntTask.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Deleted: 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-09-26 17:11:44 UTC (rev 15383)
+++ labs/jbossrules/trunk/drools-ant/src/main/java/org/drools/contrib/DroolsAntTask.java	2007-09-26 18:28:57 UTC (rev 15384)
@@ -1,365 +0,0 @@
-/*
- * Copyright 2006 JBoss Inc
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-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.FilenameFilter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.ObjectOutputStream;
-import java.io.Reader;
-import java.io.StringReader;
-
-import org.apache.tools.ant.AntClassLoader;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.DirectoryScanner;
-import org.apache.tools.ant.taskdefs.MatchingTask;
-import org.apache.tools.ant.types.Path;
-import org.apache.tools.ant.types.Reference;
-import org.drools.RuleBase;
-import org.drools.RuleBaseFactory;
-import org.drools.RuntimeDroolsException;
-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.DrlParser;
-import org.drools.compiler.DroolsParserException;
-import org.drools.compiler.PackageBuilder;
-import org.drools.compiler.PackageBuilderConfiguration;
-import org.drools.lang.Expander;
-import org.drools.lang.dsl.DSLMappingFile;
-import org.drools.lang.dsl.DefaultExpander;
-import org.drools.lang.dsl.DefaultExpanderResolver;
-
-/**
- * An ant task to allow rulebase compilation and serialization during a build.
- * 
- * @author etirelli
- */
-public class DroolsAntTask extends MatchingTask {
-
-	public static String BRLFILEEXTENSION = ".brl";
-	public static String XMLFILEEXTENSION = ".xml";
-	public static String RULEFLOWFILEEXTENSION = ".rfm";
-	public static String DSLFILEEXTENSION = ".dslr";
-
-	private File srcdir;
-	private File toFile;
-	private Path classpath;
-
-	
-	/**
-	 * Source directory to read DRL files from
-	 * 
-	 * @param directory
-	 */
-	public void setSrcDir(File directory) {
-		this.srcdir = directory;
-	}
-
-	/**
-	 * File to serialize the rulebase to
-	 * 
-	 * @param toFile
-	 */
-	public void setToFile(File toFile) {
-		this.toFile = toFile;
-	}
-
-	/**
-	 * The classpath to use when compiling the rulebase
-	 * 
-	 * @param classpath
-	 */
-	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);
-	}
-
-	/**
-	 * Adds a path to the classpath.
-	 * 
-	 * @return created classpath
-	 */
-	public Path createClasspath() {
-		if (this.classpath == null) {
-			this.classpath = new Path(getProject());
-		}
-		return this.classpath.createPath();
-	}
-
-	/**
-	 * Task's main method
-	 */
-	public void execute() throws BuildException {
-		super.execute();
-
-		// checking parameters are set
-		if (toFile == null) {
-			throw new BuildException(
-					"Destination rulebase file does not specified.");
-		}
-
-		// checking parameters are set
-		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();
-
-			// create a package builder configured to use the given classloader
-			PackageBuilder builder = getPackageBuilder(loader);
-
-			// get the list of files to be added to the rulebase
-			String[] fileNames = getFileList();
-
-			for (int i = 0; i < fileNames.length; i++) {
-				// compile rule file and add to the builder
-				compileAndAddFile(builder, fileNames[i]);
-			}
-
-			// gets the package
-			org.drools.rule.Package pkg = builder.getPackage();
-
-			// creates the rulebase
-			RuleBase ruleBase = RuleBaseFactory.newRuleBase();
-
-			// adds the package
-			ruleBase.addPackage(pkg);
-
-			// serialize the rule base to the destination file
-			serializeRulebase(ruleBase);
-
-		} catch (Exception e) {
-			throw new BuildException("RuleBaseTask failed: " + e.getMessage(),
-					e);
-		}
-	}
-
-	/**
-	 * @param ruleBase
-	 * @throws FileNotFoundException
-	 * @throws IOException
-	 */
-	private void serializeRulebase(RuleBase ruleBase)
-			throws FileNotFoundException, IOException {
-		ObjectOutputStream outstream = null;
-		try {
-			FileOutputStream fout = new FileOutputStream(toFile);
-			outstream = new ObjectOutputStream(fout);
-			outstream.writeObject(ruleBase);
-		} finally {
-			if (outstream != null) {
-				outstream.close();
-			}
-		}
-	}
-
-	/**
-	 * @param builder
-	 * @param fileName
-	 * @return
-	 * @throws FileNotFoundException
-	 * @throws DroolsParserException
-	 * @throws IOException
-	 */
-	private void compileAndAddFile(PackageBuilder builder, String fileName)
-			throws FileNotFoundException, DroolsParserException, IOException {
-		InputStreamReader instream = null;
-
-		try {
-
-			if (fileName.endsWith(DroolsAntTask.BRLFILEEXTENSION)) {
-
-				RuleModel model = BRXMLPersistence.getInstance().unmarshal(
-						loadResource(fileName));
-				String packagefile = loadResource(resolvePackageFile(this.srcdir
-						.getAbsolutePath()));
-				model.name = fileName.replace(DroolsAntTask.BRLFILEEXTENSION,
-						"");
-				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));
-			}
-
-			if (fileName.endsWith(DroolsAntTask.RULEFLOWFILEEXTENSION)) {
-				builder.addRuleFlow(instream);
-			} else if (fileName.endsWith(DroolsAntTask.XMLFILEEXTENSION)) {
-				builder.addPackageFromXml(instream);
-			} else if (fileName.endsWith(DroolsAntTask.DSLFILEEXTENSION)) {
-				DrlParser parser = new DrlParser();
-				String expandedDRL = parser.getExpandedDRL(
-						loadResource(fileName), resolveDSLFiles());
-				builder.addPackageFromDrl(new StringReader(expandedDRL));
-			} else {
-				builder.addPackageFromDrl(instream);
-			}
-		} finally {
-			if (instream != null) {
-				instream.close();
-			}
-		}
-	}
-
-	private DefaultExpanderResolver resolveDSLFiles() throws IOException {
-
-		DefaultExpanderResolver resolver = new DefaultExpanderResolver();
-		final File dir = new File(this.srcdir.getAbsolutePath());
-		DSLMappingFile file = new DSLMappingFile();
-
-		FilenameFilter filter = new FilenameFilter() {
-			public boolean accept(File dir, String name) {
-				return name.endsWith(".dsl");
-			}
-		};
-
-		String[] children = dir.list(filter);
-		if (children.length == 0) {
-			throw new BuildException(
-					"There are no DSL files for this directory:"
-							+ this.srcdir.getAbsolutePath());
-		}
-
-		for (int index = 0; index < children.length; index++) {
-			if (file.parseAndLoad(new StringReader(loadResource(children[index])))) {
-				final Expander expander = new DefaultExpander();
-				expander.addDSLMapping(file.getMapping());
-				resolver.addExpander("*", expander);
-			} else {
-				throw new RuntimeDroolsException(
-						"Error parsing and loading DSL file."
-								+ file.getErrors());
-			}
-		}
-
-		return resolver;
-	}
-
-	private String resolvePackageFile(String dirname) {
-
-		File dir = new File(dirname);
-		FilenameFilter filter = new FilenameFilter() {
-			public boolean accept(File dir, String name) {
-				return name.endsWith(".package");
-			}
-		};
-
-		String[] children = dir.list(filter);
-		if (children.length > 1) {
-			throw new BuildException(
-					"There are more than one package configuration file for this directory :"
-							+ dirname);
-		}
-
-		if (children.length == 0) {
-			throw new BuildException(
-					"There is no package configuration file for this directory:"
-							+ dirname);
-		}
-
-		return children[0];
-	}
-
-	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();
-	}
-
-	/**
-	 * @return
-	 */
-	private AntClassLoader getClassLoader() {
-		// defining a new specialized classloader and setting it as the thread
-		// context classloader
-		AntClassLoader loader = null;
-		if (classpath != null) {
-			loader = new AntClassLoader(PackageBuilder.class.getClassLoader(),
-					getProject(), classpath, false);
-		} else {
-			loader = new AntClassLoader(PackageBuilder.class.getClassLoader(),
-					false);
-		}
-		loader.setThreadContextLoader();
-		return loader;
-	}
-
-	/**
-	 * @param loader
-	 * @return
-	 */
-	private PackageBuilder getPackageBuilder(AntClassLoader loader) {
-		// creating package builder configured with the give classloader
-		PackageBuilderConfiguration conf = new PackageBuilderConfiguration();
-		conf.setClassLoader(loader);
-		PackageBuilder builder = new PackageBuilder(conf);
-		return builder;
-	}
-
-	/**
-	 * Returns the list of files to be added into the rulebase
-	 * 
-	 * @return
-	 */
-	private String[] getFileList() {
-		// scan source directory for rule files
-		DirectoryScanner directoryScanner = getDirectoryScanner(srcdir);
-		String[] fileNames = directoryScanner.getIncludedFiles();
-
-		if (fileNames == null || fileNames.length <= 0) {
-			throw new BuildException(
-					"No rule files found in include directory.");
-		}
-		return fileNames;
-	}
-
-}

Copied: labs/jbossrules/trunk/drools-ant/src/main/java/org/drools/contrib/DroolsCompilerAntTask.java (from rev 15383, labs/jbossrules/trunk/drools-ant/src/main/java/org/drools/contrib/DroolsAntTask.java)
===================================================================
--- labs/jbossrules/trunk/drools-ant/src/main/java/org/drools/contrib/DroolsCompilerAntTask.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-ant/src/main/java/org/drools/contrib/DroolsCompilerAntTask.java	2007-09-26 18:28:57 UTC (rev 15384)
@@ -0,0 +1,365 @@
+/*
+ * Copyright 2006 JBoss Inc
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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.FilenameFilter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.ObjectOutputStream;
+import java.io.Reader;
+import java.io.StringReader;
+
+import org.apache.tools.ant.AntClassLoader;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.taskdefs.MatchingTask;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.Reference;
+import org.drools.RuleBase;
+import org.drools.RuleBaseFactory;
+import org.drools.RuntimeDroolsException;
+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.DrlParser;
+import org.drools.compiler.DroolsParserException;
+import org.drools.compiler.PackageBuilder;
+import org.drools.compiler.PackageBuilderConfiguration;
+import org.drools.lang.Expander;
+import org.drools.lang.dsl.DSLMappingFile;
+import org.drools.lang.dsl.DefaultExpander;
+import org.drools.lang.dsl.DefaultExpanderResolver;
+
+/**
+ * An ant task to allow rulebase compilation and serialization during a build.
+ * 
+ * @author etirelli
+ */
+public class DroolsCompilerAntTask extends MatchingTask {
+
+	public static String BRLFILEEXTENSION = ".brl";
+	public static String XMLFILEEXTENSION = ".xml";
+	public static String RULEFLOWFILEEXTENSION = ".rfm";
+	public static String DSLFILEEXTENSION = ".dslr";
+
+	private File srcdir;
+	private File toFile;
+	private Path classpath;
+
+	
+	/**
+	 * Source directory to read DRL files from
+	 * 
+	 * @param directory
+	 */
+	public void setSrcDir(File directory) {
+		this.srcdir = directory;
+	}
+
+	/**
+	 * File to serialize the rulebase to
+	 * 
+	 * @param toFile
+	 */
+	public void setToFile(File toFile) {
+		this.toFile = toFile;
+	}
+
+	/**
+	 * The classpath to use when compiling the rulebase
+	 * 
+	 * @param classpath
+	 */
+	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);
+	}
+
+	/**
+	 * Adds a path to the classpath.
+	 * 
+	 * @return created classpath
+	 */
+	public Path createClasspath() {
+		if (this.classpath == null) {
+			this.classpath = new Path(getProject());
+		}
+		return this.classpath.createPath();
+	}
+
+	/**
+	 * Task's main method
+	 */
+	public void execute() throws BuildException {
+		super.execute();
+
+		// checking parameters are set
+		if (toFile == null) {
+			throw new BuildException(
+					"Destination rulebase file does not specified.");
+		}
+
+		// checking parameters are set
+		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();
+
+			// create a package builder configured to use the given classloader
+			PackageBuilder builder = getPackageBuilder(loader);
+
+			// get the list of files to be added to the rulebase
+			String[] fileNames = getFileList();
+
+			for (int i = 0; i < fileNames.length; i++) {
+				// compile rule file and add to the builder
+				compileAndAddFile(builder, fileNames[i]);
+			}
+
+			// gets the package
+			org.drools.rule.Package pkg = builder.getPackage();
+
+			// creates the rulebase
+			RuleBase ruleBase = RuleBaseFactory.newRuleBase();
+
+			// adds the package
+			ruleBase.addPackage(pkg);
+
+			// serialize the rule base to the destination file
+			serializeRulebase(ruleBase);
+
+		} catch (Exception e) {
+			throw new BuildException("RuleBaseTask failed: " + e.getMessage(),
+					e);
+		}
+	}
+
+	/**
+	 * @param ruleBase
+	 * @throws FileNotFoundException
+	 * @throws IOException
+	 */
+	private void serializeRulebase(RuleBase ruleBase)
+			throws FileNotFoundException, IOException {
+		ObjectOutputStream outstream = null;
+		try {
+			FileOutputStream fout = new FileOutputStream(toFile);
+			outstream = new ObjectOutputStream(fout);
+			outstream.writeObject(ruleBase);
+		} finally {
+			if (outstream != null) {
+				outstream.close();
+			}
+		}
+	}
+
+	/**
+	 * @param builder
+	 * @param fileName
+	 * @return
+	 * @throws FileNotFoundException
+	 * @throws DroolsParserException
+	 * @throws IOException
+	 */
+	private void compileAndAddFile(PackageBuilder builder, String fileName)
+			throws FileNotFoundException, DroolsParserException, IOException {
+		InputStreamReader instream = null;
+
+		try {
+
+			if (fileName.endsWith(DroolsCompilerAntTask.BRLFILEEXTENSION)) {
+
+				RuleModel model = BRXMLPersistence.getInstance().unmarshal(
+						loadResource(fileName));
+				String packagefile = loadResource(resolvePackageFile(this.srcdir
+						.getAbsolutePath()));
+				model.name = fileName.replace(DroolsCompilerAntTask.BRLFILEEXTENSION,
+						"");
+				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));
+			}
+
+			if (fileName.endsWith(DroolsCompilerAntTask.RULEFLOWFILEEXTENSION)) {
+				builder.addRuleFlow(instream);
+			} else if (fileName.endsWith(DroolsCompilerAntTask.XMLFILEEXTENSION)) {
+				builder.addPackageFromXml(instream);
+			} else if (fileName.endsWith(DroolsCompilerAntTask.DSLFILEEXTENSION)) {
+				DrlParser parser = new DrlParser();
+				String expandedDRL = parser.getExpandedDRL(
+						loadResource(fileName), resolveDSLFiles());
+				builder.addPackageFromDrl(new StringReader(expandedDRL));
+			} else {
+				builder.addPackageFromDrl(instream);
+			}
+		} finally {
+			if (instream != null) {
+				instream.close();
+			}
+		}
+	}
+
+	private DefaultExpanderResolver resolveDSLFiles() throws IOException {
+
+		DefaultExpanderResolver resolver = new DefaultExpanderResolver();
+		final File dir = new File(this.srcdir.getAbsolutePath());
+		DSLMappingFile file = new DSLMappingFile();
+
+		FilenameFilter filter = new FilenameFilter() {
+			public boolean accept(File dir, String name) {
+				return name.endsWith(".dsl");
+			}
+		};
+
+		String[] children = dir.list(filter);
+		if (children.length == 0) {
+			throw new BuildException(
+					"There are no DSL files for this directory:"
+							+ this.srcdir.getAbsolutePath());
+		}
+
+		for (int index = 0; index < children.length; index++) {
+			if (file.parseAndLoad(new StringReader(loadResource(children[index])))) {
+				final Expander expander = new DefaultExpander();
+				expander.addDSLMapping(file.getMapping());
+				resolver.addExpander("*", expander);
+			} else {
+				throw new RuntimeDroolsException(
+						"Error parsing and loading DSL file."
+								+ file.getErrors());
+			}
+		}
+
+		return resolver;
+	}
+
+	private String resolvePackageFile(String dirname) {
+
+		File dir = new File(dirname);
+		FilenameFilter filter = new FilenameFilter() {
+			public boolean accept(File dir, String name) {
+				return name.endsWith(".package");
+			}
+		};
+
+		String[] children = dir.list(filter);
+		if (children.length > 1) {
+			throw new BuildException(
+					"There are more than one package configuration file for this directory :"
+							+ dirname);
+		}
+
+		if (children.length == 0) {
+			throw new BuildException(
+					"There is no package configuration file for this directory:"
+							+ dirname);
+		}
+
+		return children[0];
+	}
+
+	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();
+	}
+
+	/**
+	 * @return
+	 */
+	private AntClassLoader getClassLoader() {
+		// defining a new specialized classloader and setting it as the thread
+		// context classloader
+		AntClassLoader loader = null;
+		if (classpath != null) {
+			loader = new AntClassLoader(PackageBuilder.class.getClassLoader(),
+					getProject(), classpath, false);
+		} else {
+			loader = new AntClassLoader(PackageBuilder.class.getClassLoader(),
+					false);
+		}
+		loader.setThreadContextLoader();
+		return loader;
+	}
+
+	/**
+	 * @param loader
+	 * @return
+	 */
+	private PackageBuilder getPackageBuilder(AntClassLoader loader) {
+		// creating package builder configured with the give classloader
+		PackageBuilderConfiguration conf = new PackageBuilderConfiguration();
+		conf.setClassLoader(loader);
+		PackageBuilder builder = new PackageBuilder(conf);
+		return builder;
+	}
+
+	/**
+	 * Returns the list of files to be added into the rulebase
+	 * 
+	 * @return
+	 */
+	private String[] getFileList() {
+		// scan source directory for rule files
+		DirectoryScanner directoryScanner = getDirectoryScanner(srcdir);
+		String[] fileNames = directoryScanner.getIncludedFiles();
+
+		if (fileNames == null || fileNames.length <= 0) {
+			throw new BuildException(
+					"No rule files found in include directory.");
+		}
+		return fileNames;
+	}
+
+}

Modified: labs/jbossrules/trunk/drools-ant/src/test/java/org/drools/contrib/DroolsAntTaskTest.java
===================================================================
--- labs/jbossrules/trunk/drools-ant/src/test/java/org/drools/contrib/DroolsAntTaskTest.java	2007-09-26 17:11:44 UTC (rev 15383)
+++ labs/jbossrules/trunk/drools-ant/src/test/java/org/drools/contrib/DroolsAntTaskTest.java	2007-09-26 18:28:57 UTC (rev 15384)
@@ -30,8 +30,16 @@
     public void setUp() {
         configureProject( "src/test/resources/DroolsAntTask.xml" );
     }
-
     
+    // After analytics left experimental we need to uncomment this unit test
+    public void FIXMEtestAnalyticsReport() {
+        try {
+            executeTarget( "analyticsreport" );
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+        
     public void testDslRules() {
         try {
             executeTarget( "dslRules" );
@@ -67,9 +75,6 @@
         } catch (Exception e) {
             e.printStackTrace();
         }
-    }
+    }    
 
-    public void tearDown() {
-    }
-
 }

Modified: labs/jbossrules/trunk/drools-ant/src/test/resources/DroolsAntTask.xml
===================================================================
--- labs/jbossrules/trunk/drools-ant/src/test/resources/DroolsAntTask.xml	2007-09-26 17:11:44 UTC (rev 15383)
+++ labs/jbossrules/trunk/drools-ant/src/test/resources/DroolsAntTask.xml	2007-09-26 18:28:57 UTC (rev 15384)
@@ -1,7 +1,9 @@
 <project default="rules">
 	
-	<property name="eclipsepath"  value=""/> <!-- Uncomment this for Maven Runner --> 
-	<!-- <property name="eclipsepath"  value="../../../"/> Uncomment this for Eclipse Runner  -->
+	<!-- Uncomment this for Maven Runner -->
+	<property name="eclipsepath"  value=""/>   
+	<!-- Uncomment this for Eclipse Runner  -->
+	<!-- <property name="eclipsepath"  value="../../../"/> -->  
 	
 	<path id="cheese.classpath">
 		<pathelement location="${eclipsepath}lib/cheese.jar"/>
@@ -14,8 +16,20 @@
 		<pathelement location="target"/>
 	</path>	
 	
-	<taskdef name="rulebase" classname="org.drools.contrib.DroolsAntTask" classpathref="drools.classpath" />
+	<taskdef name="rulebase" classname="org.drools.contrib.DroolsCompilerAntTask" classpathref="drools.classpath" />
+	<taskdef name="analytics" classname="org.drools.contrib.DroolsAnalyticsAntTask" classpathref="drools.classpath" />
 	
+	
+	<target name="analyticsreport">
+		<analytics
+			srcdir="${eclipsepath}src/test/resources/org/drools/analytics" 		
+			tofile="${eclipsepath}target/"
+			classpathref="cheese.classpath" >
+			<include name="*.drl" />
+		</analytics>
+	</target>
+	
+	
 	<target name="dslRules" >
 		<rulebase 
 			srcdir="${eclipsepath}src/test/resources/rules" 		

Added: labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/Misc.drl
===================================================================
--- labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/Misc.drl	                        (rev 0)
+++ labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/Misc.drl	2007-09-26 18:28:57 UTC (rev 15384)
@@ -0,0 +1,78 @@
+package com.misc.someData
+
+import com.sample.DroolsTest.Message;
+
+rule "nro 1."
+	when
+		Foo( bar > 10 )
+	then
+		System.out.println("Test");
+end
+
+rule "nro 2."
+	when
+		Foo( bar < 10 )
+	then
+		System.out.println("Test");
+end
+
+rule "Rule with patterns"
+	when
+		    Foo1()
+		    Foo1()
+		    TestPattern1( a == 10, b == 10, c == 10, d == 10, e == 10)
+		    TestPattern2()
+		    TestPattern3()
+		    TestPattern4()
+	then
+		System.out.println( "Test" );
+end
+
+rule "Field rule"
+	when
+		PatThePattern( gg > 100 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Field rule 2"
+	when
+		PatThePattern()
+	then
+		System.out.println( "Test" );
+end
+
+rule "Numbers 1"
+	when
+		NumbersInPattern( x == 10 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Numbers 2"
+	when
+		NumbersInPattern( x == 20 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Numbers 3"
+	when
+		NumbersInPattern( x == 30 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Numbers 5"
+	when
+		NumbersInPattern( x == 50 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Numbers 6"
+	when
+		NumbersInPattern( x == 60 )
+	then
+		System.out.println( "Test" );
+end
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/Misc2.drl
===================================================================
--- labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/Misc2.drl	                        (rev 0)
+++ labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/Misc2.drl	2007-09-26 18:28:57 UTC (rev 15384)
@@ -0,0 +1,130 @@
+package com.misc.missingRanges
+
+import com.sample.DroolsTest.Message;
+
+
+rule "Check time 1"
+	when
+		    Time( startDate > "1-Jan-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Check time 2"
+	when
+		    Foo( startDate <= "10-Jan-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Check time 3"
+	when
+		    Foo( startDate > "10-Jan-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Check time 4"
+	when
+		    Foo( startDate < "20-Jan-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Check time 5"
+	when
+		    Foo( startDate > "27-Jan-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Check time 6"
+	when
+		    Foo( startDate <= "27-Oct-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Check time 7"
+	when
+		    Foo( endDate < "10-Jan-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Check time 8"
+	when
+		    Foo( endDate == "11-Jan-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Check time 9"
+	when
+		    Foo( endDate >= "11-Jan-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Check time 10"
+	when
+		    Foo( endDate < "20-Jan-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Check time 11"
+	when
+		    Foo( endDate >= "20-Jan-2002" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Check time 12"
+	when
+		    Foo( endDate < "13-Oct-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Check time 13"
+	when
+		    Foo( endDate == "13-Oct-2002" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Check time 14"
+	when
+		    Foo( endDate == "14-Oct-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Check time 15"
+	when
+		    Foo( endDate == "15-Oct-2002" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Check time 16"
+	when
+		    Foo( endDate == "25-Oct-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Check time 17"
+	when
+		    Foo( endDate < "26-Oct-2002" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Check time 18"
+	when
+		    Foo( endDate >= "27-Oct-2007" )
+	then
+		System.out.println( "Test" );
+end

Added: labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/Misc3.drl
===================================================================
--- labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/Misc3.drl	                        (rev 0)
+++ labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/Misc3.drl	2007-09-26 18:28:57 UTC (rev 15384)
@@ -0,0 +1,36 @@
+package com.misc.missingRanges
+
+import com.sample.DroolsTest.Message;
+
+
+rule "Some rule 1"
+	when
+		    SuperPattern( temp > 1, bar <= 10.0, a == "first string", b == "second string" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Some rule 2"
+	when
+		    SuperPattern( temp == 1, a == "first string", b == "second string" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Some rule 3"
+	when
+		    sp: SuperPattern( temp < 1, bar == 10.0, a == "first string" )
+		    LesserPattern(  group contains sp )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Some rule 4"
+	when
+		    SuperPattern( temp < 10, bar >= -1.0, a == "first string", b == "second string" )
+		    SuperPattern( temp < 10 a == "first string", b == "second string" )
+		    SuperPattern( temp < 10, a == "first string", b == "second string" )
+		    SuperPattern( temp < 10, a == "first string", b == "second string" )
+	then
+		System.out.println( "Test" );
+end
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/MissingRangesForDates.drl
===================================================================
--- labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/MissingRangesForDates.drl	                        (rev 0)
+++ labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/MissingRangesForDates.drl	2007-09-26 18:28:57 UTC (rev 15384)
@@ -0,0 +1,450 @@
+package com.sample
+
+import com.sample.DroolsTest.Message;
+
+rule "Date gap rule 1"
+	when
+		DatePattern1( value == "27-08-2007" )
+	then
+		# gap > 10 <.
+end
+
+rule "Date gap rule 2"
+	when
+		DatePattern2( value >= "27-08-2000" )
+	then
+		# gap < 15.
+end
+
+rule "Date gap rule 3"
+	when
+		DatePattern3( value <= "27-08-2004" )
+	then
+		# gap > 15.
+end
+
+rule "Date gap rule 4a"
+	when
+		DatePattern4( value > "27-08-2001" )
+	then
+		# gap == 25.
+end
+
+rule "Date gap rule 4b"
+	when
+		DatePattern4( value < "27-08-2001" )
+	then
+		# gap == 25.
+end
+
+rule "Date gap rule 5a"
+	when
+		DatePattern5( value > "20-08-2007" )
+	then
+		# gap 100 > x > 50.
+end
+
+rule "Date gap rule 5b"
+	when
+		DatePattern5( value < "10-Oct-2007" )
+	then
+		# gap 100 > x > 50.
+end
+
+rule "Date gap rule 6a"
+	when
+		DatePattern6( value > "28-Oct-2007" )
+	then
+		# gap < 350.
+end
+
+rule "Date gap rule 6b"
+	when
+		DatePattern6( value == "28-08-2007" )
+	then
+		# gap < 350.
+end
+
+rule "Date gap rule 7a"
+	when
+		DatePattern7( value < "27-01-2007" )
+	then
+		# gap > 55.
+end
+
+rule "Date gap rule 7b"
+	when
+		DatePattern7( value == "27-01-2007" )
+	then
+		# gap > 55.
+end
+
+rule "Date gap rule 8a"
+	when
+		DatePattern8( value < "11-01-2007" )
+	then
+		# No gap
+end
+
+rule "Date gap rule 8b"
+	when
+		DatePattern8( value == "11-01-2007" )
+	then
+		# No gap
+end
+
+rule "Date gap rule 8c"
+	when
+		DatePattern8( value > "11-01-2007" )
+	then
+		# No gap
+end
+
+rule "Date gap rule 9a"
+	when
+		DatePattern9( value <= "14-01-2007" )
+	then
+		# No gap
+end
+
+rule "Date gap rule 9b"
+	when
+		DatePattern9( value == "15-01-2007" )
+	then
+		# No gap
+end
+
+rule "Date gap rule 9c"
+	when
+		DatePattern9( value >= "16-01-2007" )
+	then
+		# No gap
+end
+
+/*
+#
+# These rules have gaps
+#
+rule "Date range 1a, has gap"
+	when
+		    Foo1( value > "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 2a, has gap"
+	when
+		    Foo2( value >= "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 3a, has gap"
+	when
+		    Foo3( value < "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 4a, has gap"
+	when
+		    Foo4( value <= "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 5a, has gap"
+	when
+		    Foo5( value > "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 5b, has gap"
+	when
+		    Foo5( value == "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 6a, has gap"
+	when
+		    Foo6( value < "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 6b, has gap"
+	when
+		    Foo6( value == "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 7a, has gap"
+	when
+		    Foo7( value < "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 7b, has gap"
+	when
+		    Foo7( value > "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 8a, has gap"
+	when
+		    Foo8( value < "03-08-2002" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 8b, has gap"
+	when
+		    Foo8( value > "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 9a, has gap"
+	when
+		    Foo9( value <= "03-08-2002" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 9b, has gap"
+	when
+		    Foo9( value > "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 10a, has gap"
+	when
+		    Foo10( value < "03-08-2002" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 10b, has gap"
+	when
+		    Foo10( value >= "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 11a, has gap"
+	when
+		    Foo11( value <= "03-08-2002" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 11b, has gap"
+	when
+		    Foo11( value >= "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+#
+# Not rules that have gaps.
+#
+
+rule "Date range 12a, has gap"
+	when
+		    not Foo12( value > "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 13a, has gap"
+	when
+		    not Foo13( value >= "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 14a, has gap"
+	when
+		    not Foo14( value < "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 15a, has gap"
+	when
+		    not Foo15( value <= "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 16a, has gap"
+	when
+		    not Foo16( value > "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 16b, has gap"
+	when
+		    not Foo16( value == "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 17a, has gap"
+	when
+		    not Foo17( value < "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 17b, has gap"
+	when
+		    not Foo17( value == "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 18a, has gap"
+	when
+		    not Foo18( value < "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 18b, has gap"
+	when
+		    not Foo18( value > "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 19a, has gap"
+	when
+		    not Foo19( value < "03-08-2002" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 19b, has gap"
+	when
+		    not Foo19( value > "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 20a, has gap"
+	when
+		    not Foo20( value <= "03-08-2002" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 20b, has gap"
+	when
+		    not Foo20( value > "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 21a, has gap"
+	when
+		    not Foo21( value < "03-08-2002" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 21b, has gap"
+	when
+		    not Foo21( value >= "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 22a, has gap"
+	when
+		    not Foo22( value <= "03-08-2002" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 22b, has gap"
+	when
+		    not Foo22( value >= "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+#
+# No gaps
+#
+
+rule "Date range 23a, no gap"
+	when
+		    Foo23( value >= "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 23b, no gap"
+	when
+		    Foo23( value < "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 24a, no gap"
+	when
+		    Foo24( value > "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 24b, no gap"
+	when
+		    Foo24( value <= 27-08-2007 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 25a, no gap"
+	when
+		    Foo25( value >= "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 25b, no gap"
+	when
+		    Foo25( value <= "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 25a, no gap"
+	when
+		    Foo25( value > "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 25b, no gap"
+	when
+		    Foo25( value == "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Date range 25c, no gap"
+	when
+		    Foo25( value < "27-08-2007" )
+	then
+		System.out.println( "Test" );
+end
+*/
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/MissingRangesForDoubles.drl
===================================================================
--- labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/MissingRangesForDoubles.drl	                        (rev 0)
+++ labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/MissingRangesForDoubles.drl	2007-09-26 18:28:57 UTC (rev 15384)
@@ -0,0 +1,464 @@
+package com.sample
+
+import com.sample.DroolsTest.Message;
+
+rule "Double gap rule 1"
+	when
+		DoublePattern1( value == 10.0 )
+	then
+		# gap > 10 <.
+end
+
+rule "Double gap rule 2"
+	when
+		DoublePattern2( value >= 15.0 )
+	then
+		# gap < 15.
+end
+
+rule "Double gap rule 3"
+	when
+		DoublePattern3( value <= 15.0 )
+	then
+		# gap > 15.
+end
+
+rule "Double gap rule 4a"
+	when
+		DoublePattern4( value > 25.0 )
+	then
+		# gap == 25.
+end
+
+rule "Double gap rule 4b"
+	when
+		DoublePattern4( value < 25.0 )
+	then
+		# gap == 25.
+end
+
+rule "Double gap rule 5a"
+	when
+		DoublePattern5( value > 100.0 )
+	then
+		# gap 100 > x > 50.
+end
+
+rule "Double gap rule 5b"
+	when
+		DoublePattern5( value < 50.0 )
+	then
+		# gap 100 > x > 50.
+end
+
+rule "Double gap rule 6a"
+	when
+		DoublePattern6( value > 350.0 )
+	then
+		# gap < 350.
+end
+
+rule "Double gap rule 6b"
+	when
+		DoublePattern6( value == 350.0 )
+	then
+		# gap < 350.
+end
+
+rule "Double gap rule 7a"
+	when
+		DoublePattern7( value < 55.0 )
+	then
+		# gap > 55.
+end
+
+rule "Double gap rule 7b"
+	when
+		DoublePattern7( value == 55.0 )
+	then
+		# gap > 55.
+end
+
+rule "Double gap rule 8a"
+	when
+		DoublePattern8( value < 333.0 )
+	then
+		# No gap
+end
+
+rule "Double gap rule 8b"
+	when
+		DoublePattern8( value == 333.0 )
+	then
+		# No gap
+end
+
+rule "Double gap rule 8c"
+	when
+		DoublePattern8( value > 333.0 )
+	then
+		# No gap
+end
+
+rule "Double gap rule 9a"
+	when
+		DoublePattern9( value >= 400.0 )
+	then
+		# gap 400 > x > 399 
+end
+
+rule "Double gap rule 9b"
+	when
+		DoublePattern9( value <= 399.0 )
+	then
+		# gap 400 > x > 399 
+end
+
+/*
+#
+# These rules have gaps
+#
+rule "Double range 1a, has gap"
+	when
+		    Foo1( value > 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 2a, has gap"
+	when
+		    Foo2( value >= 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 3a, has gap"
+	when
+		    Foo3( value < 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 4a, has gap"
+	when
+		    Foo4( value <= 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 5a, has gap"
+	when
+		    Foo5( value > 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 5b, has gap"
+	when
+		    Foo5( value == 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 6a, has gap"
+	when
+		    Foo6( value < 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 6b, has gap"
+	when
+		    Foo6( value == 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 7a, has gap"
+	when
+		    Foo7( value < 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 7b, has gap"
+	when
+		    Foo7( value > 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 8a, has gap"
+	when
+		    Foo8( value < 40.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 8b, has gap"
+	when
+		    Foo8( value > 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 9a, has gap"
+	when
+		    Foo9( value <= 40.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 9b, has gap"
+	when
+		    Foo9( value > 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 10a, has gap"
+	when
+		    Foo10( value < 40.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 10b, has gap"
+	when
+		    Foo10( value >= 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 11a, has gap"
+	when
+		    Foo11( value <= 40.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 11b, has gap"
+	when
+		    Foo11( value >= 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+#
+# Not rules that have gaps.
+#
+
+rule "Double range 12a, has gap"
+	when
+		    not Foo12( value > 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 13a, has gap"
+	when
+		    not Foo13( value >= 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 14a, has gap"
+	when
+		    not Foo14( value < 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 15a, has gap"
+	when
+		    not Foo15( value <= 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 16a, has gap"
+	when
+		    not Foo16( value > 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 16b, has gap"
+	when
+		    not Foo16( value == 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 17a, has gap"
+	when
+		    not Foo17( value < 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 17b, has gap"
+	when
+		    not Foo17( value == 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 18a, has gap"
+	when
+		    not Foo18( value < 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 18b, has gap"
+	when
+		    not Foo18( value > 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 19a, has gap"
+	when
+		    not Foo19( value < 40.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 19b, has gap"
+	when
+		    not Foo19( value > 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 20a, has gap"
+	when
+		    not Foo20( value <= 40.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 20b, has gap"
+	when
+		    not Foo20( value > 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 21a, has gap"
+	when
+		    not Foo21( value < 40.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 21b, has gap"
+	when
+		    not Foo21( value >= 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 22a, has gap"
+	when
+		    not Foo22( value <= 40.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 22b, has gap"
+	when
+		    not Foo22( value >= 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+#
+# No gaps
+#
+
+rule "Double range 23a, no gap"
+	when
+		    Foo23( value >= 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 23b, no gap"
+	when
+		    Foo23( value < 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 24a, no gap"
+	when
+		    Foo24( value > 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 24b, no gap"
+	when
+		    Foo24( value <= 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 25a, no gap"
+	when
+		    Foo25( value >= 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 25b, no gap"
+	when
+		    Foo25( value <= 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 25a, no gap"
+	when
+		    Foo25( value > 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 25b, no gap"
+	when
+		    Foo25( value == 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 25c, no gap"
+	when
+		    Foo25( value < 42.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 27a, no gap"
+	when
+		    Foo27( value > 0.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 27b, no gap"
+	when
+		    Foo27( value == 0.0 )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Double range 27c, no gap"
+	when
+		    Foo27( value < 0.0 )
+	then
+		System.out.println( "Test" );
+end
+*/

Added: labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/MissingRangesForInts.drl
===================================================================
--- labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/MissingRangesForInts.drl	                        (rev 0)
+++ labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/MissingRangesForInts.drl	2007-09-26 18:28:57 UTC (rev 15384)
@@ -0,0 +1,122 @@
+package com.sample
+
+import com.sample.DroolsTest.Message;
+
+rule "Integer gap rule 1"
+	when
+		IntegerPattern1( value == 10 )
+	then
+		# gap > 10 <.
+end
+
+rule "Integer gap rule 2"
+	when
+		IntegerPattern2( value >= 15 )
+	then
+		# gap < 15.
+end
+
+rule "Integer gap rule 3"
+	when
+		IntegerPattern3( value <= 15 )
+	then
+		# gap > 15.
+end
+
+rule "Integer gap rule 4a"
+	when
+		IntegerPattern4( value > 25 )
+	then
+		# gap == 25.
+end
+
+rule "Integer gap rule 4b"
+	when
+		IntegerPattern4( value < 25 )
+	then
+		# gap == 25.
+end
+
+rule "Integer gap rule 5a"
+	when
+		IntegerPattern5( value > 100 )
+	then
+		# gap 100 > x > 50.
+end
+
+rule "Integer gap rule 5b"
+	when
+		IntegerPattern5( value < 50 )
+	then
+		# gap 100 > x > 50.
+end
+
+rule "Integer gap rule 6a"
+	when
+		IntegerPattern6( value > 350 )
+	then
+		# gap < 350.
+end
+
+rule "Integer gap rule 6b"
+	when
+		IntegerPattern6( value == 350 )
+	then
+		# gap < 350.
+end
+
+rule "Integer gap rule 7a"
+	when
+		IntegerPattern7( value < 55 )
+	then
+		# gap > 55.
+end
+
+rule "Integer gap rule 7b"
+	when
+		IntegerPattern7( value == 55 )
+	then
+		# gap > 55.
+end
+
+rule "Integer gap rule 8a"
+	when
+		IntegerPattern8( value < 333 )
+	then
+		# No gap
+end
+
+rule "Integer gap rule 8b"
+	when
+		IntegerPattern8( value == 333 )
+	then
+		# No gap
+end
+
+rule "Integer gap rule 8c"
+	when
+		IntegerPattern8( value > 333 )
+	then
+		# No gap
+end
+
+rule "Integer gap rule 9a"
+	when
+		IntegerPattern9( value <= 122 )
+	then
+		# No gap
+end
+
+rule "Integer gap rule 9b"
+	when
+		IntegerPattern9( value == 123 )
+	then
+		# No gap
+end
+
+rule "Integer gap rule 9c"
+	when
+		IntegerPattern9( value >= 124 )
+	then
+		# No gap
+end
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/MissingRangesForVariables.drl
===================================================================
--- labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/MissingRangesForVariables.drl	                        (rev 0)
+++ labs/jbossrules/trunk/drools-ant/src/test/resources/org/drools/analytics/MissingRangesForVariables.drl	2007-09-26 18:28:57 UTC (rev 15384)
@@ -0,0 +1,145 @@
+package com.sample
+
+import com.sample.DroolsTest.Message;
+/*
+#
+# These rules have gaps
+#
+rule "Missing variable range 1a, warning"
+	when
+		    $s :Something( )
+		    Foo1w( value > $s.a.b.c.d )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Missing variable range 1b, warning"
+	when
+		    $s :Something( )
+		    Foo1w( value < $s.a.b.c.d )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Missing variable range 2a, warning"
+	when
+		    $s :Something( )
+		    Foo2w( value > $s.bar )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Missing variable range 2b, warning"
+	when
+		    $s :Something( )
+		    Foo2w( value < $s.bar )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Missing variable range 3a, warning"
+	when
+		    Something( $bar :bar)
+		    Foo3w( value > $bar )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Missing variable range 3b, warning"
+	when
+		    Something( $bar :bar)
+		    Foo3w( value < $bar )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Missing variable range 4a, warning"
+	when
+		    Something( $bar :bar)
+		    Foo4w( value > $bar )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Missing variable range 4b, warning"
+	when
+		    Something( $bar :bar)
+		    Foo4w( value == $bar )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Missing variable range 5a, warning"
+	when
+		    Something( $bar :bar)
+		    Foo5w( value < $bar )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Missing variable range 5b, warning"
+	when
+		    Something( $bar :bar)
+		    Foo5w( value == $bar )
+	then
+		System.out.println( "Test" );
+end
+*/
+#
+# These rules have no gaps
+#
+rule "Missing variable range 1a, covers all"
+	when
+		    $s :Something( )
+		    Foo1a( value >= $s.a.b.c.d )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Missing variable range 1b, covers all"
+	when
+		    $s :Something()
+		    Foo1a( value < $s.a.b.c.d )
+	then
+		System.out.println( "Test" );
+end
+/*
+rule "Missing variable range 2a, covers all"
+	when
+		    $s :Something()
+		    Foo2a( value > $s.bar )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Missing variable range 2b, covers all"
+	when
+		    $s :Something( )
+		    Foo2a( value =< $s.bar )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Missing variable range 3a, covers all"
+	when
+		    Something( $bar :bar)
+		    Foo3a( value > $bar )
+	then
+		System.out.println( "Test" );
+end
+
+rule "Missing variable range 3b, covers all"
+	when
+		    Something( $bar :bar)
+		    Foo3a( value == $bar )
+	then
+		System.out.println( "Test" );
+end
+rule "Missing variable range 3c, covers all"
+	when
+		    Something( $bar :bar)
+		    Foo3a( value < $bar )
+	then
+		System.out.println( "Test" );
+end
+*/
\ No newline at end of file




More information about the jboss-svn-commits mailing list