}
private GroovyShell createEngine(AbstractBuild<?, ?> build, TaskListener listener) {
ClassLoader cl = Jenkins.getInstance().getPluginManager().uberClassLoader;
ScriptSandbox sandbox = null;
CompilerConfiguration cc = new CompilerConfiguration();
cc.addCompilationCustomizers(new ImportCustomizer().addStarImports(
"jenkins",
"jenkins.model",
"hudson",
"hudson.model"));
ExtendedEmailPublisher publisher = build.getProject().getPublishersList().get(ExtendedEmailPublisher.class);
if (publisher.getDescriptor().isSecurityEnabled()) {
cc.addCompilationCustomizers(new SandboxTransformer());
sandbox = new ScriptSandbox();
}
Binding binding = new Binding();
binding.setVariable("build", build);
binding.setVariable("project", build.getParent());
binding.setVariable("rooturl", publisher.getDescriptor().getHudsonUrl());
binding.setVariable("out", listener.getLogger());
GroovyShell shell = new GroovyShell(cl, binding, cc);
if (sandbox != null) {
sandbox.register();
}
return shell;
}