Search in sources :

Example 86 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project bytecode-viewer by Konloch.

the class GroovyPluginLaunchStrategy method run.

@Override
public Plugin run(File file) throws Throwable {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("groovy");
    if (engine == null)
        throw new Exception("Cannot find Groovy script engine! Please contact Konloch.");
    Reader reader = new FileReader(file);
    engine.eval(reader);
    return (Plugin) engine.eval("new " + file.getName().replace(".gy", "").replace(".groovy", "") + "();");
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager) FileReader(java.io.FileReader) Reader(java.io.Reader) FileReader(java.io.FileReader) ScriptEngine(javax.script.ScriptEngine) Plugin(the.bytecode.club.bytecodeviewer.api.Plugin)

Example 87 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project bytecode-viewer by Konloch.

the class PythonPluginLaunchStrategy method run.

@Override
public Plugin run(File file) throws Throwable {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("python");
    if (engine == null)
        throw new Exception("Cannot find Jython script engine! Please contact Konloch.");
    Reader reader = new FileReader(file);
    engine.eval(reader);
    return (Plugin) engine.eval(file.getName().replace(".py", "").replace(".python", "") + "()");
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager) FileReader(java.io.FileReader) Reader(java.io.Reader) FileReader(java.io.FileReader) ScriptEngine(javax.script.ScriptEngine) Plugin(the.bytecode.club.bytecodeviewer.api.Plugin)

Example 88 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project bytecode-viewer by Konloch.

the class RubyPluginLaunchStrategy method run.

@Override
public Plugin run(File file) throws Throwable {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("jruby");
    if (engine == null)
        throw new Exception("Cannot find jRuby script engine! Please contact Konloch.");
    Reader reader = new FileReader(file);
    engine.eval(reader);
    return (Plugin) engine.eval(file.getName().replace(".rb", "").replace(".ruby", "") + ".new");
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager) FileReader(java.io.FileReader) Reader(java.io.Reader) FileReader(java.io.FileReader) ScriptEngine(javax.script.ScriptEngine) Plugin(the.bytecode.club.bytecodeviewer.api.Plugin)

Example 89 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project incubator-atlas by apache.

the class Titan0Graph method getGremlinScriptEngine.

@Override
public ScriptEngine getGremlinScriptEngine() throws AtlasBaseException {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("gremlin-groovy");
    if (engine == null) {
        throw new AtlasBaseException(AtlasErrorCode.FAILED_TO_OBTAIN_GREMLIN_SCRIPT_ENGINE, "gremlin-groovy");
    }
    //Do not cache script compilations due to memory implications
    engine.getContext().setAttribute("#jsr223.groovy.engine.keep.globals", "phantom", ScriptContext.ENGINE_SCOPE);
    return engine;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ScriptEngineManager(javax.script.ScriptEngineManager) ScriptEngine(javax.script.ScriptEngine)

Example 90 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project lucene-solr by apache.

the class StatelessScriptUpdateProcessorFactoryTest method testForceEngine.

public void testForceEngine() throws Exception {
    Assume.assumeNotNull((new ScriptEngineManager()).getEngineByName("javascript"));
    final String chain = "force-script-engine";
    SolrInputDocument d = processAdd(chain, doc(f("id", "5"), f("name", " foo "), f("subject", "bar")));
    assertEquals(chain + " didn't add Double field", 42.3d, d.getFieldValue("script_added_d"));
    assertEquals(chain + " didn't add integer field", new Integer(42), d.getFieldValue("script_added_i"));
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) ScriptEngineManager(javax.script.ScriptEngineManager)

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