mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-23 00:08:51 -05:00
Make sure not to expose public locks
This commit is contained in:
parent
f0e3b5fa46
commit
580f2bd8f4
@ -224,10 +224,7 @@ public class ExpressionFormat extends Format {
|
|||||||
return compilation;
|
return compilation;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ScriptEngine engine;
|
protected static Compilable createScriptEngine() {
|
||||||
private static Map<String, CompiledScript> scriptletCache = new HashMap<String, CompiledScript>();
|
|
||||||
|
|
||||||
protected static ScriptEngine createScriptEngine() {
|
|
||||||
CompilerConfiguration config = new CompilerConfiguration();
|
CompilerConfiguration config = new CompilerConfiguration();
|
||||||
|
|
||||||
// include default functions
|
// include default functions
|
||||||
@ -239,26 +236,29 @@ public class ExpressionFormat extends Format {
|
|||||||
return new GroovyScriptEngineImpl(classLoader);
|
return new GroovyScriptEngineImpl(classLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static synchronized ScriptEngine getGroovyScriptEngine() throws ScriptException {
|
private static Compilable engine;
|
||||||
if (engine == null) {
|
private static Map<String, CompiledScript> scriptletCache = new HashMap<String, CompiledScript>();
|
||||||
engine = createScriptEngine();
|
|
||||||
}
|
|
||||||
return engine;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static synchronized CompiledScript compileScriptlet(String expression) throws ScriptException {
|
protected static CompiledScript compileScriptlet(String expression) throws ScriptException {
|
||||||
// simple expressions like {n} don't need to be interpreted by the script engine
|
// simple expressions like {n} don't need to be interpreted by the script engine
|
||||||
if (SourceVersion.isIdentifier(expression) && !SourceVersion.isKeyword(expression)) {
|
if (SourceVersion.isIdentifier(expression) && !SourceVersion.isKeyword(expression)) {
|
||||||
return new Variable(expression);
|
return new Variable(expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
CompiledScript scriptlet = scriptletCache.get(expression);
|
synchronized (scriptletCache) {
|
||||||
if (scriptlet == null) {
|
CompiledScript scriptlet = scriptletCache.get(expression);
|
||||||
Compilable engine = (Compilable) getGroovyScriptEngine();
|
if (scriptlet == null) {
|
||||||
scriptlet = engine.compile(expression);
|
// lazy initialize script engine
|
||||||
scriptletCache.put(expression, scriptlet);
|
if (engine == null) {
|
||||||
|
engine = createScriptEngine();
|
||||||
|
}
|
||||||
|
|
||||||
|
// compile and cache script
|
||||||
|
scriptlet = engine.compile(expression);
|
||||||
|
scriptletCache.put(expression, scriptlet);
|
||||||
|
}
|
||||||
|
return scriptlet;
|
||||||
}
|
}
|
||||||
return scriptlet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Variable extends CompiledScript {
|
private static class Variable extends CompiledScript {
|
||||||
|
Loading…
Reference in New Issue
Block a user