@Override public Object clone() { return super.clone(); } }
/** * @return script language or DEFAULT_SCRIPT_LANGUAGE if none is set */ private String getScriptLanguageWithDefault() { String lang = getScriptLanguage(); if (StringUtils.isNotEmpty(lang)) { return lang; } return DEFAULT_SCRIPT_LANGUAGE; }
populateBindings(bindings); File scriptFile = new File(getFilename()); && !("bsh.engine.BshScriptEngine".equals(scriptEngine.getClass().getName())); // NOSONAR // $NON-NLS-1$ try { if (!StringUtils.isEmpty(getFilename())) { if (scriptFile.exists() && scriptFile.canRead()) { if (supportsCompilable) { String cacheKey = getScriptLanguage() + "#" + // $NON-NLS-1$ scriptFile.getAbsolutePath() + "#" + // $NON-NLS-1$ scriptFile.lastModified(); + "' does not exist or is unreadable for element:" + getName()); } else if (!StringUtils.isEmpty(getScript())) { if (supportsCompilable && !ScriptingBeanInfoSupport.FALSE_AS_STRING.equals(cacheKey)) { computeScriptMD5(); CompiledScript compiledScript = compiledScriptsCache.get(this.scriptMd5); if (compiledScript == null) { compiledScript = compiledScriptsCache.get(this.scriptMd5); if (compiledScript == null) { compiledScript = ((Compilable) scriptEngine).compile(getScript()); compiledScriptsCache.put(this.scriptMd5, compiledScript); return scriptEngine.eval(getScript(), bindings); throw new ScriptException("Both script file and script text are empty for element:" + getName());
/** * @return {@link ScriptEngine} for language defaulting to groovy if language is not set * @throws ScriptException when no {@link ScriptEngine} could be found */ protected ScriptEngine getScriptEngine() throws ScriptException { String lang = getScriptLanguageWithDefault(); ScriptEngine scriptEngine = getInstance().getEngineByName(lang); if (scriptEngine == null) { throw new ScriptException("Cannot find engine named: '"+lang+"', ensure you set language field in JSR223 Test Element: "+getName()); } return scriptEngine; }
final String label = getName(); final String fileName = getFilename(); final String scriptParameters = getParameters();
/** {@inheritDoc} */ @Override public void setParameters(Collection<CompoundVariable> parameters) throws InvalidVariableException { checkParameterCount(parameters, 1, 2); values = parameters.toArray(); scriptEngine = JSR223TestElement.getInstance().getEngineByName(GROOVY_ENGINE_NAME); //$NON-NLS-N$ String fileName = JMeterUtils.getProperty(INIT_FILE); if(!StringUtils.isEmpty(fileName)) { File file = new File(fileName); if(!(file.exists() && file.canRead())) { // File maybe relative to JMeter home File oldFile = file; file = new File(JMeterUtils.getJMeterHome(), fileName); if(!(file.exists() && file.canRead())) { throw new InvalidVariableException("Cannot read file, neither from:"+oldFile.getAbsolutePath()+ ", nor from:"+file.getAbsolutePath()+", check property '"+INIT_FILE+"'"); } } try (Reader reader = Files.newBufferedReader(file.toPath(), Charset.defaultCharset())) { Bindings bindings = scriptEngine.createBindings(); bindings.put("log", log); scriptEngine.eval(reader, bindings); } catch(Exception ex) { throw new InvalidVariableException("Failed loading script:"+file.getAbsolutePath(), ex); } } }
/** * compute MD5 if it is null */ private void computeScriptMD5() { // compute the md5 of the script if needed if(scriptMd5 == null) { scriptMd5 = DigestUtils.md5Hex(getScript()); } }
@Override public Object clone() { return super.clone(); } }
@Override public Object clone() { return super.clone(); } }
@Override public Object clone() { return super.clone(); } }
@Override public Object clone() { return super.clone(); } }
@Override public Object clone() { return super.clone(); }