use of jdk.nashorn.api.scripting.ScriptObjectMirror in project phoenicis by PhoenicisOrg.
the class GenericContainersManager method deleteContainer.
/**
* {@inheritDoc}
* @param container
* @param errorCallback
*/
@Override
public void deleteContainer(ContainerDTO container, Consumer<Exception> errorCallback) {
try {
this.fileUtilities.remove(new File(container.getPath()));
} catch (IOException e) {
LOGGER.error("Cannot delete container (" + container.getPath() + ")! Exception: " + e.toString());
errorCallback.accept(e);
}
List<ShortcutCategoryDTO> categories = this.libraryManager.fetchShortcuts();
categories.stream().flatMap(shortcutCategoryDTO -> shortcutCategoryDTO.getShortcuts().stream()).forEach(shortcutDTO -> {
final InteractiveScriptSession interactiveScriptSession = this.scriptInterpreter.createInteractiveSession();
interactiveScriptSession.eval("include([\"Engines\", \"" + container.getEngine() + "\", \"Shortcuts\", \"Reader\"]);", ignored -> interactiveScriptSession.eval("new ShortcutReader()", output -> {
final ScriptObjectMirror shortcutReader = (ScriptObjectMirror) output;
shortcutReader.callMember("of", shortcutDTO);
final String containerName = (String) shortcutReader.callMember("container");
if (containerName.equals(container.getName())) {
this.shortcutManager.deleteShortcut(shortcutDTO);
}
}, errorCallback), errorCallback);
});
}
use of jdk.nashorn.api.scripting.ScriptObjectMirror in project phoenicis by PhoenicisOrg.
the class LibraryController method createShortcut.
/**
* creates a new shortcut
* @param shortcutCreationDTO DTO describing the new shortcut
*/
private void createShortcut(ShortcutCreationDTO shortcutCreationDTO) {
// get container
// TODO: smarter way using container manager
final String executablePath = shortcutCreationDTO.getExecutable().getAbsolutePath();
final String pathInContainers = executablePath.replace(containersPath, "");
final String[] split = pathInContainers.split("/");
final String engineContainer = split[0];
final String engine = (Character.toUpperCase(engineContainer.charAt(0)) + engineContainer.substring(1)).replace("prefix", "");
final String container = split[1];
final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
interactiveScriptSession.eval("include([\"Engines\", \"" + engine + "\", \"Shortcuts\", \"" + engine + "\"]);", ignored -> interactiveScriptSession.eval("new " + engine + "Shortcut()", output -> {
final ScriptObjectMirror shortcutObject = (ScriptObjectMirror) output;
shortcutObject.callMember("name", shortcutCreationDTO.getName());
shortcutObject.callMember("category", shortcutCreationDTO.getCategory());
shortcutObject.callMember("description", shortcutCreationDTO.getDescription());
shortcutObject.callMember("miniature", shortcutCreationDTO.getMiniature());
shortcutObject.callMember("search", shortcutCreationDTO.getExecutable().getName());
shortcutObject.callMember("prefix", container);
shortcutObject.callMember("create");
}, e -> this.showErrorMessage(e, tr("Error while creating shortcut"))), e -> this.showErrorMessage(e, tr("Error while creating shortcut")));
}
use of jdk.nashorn.api.scripting.ScriptObjectMirror in project phoenicis by PhoenicisOrg.
the class ShortcutRunner method run.
public void run(ShortcutDTO shortcutDTO, List<String> arguments, Consumer<Exception> errorCallback) {
final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
interactiveScriptSession.eval("include([\"Engines\", \"Wine\", \"Shortcuts\", \"Reader\"]);", ignored -> interactiveScriptSession.eval("new ShortcutReader()", output -> {
final ScriptObjectMirror shortcutReader = (ScriptObjectMirror) output;
shortcutReader.callMember("of", shortcutDTO);
shortcutReader.callMember("run", arguments);
}, errorCallback), errorCallback);
}
use of jdk.nashorn.api.scripting.ScriptObjectMirror in project phoenicis by PhoenicisOrg.
the class ShortcutRunner method stop.
public void stop(ShortcutDTO shortcutDTO, Consumer<Exception> errorCallback) {
final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
interactiveScriptSession.eval("include([\"Engines\", \"Wine\", \"Shortcuts\", \"Reader\"]);", ignored -> interactiveScriptSession.eval("new ShortcutReader()", output -> {
final ScriptObjectMirror shortcutReader = (ScriptObjectMirror) output;
shortcutReader.callMember("of", shortcutDTO);
shortcutReader.callMember("stop");
}, errorCallback), errorCallback);
}
use of jdk.nashorn.api.scripting.ScriptObjectMirror in project phoenicis by PhoenicisOrg.
the class EngineToolsManager method runTool.
/**
* runs a tool in a given container
* @param engineId ID of the engine which provides the tool (e.g. "Wine")
* @param container name of the container
* @param toolId ID of the tool
* @param doneCallback callback executed after the script ran
* @param errorCallback callback executed in case of an error
*/
public void runTool(String engineId, String container, String toolId, Runnable doneCallback, Consumer<Exception> errorCallback) {
final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
interactiveScriptSession.eval("include([\"Engines\", \"" + engineId + "\", \"Tools\", \"" + toolId + "\"]);", ignored -> interactiveScriptSession.eval("new " + toolId + "()", output -> {
final ScriptObjectMirror toolObject = (ScriptObjectMirror) output;
toolObject.callMember("run", container);
doneCallback.run();
}, errorCallback), errorCallback);
}
Aggregations