Search in sources :

Example 21 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project enhydrator by AdamBien.

the class ScriptingEnvironmentProviderTest method emptyRowHasMemory.

@Test
public void emptyRowHasMemory() {
    Row row = new Row();
    Memory expected = new Memory();
    row.useMemory(expected);
    Bindings bindings = ScriptingEnvironmentProvider.create(new ScriptEngineManager(), null, row);
    Object actual = bindings.get("$MEMORY");
    assertNotNull(actual);
    assertThat(actual, is(expected));
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager) Row(com.airhacks.enhydrator.in.Row) Bindings(javax.script.Bindings) Test(org.junit.Test)

Example 22 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project enhydrator by AdamBien.

the class ScriptableSource method init.

public void init() throws IllegalStateException, IllegalArgumentException {
    this.rows = new ArrayList<>();
    this.charset = Charset.forName(charsetName);
    ScriptEngineManager manager = new ScriptEngineManager();
    this.nashorn = manager.getEngineByName("javascript");
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager)

Example 23 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project enhydrator by AdamBien.

the class ScriptableSink method init.

@Override
public void init() {
    requireNonNull(this.scriptFile, "Cannot initialize ScriptableSink without script.");
    try {
        this.scriptContent = load(this.scriptFile);
    } catch (IOException ex) {
        throw new IllegalStateException("Cannot load script from: " + this.scriptFile, ex);
    }
    ScriptEngineManager sem = new ScriptEngineManager();
    this.engine = sem.getEngineByName("javascript");
    try {
        this.engine.eval(this.scriptContent);
    } catch (ScriptException ex) {
        throw new IllegalStateException("Parsing script failed. Problem in line: " + ex.getLineNumber() + " and column: " + ex.getColumnNumber(), ex);
    }
    this.invocable = (Invocable) engine;
    this.sink = this.invocable.getInterface(Sink.class);
    requireNonNull(this.sink, "Sink instantiation failed - script: " + this.scriptContent + " is incompatible");
    this.sink.init();
}
Also used : ScriptException(javax.script.ScriptException) ScriptEngineManager(javax.script.ScriptEngineManager) IOException(java.io.IOException)

Example 24 with ScriptEngineManager

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

the class Nashorn2 method main.

public static void main(String[] args) throws Exception {
    ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
    engine.eval(new FileReader("res/nashorn2.js"));
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager) FileReader(java.io.FileReader) ScriptEngine(javax.script.ScriptEngine)

Example 25 with ScriptEngineManager

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

the class Nashorn3 method main.

public static void main(String[] args) throws Exception {
    ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
    engine.eval("load('res/nashorn3.js')");
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager) ScriptEngine(javax.script.ScriptEngine)

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