*
* @throws Exception if a problem occurred
*/
public void doExecute() throws Exception {
final ResetScriptRunner runner; // delegate pattern
final Context context = getContext();
if (context.getRunner() == null) {
runner = new ResetScriptRunner();
runner.setLanguage(getLanguage());
context.setRunner(runner);
LOG.debug("Creating new Script Runner with language: " + fLanguage);
}
else {
runner = context.getRunner();
runner.reset();
}
buildScript();
getProject().addReference("step", this);
if (context.getCurrentResponse() == null) {
LOG.warn("No response found. Previous invoke missing? Related scripting variables not created");
}
else {
setupResponseScriptingVariables(context);
}
try {
executeByRunner(runner, getProject().replaceProperties(fScriptText), this, getProject());
// languages like groovy can throw assert errors which are useful to fail test
// but what about an assert in groovy's implementation that has failed - this should
// probably be configurable to potentially throw StepExecutionError
} catch (AssertionError ae) {
final String msg = "Assertion error during scriptStep: " + ae.getMessage();
LOG.debug(msg, ae);
throw new StepFailedException(msg, this);
} catch (BuildException be) {
LOG.debug(be.getMessage(), be);
throw new StepExecutionException("Error invoking script: " + be.getMessage(), this);
} finally {
if (!isKeep()) {
context.setRunner(null);
}
}
}