use of hudson.remoting.ChannelClosedException in project hudson-2.x by hudson.
the class GroovyshCommand method createShell.
protected Groovysh createShell(InputStream stdin, PrintStream stdout, PrintStream stderr) {
Binding binding = new Binding();
// redirect "println" to the CLI
binding.setProperty("out", new PrintWriter(stdout, true));
binding.setProperty("hudson", hudson.model.Hudson.getInstance());
IO io = new IO(new BufferedInputStream(stdin), stdout, stderr);
final ClassLoader cl = Thread.currentThread().getContextClassLoader();
Closure registrar = new Closure(null, null) {
public Object doCall(Object[] args) {
assert (args.length == 1);
assert (args[0] instanceof Shell);
Shell shell = (Shell) args[0];
XmlCommandRegistrar r = new XmlCommandRegistrar(shell, cl);
r.register(GroovyshCommand.class.getResource("commands.xml"));
return null;
}
};
Groovysh shell = new Groovysh(cl, binding, io, registrar);
shell.getImports().add("import hudson.model.*");
// defaultErrorHook doesn't re-throw IOException, so ShellRunner in
// Groovysh will keep looping forever if we don't terminate when the
// channel is closed
final Closure originalErrorHook = shell.getErrorHook();
shell.setErrorHook(new Closure(shell, shell) {
public Object doCall(Object[] args) throws ChannelClosedException {
if (args.length == 1 && args[0] instanceof ChannelClosedException) {
throw (ChannelClosedException) args[0];
}
return originalErrorHook.call(args);
}
});
return shell;
}
Aggregations