use of javax.script.ScriptEngine in project scheduling by ow2-proactive.
the class EvalScriptCommand method execute.
@Override
public void execute(ApplicationContext currentContext) throws CLIException {
ScriptEngine engine = currentContext.getEngine();
Writer writer = currentContext.getDevice().getWriter();
if (scriptArgs != null) {
engine.getContext().getBindings(ScriptContext.ENGINE_SCOPE).putAll(bindings(scriptArgs));
}
String script = FileUtility.readFileToString(new File(scriptPathname));
try {
engine.eval(script);
} catch (ScriptException e) {
e.printStackTrace(new PrintWriter(writer, true));
}
}
use of javax.script.ScriptEngine in project scheduling by ow2-proactive.
the class Script method findScriptEngineCandidates.
private Map<ScriptEngine, Integer> findScriptEngineCandidates(boolean findByName) {
Map<ScriptEngine, Integer> matchPositionPerScriptEngineCandidate = new HashMap<>();
int matchPosition;
List<String> lookupCriteria;
for (ScriptEngineFactory factory : new ScriptEngineManager().getEngineFactories()) {
matchPosition = 0;
if (findByName) {
lookupCriteria = factory.getNames();
} else {
lookupCriteria = factory.getExtensions();
}
for (String criteria : lookupCriteria) {
if (criteria.equalsIgnoreCase(scriptEngineLookupName)) {
matchPositionPerScriptEngineCandidate.put(factory.getScriptEngine(), matchPosition);
}
matchPosition++;
}
}
return matchPositionPerScriptEngineCandidate;
}
use of javax.script.ScriptEngine in project scheduling by ow2-proactive.
the class Script method findBestScriptEngine.
private ScriptEngine findBestScriptEngine(Map<ScriptEngine, Integer> scriptEngineCandidates) {
int minimumMatchingIndex = Integer.MAX_VALUE;
ScriptEngine bestScriptEngine = null;
for (Entry<ScriptEngine, Integer> candidate : scriptEngineCandidates.entrySet()) {
if (candidate.getValue() < minimumMatchingIndex) {
minimumMatchingIndex = candidate.getValue();
bestScriptEngine = candidate.getKey();
}
}
return bestScriptEngine;
}
use of javax.script.ScriptEngine in project yamcs-studio by yamcs.
the class ScriptStoreFactory method initJdkJSEngine.
/**
* Must be called in UI Thread.
*
* @throws Exception
*/
private static void initJdkJSEngine() throws Exception {
ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript");
final Display display = Display.getCurrent();
displayScriptEngineMap.put(display, engine);
}
use of javax.script.ScriptEngine 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;
}
Aggregations