Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions rules/src/main/java/ch/maxant/rules/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ public class Engine {

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scranefield please update the unit tests too, then i'll happily merge your PR and build a new version and make it available at maven central. Thanks for the PR!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Would that just involve adding a new test to DefaultEngineTest.java?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please

protected final boolean throwExceptionIfCompilationFails;
protected final String inputName;

protected final Map<String,Object> varBindings;

//reserved for subclasses and not used in this class - yuck, but hey.
protected final String[] javascriptFilesToLoad;
protected final Integer poolSize;
Expand All @@ -140,6 +141,7 @@ public Engine(final Collection<Rule> rules, String inputName, boolean throwExcep
this(rules, inputName, throwExceptionIfCompilationFails, null, null, new HashMap<String, Object>());
}


/**
* See {@link #Engine(Collection, String, boolean, Map)}
*/
Expand All @@ -165,13 +167,14 @@ public Engine(final Collection<Rule> rules, String inputName, boolean throwExcep

protected Engine(final Collection<Rule> rules, String inputName, boolean throwExceptionIfCompilationFails, Integer poolSize, String[] javascriptFilesToLoad, Map<String, Object > statics) throws DuplicateNameException, CompileException, ParseException {
this.inputName = inputName;
this.varBindings = varBindings;
this.throwExceptionIfCompilationFails = throwExceptionIfCompilationFails;
this.javascriptFilesToLoad = javascriptFilesToLoad;
this.poolSize = poolSize;
this.statics = statics;
init(rules);
}
/** handles the initialisation */
protected void init(Collection<Rule> rules) throws DuplicateNameException, CompileException, ParseException {
log.info("\r\n\r\n*****Initialising rule engine...*****");
Expand Down Expand Up @@ -441,6 +444,7 @@ public <Input> List<Rule> getMatchingRules(String nameSpacePattern, Input input)
}

Map<String, Object> vars = new HashMap<String, Object>(statics); // initialise with static stuff

vars.put(inputName, input);

List<Rule> matchingRules = new ArrayList<Rule>();
Expand Down Expand Up @@ -485,4 +489,4 @@ private Rule getRule() {

}


2 changes: 1 addition & 1 deletion rules/src/main/java/ch/maxant/rules/JavascriptEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public JavascriptEngine(final Collection<Rule> rules, String inputName, boolean
}
}
}

/**
* Subclasses may override this. But the default will create a config which sets up the
* pool using the size passed into the constructor, otherwise accessible as
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
public abstract class AbstractEngineTest {

public abstract Engine getEngine(List<Rule> rules, boolean throwExceptionIfCompilationFails) throws DuplicateNameException, CompileException, ParseException, ScriptException, IOException;

public abstract Engine getEngine(List<Rule> rules, String inputName, Map<String,Object> varBindings, boolean throwExceptionIfCompilationFails) throws DuplicateNameException, CompileException, ParseException, ScriptException, IOException;

protected abstract boolean isJavascriptTest();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public class DefaultEngineTest extends AbstractEngineTest {
public Engine getEngine(List<Rule> rules, boolean throwExceptionIfCompilationFails) throws DuplicateNameException, CompileException, ParseException {
return new Engine(rules, throwExceptionIfCompilationFails);
}

@Override
public Engine getEngine(List<Rule> rules, String inputName, Map<String,Object> varBindings, boolean throwExceptionIfCompilationFails) throws DuplicateNameException, CompileException, ParseException {
return new Engine(rules, inputName, varBindings, throwExceptionIfCompilationFails);
}

@Override
protected boolean isJavascriptTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public Engine getEngine(List<Rule> rules, boolean throwExceptionIfCompilationFai
return new JavascriptEngine(rules, throwExceptionIfCompilationFails);
}

@Override
public Engine getEngine(List<Rule> rules, String inputName, Map<String,Object> varBindings, boolean throwExceptionIfCompilationFails)
throws DuplicateNameException, CompileException, ParseException, ScriptException, IOException {
return new JavascriptEngine(rules, inputName, varBindings, throwExceptionIfCompilationFails);
}

@Override
protected boolean isJavascriptTest() {
return true;
Expand Down