Skip to content

Commit

Permalink
stable. fixed issue 4 and updated dependencies to latest versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ant committed Feb 21, 2017
1 parent c9804de commit 991d20e
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 57 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ target/
rules-js/test/coverage
**/node_modules/

*.iml
.idea
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

Simple Rule Engine from Ant's blog. Able to process MVEL and Javascript rules in JVM, or run on Node.js.

Version 2.2.1:
- Fixed https://github.com/maxant/rules/issues/4 - added checks to log level in order to improve performance.
- Updated dependencies to latest versions

Version 2.2.0:
See [http://blog.maxant.co.uk/pebble/2015/08/22/1440237900000.html](http://blog.maxant.co.uk/pebble/2015/08/22/1440237900000.html) => Support for Javascript rules in JVM via Nashorn.
- See [http://blog.maxant.co.uk/pebble/2015/08/22/1440237900000.html](http://blog.maxant.co.uk/pebble/2015/08/22/1440237900000.html) => Support for Javascript rules in JVM via Nashorn.

Version 2.1.0:
See [http://blog.maxant.co.uk/pebble/2011/11/12/1321129560000.html](http://blog.maxant.co.uk/pebble/2011/11/12/1321129560000.html) and
- See [http://blog.maxant.co.uk/pebble/2011/11/12/1321129560000.html](http://blog.maxant.co.uk/pebble/2011/11/12/1321129560000.html) and
[http://blog.maxant.co.uk/pebble/2014/10/03/1412371560000.html](http://blog.maxant.co.uk/pebble/2014/10/03/1412371560000.html) and also
[http://blog.maxant.co.uk/pebble/2014/11/15/1416087180000.html](http://blog.maxant.co.uk/pebble/2014/11/15/1416087180000.html) for Node.js.

Expand Down
4 changes: 2 additions & 2 deletions rules-java8/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>ch.maxant</groupId>
<artifactId>rules-parent</artifactId>
<version>2.2.1-SNAPSHOT</version>
<version>2.2.1</version>
<relativePath>../rules-parent</relativePath>
</parent>
<artifactId>rules-java8</artifactId>
Expand Down Expand Up @@ -33,7 +33,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand Down
10 changes: 5 additions & 5 deletions rules-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>ch.maxant</groupId>
<artifactId>rules-parent</artifactId>
<version>2.2.1-SNAPSHOT</version>
<version>2.2.1</version>
<packaging>pom</packaging>
<url>http://blog.maxant.co.uk/pebble/2011/11/12/1321129560000.html</url>

Expand Down Expand Up @@ -43,7 +43,7 @@
<!-- build sources -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -57,7 +57,7 @@
<!-- build javadoc -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<version>2.10.4</version>
<configuration>
<!-- <additionalparam>-Xdoclint:none</additionalparam> -->
<encoding>UTF-8</encoding>
Expand All @@ -76,7 +76,7 @@
<!-- still supporting java 6 -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<version>3.6.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
Expand All @@ -103,7 +103,7 @@
<!-- plugin for deploying to staging area of sonatype which then deploys to maven central -->
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.6</version>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>sonatype</serverId>
Expand Down
2 changes: 1 addition & 1 deletion rules-scala/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>ch.maxant</groupId>
<artifactId>rules-parent</artifactId>
<version>2.2.1-SNAPSHOT</version>
<version>2.2.1</version>
<relativePath>../rules-parent</relativePath>
</parent>
<properties>
Expand Down
6 changes: 3 additions & 3 deletions rules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<parent>
<groupId>ch.maxant</groupId>
<artifactId>rules-parent</artifactId>
<version>2.2.1-SNAPSHOT</version>
<version>2.2.1</version>
<relativePath>../rules-parent</relativePath>
</parent>
<properties>
<mvel2-version>2.2.6.Final</mvel2-version>
<mvel2-version>2.3.1.Final</mvel2-version>
</properties>
<artifactId>rules</artifactId>
<packaging>jar</packaging>
Expand All @@ -32,7 +32,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<version>3.0.2</version>
<executions>
<execution>
<goals>
Expand Down
18 changes: 6 additions & 12 deletions rules/src/main/java/ch/maxant/rules/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,14 @@
*/
package ch.maxant.rules;

import org.mvel2.MVEL;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;

import org.mvel2.MVEL;

/**
* A Rule Engine. Can evaluate rules and execute {@link IAction}s or simply provide an
* ordered list of the best matching {@link Rule}s.<br>
Expand Down Expand Up @@ -400,9 +394,9 @@ public <Input> List<Rule> getMatchingRules(String nameSpacePattern, Input input)
String msg = r.getRule().getFullyQualifiedName() + "-{" + r.getRule().getExpression() + "}";
if(String.valueOf(o).equals("true")){
matchingRules.add(r.getRule());
log.info("matched: " + msg);
if(log.isLoggable(Level.INFO)) log.info("matched: " + msg);
}else{
log.info("unmatched: " + msg);
if(log.isLoggable(Level.INFO)) log.info("unmatched: " + msg);
}
}

Expand Down
55 changes: 23 additions & 32 deletions rules/src/main/java/ch/maxant/rules/JavascriptEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,23 @@
*/
package ch.maxant.rules;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Logger;
import java.util.regex.Pattern;

import javax.script.Compilable;
import javax.script.CompiledScript;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

import org.apache.commons.pool2.BasePooledObjectFactory;
import org.apache.commons.pool2.ObjectPool;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;

import javax.script.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;

/**
* A Javascript based Subclass of {@link Engine}. <br>
* <b>ONLY TESTED WITH JAVA 8 AND NASHORN!!</b><br>
Expand All @@ -61,15 +50,17 @@ public class JavascriptEngine extends Engine {
static {
ScriptEngine engine = ENGINE_MANAGER.getEngineByMimeType(MIME_TYPE);
ScriptEngineFactory factory = engine.getFactory();
log.info("Using JavaScript engine " + factory.getEngineName() + "/"
+ factory.getEngineVersion() + "/"
+ factory.getLanguageName() + "/"
+ factory.getLanguageVersion() + "/"
+ factory.getExtensions() + "/"
+ factory.getMimeTypes() + "/"
+ factory.getNames() + "/"
+ "threading model: " + factory.getParameter("THREADING")
);
if(log.isLoggable(Level.INFO)){
log.info("Using JavaScript engine " + factory.getEngineName() + "/"
+ factory.getEngineVersion() + "/"
+ factory.getLanguageName() + "/"
+ factory.getLanguageVersion() + "/"
+ factory.getExtensions() + "/"
+ factory.getMimeTypes() + "/"
+ factory.getNames() + "/"
+ "threading model: " + factory.getParameter("THREADING")
);
}
}

private final class PoolableEngineFactory extends BasePooledObjectFactory<Engine> {
Expand Down Expand Up @@ -291,9 +282,9 @@ public <Input> List<Rule> getMatchingRules(String nameSpacePattern, Input input)
String msg = r.getFullyQualifiedName() + "-{" + r.getExpression() + "}";
if(String.valueOf(result).equals("true")){
matchingRules.add(r);
log.info("matched: " + msg);
if(log.isLoggable(Level.INFO)) log.info("matched: " + msg);
}else{
log.info("unmatched: " + msg);
if(log.isLoggable(Level.INFO)) log.info("unmatched: " + msg);
}
}
//order by priority!
Expand Down
4 changes: 4 additions & 0 deletions rules/src/main/resources/releaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2.2.1 - 201702212200
======================
Fixed https://github.com/maxant/rules/issues/4 and updated dependencies.

2.2.0 - 201508220000
======================
Added support for JavaScript rules in JVM, using Nashorn.
Expand Down

0 comments on commit 991d20e

Please sign in to comment.