[jboss-svn-commits] JBL Code SVN: r13518 - in labs/jbossrules/trunk/drools-compiler: src/main/java/org/drools/compiler and 4 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sat Jul 14 21:48:27 EDT 2007
Author: mark.proctor at jboss.com
Date: 2007-07-14 21:48:27 -0400 (Sat, 14 Jul 2007)
New Revision: 13518
Modified:
labs/jbossrules/trunk/drools-compiler/.classpath
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/Dialect.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/DialectConfiguration.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/DialectRegistry.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilderConfiguration.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/java/JavaDialectConfiguration.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELDialectConfiguration.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderConfigurationTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java
Log:
JBRULES-1010 pluggeable Dialect Configuration.
JBRULES-357 When an exception is thrown from PackageBuilder detect what jars are missing
-searches for the jar on setCompiler
Modified: labs/jbossrules/trunk/drools-compiler/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-compiler/.classpath 2007-07-15 00:02:34 UTC (rev 13517)
+++ labs/jbossrules/trunk/drools-compiler/.classpath 2007-07-15 01:48:27 UTC (rev 13518)
@@ -5,14 +5,14 @@
<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/xpp3/xpp3/1.1.3.4.O/xpp3-1.1.3.4.O.jar"/>
<classpathentry kind="var" path="M2_REPO/org/antlr/antlr-runtime/3.0/antlr-runtime-3.0.jar"/>
<classpathentry kind="var" path="M2_REPO/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/xstream/xstream/1.1.3/xstream-1.1.3.jar"/>
<classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
+ <classpathentry kind="src" path="/drools-core"/>
<classpathentry kind="var" path="M2_REPO/org/mvel/mvel14/1.2pre3/mvel14-1.2pre3.jar"/>
- <classpathentry kind="var" path="M2_REPO/xstream/xstream/1.1.3/xstream-1.1.3.jar"/>
+ <classpathentry kind="var" path="M2_REPO/xerces/xercesImpl/2.4.0/xercesImpl-2.4.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/janino/janino/2.5.7/janino-2.5.7.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/xpp3/xpp3/1.1.3.4.O/xpp3-1.1.3.4.O.jar"/>
- <classpathentry kind="var" path="M2_REPO/janino/janino/2.5.7/janino-2.5.7.jar"/>
- <classpathentry kind="var" path="M2_REPO/xerces/xercesImpl/2.4.0/xercesImpl-2.4.0.jar"/>
- <classpathentry kind="src" path="/drools-core"/>
</classpath>
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/Dialect.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/Dialect.java 2007-07-15 00:02:34 UTC (rev 13517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/Dialect.java 2007-07-15 01:48:27 UTC (rev 13518)
@@ -21,6 +21,12 @@
import org.drools.rule.builder.RuleConditionBuilder;
import org.drools.rule.builder.SalienceBuilder;
+/**
+ * A Dialect implementation handles the building and execution of code expressions and blocks for a rule.
+ * This api is considered unstable, and subject to change. Those wishing to implement their own dialects
+ * should look ove the MVEL and Java dialect implementations.
+ *
+ */
public interface Dialect {
void init(PackageBuilder builder);
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/DialectConfiguration.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/DialectConfiguration.java 2007-07-15 00:02:34 UTC (rev 13517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/DialectConfiguration.java 2007-07-15 01:48:27 UTC (rev 13518)
@@ -1,5 +1,11 @@
package org.drools.compiler;
+/**
+ * Each Dialect can have its own configuration. Implementations of this class are typically
+ * loaded via reflection in PackageBuilderConfiguration during the call to buildDialectRegistry().
+ * This Class api is subject to change.
+ *
+ */
public interface DialectConfiguration {
public void init(PackageBuilderConfiguration configuration);
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/DialectRegistry.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/DialectRegistry.java 2007-07-15 00:02:34 UTC (rev 13517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/DialectRegistry.java 2007-07-15 01:48:27 UTC (rev 13518)
@@ -6,7 +6,12 @@
import java.util.List;
import java.util.Map;
-
+/**
+ * A Registry of DialectConfigurations. It is also responsible for issueing actions to all registered
+ * dialects.
+ * This Class api is subject to change.
+ *
+ */
public class DialectRegistry {
private Map map;
@@ -14,60 +19,95 @@
this.map = new HashMap();
}
+ /**
+ * Add a DialectConfiguration to the registry
+ * @param name
+ * @param dialect
+ */
public void addDialectConfiguration(final String name,
- final DialectConfiguration dialect) {
+ final DialectConfiguration dialect) {
this.map.put( name,
dialect );
}
+ /**
+ * Get a DialectConfiguration for a named dialect
+ * @param name
+ * @return
+ */
public DialectConfiguration getDialectConfiguration(final String name) {
return (DialectConfiguration) this.map.get( name );
}
-
+
+ /**
+ * Initialise all registered dialects for the given PackageBuilder.
+ * @param builder
+ */
public void initAll(PackageBuilder builder) {
for ( Iterator it = this.map.values().iterator(); it.hasNext(); ) {
- DialectConfiguration dialect = ( DialectConfiguration ) it.next();
+ DialectConfiguration dialect = (DialectConfiguration) it.next();
dialect.getDialect().init( builder );
- }
+ }
}
-
+
+ /**
+ * Instruct all registered dialects to compile what ever they have attempted to build.
+ *
+ */
public void compileAll() {
for ( Iterator it = this.map.values().iterator(); it.hasNext(); ) {
- DialectConfiguration dialect = ( DialectConfiguration ) it.next();
+ DialectConfiguration dialect = (DialectConfiguration) it.next();
dialect.getDialect().compileAll();
}
}
-
+
+ /**
+ * Return an Iterator of DialectConfigurations
+ * @return
+ */
public Iterator iterator() {
return this.map.values().iterator();
}
-
+
+ /**
+ * Add all registered Dialect results to the provided List.
+ * @param list
+ * @return
+ */
public List addResults(List list) {
if ( list == null ) {
list = new ArrayList();
}
for ( Iterator it = this.map.values().iterator(); it.hasNext(); ) {
- DialectConfiguration dialect = ( DialectConfiguration ) it.next();
+ DialectConfiguration dialect = (DialectConfiguration) it.next();
List results = dialect.getDialect().getResults();
if ( results != null ) {
list.addAll( results );
}
- }
+ }
return list;
}
+ /**
+ * Iterates all registered dialects, informing them of an import added to the PackageBuilder
+ * @param importEntry
+ */
public void addImport(String importEntry) {
for ( Iterator it = this.map.values().iterator(); it.hasNext(); ) {
- DialectConfiguration dialect = ( DialectConfiguration ) it.next();
+ DialectConfiguration dialect = (DialectConfiguration) it.next();
dialect.getDialect().addImport( importEntry );
}
}
-
+
+ /**
+ * Iterates all registered dialects, informing them of a static imports added to the PackageBuilder
+ * @param staticImportEntry
+ */
public void addStaticImport(String staticImportEntry) {
for ( Iterator it = this.map.values().iterator(); it.hasNext(); ) {
- DialectConfiguration dialect = ( DialectConfiguration ) it.next();
+ DialectConfiguration dialect = (DialectConfiguration) it.next();
dialect.getDialect().addStaticImport( staticImportEntry );
- }
+ }
}
-
+
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java 2007-07-15 00:02:34 UTC (rev 13517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java 2007-07-15 01:48:27 UTC (rev 13518)
@@ -54,6 +54,12 @@
* This is the main compiler class for parsing and compiling rules and
* assembling or merging them into a binary Package instance. This can be done
* by merging into existing binary packages, or totally from source.
+ *
+ * If you are using the Java dialect the JavaDialectConfiguration will attempt to
+ * validate that the specified compiler is in the classpath, using ClassLoader.loasClass(String).
+ * If you intented to just Janino sa the compiler you must either overload the compiler
+ * property before instantiating this class or the PackageBuilder, or make sure Eclipse is in the
+ * classpath, as Eclipse is the default.
*/
public class PackageBuilder {
@@ -91,6 +97,11 @@
null );
}
+ /**
+ * Pass a specific configuration for the PackageBuilder
+ *
+ * @param configuration
+ */
public PackageBuilder(final PackageBuilderConfiguration configuration) {
this( null,
configuration );
@@ -440,7 +451,12 @@
return this.pkg;
}
-
+
+ /**
+ * Return the PackageBuilderConfiguration for this PackageBuilder session
+ * @return
+ * The PackageBuilderConfiguration
+ */
public PackageBuilderConfiguration getPackageBuilderConfiguration() {
return this.configuration;
}
@@ -455,6 +471,11 @@
}
}
+ /**
+ * Return the ClassFieldExtractorCache, this should only be used internally, and is subject to change
+ * @return
+ * the ClsasFieldExtractorCache
+ */
public ClassFieldExtractorCache getClassFieldExtractorCache() {
return this.classFieldExtractorCache;
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilderConfiguration.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilderConfiguration.java 2007-07-15 00:02:34 UTC (rev 13517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilderConfiguration.java 2007-07-15 01:48:27 UTC (rev 13518)
@@ -31,16 +31,19 @@
/**
* This class configures the package compiler.
- * There are options to use various flavours of runtime compilers.
- * Apache JCI is used as the interface to all the runtime compilers.
- * You may also use this class to override the class loader defaults that are otherwise used.
+ * Dialects and their DialectConfigurations are handled by the DialectRegistry
* Normally you will not need to look at this class, unless you want to override the defaults.
*
- * You can also use the system property "drools.compiler" to set the desired compiler.
- * The valid values are "ECLIPSE" and "JANINO" only.
- * s
- * The default Java language level is 1.4 but it can be configured using the
- * system property "drools.compiler.lnglevel". Valid values are 1.4, 1.5 and 1.6.
+ * drools.dialect.default = <String>
+ * drools.accumulate.function.<function name> = <qualified class>
+ *
+ * default dialect is java.
+ * Available preconfigured Accumulate functions are:
+ * drools.accumulate.function.average = org.drools.base.accumulators.AverageAccumulateFunction
+ * drools.accumulate.function.max = org.drools.base.accumulators.MaxAccumulateFunction
+ * drools.accumulate.function.min = org.drools.base.accumulators.MinAccumulateFunction
+ * drools.accumulate.function.count = org.drools.base.accumulators.CountAccumulateFunction
+ * drools.accumulate.function.sum = org.drools.base.accumulators.SumAccumulateFunction
*/
public class PackageBuilderConfiguration {
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/java/JavaDialectConfiguration.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/java/JavaDialectConfiguration.java 2007-07-15 00:02:34 UTC (rev 13517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/java/JavaDialectConfiguration.java 2007-07-15 01:48:27 UTC (rev 13518)
@@ -9,6 +9,28 @@
import org.drools.compiler.PackageBuilder;
import org.drools.compiler.PackageBuilderConfiguration;
+/**
+ *
+ * There are options to use various flavours of runtime compilers.
+ * Apache JCI is used as the interface to all the runtime compilers.
+ *
+ * You can also use the system property "drools.compiler" to set the desired compiler.
+ * The valid values are "ECLIPSE" and "JANINO" only.
+ *
+ * drools.dialect.java.compiler = <ECLIPSE|JANINO>
+ * drools.dialect.java.lngLevel = <1.4|1.5|1.6>
+ *
+ * The default compiler is Eclipse and the default lngLevel is 1.4.
+ * The lngLevel will attempt to autodiscover your system using the
+ * system property "java.version"
+ *
+ * The JavaDialectConfiguration will attempt to validate that the specified compiler
+ * is in the classpath, using ClassLoader.loasClass(String). If you intented to
+ * just Janino sa the compiler you must either overload the compiler property before
+ * instantiating this class or the PackageBuilder, or make sure Eclipse is in the
+ * classpath, as Eclipse is the default.
+ *
+ */
public class JavaDialectConfiguration
implements
DialectConfiguration {
@@ -31,7 +53,8 @@
public void init(final PackageBuilderConfiguration conf) {
this.conf = conf;
- setCompiler( getDefaultCompiler() );
+ setCompiler( getDefaultCompiler() );
+
setJavaLanguageLevel( getDefaultLanguageLevel() );
}
@@ -67,6 +90,21 @@
* This overrides the default, and even what was set as a system property.
*/
public void setCompiler(final int compiler) {
+ // check that the jar for the specified compiler are present
+ if ( compiler == ECLIPSE ) {
+ try {
+ getClass().getClassLoader().loadClass( "org.eclipse.jdt.internal.compiler.Compiler" );
+ } catch ( ClassNotFoundException e ) {
+ throw new RuntimeException( "The Eclipse JDT Core jar is not in the classpath" );
+ }
+ } else if ( compiler == JANINO ){
+ try {
+ getClass().getClassLoader().loadClass( "org.codehaus.janino.Parser" );
+ } catch ( ClassNotFoundException e ) {
+ throw new RuntimeException( "The Janino jar is not in the classpath" );
+ }
+ }
+
switch ( compiler ) {
case JavaDialectConfiguration.ECLIPSE :
this.compiler = JavaDialectConfiguration.ECLIPSE;
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELDialectConfiguration.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELDialectConfiguration.java 2007-07-15 00:02:34 UTC (rev 13517)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELDialectConfiguration.java 2007-07-15 01:48:27 UTC (rev 13518)
@@ -5,6 +5,15 @@
import org.drools.compiler.PackageBuilder;
import org.drools.compiler.PackageBuilderConfiguration;
+/**
+ * The MVEL dialect.
+ *
+ * drools.dialect.mvel.strict = <true|false>
+ *
+ * Default strict is true, which means all expressions and the consequence are type safe.
+ * However dynamic mode is still used while executed nested accessors in the field constraints.
+ *
+ */
public class MVELDialectConfiguration
implements
DialectConfiguration {
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderConfigurationTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderConfigurationTest.java 2007-07-15 00:02:34 UTC (rev 13517)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/compiler/PackageBuilderConfigurationTest.java 2007-07-15 01:48:27 UTC (rev 13518)
@@ -45,6 +45,16 @@
public class PackageBuilderConfigurationTest extends TestCase {
+ protected void setUp() throws Exception {
+ System.getProperties().remove( "drools.dialect.java.compiler" );
+ System.getProperties().remove( "drools.dialect.default" );
+ }
+
+ protected void tearDown() throws Exception {
+ System.getProperties().remove( "drools.dialect.java.compiler" );
+ System.getProperties().remove( "drools.dialect.default" );
+ }
+
public void testSystemProperties() {
PackageBuilderConfiguration cfg = new PackageBuilderConfiguration();
JavaDialectConfiguration javaConf = ( JavaDialectConfiguration ) cfg.getDialectConfiguration( "java" );
@@ -81,10 +91,7 @@
final PackageBuilderConfiguration cfg3 = new PackageBuilderConfiguration();
JavaDialectConfiguration javaConf3 = ( JavaDialectConfiguration ) cfg3.getDialectConfiguration( "java" );
assertEquals( javaConf.getCompiler(),
- javaConf3.getCompiler() );
-
- System.getProperties().remove( "drools.dialect.java.compiler" );
-
+ javaConf3.getCompiler() );
}
public void testProgrammaticProperties() {
@@ -99,7 +106,7 @@
final PackageBuilderConfiguration cfg2 = new PackageBuilderConfiguration(properties);
assertEquals( cfg1.getDefaultDialect().getClass(),
- cfg2.getDefaultDialect().getClass() );
+ cfg2.getDefaultDialect().getClass() );
}
public void testMockDialect() {
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java 2007-07-15 00:02:34 UTC (rev 13517)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java 2007-07-15 01:48:27 UTC (rev 13518)
@@ -641,7 +641,7 @@
list.get( 0 ) );
}
- public void testJaninoEval() throws Exception {
+ public void testJaninoEval() throws Exception {
final PackageBuilderConfiguration config = new PackageBuilderConfiguration();
JavaDialectConfiguration javaConf = ( JavaDialectConfiguration ) config.getDialectConfiguration( "java" );
javaConf.setCompiler( JavaDialectConfiguration.JANINO );
More information about the jboss-svn-commits
mailing list