use of javax.script.ScriptEngine in project meecrowave by apache.
the class MeecrowaveRunMojo method scriptCustomization.
private void scriptCustomization(final List<String> customizers, final String ext, final Map<String, Object> customBindings) {
if (customizers == null || customizers.isEmpty()) {
return;
}
final ScriptEngine engine = new ScriptEngineManager().getEngineByExtension(ext);
if (engine == null) {
throw new IllegalStateException("No engine for " + ext + ". Maybe add the JSR223 implementation as plugin dependency.");
}
for (final String js : customizers) {
try {
final SimpleBindings bindings = new SimpleBindings();
bindings.put("project", project);
engine.eval(new StringReader(js), bindings);
bindings.putAll(customBindings);
} catch (final ScriptException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
}
use of javax.script.ScriptEngine in project metrics by dropwizard.
the class PickledGraphiteTest method setUp.
@Before
public void setUp() throws Exception {
final AtomicBoolean connected = new AtomicBoolean(true);
final AtomicBoolean closed = new AtomicBoolean(false);
when(socket.isConnected()).thenAnswer(invocation -> connected.get());
when(socket.isClosed()).thenAnswer(invocation -> closed.get());
doAnswer(invocation -> {
connected.set(false);
closed.set(true);
return null;
}).when(socket).close();
when(socket.getOutputStream()).thenReturn(output);
// Mock behavior of socket.getOutputStream().close() calling socket.close();
doAnswer(invocation -> {
invocation.callRealMethod();
socket.close();
return null;
}).when(output).close();
when(socketFactory.createSocket(any(InetAddress.class), anyInt())).thenReturn(socket);
ScriptEngine engine = new ScriptEngineManager().getEngineByName("python");
Compilable compilable = (Compilable) engine;
try (InputStream is = PickledGraphiteTest.class.getResource("/upickle.py").openStream()) {
unpickleScript = compilable.compile(new InputStreamReader(is, UTF_8));
}
}
use of javax.script.ScriptEngine in project Lucee by lucee.
the class Script2 method getScriptEngine.
public ScriptEngine getScriptEngine() throws PageException {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName(language);
// get engine by engine name
if (engine == null) {
Iterator<ScriptEngineFactory> it = manager.getEngineFactories().iterator();
ScriptEngineFactory factory;
while (it.hasNext()) {
factory = it.next();
if (language.equalsIgnoreCase(factory.getEngineName())) {
engine = factory.getScriptEngine();
break;
}
}
}
// get engine by language name
if (engine == null) {
Iterator<ScriptEngineFactory> it = manager.getEngineFactories().iterator();
ScriptEngineFactory factory;
while (it.hasNext()) {
factory = it.next();
if (language.equalsIgnoreCase(factory.getEngineName())) {
engine = factory.getScriptEngine();
break;
}
}
}
if (engine == null) {
Iterator<ScriptEngineFactory> it = manager.getEngineFactories().iterator();
ScriptEngineFactory factory;
StringBuilder sb = new StringBuilder();
while (it.hasNext()) {
factory = it.next();
if (sb.length() > 0)
sb.append(',');
sb.append(factory.getEngineName());
}
throw this.engine.getExceptionUtil().createApplicationException("language [" + language + "] is not supported, supported languages are [" + sb + "]");
}
return engine;
}
use of javax.script.ScriptEngine in project Lucee by lucee.
the class Main method main.
public static void main(final String[] args) throws Exception {
String lang = "CFML";
String code = null;
String arg;
final String pw = null, key = null;
for (int i = 0; i < args.length; i++) {
arg = args[i];
if ("-l".equals(arg)) {
if (args.length > i + 1)
lang = args[++i].trim();
} else if ("-e".equals(arg))
if (args.length > i + 1)
code = args[++i].trim();
}
final int dialect = CFMLEngine.DIALECT_CFML;
if (code == null)
printUsage("-e is missing", System.err);
final LuceeScriptEngineFactory factory = new LuceeScriptEngineFactory();
System.out.println(factory.getScriptEngine().eval(code));
final ScriptEngine engine = new ScriptEngineManager().getEngineByName(lang);
if (engine == null)
System.out.println("could not load a engine with the name:" + lang);
else
System.out.println(engine.eval(code));
}
use of javax.script.ScriptEngine in project tomee by apache.
the class OpenEJBScripter method evaluate.
public Object evaluate(final String language, final String script, final ScriptContext context) throws ScriptException {
if (!ENGINE_FACTORIES.containsKey(language)) {
throw new IllegalArgumentException("can't find factory for language " + language + ". You probably need to add the jar to openejb libs.");
}
ScriptContext executionContext = context;
if (executionContext == null) {
executionContext = new SimpleScriptContext();
}
// we bind local variables (per execution) every time we execute a script
bindLocal(executionContext);
final ScriptEngine engine = engine(language);
return engine.eval(script, executionContext);
}
Aggregations