Search in sources :

Example 76 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project sass-maven-plugin by Jasig.

the class AbstractSassMojo method executeSassScript.

/**
     * Execute the SASS Compilation Ruby Script
     */
protected void executeSassScript(String sassScript) throws MojoExecutionException, MojoFailureException {
    final Log log = this.getLog();
    System.setProperty("org.jruby.embed.localcontext.scope", "threadsafe");
    log.debug("Execute SASS Ruby Script:\n" + sassScript);
    final ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
    final ScriptEngine jruby = scriptEngineManager.getEngineByName("jruby");
    try {
        CompilerCallback compilerCallback = new CompilerCallback(log);
        jruby.getBindings(ScriptContext.ENGINE_SCOPE).put("compiler_callback", compilerCallback);
        jruby.eval(sassScript);
        if (failOnError && compilerCallback.hadError()) {
            throw new MojoFailureException("SASS compilation encountered errors (see above for details).");
        }
    } catch (final ScriptException e) {
        throw new MojoExecutionException("Failed to execute SASS ruby script:\n" + sassScript, e);
    }
}
Also used : ScriptException(javax.script.ScriptException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Log(org.apache.maven.plugin.logging.Log) ScriptEngineManager(javax.script.ScriptEngineManager) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ScriptEngine(javax.script.ScriptEngine)

Example 77 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project spring-framework by spring-projects.

the class ScriptTemplateView method createEngineFromName.

protected ScriptEngine createEngineFromName() {
    if (this.scriptEngineManager == null) {
        this.scriptEngineManager = new ScriptEngineManager(getApplicationContext().getClassLoader());
    }
    ScriptEngine engine = StandardScriptUtils.retrieveEngineByName(this.scriptEngineManager, this.engineName);
    loadScripts(engine);
    return engine;
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager) ScriptEngine(javax.script.ScriptEngine)

Example 78 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project groovy by apache.

the class JSR223SpecTest method testSimpleExample.

@Test
public void testSimpleExample() throws ScriptException {
    // tag::jsr223_init[]
    ScriptEngineManager factory = new ScriptEngineManager();
    ScriptEngine engine = factory.getEngineByName("groovy");
    // end::jsr223_init[]
    // tag::jsr223_basic[]
    Integer sum = (Integer) engine.eval("(1..10).sum()");
    assertEquals(new Integer(55), sum);
    // end::jsr223_basic[]
    // tag::jsr223_variables[]
    engine.put("first", "HELLO");
    engine.put("second", "world");
    String result = (String) engine.eval("first.toLowerCase() + ' ' + second.toUpperCase()");
    assertEquals("hello WORLD", result);
// end::jsr223_variables[]
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager) ScriptEngine(javax.script.ScriptEngine) Test(org.junit.Test)

Example 79 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project intellij-community by JetBrains.

the class JavaFxInjectPageLanguageIntention method getAvailableLanguages.

public static Set<String> getAvailableLanguages(Project project) {
    final List<ScriptEngineFactory> engineFactories = new ScriptEngineManager(composeUserClassLoader(project)).getEngineFactories();
    if (engineFactories != null) {
        final Set<String> availableNames = new TreeSet<>();
        for (ScriptEngineFactory factory : engineFactories) {
            final String engineName = (String) factory.getParameter(ScriptEngine.NAME);
            availableNames.add(engineName);
        }
        return availableNames;
    }
    return null;
}
Also used : ScriptEngineFactory(javax.script.ScriptEngineFactory) ScriptEngineManager(javax.script.ScriptEngineManager)

Example 80 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project java8-tutorial by winterbe.

the class Nashorn1 method main.

public static void main(String[] args) throws Exception {
    ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
    engine.eval(new FileReader("res/nashorn1.js"));
    Invocable invocable = (Invocable) engine;
    Object result = invocable.invokeFunction("fun1", "Peter Parker");
    System.out.println(result);
    System.out.println(result.getClass());
    invocable.invokeFunction("fun2", new Date());
    invocable.invokeFunction("fun2", LocalDateTime.now());
    invocable.invokeFunction("fun2", new Person());
}
Also used : Invocable(javax.script.Invocable) ScriptEngineManager(javax.script.ScriptEngineManager) FileReader(java.io.FileReader) Person(com.winterbe.java8.samples.lambda.Person) ScriptEngine(javax.script.ScriptEngine) Date(java.util.Date)

Aggregations

ScriptEngineManager (javax.script.ScriptEngineManager)109 ScriptEngine (javax.script.ScriptEngine)66 Test (org.junit.Test)23 ScriptException (javax.script.ScriptException)20 ScriptEngineFactory (javax.script.ScriptEngineFactory)14 File (java.io.File)12 Invocable (javax.script.Invocable)11 QuickTest (com.hazelcast.test.annotation.QuickTest)10 IOException (java.io.IOException)10 FileReader (java.io.FileReader)9 Bindings (javax.script.Bindings)9 Before (org.junit.Before)9 Map (java.util.Map)8 GroovyScriptEngineFactory (org.codehaus.groovy.jsr223.GroovyScriptEngineFactory)8 Reader (java.io.Reader)7 HashMap (java.util.HashMap)6 SimpleBindings (javax.script.SimpleBindings)6 PrintWriter (java.io.PrintWriter)4 StringWriter (java.io.StringWriter)4 InputStreamReader (java.io.InputStreamReader)3