private String eval(ShellSession session, String name, String def) { try { GroovyShell shell = getGroovyShell(session); Object ret = shell.getContext().getVariable(name); if (ret instanceof Closure) { log.log(Level.FINEST, "Invoking " + name + " closure"); Closure c = (Closure)ret; ret = c.call(); } else if (ret == null) { log.log(Level.FINEST, "No " + name + " will use empty"); return def; } return String.valueOf(ret); } catch (Exception e) { log.log(Level.SEVERE, "Could not get a " + name + " message, will use empty", e); return def; } }
@Override protected void setUp() throws Exception { super.setUp(); // List<CRaSHPlugin<?>> plugins = getPlugins(); TestPluginLifeCycle lifeCycle = new TestPluginLifeCycle(plugins.toArray(new CRaSHPlugin[plugins.size()])); // lifeCycle.start(); // this.shell = lifeCycle.createShell(); this.session = (ShellSession)shell; // A bit nasty but will do for tests :-) this.groovyShell = GroovyCompiler.getGroovyShell((ShellSession)shell); this.lifeCycle = lifeCycle; }
public void open(CommandContext<? super Object> consumer) throws IOException, CommandException { this.consumer = (CommandContext<Object>)consumer; GroovyShell shell = GroovyCompiler.getGroovyShell(session); ShellBinding binding = (ShellBinding)shell.getContext(); binding.setCurrent(new InvocationContextImpl<Object>(this.consumer)); Object o; try { o = shell.evaluate(request); } finally { binding.setCurrent(null); } if (o != null) { try { consumer.provide(o); } catch (IOException e) { throw e; } catch (CommandException e) { throw e; } catch (Exception e) { throw new CommandException(ErrorKind.EVALUATION, "An error occured during the evalution of '" + request + "'", e); } } } public void close() throws IOException, CommandException {
private String eval(ShellSession session, String name, String def) { try { GroovyShell shell = getGroovyShell(session); Object ret = shell.getContext().getVariable(name); if (ret instanceof Closure) { log.log(Level.FINEST, "Invoking " + name + " closure"); Closure c = (Closure)ret; ret = c.call(); } else if (ret == null) { log.log(Level.FINEST, "No " + name + " will use empty"); return def; } return String.valueOf(ret); } catch (Exception e) { log.log(Level.SEVERE, "Could not get a " + name + " message, will use empty", e); return def; } }
private String eval(ShellSession session, String name, String def) { try { GroovyShell shell = getGroovyShell(session); Object ret = shell.getContext().getVariable(name); if (ret instanceof Closure) { log.log(Level.FINEST, "Invoking " + name + " closure"); Closure c = (Closure)ret; ret = c.call(); } else if (ret == null) { log.log(Level.FINEST, "No " + name + " will use empty"); return def; } return String.valueOf(ret); } catch (Exception e) { log.log(Level.SEVERE, "Could not get a " + name + " message, will use empty", e); return def; } }
public void open(CommandContext<? super Object> consumer) throws IOException, CommandException { this.consumer = (CommandContext<Object>)consumer; GroovyShell shell = GroovyCompiler.getGroovyShell(session); ShellBinding binding = (ShellBinding)shell.getContext(); binding.setCurrent(new InvocationContextImpl<Object>(this.consumer)); Object o; try { o = shell.evaluate(request); } finally { binding.setCurrent(null); } if (o != null) { try { consumer.provide(o); } catch (IOException e) { throw e; } catch (CommandException e) { throw e; } catch (Exception e) { throw new CommandException(ErrorKind.EVALUATION, "An error occured during the evalution of '" + request + "'", e); } } } public void close() throws IOException, CommandException {
public void open(CommandContext<? super Object> consumer) throws IOException, CommandException { this.consumer = (CommandContext<Object>)consumer; GroovyShell shell = GroovyCompiler.getGroovyShell(session); ShellBinding binding = (ShellBinding)shell.getContext(); binding.setCurrent(new InvocationContextImpl<Object>(this.consumer)); Object o; try { o = shell.evaluate(request); } finally { binding.setCurrent(null); } if (o != null) { try { consumer.provide(o); } catch (IOException e) { throw e; } catch (CommandException e) { throw e; } catch (Exception e) { throw new CommandException(ErrorKind.EVALUATION, "An error occured during the evalution of '" + request + "'", e); } } } public void close() throws IOException, CommandException {