From 236955ddea287f70a5537bd185313dd9a2f911a8 Mon Sep 17 00:00:00 2001 From: coding Date: Thu, 2 Nov 2017 17:36:32 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=92=A4=E9=94=80=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E6=8B=A6=E6=88=AA=20=E6=8A=9B=E5=88=B0=E5=A4=96=E5=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/pw/yumc/MiaoScript/ScriptEngine.java | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/main/java/pw/yumc/MiaoScript/ScriptEngine.java b/src/main/java/pw/yumc/MiaoScript/ScriptEngine.java index 401249b..f859f58 100644 --- a/src/main/java/pw/yumc/MiaoScript/ScriptEngine.java +++ b/src/main/java/pw/yumc/MiaoScript/ScriptEngine.java @@ -12,6 +12,7 @@ import java.nio.file.Path; import javax.script.ScriptEngineManager; import javax.script.ScriptException; +import lombok.SneakyThrows; import pw.yumc.YumCore.engine.MiaoScriptEngine; /** @@ -31,30 +32,24 @@ public class ScriptEngine { enableEngine(); } + @SneakyThrows public void enableEngine() { - try { - ScriptEngineManager manager = new ScriptEngineManager(null); - this.engine = new MiaoScriptEngine(manager, "nashorn"); - this.engine.put("base", new Base()); - Path bios = Paths.get(root, "bios.js"); - // 如果存在自定义bios就加载自定义的 - if (Files.exists(bios)) { - this.engine.eval("load('" + bios.toFile().getCanonicalPath() + "')"); - } else { - 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); + ScriptEngineManager manager = new ScriptEngineManager(null); + this.engine = new MiaoScriptEngine(manager, "nashorn"); + this.engine.put("base", new Base()); + Path bios = Paths.get(root, "bios.js"); + // 如果存在自定义bios就加载自定义的 + if (Files.exists(bios)) { + this.engine.eval("load('" + bios.toFile().getCanonicalPath() + "')"); + } else { + this.engine.eval(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("bios.js"))); } + engine.invokeFunction("boot", root, logger); } + @SneakyThrows public void disableEngine() { - try { - engine.invokeFunction("disable"); - } catch (ScriptException | NoSuchMethodException e) { - // logger.log(Level.SEVERE, "MiaoScript 关闭失败!", e); - } + engine.invokeFunction("disable"); } public MiaoScriptEngine getEngine() {