List of utility methods to do Script Engine
ScriptEngineManager | getScriptEngineManager() get Script Engine Manager if (scriptEngineManager == null) { scriptEngineManager = new ScriptEngineManager(); return scriptEngineManager; |
String | getStringOrExcept(ScriptEngine e, String vname) get String Or Except Object r = e.get(vname); if (r == null || !(r instanceof String)) { throw new IllegalArgumentException("No variable named " + vname + " in script engine that is a String"); return (String) r; |
String | getVersionString(ScriptEngineFactory factory) get Version String return factory.getLanguageVersion();
|
void | importClass(ScriptEngine e, Class> pkg, Bindings... b) import Class try { if (b.length == 0) { e.eval("importClass(Packages." + pkg.getName() + ")"); } else { e.eval("importClass(Packages." + pkg.getName() + ")", b[0]); } catch (ScriptException e1) { throw new RuntimeException(e1); ... |
boolean | isJsEngineAvailable(String engineName, Logger logger) Checks if a JS engine is available boolean engineExists = new ScriptEngineManager().getEngineByName(engineName) != null; if (!engineExists) { logger.warn("The JS engine '" + engineName + "' is not available for tests."); return engineExists; |
void | listGems(ScriptEngine jruby) Used to print a list of install gems to stdout StringBuilder script = new StringBuilder(); script.append("require 'rubygems'\n"); script.append("require 'rubygems/gem_runner'\n"); script.append("Gem::GemRunner.new.run [\"list\"]\n"); jruby.eval(script.toString()); |
void | listScriptEngines() list Script Engines ScriptEngineManager mgr = new ScriptEngineManager(); List<ScriptEngineFactory> factories = mgr.getEngineFactories(); int num = 0; for (ScriptEngineFactory factory : factories) { System.out.println("ScriptEngineFactory Info"); String engName = factory.getEngineName(); String engVersion = factory.getEngineVersion(); String langName = factory.getLanguageName(); ... |
void | registerFactoryToManager(ScriptEngineFactory factory, ScriptEngineManager scriptEngineManager) register Factory To Manager for (String name : factory.getNames()) { scriptEngineManager.registerEngineName(name, factory); for (String extension : factory.getExtensions()) { scriptEngineManager.registerEngineExtension(extension, factory); for (String mime : factory.getMimeTypes()) { scriptEngineManager.registerEngineMimeType(mime, factory); ... |
ScriptEngine | retrieveEngineByName(ScriptEngineManager scriptEngineManager, String engineName) Retrieve a ScriptEngine from the given ScriptEngineManager by name, delegating to ScriptEngineManager#getEngineByName but throwing a descriptive exception if not found or if initialization failed. ScriptEngine engine = scriptEngineManager.getEngineByName(engineName); if (engine == null) { Set<String> engineNames = new LinkedHashSet<>(); for (ScriptEngineFactory engineFactory : scriptEngineManager.getEngineFactories()) { List<String> factoryNames = engineFactory.getNames(); if (factoryNames.contains(engineName)) { try { engine = engineFactory.getScriptEngine(); ... |
Object | scriptEngine(String epStr, Map per) script Engine ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); for (Iterator iterator = per.keySet().iterator(); iterator.hasNext();) { String type = (String) iterator.next(); engine.put(type, per.get(type)); return engine.eval(epStr); |