[jboss-svn-commits] JBL Code SVN: r17679 - in labs/jbossrules/branches/Branch_4_0_2_SOA_4_2: drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel and 6 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jan 10 11:27:23 EST 2008
Author: fmeyer
Date: 2008-01-10 11:27:23 -0500 (Thu, 10 Jan 2008)
New Revision: 17679
Added:
labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/test/resources/org/drools/integrationtests/test_DuplicateLocalVariableMVELConsequence.drl
labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/test/resources/org/drools/integrationtests/test_LocalVariableMVELConsequence.drl
labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/m2_repo/org/mvel/mvel14/1.2.20/
labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/m2_repo/org/mvel/mvel14/1.2.20/mvel14-1.2.20.jar
labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/m2_repo/org/mvel/mvel14/1.2.20/mvel14-1.2.20.pom
Removed:
labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/m2_repo/org/mvel/mvel14/1.2.20/mvel14-1.2.20.jar
labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/m2_repo/org/mvel/mvel14/1.2.20/mvel14-1.2.20.pom
Modified:
labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELAccumulateBuilder.java
labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELConsequenceBuilder.java
labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELDialect.java
labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELEvalBuilder.java
labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELFromBuilder.java
labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELPredicateBuilder.java
labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELReturnValueBuilder.java
labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELSalienceBuilder.java
labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/test/java/org/drools/Cheese.java
labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/test/java/org/drools/integrationtests/DynamicRulesTest.java
labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/test/java/org/drools/integrationtests/MVELTest.java
labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java
labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELFactory.java
labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/pom.xml
Log:
SOA-298 org.mvel.CompileException: variable already defined within scope JBRULES-1397
Modified: labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELAccumulateBuilder.java
===================================================================
--- labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELAccumulateBuilder.java 2008-01-10 16:26:50 UTC (rev 17678)
+++ labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELAccumulateBuilder.java 2008-01-10 16:27:23 UTC (rev 17679)
@@ -99,6 +99,7 @@
analysis,
null,
source.getOuterDeclarations(),
+ null,
context );
AccumulateFunction function = context.getConfiguration().getAccumulateFunction( accumDescr.getFunctionIdentifier() );
@@ -117,12 +118,12 @@
null,
accumDescr.getActionCode(),
initCodeAnalysis.getMvelVariables() );
- actionCodeAnalysis.setMvelVariables( initCodeAnalysis.getMvelVariables() );
+ //actionCodeAnalysis.setMvelVariables( initCodeAnalysis.getMvelVariables() );
final MVELAnalysisResult resultCodeAnalysis = (MVELAnalysisResult) dialect.analyzeExpression( context,
accumDescr,
accumDescr.getResultCode(),
initCodeAnalysis.getMvelVariables() );
- resultCodeAnalysis.setMvelVariables( initCodeAnalysis.getMvelVariables() );
+ //resultCodeAnalysis.setMvelVariables( initCodeAnalysis.getMvelVariables() );
final List requiredDeclarations = new ArrayList( initCodeAnalysis.getBoundIdentifiers()[0] );
requiredDeclarations.addAll( actionCodeAnalysis.getBoundIdentifiers()[0] );
@@ -144,11 +145,13 @@
initCodeAnalysis,
null,
source.getOuterDeclarations(),
+ null,
context );
final Serializable action = dialect.compile( (String) accumDescr.getActionCode(),
actionCodeAnalysis,
null,
source.getOuterDeclarations(),
+ initCodeAnalysis.getMvelVariables(),
context );
Serializable reverse = null;
@@ -157,6 +160,7 @@
resultCodeAnalysis,
null,
source.getOuterDeclarations(),
+ initCodeAnalysis.getMvelVariables(),
context );
}
@@ -164,6 +168,7 @@
resultCodeAnalysis,
null,
source.getOuterDeclarations(),
+ initCodeAnalysis.getMvelVariables(),
context );
accumulator = new MVELAccumulator( factory,
Modified: labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELConsequenceBuilder.java
===================================================================
--- labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELConsequenceBuilder.java 2008-01-10 16:26:50 UTC (rev 17678)
+++ labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELConsequenceBuilder.java 2008-01-10 16:27:23 UTC (rev 17679)
@@ -81,6 +81,7 @@
analysis,
dialect.getInterceptors(),
null,
+ null,
context );
final DroolsMVELFactory factory = new DroolsMVELFactory( context.getDeclarationResolver().getDeclarations(),
@@ -94,7 +95,7 @@
context.getErrors().add( new RuleError( context.getRule(),
context.getRuleDescr(),
null,
- "Unable to build expression for 'consequence' '" + context.getRuleDescr().getConsequence() + "'" ) );
+ "Unable to build expression for 'consequence': "+e.getMessage()+" '" + context.getRuleDescr().getConsequence() + "'" ) );
}
}
Modified: labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELDialect.java
===================================================================
--- labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELDialect.java 2008-01-10 16:26:50 UTC (rev 17678)
+++ labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELDialect.java 2008-01-10 16:27:23 UTC (rev 17679)
@@ -66,46 +66,46 @@
implements
Dialect {
- public final static String ID = "mvel";
+ public final static String ID = "mvel";
- private final static String EXPRESSION_DIALECT_NAME = "MVEL";
+ private final static String EXPRESSION_DIALECT_NAME = "MVEL";
- private final MVELRuleClassBuilder rule = new MVELRuleClassBuilder();
+ private final MVELRuleClassBuilder rule = new MVELRuleClassBuilder();
- private final PatternBuilder pattern = new PatternBuilder();
- private final QueryBuilder query = new QueryBuilder();
- private final MVELAccumulateBuilder accumulate = new MVELAccumulateBuilder();
- private final SalienceBuilder salience = new MVELSalienceBuilder();
- private final MVELEvalBuilder eval = new MVELEvalBuilder();
- private final MVELPredicateBuilder predicate = new MVELPredicateBuilder();
- private final MVELReturnValueBuilder returnValue = new MVELReturnValueBuilder();
- private final MVELConsequenceBuilder consequence = new MVELConsequenceBuilder();
+ private final PatternBuilder pattern = new PatternBuilder();
+ private final QueryBuilder query = new QueryBuilder();
+ private final MVELAccumulateBuilder accumulate = new MVELAccumulateBuilder();
+ private final SalienceBuilder salience = new MVELSalienceBuilder();
+ private final MVELEvalBuilder eval = new MVELEvalBuilder();
+ private final MVELPredicateBuilder predicate = new MVELPredicateBuilder();
+ private final MVELReturnValueBuilder returnValue = new MVELReturnValueBuilder();
+ private final MVELConsequenceBuilder consequence = new MVELConsequenceBuilder();
//private final JavaRuleClassBuilder rule = new JavaRuleClassBuilder();
- private final MVELFromBuilder from = new MVELFromBuilder();
- private final JavaFunctionBuilder function = new JavaFunctionBuilder();
- private final CollectBuilder collect = new CollectBuilder();
- private final ForallBuilder forall = new ForallBuilder();
+ private final MVELFromBuilder from = new MVELFromBuilder();
+ private final JavaFunctionBuilder function = new JavaFunctionBuilder();
+ private final CollectBuilder collect = new CollectBuilder();
+ private final ForallBuilder forall = new ForallBuilder();
- private Map interceptors;
+ private Map interceptors;
- private List results;
+ private List results;
//private final JavaFunctionBuilder function = new JavaFunctionBuilder();
- private MemoryResourceReader src;
+ private MemoryResourceReader src;
- private Package pkg;
- private MVELDialectConfiguration configuration;
- private TypeResolver typeResolver;
- private ClassFieldExtractorCache classFieldExtractorCache;
- private MVELExprAnalyzer analyzer;
+ private Package pkg;
+ private MVELDialectConfiguration configuration;
+ private TypeResolver typeResolver;
+ private ClassFieldExtractorCache classFieldExtractorCache;
+ private MVELExprAnalyzer analyzer;
- private Map imports;
- private Map packageImports;
+ private Map imports;
+ private Map packageImports;
- private boolean strictMode;
-
- private static Boolean languageSet = new Boolean( false );
+ private boolean strictMode;
+ private static Boolean languageSet = new Boolean( false );
+
public void addFunction(FunctionDescr functionDescr,
TypeResolver typeResolver) {
throw new UnsupportedOperationException( "MVEL does not support functions" );
@@ -117,7 +117,7 @@
public MVELDialect() {
}
-
+
public static void setLanguageLevel(int level) {
synchronized ( languageSet ) {
// this synchronisation is needed as setLanguageLevel is now thread safe
@@ -139,8 +139,8 @@
this.strictMode = this.configuration.isStrict();
// we currently default to reflective optimisation
- OptimizerFactory.setDefaultOptimizer("reflective");
-
+ OptimizerFactory.setDefaultOptimizer( "reflective" );
+
MVEL.setThreadSafe( true );
this.analyzer = new MVELExprAnalyzer();
@@ -203,14 +203,14 @@
this.builders.put( FunctionDescr.class,
this.function );
- }
+ }
public void init(Package pkg) {
this.pkg = pkg;
this.results = new ArrayList();
this.src = new MemoryResourceReader();
- if( this.pkg != null ) {
- this.addImport( this.pkg.getName()+".*" );
+ if ( this.pkg != null ) {
+ this.addImport( this.pkg.getName() + ".*" );
}
}
@@ -218,11 +218,11 @@
//MVEL:test null to Fix failing test on org.drools.rule.builder.dialect.mvel.MVELConsequenceBuilderTest.testImperativeCodeError()
// @todo: why is this here, MVEL doesn't compile anything? mdp
- String pkgName = this.pkg == null? "": this.pkg.getName();
+ String pkgName = this.pkg == null ? "" : this.pkg.getName();
final String ruleClassName = JavaDialect.getUniqueLegalName( pkgName,
- ruleDescr.getName(),
- "mvel",
- this.src );
+ ruleDescr.getName(),
+ "mvel",
+ this.src );
ruleDescr.setClassName( StringUtils.ucFirst( ruleClassName ) );
ruleDescr.setDialect( this );
}
@@ -232,7 +232,7 @@
}
public void addRule(RuleBuildContext context) {
- //MVEL: Compiler change
+ //MVEL: Compiler change
final RuleDescr ruleDescr = context.getRuleDescr();
// setup the line mappins for this rule
@@ -241,20 +241,25 @@
mapping.setStartLine( ruleDescr.getConsequenceLine() );
mapping.setOffset( ruleDescr.getConsequenceOffset() );
- context.getPkg().getPackageCompilationData().getLineMappings().put( name, mapping );
+ context.getPkg().getPackageCompilationData().getLineMappings().put( name,
+ mapping );
}
public void addImport(String importEntry) {
if ( importEntry.endsWith( ".*" ) ) {
- importEntry = importEntry.substring( 0, importEntry.length()-2 );
- this.packageImports.put( importEntry, importEntry );
+ importEntry = importEntry.substring( 0,
+ importEntry.length() - 2 );
+ this.packageImports.put( importEntry,
+ importEntry );
} else {
try {
Class cls = this.typeResolver.resolveType( importEntry );
- this.imports.put( ParseTools.getSimpleClassName( cls ), cls );
+ this.imports.put( ParseTools.getSimpleClassName( cls ),
+ cls );
} catch ( ClassNotFoundException e ) {
- this.results.add( new ImportError( importEntry, 1 ) );
+ this.results.add( new ImportError( importEntry,
+ 1 ) );
}
}
}
@@ -282,12 +287,14 @@
Method[] methods = cls.getDeclaredMethods();
for ( int i = 0; i < methods.length; i++ ) {
if ( methods[i].getName().equals( methodName ) ) {
- this.imports.put( methodName, methods[i] );
+ this.imports.put( methodName,
+ methods[i] );
break;
}
}
} catch ( ClassNotFoundException e ) {
- this.results.add( new ImportError( staticImportEntry, -1 ) );
+ this.results.add( new ImportError( staticImportEntry,
+ -1 ) );
}
}
@@ -325,7 +332,7 @@
context.getErrors().add( new RuleError( context.getRule(),
descr,
null,
- "Unable to determine the used declarations.\n" + e.getMessage()) );
+ "Unable to determine the used declarations.\n" + e.getMessage() ) );
}
return result;
}
@@ -355,7 +362,7 @@
context.getErrors().add( new RuleError( context.getRule(),
descr,
e,
- "Unable to determine the used declarations.\n" + e.getMessage()) );
+ "Unable to determine the used declarations.\n" + e.getMessage() ) );
}
return result;
}
@@ -364,13 +371,17 @@
final Dialect.AnalysisResult analysis,
final Map interceptors,
final Map outerDeclarations,
+ final Map otherInputVariables,
final RuleBuildContext context) {
- final ParserContext parserContext = getParserContext(analysis, outerDeclarations, context );
+ final ParserContext parserContext = getParserContext( analysis,
+ outerDeclarations,
+ otherInputVariables,
+ context );
ExpressionCompiler compiler = new ExpressionCompiler( text.trim() );
- if (MVELDebugHandler.isDebugMode()) {
- System.out.println("Source before MVEL Compilation:\n"+text.trim());
+ if ( MVELDebugHandler.isDebugMode() ) {
+ System.out.println( "Source before MVEL Compilation:\n" + text.trim() );
compiler.setDebugSymbols( true );
}
@@ -378,13 +389,16 @@
return expr;
}
- public ParserContext getParserContext(final Dialect.AnalysisResult analysis, final Map outerDeclarations, final RuleBuildContext context) {
+ public ParserContext getParserContext(final Dialect.AnalysisResult analysis,
+ final Map outerDeclarations,
+ final Map otherInputDeclarations,
+ final RuleBuildContext context) {
final ParserContext parserContext = new ParserContext( this.imports,
null,
- context.getPkg().getName()+"."+context.getRuleDescr().getClassName() );
+ context.getPkg().getName() + "." + context.getRuleDescr().getClassName() );
for ( Iterator it = this.packageImports.values().iterator(); it.hasNext(); ) {
- String packageImport = ( String ) it.next();
+ String packageImport = (String) it.next();
parserContext.addPackageImport( packageImport );
}
@@ -410,15 +424,14 @@
(Class) globalTypes.get( identifier ) );
}
- Map mvelVars = ((MVELAnalysisResult) analysis).getMvelVariables();
- if ( mvelVars != null ) {
- for ( Iterator it = mvelVars.entrySet().iterator(); it.hasNext(); ) {
+ if ( otherInputDeclarations != null ) {
+ for ( Iterator it = otherInputDeclarations.entrySet().iterator(); it.hasNext(); ) {
Entry entry = (Entry) it.next();
parserContext.addInput( (String) entry.getKey(),
(Class) entry.getValue() );
}
}
-
+
if ( outerDeclarations != null ) {
for ( Iterator it = outerDeclarations.entrySet().iterator(); it.hasNext(); ) {
Entry entry = (Entry) it.next();
@@ -505,6 +518,4 @@
return ID;
}
-
-
}
\ No newline at end of file
Modified: labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELEvalBuilder.java
===================================================================
--- labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELEvalBuilder.java 2008-01-10 16:26:50 UTC (rev 17678)
+++ labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELEvalBuilder.java 2008-01-10 16:27:23 UTC (rev 17679)
@@ -91,6 +91,7 @@
analysis,
null,
null,
+ null,
context );
eval.setEvalExpression( new MVELEvalExpression( expr,
Modified: labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELFromBuilder.java
===================================================================
--- labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELFromBuilder.java 2008-01-10 16:26:50 UTC (rev 17678)
+++ labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELFromBuilder.java 2008-01-10 16:27:23 UTC (rev 17679)
@@ -76,6 +76,7 @@
analysis,
null,
null,
+ null,
context );
dataProvider = new MVELDataProvider( expr,
Modified: labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELPredicateBuilder.java
===================================================================
--- labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELPredicateBuilder.java 2008-01-10 16:26:50 UTC (rev 17678)
+++ labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELPredicateBuilder.java 2008-01-10 16:27:23 UTC (rev 17679)
@@ -59,18 +59,23 @@
localMap.put( localDeclarations[i].getIdentifier(),
localDeclarations[i] );
}
-
+
try {
final DroolsMVELFactory factory = new DroolsMVELFactory( previousMap,
localMap,
- context.getPkg().getGlobals() );
-
+ context.getPkg().getGlobals() );
+
Dialect.AnalysisResult analysis = context.getDialect().analyzeExpression( context,
predicateDescr,
predicateDescr.getContent() );
-
- final Serializable expr = ((MVELDialect) context.getDialect()).compile( (String) predicateDescr.getContent(), analysis, null, null, context );
-
+
+ final Serializable expr = ((MVELDialect) context.getDialect()).compile( (String) predicateDescr.getContent(),
+ analysis,
+ null,
+ null,
+ null,
+ context );
+
predicate.setPredicateExpression( new MVELPredicateExpression( expr,
factory ) );
} catch ( final Exception e ) {
Modified: labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELReturnValueBuilder.java
===================================================================
--- labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELReturnValueBuilder.java 2008-01-10 16:26:50 UTC (rev 17678)
+++ labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELReturnValueBuilder.java 2008-01-10 16:27:23 UTC (rev 17679)
@@ -51,23 +51,30 @@
Map previousMap = new HashMap();
for ( int i = 0, length = previousDeclarations.length; i < length; i++ ) {
previousMap.put( previousDeclarations[i].getIdentifier(),
- previousDeclarations[i] );
+ previousDeclarations[i] );
}
Map localMap = new HashMap();
for ( int i = 0, length = localDeclarations.length; i < length; i++ ) {
localMap.put( localDeclarations[i].getIdentifier(),
- localDeclarations[i] );
- }
-
- final DroolsMVELFactory factory = new DroolsMVELFactory(previousMap, localMap, context.getPkg().getGlobals() );
-
+ localDeclarations[i] );
+ }
+
+ final DroolsMVELFactory factory = new DroolsMVELFactory( previousMap,
+ localMap,
+ context.getPkg().getGlobals() );
+
Dialect.AnalysisResult analysis = context.getDialect().analyzeExpression( context,
returnValueRestrictionDescr,
returnValueRestrictionDescr.getContent() );
-
- final Serializable expr = ((MVELDialect) context.getDialect()).compile( (String) returnValueRestrictionDescr.getContent(), analysis, null, null, context );
-
+
+ final Serializable expr = ((MVELDialect) context.getDialect()).compile( (String) returnValueRestrictionDescr.getContent(),
+ analysis,
+ null,
+ null,
+ null,
+ context );
+
returnValueRestriction.setReturnValueExpression( new MVELReturnValueExpression( expr,
factory ) );
}
Modified: labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELSalienceBuilder.java
===================================================================
--- labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELSalienceBuilder.java 2008-01-10 16:26:50 UTC (rev 17678)
+++ labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/main/java/org/drools/rule/builder/dialect/mvel/MVELSalienceBuilder.java 2008-01-10 16:27:23 UTC (rev 17679)
@@ -38,6 +38,7 @@
analysis,
null,
null,
+ null,
context );
MVELSalienceExpression salience = new MVELSalienceExpression( expr,
Modified: labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/test/java/org/drools/Cheese.java
===================================================================
--- labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/test/java/org/drools/Cheese.java 2008-01-10 16:26:50 UTC (rev 17678)
+++ labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/test/java/org/drools/Cheese.java 2008-01-10 16:27:23 UTC (rev 17679)
@@ -23,21 +23,25 @@
implements
Serializable {
- public static final String STILTON = "stilton";
+ public static final String STILTON = "stilton";
/**
*
*/
- private static final long serialVersionUID = 400L;
- private String type;
- private int price;
- private int oldPrice;
- private Date usedBy;
+ private static final long serialVersionUID = 400L;
+ private String type;
+ private int price;
+ private int oldPrice;
+ private Date usedBy;
public Cheese() {
}
+ public Cheese(final String type) {
+ this.type = type;
+ }
+
public Cheese(final String type,
final int price) {
super();
@@ -47,7 +51,7 @@
public Cheese(final String type,
final int price,
- final int oldPrice ) {
+ final int oldPrice) {
super();
this.type = type;
this.price = price;
@@ -110,6 +114,4 @@
this.usedBy = usedBy;
}
-
-
}
\ No newline at end of file
Modified: labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/test/java/org/drools/integrationtests/DynamicRulesTest.java
===================================================================
--- labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/test/java/org/drools/integrationtests/DynamicRulesTest.java 2008-01-10 16:26:50 UTC (rev 17678)
+++ labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/test/java/org/drools/integrationtests/DynamicRulesTest.java 2008-01-10 16:27:23 UTC (rev 17679)
@@ -20,8 +20,6 @@
import org.drools.Cheese;
import org.drools.FactA;
import org.drools.FactB;
-import org.drools.Order;
-import org.drools.OrderItem;
import org.drools.Person;
import org.drools.PersonInterface;
import org.drools.Precondition;
@@ -47,7 +45,7 @@
config );
}
- public void xxxtestDynamicRuleAdditions() throws Exception {
+ public void testDynamicRuleAdditions() throws Exception {
Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_Dynamic1.drl" ) );
PackageBuilder builder = new PackageBuilder();
@@ -142,7 +140,7 @@
}
- public void xxxtestDynamicRuleRemovals() throws Exception {
+ public void testDynamicRuleRemovals() throws Exception {
final PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_Dynamic1.drl" ) ) );
@@ -216,7 +214,7 @@
workingMemory.getAgenda().getActivations().length );
}
- public void xxxtestDynamicRuleRemovalsUnusedWorkingMemory() throws Exception {
+ public void testDynamicRuleRemovalsUnusedWorkingMemory() throws Exception {
final PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_Dynamic1.drl" ) ) );
@@ -256,7 +254,7 @@
}
}
- public void xxxtestDynamicFunction() throws Exception {
+ public void testDynamicFunction() throws Exception {
PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_DynamicFunction1.drl" ) ) );
@@ -326,7 +324,7 @@
list.get( 2 ) );
}
- public void xxxtestRemovePackage() throws Exception {
+ public void testRemovePackage() throws Exception {
final PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_RemovePackage.drl" ) ) );
@@ -354,7 +352,7 @@
ruleBaseWM.addPackage( serialisePackage( builder1.getPackage() ) );
}
- public void xxxtestDynamicRules() throws Exception {
+ public void testDynamicRules() throws Exception {
final RuleBase ruleBase = getRuleBase();
final WorkingMemory workingMemory = ruleBase.newStatefulSession();
final Cheese a = new Cheese( "stilton",
@@ -375,7 +373,7 @@
workingMemory.fireAllRules();
}
- public void xxxtestDynamicRules2() throws Exception {
+ public void testDynamicRules2() throws Exception {
final RuleBase ruleBase = getRuleBase();
final WorkingMemory workingMemory = ruleBase.newStatefulSession();
@@ -397,7 +395,7 @@
workingMemory.fireAllRules();
}
- public void xxxtestRuleBaseAddRemove() throws Exception {
+ public void testRuleBaseAddRemove() throws Exception {
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
//add and remove
@@ -415,7 +413,7 @@
ruleBase.removePackage( pkg.getName() );
}
- public void xxxtestClassLoaderSwitchsUsingConf() throws Exception {
+ public void testClassLoaderSwitchsUsingConf() throws Exception {
try {
// Creates first class loader and use it to load fact classes
ClassLoader loader1 = new SubvertedClassLoader( new URL[]{getClass().getResource( "/" )},
@@ -460,7 +458,7 @@
}
- public void xxxtestClassLoaderSwitchsUsingContext() throws Exception {
+ public void testClassLoaderSwitchsUsingContext() throws Exception {
try {
// Creates first class loader and use it to load fact classes
ClassLoader original = Thread.currentThread().getContextClassLoader();
Modified: labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/test/java/org/drools/integrationtests/MVELTest.java
===================================================================
--- labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/test/java/org/drools/integrationtests/MVELTest.java 2008-01-10 16:26:50 UTC (rev 17678)
+++ labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/test/java/org/drools/integrationtests/MVELTest.java 2008-01-10 16:27:23 UTC (rev 17679)
@@ -16,6 +16,7 @@
import junit.framework.TestCase;
import org.drools.Cheese;
+import org.drools.Person;
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.WorkingMemory;
@@ -78,6 +79,53 @@
return MVEL.executeExpression(compiled, new Object(), new HashMap());
}
+ public void testLocalVariableMVELConsequence() throws Exception {
+ final PackageBuilder builder = new PackageBuilder();
+ builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_LocalVariableMVELConsequence.drl" ) ) );
+ final Package pkg = builder.getPackage();
+
+ final RuleBase ruleBase = getRuleBase();
+ ruleBase.addPackage( pkg );
+ final WorkingMemory workingMemory = ruleBase.newStatefulSession();
+
+ final List list = new ArrayList();
+ workingMemory.setGlobal( "results",
+ list );
+
+ workingMemory.insert( new Person( "bob", "stilton" ) );
+ workingMemory.insert( new Person( "mark", "brie" ) );
+
+ try {
+ workingMemory.fireAllRules();
+
+ assertEquals( "should have fired twice",
+ 2,
+ list.size() );
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail( "Should not raise any exception");
+ }
+
+ }
+
+ public void testDuplicateLocalVariableMVELConsequence() throws Exception {
+ final PackageBuilder builder = new PackageBuilder();
+ builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_DuplicateLocalVariableMVELConsequence.drl" ) ) );
+
+ try {
+ final Package pkg = builder.getPackage();
+
+ final RuleBase ruleBase = getRuleBase();
+ ruleBase.addPackage( pkg );
+
+ fail( "Should have raised exception because of the duplicate variable definition");
+ } catch (Exception e) {
+ // success
+ }
+
+ }
+
private RuleBase loadRuleBase(final Reader reader) throws IOException,
DroolsParserException,
Exception {
Modified: labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java
===================================================================
--- labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java 2008-01-10 16:26:50 UTC (rev 17678)
+++ labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java 2008-01-10 16:27:23 UTC (rev 17679)
@@ -4410,6 +4410,4 @@
assertEquals( fact.getData(), list.get( 0 ) );
}
-
-
}
\ No newline at end of file
Copied: labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/test/resources/org/drools/integrationtests/test_DuplicateLocalVariableMVELConsequence.drl (from rev 17489, labs/jbossrules/branches/4.0.x/drools-compiler/src/test/resources/org/drools/integrationtests/test_DuplicateLocalVariableMVELConsequence.drl)
===================================================================
--- labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/test/resources/org/drools/integrationtests/test_DuplicateLocalVariableMVELConsequence.drl (rev 0)
+++ labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/test/resources/org/drools/integrationtests/test_DuplicateLocalVariableMVELConsequence.drl 2008-01-10 16:27:23 UTC (rev 17679)
@@ -0,0 +1,26 @@
+package org.drools;
+
+global java.util.List results;
+
+rule "test local variable in mvel consequence - same type"
+ dialect "mvel"
+ when
+ $p : Person( $likes : likes )
+ then
+ Cheese c = new Cheese( $likes );
+ results.add( c );
+ // bellow should raise a duplicate local variable declaration
+ Cheese c = new Cheese( "stilton" );
+end
+
+
+rule "test local variable in mvel consequence - different type"
+ dialect "mvel"
+ when
+ $p : Person( $likes : likes )
+ then
+ Cheese c = new Cheese( $likes );
+ results.add( c );
+ // bellow should raise a duplicate local variable declaration
+ String c = new String( "stilton" );
+end
\ No newline at end of file
Copied: labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/test/resources/org/drools/integrationtests/test_LocalVariableMVELConsequence.drl (from rev 17459, labs/jbossrules/branches/4.0.x/drools-compiler/src/test/resources/org/drools/integrationtests/test_LocalVariableMVELConsequence.drl)
===================================================================
--- labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/test/resources/org/drools/integrationtests/test_LocalVariableMVELConsequence.drl (rev 0)
+++ labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-compiler/src/test/resources/org/drools/integrationtests/test_LocalVariableMVELConsequence.drl 2008-01-10 16:27:23 UTC (rev 17679)
@@ -0,0 +1,12 @@
+package org.drools;
+
+global java.util.List results;
+
+rule "test local variable in mvel consequence"
+ dialect "mvel"
+ when
+ $p : Person( $likes : likes )
+ then
+ Cheese c = new Cheese( $likes );
+ results.add( c );
+end
\ No newline at end of file
Modified: labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELFactory.java
===================================================================
--- labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELFactory.java 2008-01-10 16:26:50 UTC (rev 17678)
+++ labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/drools-core/src/main/java/org/drools/base/mvel/DroolsMVELFactory.java 2008-01-10 16:27:23 UTC (rev 17679)
@@ -163,7 +163,15 @@
this.knowledgeHelper = knowledgeHelper;
this.object = object;
this.workingMemory = workingMemory;
- this.localVariables = variables;
+ if ( variables == null ) {
+ if ( this.localVariables == null ) {
+ this.localVariables = new HashMap();
+ } else {
+ this.localVariables.clear();
+ }
+ } else {
+ this.localVariables = variables;
+ }
}
public KnowledgeHelper getKnowledgeHelper() {
@@ -192,41 +200,29 @@
public VariableResolver createVariable(String name,
Object value) {
VariableResolver vr = getVariableResolver( name );
- if ( vr != null ) {
- if ( this.localVariables == null ) {
- this.localVariables = new HashMap();
- }
- vr.setValue( value );
- return vr;
- } else {
- if ( this.localVariables == null ) {
- this.localVariables = new HashMap();
- }
+ if ( vr == null ) {
addResolver( name,
vr = new LocalVariableResolver( this,
name ) );
- vr.setValue( value );
- return vr;
}
+
+ vr.setValue( value );
+ return vr;
}
public VariableResolver createVariable(String name,
Object value,
Class type) {
VariableResolver vr = getVariableResolver( name );
- if ( vr != null && vr.getType() != null ) {
- throw new CompileException( "variable already defined within scope: " + vr.getType() + " " + name );
- } else {
- if ( this.localVariables == null ) {
- this.localVariables = new HashMap();
- }
+ if ( vr == null ) {
addResolver( name,
vr = new LocalVariableResolver( this,
name,
type ) );
- vr.setValue( value );
- return vr;
- }
+ }
+
+ vr.setValue( value );
+ return vr;
}
public boolean isResolveable(String name) {
@@ -253,12 +249,7 @@
(Class) this.globals.get( name ),
this ) );
return true;
- } else if ( this.variableResolvers != null && this.variableResolvers.containsKey( name ) ) {
- addResolver( name,
- new LocalVariableResolver( this,
- name ) );
- return true;
- } else if ( nextFactory != null ) {
+ } else if ( nextFactory != null ) {
return nextFactory.isResolveable( name );
}
Copied: labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/m2_repo/org/mvel/mvel14/1.2.20 (from rev 17655, labs/jbossrules/branches/4.0.x/m2_repo/org/mvel/mvel14/1.2.20)
Deleted: labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/m2_repo/org/mvel/mvel14/1.2.20/mvel14-1.2.20.jar
===================================================================
(Binary files differ)
Copied: labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/m2_repo/org/mvel/mvel14/1.2.20/mvel14-1.2.20.jar (from rev 17655, labs/jbossrules/branches/4.0.x/m2_repo/org/mvel/mvel14/1.2.20/mvel14-1.2.20.jar)
===================================================================
(Binary files differ)
Deleted: labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/m2_repo/org/mvel/mvel14/1.2.20/mvel14-1.2.20.pom
===================================================================
--- labs/jbossrules/branches/4.0.x/m2_repo/org/mvel/mvel14/1.2.20/mvel14-1.2.20.pom 2008-01-09 17:28:27 UTC (rev 17655)
+++ labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/m2_repo/org/mvel/mvel14/1.2.20/mvel14-1.2.20.pom 2008-01-10 16:27:23 UTC (rev 17679)
@@ -1,39 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.codehaus.mvel</groupId>
- <artifactId>mvel</artifactId>
- <packaging>jar</packaging>
- <version>1.2.20-java1.4</version>
- <name>mvel</name>
- <url>http://mvel.codehaus.org</url>
-
- <description>MVFLEX Expression Language 1.2 for Java 1.4</description>
-
- <inceptionYear>2005</inceptionYear>
-
- <url>http://mvel.codehaus.org/</url>
-
- <issueManagement>
- <url>http://jira.codehaus.org/browse/MVEL</url>
- </issueManagement>
-
- <licenses>
- <license>
- <name>The Apache Software License, Version 2.0</name>
- <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
- <distribution>repo</distribution>
- </license>
- </licenses>
-
- <scm>
- <connection>scm:svn:http://svn.codehaus.org/mvel/</connection>
- <developerConnection>scm:svn:https://svn.codehaus.org/mvel/</developerConnection>
- <url>http://svn.mvel.codehaus.org/</url>
- </scm>
-
- <organization>
- <name>Codehaus</name>
- <url>http://codehaus.org</url>
- </organization>
-</project>
Copied: labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/m2_repo/org/mvel/mvel14/1.2.20/mvel14-1.2.20.pom (from rev 17655, labs/jbossrules/branches/4.0.x/m2_repo/org/mvel/mvel14/1.2.20/mvel14-1.2.20.pom)
===================================================================
--- labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/m2_repo/org/mvel/mvel14/1.2.20/mvel14-1.2.20.pom (rev 0)
+++ labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/m2_repo/org/mvel/mvel14/1.2.20/mvel14-1.2.20.pom 2008-01-10 16:27:23 UTC (rev 17679)
@@ -0,0 +1,38 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.codehaus.mvel</groupId>
+ <artifactId>mvel</artifactId>
+ <packaging>jar</packaging>
+ <version>1.2.20-java1.4</version>
+ <name>mvel</name>
+
+ <description>MVFLEX Expression Language 1.2 for Java 1.4</description>
+
+ <inceptionYear>2005</inceptionYear>
+
+ <url>http://mvel.codehaus.org/</url>
+
+ <issueManagement>
+ <url>http://jira.codehaus.org/browse/MVEL</url>
+ </issueManagement>
+
+ <licenses>
+ <license>
+ <name>The Apache Software License, Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+
+ <scm>
+ <connection>scm:svn:http://svn.codehaus.org/mvel/</connection>
+ <developerConnection>scm:svn:https://svn.codehaus.org/mvel/</developerConnection>
+ <url>http://svn.mvel.codehaus.org/</url>
+ </scm>
+
+ <organization>
+ <name>Codehaus</name>
+ <url>http://codehaus.org</url>
+ </organization>
+</project>
Modified: labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/pom.xml
===================================================================
--- labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/pom.xml 2008-01-10 16:26:50 UTC (rev 17678)
+++ labs/jbossrules/branches/Branch_4_0_2_SOA_4_2/pom.xml 2008-01-10 16:27:23 UTC (rev 17679)
@@ -732,7 +732,7 @@
<dependency>
<groupId>org.mvel</groupId>
<artifactId>mvel14</artifactId>
- <version>1.2.8</version>
+ <version>1.2.20</version>
</dependency>
<!-- drools-compiler -->
More information about the jboss-svn-commits
mailing list