@Test (expected = ScriptLoadException.class) public void testLoadNotExistentFile () throws ScriptLoadException { JSRhinoScriptEngine engine = new JSRhinoScriptEngine(); engine.loadFile(new File("not-existent-file.js")); }
@Override public void loadFile(File file) throws ScriptLoadException { Objects.requireNonNull(file); if (!file.exists()) { throw new ScriptLoadException("js script file doesn't exists: " + file.getAbsolutePath()); } ExceptionUtils.throwSLEOnException(SCRIPTS_TAG, "Cannot read script file: " + file.getAbsolutePath() + ", IOException: ", () -> { File relFile = FileUtils.getRelativeFile(file, new File(".")); String scriptName = relFile.getPath().replace("\\", "/"); if (!this.scripts.containsKey(scriptName)) { String content = FileUtils.readFile(file.getAbsolutePath(), StandardCharsets.UTF_8); this.compile(scriptName, content); } this.execScript(scriptName); }); }
JSRhinoScriptEngine implements IScriptEngine { @Override public void loadFile(File file) throws ScriptLoadException { Objects.requireNonNull(file); if (!file.exists()) { throw new ScriptLoadException("js script file doesn't exists: " + file.getAbsolutePath()); } ExceptionUtils.throwSLEOnException(SCRIPTS_TAG, "Cannot read script file: " + file.getAbsolutePath() + ", IOException: ", () -> { File relFile = FileUtils.getRelativeFile(file, new File(".")); String scriptName = relFile.getPath().replace("\\", "/"); if (!this.scripts.containsKey(scriptName)) { String content = FileUtils.readFile(file.getAbsolutePath(), StandardCharsets.UTF_8); this.compile(scriptName, content); } this.execScript(scriptName); }); } }
JSRhinoScriptEngine implements IScriptEngine { @Override public void loadFile(File file) throws ScriptLoadException { Objects.requireNonNull(file); if (!file.exists()) { throw new ScriptLoadException("js script file doesn't exists: " + file.getAbsolutePath()); } ExceptionUtils.throwSLEOnException(SCRIPTS_TAG, "Cannot read script file: " + file.getAbsolutePath() + ", IOException: ", () -> { File relFile = FileUtils.getRelativeFile(file, new File(".")); String scriptName = relFile.getPath().replace("\\", "/"); if (!this.scripts.containsKey(scriptName)) { String content = FileUtils.readFile(file.getAbsolutePath(), StandardCharsets.UTF_8); this.compile(scriptName, content); } this.execScript(scriptName); }); } JSRhinoScriptEngine(); }
JSRhinoScriptEngine implements IScriptEngine { @Override public void loadFile(File file) throws ScriptLoadException { Objects.requireNonNull(file); if (!file.exists()) { throw new ScriptLoadException("js script file doesn't exists: " + file.getAbsolutePath()); } ExceptionUtils.throwSLEOnException(SCRIPTS_TAG, "Cannot read script file: " + file.getAbsolutePath() + ", IOException: ", () -> { File relFile = FileUtils.getRelativeFile(file, new File(".")); String scriptName = relFile.getPath().replace("\\", "/"); if (!this.scripts.containsKey(scriptName)) { String content = FileUtils.readFile(file.getAbsolutePath(), StandardCharsets.UTF_8); this.compile(scriptName, content); } this.execScript(scriptName); }); } JSRhinoScriptEngine(); @Override void compile(String scriptName, String programStr); @Override void loadFile(File file); @Override Object execFunc(String funcName, Object... args); @Override Object execFunc(String funcName); @Override Object execScript(String scriptName, Object... args); @Override void shutdown(); }
JSRhinoScriptEngine implements IScriptEngine { @Override public void loadFile(File file) throws ScriptLoadException { Objects.requireNonNull(file); if (!file.exists()) { throw new ScriptLoadException("js script file doesn't exists: " + file.getAbsolutePath()); } ExceptionUtils.throwSLEOnException(SCRIPTS_TAG, "Cannot read script file: " + file.getAbsolutePath() + ", IOException: ", () -> { File relFile = FileUtils.getRelativeFile(file, new File(".")); String scriptName = relFile.getPath().replace("\\", "/"); if (!this.scripts.containsKey(scriptName)) { String content = FileUtils.readFile(file.getAbsolutePath(), StandardCharsets.UTF_8); this.compile(scriptName, content); } this.execScript(scriptName); }); } JSRhinoScriptEngine(); @Override void compile(String scriptName, String programStr); @Override void loadFile(File file); @Override Object execFunc(String funcName, Object... args); @Override Object execFunc(String funcName); @Override Object execScript(String scriptName, Object... args); @Override void shutdown();  }