Search in sources :

Example 11 with ScriptObjectMirror

use of jdk.nashorn.api.scripting.ScriptObjectMirror in project POL-POM-5 by PhoenicisOrg.

the class WinePrefixContainerController method changeSetting.

public void changeSetting(WinePrefixContainerDTO winePrefix, RegistryParameter setting, Runnable doneCallback, Consumer<Exception> errorCallback) {
    final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
    final String registryPatch = registryWriter.generateRegFileContent(setting.toRegistryPatch());
    LOGGER.info("Updating registry for prefix: " + winePrefix.getPath());
    LOGGER.info(registryPatch);
    interactiveScriptSession.eval("include([\"Engines\", \"Wine\", \"Engine\", \"Object\"]);", ignored -> interactiveScriptSession.eval("new Wine()", output -> {
        final ScriptObjectMirror wine = (ScriptObjectMirror) output;
        wine.callMember("prefix", winePrefix.getName());
        final ScriptObjectMirror regedit = (ScriptObjectMirror) wine.callMember("regedit");
        regedit.callMember("patch", registryPatch);
        wine.callMember("wait");
        doneCallback.run();
    }, errorCallback), errorCallback);
}
Also used : Consumer(java.util.function.Consumer) RegistryWriter(org.phoenicis.win32.registry.RegistryWriter) RegistryParameter(org.phoenicis.containers.wine.parameters.RegistryParameter) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) WinePrefixContainerDTO(org.phoenicis.containers.dto.WinePrefixContainerDTO) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) ContainerDTO(org.phoenicis.containers.dto.ContainerDTO) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession)

Example 12 with ScriptObjectMirror

use of jdk.nashorn.api.scripting.ScriptObjectMirror in project POL-POM-5 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);
    });
}
Also used : ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) WinePrefixContainerInputConfiguration(org.phoenicis.containers.wine.configurations.WinePrefixContainerInputConfiguration) ContainerCategoryDTO(org.phoenicis.containers.dto.ContainerCategoryDTO) LoggerFactory(org.slf4j.LoggerFactory) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) Map(java.util.Map) ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ContainerDTO(org.phoenicis.containers.dto.ContainerDTO) WinePrefixContainerDisplayConfiguration(org.phoenicis.containers.wine.configurations.WinePrefixContainerDisplayConfiguration) Logger(org.slf4j.Logger) FileUtilities(org.phoenicis.tools.files.FileUtilities) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) Consumer(java.util.function.Consumer) List(java.util.List) ShortcutManager(org.phoenicis.library.ShortcutManager) ConfigFile(org.phoenicis.tools.config.ConfigFile) Safe(org.phoenicis.configuration.security.Safe) CompatibleConfigFileFormatFactory(org.phoenicis.tools.config.CompatibleConfigFileFormatFactory) CollectionUtils(org.springframework.util.CollectionUtils) WinePrefixContainerDTO(org.phoenicis.containers.dto.WinePrefixContainerDTO) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) LibraryManager(org.phoenicis.library.LibraryManager) Collections(java.util.Collections) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) IOException(java.io.IOException) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) File(java.io.File) ConfigFile(org.phoenicis.tools.config.ConfigFile)

Example 13 with ScriptObjectMirror

use of jdk.nashorn.api.scripting.ScriptObjectMirror in project POL-POM-5 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);
}
Also used : Logger(org.slf4j.Logger) Files(java.nio.file.Files) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LoggerFactory(org.slf4j.LoggerFactory) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) File(java.io.File) ShortcutInfoDTO(org.phoenicis.library.dto.ShortcutInfoDTO) Consumer(java.util.function.Consumer) Safe(org.phoenicis.configuration.security.Safe) ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) URI(java.net.URI) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession)

Example 14 with ScriptObjectMirror

use of jdk.nashorn.api.scripting.ScriptObjectMirror in project vue-gwt by Axellience.

the class VueTemplateCompiler method compile.

/**
 * Compile the given HTML template to JS functions using vue-template-compiler.
 * @param htmlTemplate The HTML Component template to compile
 * @return An object containing the render functions
 * @throws VueTemplateCompilerException If the compilation fails
 */
public VueTemplateCompilerResult compile(String htmlTemplate) throws VueTemplateCompilerException {
    ScriptObjectMirror templateCompilerResult;
    try {
        templateCompilerResult = (ScriptObjectMirror) engine.invokeFunction("compile", htmlTemplate);
    } catch (ScriptException | NoSuchMethodException e) {
        e.printStackTrace();
        throw new VueTemplateCompilerException("An error occurred while compiling the template: " + htmlTemplate + " -> " + e.getMessage());
    }
    String renderFunction = (String) templateCompilerResult.get("render");
    String[] staticRenderFunctions = ((ScriptObjectMirror) templateCompilerResult.get("staticRenderFns")).to(String[].class);
    return new VueTemplateCompilerResult(renderFunction, staticRenderFunctions);
}
Also used : ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) ScriptException(javax.script.ScriptException)

Example 15 with ScriptObjectMirror

use of jdk.nashorn.api.scripting.ScriptObjectMirror in project JSCover by tntim96.

the class BranchInstrumentorIntegrationTest method shouldWrapNonCoalesce.

@Test
public void shouldWrapNonCoalesce() throws Exception {
    String source = "function test(a) {\n  var x = a > 7;\n  }\ntest(3);";
    runScript(source, true);
    ScriptObjectMirror coverageData = (ScriptObjectMirror) engine.eval("_$jscoverage['test.js'].branchData[2][1]");
    assertThat(coverageData.get("evalTrue"), equalTo(0));
    assertThat(coverageData.get("evalFalse"), equalTo(1.0));
}
Also used : ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) Test(org.junit.Test)

Aggregations

ScriptObjectMirror (jdk.nashorn.api.scripting.ScriptObjectMirror)76 Test (org.junit.Test)34 InteractiveScriptSession (org.phoenicis.scripts.interpreter.InteractiveScriptSession)28 ScriptInterpreter (org.phoenicis.scripts.interpreter.ScriptInterpreter)28 Consumer (java.util.function.Consumer)27 List (java.util.List)23 LoggerFactory (org.slf4j.LoggerFactory)20 File (java.io.File)17 IOException (java.io.IOException)17 Logger (org.slf4j.Logger)14 WinePrefixContainerDTO (org.phoenicis.containers.dto.WinePrefixContainerDTO)12 Map (java.util.Map)11 ArrayList (java.util.ArrayList)10 RegistryParameter (org.phoenicis.containers.wine.parameters.RegistryParameter)10 LibraryManager (org.phoenicis.library.LibraryManager)10 ShortcutManager (org.phoenicis.library.ShortcutManager)10 ShortcutCategoryDTO (org.phoenicis.library.dto.ShortcutCategoryDTO)10 ShortcutDTO (org.phoenicis.library.dto.ShortcutDTO)10 RegistryWriter (org.phoenicis.win32.registry.RegistryWriter)10 URI (java.net.URI)8