use of org.phoenicis.scripts.interpreter.ScriptException in project POL-POM-5 by PlayOnLinux.
the class NashornEngineFactory method createEngine.
NashornEngine createEngine() {
final Set<List<String>> includedScripts = new HashSet<>();
final NashornEngine nashornEngine = new NashornEngine(new ScriptEngineManager().getEngineByName("nashorn"));
nashornEngine.eval(new InputStreamReader(getClass().getResourceAsStream("utils.js")), this::throwException);
nashornEngine.put("Bean", (Function<String, Object>) title -> applicationContext.getBean(title), this::throwException);
nashornEngine.put("SetupWizard", (Function<String, UiSetupWizardImplementation>) (name) -> {
final UiSetupWizardImplementation uiSetupWizardImplementation = uiSetupWizardFactory.create(name);
nashornEngine.addErrorHandler(e -> uiSetupWizardImplementation.close());
return uiSetupWizardImplementation;
}, this::throwException);
nashornEngine.put("EngineProgressUi", (Function<String, UiProgressWizardImplementation>) (name) -> {
final UiProgressWizardImplementation uiProgressWizardImplementation = uiProgressWizardFactory.create(name);
nashornEngine.addErrorHandler(e -> uiProgressWizardImplementation.close());
return uiProgressWizardImplementation;
}, this::throwException);
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);
return nashornEngine;
}
use of org.phoenicis.scripts.interpreter.ScriptException in project POL-POM-5 by PlayOnLinux.
the class UiSetupWizardImplementation method licenceFile.
/**
* 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);
}
}
Aggregations