}
}
if(engine instanceof Compilable && Config.SCRIPT_ALLOW_COMPILATION)
{
ScriptContext context = new SimpleScriptContext();
context.setAttribute("mainClass", getClassForFile(file).replace('/', '.').replace('\\', '.'), ScriptContext.ENGINE_SCOPE);
context.setAttribute(ScriptEngine.FILENAME, file.getName(), ScriptContext.ENGINE_SCOPE);
context.setAttribute("classpath", SCRIPT_FOLDER.getAbsolutePath(), ScriptContext.ENGINE_SCOPE);
context.setAttribute("sourcepath", SCRIPT_FOLDER.getAbsolutePath(), ScriptContext.ENGINE_SCOPE);
context.setAttribute(JythonScriptEngine.JYTHON_ENGINE_INSTANCE, engine, ScriptContext.ENGINE_SCOPE);
setCurrentLoadingScript(file);
ScriptContext ctx = engine.getContext();
try
{
engine.setContext(context);
if(Config.SCRIPT_CACHE)
{
CompiledScript cs = _cache.loadCompiledScript(engine, file);
cs.eval(context);
}
else
{
Compilable eng = (Compilable) engine;
CompiledScript cs = eng.compile(lnr);
cs.eval(context);
}
}
finally
{
engine.setContext(ctx);
setCurrentLoadingScript(null);
context.removeAttribute(ScriptEngine.FILENAME, ScriptContext.ENGINE_SCOPE);
context.removeAttribute("mainClass", ScriptContext.ENGINE_SCOPE);
}
}
else
{
ScriptContext context = new SimpleScriptContext();
context.setAttribute("mainClass", getClassForFile(file).replace('/', '.').replace('\\', '.'), ScriptContext.ENGINE_SCOPE);
context.setAttribute(ScriptEngine.FILENAME, file.getName(), ScriptContext.ENGINE_SCOPE);
context.setAttribute("classpath", SCRIPT_FOLDER.getAbsolutePath(), ScriptContext.ENGINE_SCOPE);
context.setAttribute("sourcepath", SCRIPT_FOLDER.getAbsolutePath(), ScriptContext.ENGINE_SCOPE);
setCurrentLoadingScript(file);
try
{
engine.eval(lnr, context);
}