use of org.phoenicis.scripts.exceptions.ScriptException in project POL-POM-5 by PlayOnLinux.
the class IncludeInjector method injectInto.
@Override
public void injectInto(PhoenicisScriptEngine phoenicisScriptEngine) {
// store scripts that are currently in progress
final Stack<String> includeStack = new Stack<>();
// store included scripts (include path -> JS object)
final Map<String, Object> includedScripts = new HashMap<>();
phoenicisScriptEngine.put("include", (Function<String, Object>) argument -> {
if (includeStack.contains(argument)) {
throw new CircularIncludeException(argument, includeStack);
}
includeStack.push(argument);
if (!includedScripts.containsKey(argument)) {
final String script = scriptFetcher.getScript(argument);
if (script == null) {
throw new ScriptNotFoundException(argument);
}
try {
String extendedString = String.format("(module) => { %s }", script);
Value includeFunction = (Value) phoenicisScriptEngine.evalAndReturn(extendedString, this::throwException);
Value module = (Value) phoenicisScriptEngine.evalAndReturn("({})", this::throwException);
includeFunction.execute(module);
if (module.hasMember("default")) {
includedScripts.put(argument, module.getMember("default"));
} else {
includedScripts.put(argument, module);
}
} catch (ScriptException se) {
throw new IncludeException(argument, se);
}
}
includeStack.pop();
return includedScripts.get(argument);
}, this::throwException);
}
use of org.phoenicis.scripts.exceptions.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);
}
}
use of org.phoenicis.scripts.exceptions.ScriptException in project POL-POM-5 by PhoenicisOrg.
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);
}
}
use of org.phoenicis.scripts.exceptions.ScriptException in project POL-POM-5 by PlayOnLinux.
the class VerbsManager method installVerb.
/**
* Installs a Verb in a given container
*
* @param engineId ID of the engine which provides the Verb (e.g. "Wine")
* @param container name of the container
* @param verbId ID of the Verb
* @param doneCallback callback executed after the script ran
* @param errorCallback callback executed in case of an error
*/
public void installVerb(String engineId, String container, String verbId, Runnable doneCallback, Consumer<Exception> errorCallback) {
final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
final String script = String.format("include(\"%s\");", verbId);
interactiveScriptSession.eval(script, output -> {
final Value verbClass = (Value) output;
try {
verbClass.invokeMember("install", container);
} catch (ScriptException se) {
errorCallback.accept(se);
}
doneCallback.run();
}, errorCallback);
}
use of org.phoenicis.scripts.exceptions.ScriptException in project POL-POM-5 by PhoenicisOrg.
the class VerbsManager method installVerb.
/**
* Installs a Verb in a given container
*
* @param engineId ID of the engine which provides the Verb (e.g. "Wine")
* @param container name of the container
* @param verbId ID of the Verb
* @param doneCallback callback executed after the script ran
* @param errorCallback callback executed in case of an error
*/
public void installVerb(String engineId, String container, String verbId, Runnable doneCallback, Consumer<Exception> errorCallback) {
final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
final String script = String.format("include(\"%s\");", verbId);
interactiveScriptSession.eval(script, output -> {
final Value verbClass = (Value) output;
try {
verbClass.invokeMember("install", container);
} catch (ScriptException se) {
errorCallback.accept(se);
}
doneCallback.run();
}, errorCallback);
}
Aggregations