use of org.phoenicis.scripts.interpreter.InteractiveScriptSession in project POL-POM-5 by PhoenicisOrg.
the class EnginesController method deleteEngine.
private void deleteEngine(EngineDTO engineDTO, Consumer<Exception> errorCallback) {
final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
interactiveScriptSession.eval("include([\"Engines\", \"" + engineDTO.getCategory() + "\", \"Engine\", \"Object\"]);", ignored -> interactiveScriptSession.eval("new Wine()", output -> {
final ScriptObjectMirror wine = (ScriptObjectMirror) output;
wine.callMember("delete", engineDTO.getCategory(), engineDTO.getSubCategory(), engineDTO.getVersion(), engineDTO.getUserData());
}, errorCallback), errorCallback);
}
use of org.phoenicis.scripts.interpreter.InteractiveScriptSession in project POL-POM-5 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 org.phoenicis.scripts.interpreter.InteractiveScriptSession in project POL-POM-5 by PhoenicisOrg.
the class WinePrefixContainerController method runInContainer.
public void runInContainer(ContainerDTO container, String command, Runnable doneCallback, Consumer<Exception> errorCallback) {
final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
interactiveScriptSession.eval("include([\"Engines\", \"" + container.getEngine() + "\", \"Engine\", \"Object\"]);", ignored -> interactiveScriptSession.eval("new " + container.getEngine() + "()", output -> {
final ScriptObjectMirror wine = (ScriptObjectMirror) output;
wine.callMember("prefix", container.getName());
wine.callMember("run", command);
wine.callMember("wait");
doneCallback.run();
}, errorCallback), errorCallback);
}
use of org.phoenicis.scripts.interpreter.InteractiveScriptSession in project phoenicis by PhoenicisOrg.
the class ShortcutManager method uninstallFromShortcut.
public void uninstallFromShortcut(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("uninstall");
}, errorCallback), errorCallback);
}
use of org.phoenicis.scripts.interpreter.InteractiveScriptSession in project phoenicis by PhoenicisOrg.
the class EnginesSource method fetchAvailableEngines.
public void fetchAvailableEngines(List<CategoryDTO> categoryDTOS, Consumer<List<EngineCategoryDTO>> callback) {
final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
StringBuilder includesBuilder = new StringBuilder();
StringBuilder constructorsBuilder = new StringBuilder();
constructorsBuilder.append("function fetchEngines() {\n");
constructorsBuilder.append("var engines = [];\n");
for (CategoryDTO categoryDTO : categoryDTOS) {
final String engineName = categoryDTO.getName();
includesBuilder.append("include([\"Engines\", \"" + engineName + "\", \"Engine\", \"Object\"]);\n");
constructorsBuilder.append("engines[\"" + engineName + "\"] = new " + engineName + "().getAvailableVersions();\n");
}
constructorsBuilder.append("return engines;\n");
constructorsBuilder.append("}\n");
constructorsBuilder.append("fetchEngines();");
interactiveScriptSession.eval(includesBuilder.toString(), ignored -> interactiveScriptSession.eval(constructorsBuilder.toString(), output -> {
List<EngineCategoryDTO> engines = new ArrayList<>();
for (Map.Entry<String, Object> entry : ((Map<String, Object>) output).entrySet()) {
final EngineCategoryDTO engineCategoryDTO = new EngineCategoryDTO.Builder().withName(entry.getKey()).withDescription(entry.getKey()).withSubCategories(unSerialize(entry.getValue())).build();
engines.add(engineCategoryDTO);
}
callback.accept(engines);
}, this::throwError), this::throwError);
}
Aggregations