mirror of
https://github.com/mitb-archive/filebot
synced 2025-01-11 22:08:01 -05:00
* fixed possible PermGen memory problems caused by repeatedly initializing the Groovy with custom additions
This commit is contained in:
parent
e48bbbe2ee
commit
ce339c273d
@ -2,20 +2,16 @@
|
||||
package net.sourceforge.filebot.format;
|
||||
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
import java.security.AccessController;
|
||||
|
||||
import javax.script.Bindings;
|
||||
import javax.script.Compilable;
|
||||
import javax.script.CompiledScript;
|
||||
import javax.script.ScriptContext;
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptException;
|
||||
import javax.script.SimpleBindings;
|
||||
import javax.script.SimpleScriptContext;
|
||||
|
||||
import org.codehaus.groovy.jsr223.GroovyScriptEngineFactory;
|
||||
|
||||
|
||||
public class ExpressionFilter {
|
||||
|
||||
@ -30,7 +26,7 @@ public class ExpressionFilter {
|
||||
public ExpressionFilter(String expression) throws ScriptException {
|
||||
this.expression = expression;
|
||||
|
||||
Compilable engine = (Compilable) initScriptEngine();
|
||||
Compilable engine = (Compilable) ExpressionFormat.getGroovyScriptEngine();
|
||||
this.userScript = new SecureCompiledScript(engine.compile(expression)); // sandboxed script
|
||||
this.asBooleanScript = engine.compile("value as Boolean");
|
||||
}
|
||||
@ -46,14 +42,6 @@ public class ExpressionFilter {
|
||||
}
|
||||
|
||||
|
||||
protected ScriptEngine initScriptEngine() throws ScriptException {
|
||||
// use Groovy script engine
|
||||
ScriptEngine engine = new GroovyScriptEngineFactory().getScriptEngine();
|
||||
engine.eval(new InputStreamReader(ExpressionFormat.class.getResourceAsStream("ExpressionFormat.lib.groovy")));
|
||||
return engine;
|
||||
}
|
||||
|
||||
|
||||
public boolean matches(Object value) throws ScriptException {
|
||||
return matches(new ExpressionBindings(value));
|
||||
}
|
||||
|
@ -29,6 +29,18 @@ import org.codehaus.groovy.jsr223.GroovyScriptEngineFactory;
|
||||
|
||||
public class ExpressionFormat extends Format {
|
||||
|
||||
private static ScriptEngine engine;
|
||||
|
||||
|
||||
protected static synchronized ScriptEngine getGroovyScriptEngine() throws ScriptException {
|
||||
if (engine == null) {
|
||||
engine = new GroovyScriptEngineFactory().getScriptEngine();
|
||||
engine.eval(new InputStreamReader(ExpressionFormat.class.getResourceAsStream("ExpressionFormat.lib.groovy")));
|
||||
}
|
||||
return engine;
|
||||
}
|
||||
|
||||
|
||||
private final String expression;
|
||||
|
||||
private final Object[] compilation;
|
||||
@ -38,15 +50,7 @@ public class ExpressionFormat extends Format {
|
||||
|
||||
public ExpressionFormat(String expression) throws ScriptException {
|
||||
this.expression = expression;
|
||||
this.compilation = secure(compile(expression, (Compilable) initScriptEngine()));
|
||||
}
|
||||
|
||||
|
||||
protected ScriptEngine initScriptEngine() throws ScriptException {
|
||||
// use Groovy script engine
|
||||
ScriptEngine engine = new GroovyScriptEngineFactory().getScriptEngine();
|
||||
engine.eval(new InputStreamReader(ExpressionFormat.class.getResourceAsStream("ExpressionFormat.lib.groovy")));
|
||||
return engine;
|
||||
this.compilation = secure(compile(expression, (Compilable) getGroovyScriptEngine()));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user