@Override public ScriptEngineFactory getFactory() { return engine.getFactory(); }
@Override public ScriptEngineFactory getFactory() { return engine.getFactory(); }
@Override public ScriptEngineFactory getFactory() { return engine.getFactory(); }
@Override public ScriptEngineFactory getFactory() { return engine.getFactory(); }
Object threadingParameter = scriptEngine.getFactory().getParameter("THREADING"); if (threadingParameter != null) {
log.error("Error adding script engine {}", new Object[]{scriptEngine.getFactory().getEngineName()});
boolean includeMethodFromExpression(ITestNGMethod tm) { Map<String, String> groups = Maps.newHashMap(); for (String group : tm.getGroups()) { groups.put(group, group); } try { setContext(engine, groups, tm); Object evalResult = engine.eval(expression); if (evalResult == null) { String msg = String.format("The " + engine.getFactory().getLanguageName() + " expression [%s] evaluated to null.", expression); throw new TestNGException(msg); } return (Boolean) evalResult; } catch (ScriptException e) { throw new TestNGException(e); } finally { resetContext(engine); } }
@Test public void testBase() { ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine engine = factory.getEngineByName("jphp"); ScriptEngineFactory f = engine.getFactory(); Assert.assertNotNull(engine); Assert.assertTrue(engine instanceof Compilable); Assert.assertNotNull(f); Assert.assertEquals(Information.NAME, f.getEngineName()); Assert.assertEquals("php", f.getLanguageName()); }
/** * Allows checking whether the script engine can be cached. * * @param scriptEngine the script engine to check. * @return true if the script engine may be cached. */ protected boolean isCachable(ScriptEngine scriptEngine) { // Check if script-engine supports multithreading. If true it can be cached. Object threadingParameter = scriptEngine.getFactory().getParameter("THREADING"); return threadingParameter != null; }
/** * Allows checking whether the script engine can be cached. * * @param scriptEngine the script engine to check. * @return true if the script engine may be cached. */ protected boolean isCachable(ScriptEngine scriptEngine) { // Check if script-engine supports multithreading. If true it can be cached. Object threadingParameter = scriptEngine.getFactory().getParameter("THREADING"); return threadingParameter != null; }
protected AbstractScriptExecutor(String language) { Assert.hasText(language, "language must not be empty"); this.language = language; this.scriptEngine = new ScriptEngineManager().getEngineByName(this.language); Assert.notNull(this.scriptEngine, invalidLanguageMessage(this.language)); if (this.logger.isDebugEnabled()) { this.logger.debug("Using script engine : " + this.scriptEngine.getFactory().getEngineName()); } }
private String getLanguageFromFileExtension(String scriptLocation, ParserContext parserContext, Element element) { ScriptEngineManager engineManager = new ScriptEngineManager(); ScriptEngine engine = null; int index = scriptLocation.lastIndexOf(".") + 1; if (index < 1) { return null; } String extension = scriptLocation.substring(index); engine = engineManager.getEngineByExtension(extension); if (engine == null) { parserContext.getReaderContext().error( "No suitable scripting engine found for extension '" + extension + "'", element); } return engine.getFactory().getLanguageName(); } }
public CompiledScript compile(ScriptEngine scriptEngine, String language, String src) { if(scriptEngine instanceof Compilable && !scriptEngine.getFactory().getLanguageName().equalsIgnoreCase("ecmascript")) { Compilable compilingEngine = (Compilable) scriptEngine; try { CompiledScript compiledScript = compilingEngine.compile(src); LOG.debugCompiledScriptUsing(language); return compiledScript; } catch (ScriptException e) { throw new ScriptCompilationException("Unable to compile script: " + e.getMessage(), e); } } else { // engine does not support compilation return null; } }
public CompiledScript compile(ScriptEngine scriptEngine, String language, String src) { if(scriptEngine instanceof Compilable && !scriptEngine.getFactory().getLanguageName().equalsIgnoreCase("ecmascript")) { Compilable compilingEngine = (Compilable) scriptEngine; try { CompiledScript compiledScript = compilingEngine.compile(src); LOG.debugCompiledScriptUsing(language); return compiledScript; } catch (ScriptException e) { throw new ScriptCompilationException("Unable to compile script: " + e.getMessage(), e); } } else { // engine does not support compilation return null; } }
private ScriptEngine getScriptEngine() throws SchemaCrawlerException { final String scriptFileName = outputOptions.getOutputFormatValue(); if (isBlank(scriptFileName)) { throw new SchemaCrawlerCommandLineException("Please specify a script to execute"); } final String scriptExtension = getFileExtension(scriptFileName); final ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); final ScriptEngine scriptEngine; if (isBlank(scriptExtension)) { scriptEngine = scriptEngineManager.getEngineByName("nashorn"); } else { scriptEngine = scriptEngineManager.getEngineByExtension(scriptExtension); } if (scriptEngine == null) { throw new SchemaCrawlerException("Script engine not found"); } logScriptEngineDetails(Level.CONFIG, scriptEngine.getFactory()); return scriptEngine; }
protected Object evaluateScriptExpression(String expressionLanguage, VariableContext variableContext, String expressionText, CachedCompiledScriptSupport cachedCompiledScriptSupport) { ScriptEngine scriptEngine = getScriptEngineForName(expressionLanguage); // wrap script engine bindings + variable context and pass enhanced // bindings to the script engine. Bindings bindings = VariableContextScriptBindings.wrap(scriptEngine.createBindings(), variableContext); bindings.put("variableContext", variableContext); try { if (scriptEngine instanceof Compilable) { CompiledScript compiledScript = cachedCompiledScriptSupport.getCachedCompiledScript(); if (compiledScript == null) { synchronized (cachedCompiledScriptSupport) { compiledScript = cachedCompiledScriptSupport.getCachedCompiledScript(); if(compiledScript == null) { Compilable compilableScriptEngine = (Compilable) scriptEngine; compiledScript = compilableScriptEngine.compile(expressionText); cachedCompiledScriptSupport.cacheCompiledScript(compiledScript); } } } return compiledScript.eval(bindings); } else { return scriptEngine.eval(expressionText, bindings); } } catch (ScriptException e) { throw LOG.unableToEvaluateExpression(expressionText, scriptEngine.getFactory().getLanguageName(), e); } }
/** * Checks whether the given engine is thread-safe or not. * * @return true if the given engine is thread-safe, false otherwise. */ private boolean engineAllowsParallelAccessFromMultipleThreads() { String threadingType = (String) engine.getFactory().getParameter( "THREADING" ); return "THREAD-ISOLATED".equals( threadingType ) || "STATELESS".equals( threadingType ); } }
/** * Allows checking whether the script engine can be cached. * * @param scriptEngine the script engine to check. * @return true if the script engine may be cached. */ protected boolean isCachable(ScriptEngine scriptEngine) { // Check if script-engine supports multithreading. If true it can be cached. Object threadingParameter = scriptEngine.getFactory().getParameter("THREADING"); return threadingParameter != null; }
@Override public boolean isThreadSafe(String key, ScriptEngine instance) { final ScriptEngineFactory factory = instance.getFactory(); final Object threadingAbility = factory.getParameter("THREADING"); return threadingAbility != null && ("THREAD-ISOLATED".equals(threadingAbility) || "STATELESS".equals(threadingAbility)); }
/** * {@inheritDoc} */ public ScriptEngineFactory getFactory() { return getScriptEngine().getFactory(); } }