/** * Throws a ScriptException error (can be use as a lambda) * * @param parentException Parent exception */ default void throwException(Exception parentException) { throw new org.phoenicis.scripts.interpreter.ScriptException(parentException); } }
T get() { if (Thread.currentThread().isInterrupted()) { throw new ScriptException("The script was interrupted"); } return message; } }
void block() { senderThread = Thread.currentThread(); try { semaphore.acquire(); } catch (InterruptedException e) { throw new ScriptException(e); } }
/** * Show the content of a licence file * * @param textToShow a message above the licence * @param licenceFile the licence file to display (with 'from java.io import File') */ @Override public Void licenceFile(String textToShow, File licenceFile) { try { try (final FileInputStream content = new FileInputStream(licenceFile)) { final StringWriter writer = new StringWriter(); IOUtils.copy(content, writer, "UTF-8"); return licence(textToShow, writer.toString()); } } catch (IOException e) { throw new ScriptException("Cannot acces the licence file", e); } }
public String getScript(List<String> path) { final ScriptDTO script = repositoryManager.getScript(path); if (script == null) { throw new ScriptException("Script not found: " + path); } return script.getScript(); }
@Override public void injectInto(NashornEngine nashornEngine) { final Set<List<String>> includedScripts = new HashSet<>(); nashornEngine.put("include", (Consumer<ScriptObjectMirror>) args -> { final String[] arguments = args.to(String[].class); final String script = scriptFetcher.getScript(arguments); if (script == null) { throwException(new ScriptException(Arrays.asList(arguments).toString() + " is not found")); } if (includedScripts.add(Arrays.asList(arguments))) { nashornEngine.eval("//# sourceURL=" + Arrays.asList(arguments).toString() + "\n" + script, this::throwException); } }, this::throwException); } }