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[]
}
use of javax.script.ScriptEngineManager in project camel by apache.
the class ScriptBuilder method tryCreateScriptEngine.
/**
* Attemps to create the script engine for the given langauge using the classloader
*
* @return the engine, or <tt>null</tt> if not able to create
*/
private static ScriptEngine tryCreateScriptEngine(String language, ClassLoader classLoader) {
ScriptEngineManager manager = new ScriptEngineManager(classLoader);
ScriptEngine engine = null;
// some script names has alias
String[] names = getScriptNames(language);
for (String name : names) {
try {
engine = manager.getEngineByName(name);
if (engine != null) {
break;
}
} catch (NoClassDefFoundError ex) {
LOG.warn("Cannot load ScriptEngine for " + name + ". Please ensure correct JARs is provided on classpath (stacktrace in DEBUG logging).");
// include stacktrace in debug logging
LOG.debug("Cannot load ScriptEngine for " + name + ". Please ensure correct JARs is provided on classpath.", ex);
}
}
if (engine == null) {
engine = checkForOSGiEngine(language);
}
if (engine != null && isPython(language)) {
ScriptContext context = engine.getContext();
context.setAttribute("com.sun.script.jython.comp.mode", "eval", ScriptContext.ENGINE_SCOPE);
}
return engine;
}
use of javax.script.ScriptEngineManager in project camel by apache.
the class Jsr223Test method testLanguageNames.
@Test
public void testLanguageNames() throws Exception {
ScriptEngineManager manager = new ScriptEngineManager();
for (String scriptName : scriptNames) {
ScriptEngine engine = manager.getEngineByName(scriptName);
assertNotNull("We should get the script engine for " + scriptName, engine);
}
}
use of javax.script.ScriptEngineManager in project es6draft by anba.
the class InvocableTest method setUp.
@Before
public void setUp() {
manager = new ScriptEngineManager();
engine = manager.getEngineByName("es6draft");
assertThat(engine, notNullValue());
assertThat(engine, instanceOf(Invocable.class));
invocable = (Invocable) engine;
}
use of javax.script.ScriptEngineManager in project es6draft by anba.
the class TypeConversionTest method setUp.
@Before
public void setUp() {
manager = new ScriptEngineManager();
engine = manager.getEngineByName("es6draft");
assertThat(engine, notNullValue());
}
Aggregations