feat: 撤销异常拦截 抛到外层

merge/1/HEAD
coding 2017-11-02 17:36:32 +00:00
parent 0272518f72
commit 236955ddea
1 changed files with 14 additions and 19 deletions

View File

@ -12,6 +12,7 @@ import java.nio.file.Path;
import javax.script.ScriptEngineManager; import javax.script.ScriptEngineManager;
import javax.script.ScriptException; import javax.script.ScriptException;
import lombok.SneakyThrows;
import pw.yumc.YumCore.engine.MiaoScriptEngine; import pw.yumc.YumCore.engine.MiaoScriptEngine;
/** /**
@ -31,30 +32,24 @@ public class ScriptEngine {
enableEngine(); enableEngine();
} }
@SneakyThrows
public void enableEngine() { public void enableEngine() {
try { ScriptEngineManager manager = new ScriptEngineManager(null);
ScriptEngineManager manager = new ScriptEngineManager(null); this.engine = new MiaoScriptEngine(manager, "nashorn");
this.engine = new MiaoScriptEngine(manager, "nashorn"); this.engine.put("base", new Base());
this.engine.put("base", new Base()); Path bios = Paths.get(root, "bios.js");
Path bios = Paths.get(root, "bios.js"); // 如果存在自定义bios就加载自定义的
// 如果存在自定义bios就加载自定义的 if (Files.exists(bios)) {
if (Files.exists(bios)) { this.engine.eval("load('" + bios.toFile().getCanonicalPath() + "')");
this.engine.eval("load('" + bios.toFile().getCanonicalPath() + "')"); } else {
} else { this.engine.eval(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("bios.js")));
this.engine.eval(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("bios.js")));
}
engine.invokeFunction("boot", root, logger);
} catch (Exception e) {
// logger.log(Level.SEVERE, "MiaoScript 启动失败!", e);
} }
engine.invokeFunction("boot", root, logger);
} }
@SneakyThrows
public void disableEngine() { public void disableEngine() {
try { engine.invokeFunction("disable");
engine.invokeFunction("disable");
} catch (ScriptException | NoSuchMethodException e) {
// logger.log(Level.SEVERE, "MiaoScript 关闭失败!", e);
}
} }
public MiaoScriptEngine getEngine() { public MiaoScriptEngine getEngine() {