use of javax.script.ScriptEngineManager in project lucene-solr by apache.
the class StatelessScriptUpdateProcessorFactoryTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
Assume.assumeNotNull((new ScriptEngineManager()).getEngineByExtension("js"));
initCore("solrconfig-script-updateprocessor.xml", "schema12.xml");
}
use of javax.script.ScriptEngineManager in project lucene-solr by apache.
the class ScriptEngineTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
assumeFalse("https://twitter.com/UweSays/status/260487231880433664 / SOLR-4233: OS X bogusly starts AWT!", Constants.MAC_OS_X);
Assume.assumeNotNull((new ScriptEngineManager()).getEngineByExtension("js"));
Assume.assumeNotNull((new ScriptEngineManager()).getEngineByName("JavaScript"));
}
use of javax.script.ScriptEngineManager in project lucene-solr by apache.
the class StatelessScriptUpdateProcessorFactory method initEngines.
//================================================ Helper Methods ==================================================
/**
* Initializes a list of script engines - an engine per script file.
*
* @param req The solr request.
* @param rsp The solr response
* @return The list of initialized script engines.
*/
private List<EngineInfo> initEngines(SolrQueryRequest req, SolrQueryResponse rsp) throws SolrException {
List<EngineInfo> scriptEngines = new ArrayList<>();
ScriptEngineManager scriptEngineManager = new ScriptEngineManager(resourceLoader.getClassLoader());
scriptEngineManager.put("logger", log);
scriptEngineManager.put("req", req);
scriptEngineManager.put("rsp", rsp);
if (params != null) {
scriptEngineManager.put("params", params);
}
for (ScriptFile scriptFile : scriptFiles) {
ScriptEngine engine = null;
if (null != engineName) {
engine = scriptEngineManager.getEngineByName(engineName);
if (engine == null) {
String details = getSupportedEngines(scriptEngineManager, false);
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "No ScriptEngine found by name: " + engineName + (null != details ? " -- supported names: " + details : ""));
}
} else {
engine = scriptEngineManager.getEngineByExtension(scriptFile.getExtension());
if (engine == null) {
String details = getSupportedEngines(scriptEngineManager, true);
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "No ScriptEngine found by file extension: " + scriptFile.getFileName() + (null != details ? " -- supported extensions: " + details : ""));
}
}
if (!(engine instanceof Invocable)) {
String msg = "Engine " + ((null != engineName) ? engineName : ("for script " + scriptFile.getFileName())) + " does not support function invocation (via Invocable): " + engine.getClass().toString() + " (" + engine.getFactory().getEngineName() + ")";
log.error(msg);
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, msg);
}
if (scriptEngineCustomizer != null) {
scriptEngineCustomizer.customize(engine);
}
scriptEngines.add(new EngineInfo((Invocable) engine, scriptFile));
try {
Reader scriptSrc = scriptFile.openReader(resourceLoader);
try {
engine.eval(scriptSrc);
} catch (ScriptException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unable to evaluate script: " + scriptFile.getFileName(), e);
} finally {
IOUtils.closeQuietly(scriptSrc);
}
} catch (IOException ioe) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unable to evaluate script: " + scriptFile.getFileName(), ioe);
}
}
return scriptEngines;
}
use of javax.script.ScriptEngineManager in project yyl_example by Relucent.
the class BindingsScript method main.
public static void main(String[] args) {
try {
ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript");
String script = "print('hello')";
Bindings bindings = new SimpleBindings();
if (engine instanceof Compilable) {
System.out.println("Compiling....");
Compilable compEngine = (Compilable) engine;
CompiledScript cs = compEngine.compile(script);
cs.eval(bindings);
} else {
engine.eval(script, bindings);
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of javax.script.ScriptEngineManager in project yyl_example by Relucent.
the class HelloWorld method main.
public static void main(String[] args) throws Exception {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
testHelloWorld(engine);
testScriptVariables(engine);
testInvokeScriptMethod(engine);
testScriptInterface(engine);
testUsingJDKClasses(engine);
}
Aggregations