public CommandInvoker<Void, Object> create(ShellSession session) throws CommandNotFoundException, CommandException { LinkedList<CommandInvoker> pipes = new LinkedList<CommandInvoker>(); for (PipeLineFactory current = this;current != null;current = current.next) { Command<?> command = session.getCommand(current.name); if (command == null) { throw new CommandNotFoundException(current.name); } CommandInvoker commandInvoker = command.resolveInvoker(current.rest); if (commandInvoker == null) { throw new CommandNotFoundException(current.name); } pipes.add(commandInvoker); } return new PipeLine(pipes.toArray(new CommandInvoker[pipes.size()])); }
termPrefix = termPrefix.substring(pos); try { Command<?> command = session.getCommand(commandName); if (command != null) { completion = command.complete(new RuntimeContextImpl(session, session.getContext().getAttributes()), termPrefix);
termPrefix = termPrefix.substring(pos); try { Command<?> command = session.getCommand(commandName); if (command != null) { completion = command.complete(new RuntimeContextImpl(session, session.getContext().getAttributes()), termPrefix);
@Override public Object getVariable(String name) { if (name.equals("context")) { return proxy; } else { if (session != null) { try { Command<?> cmd = session.getCommand(name); if (cmd != null) { return new PipeLineClosure(new InvocationContextImpl<Object>(proxy), name, cmd); } } catch (CommandException ignore) { // Really ? } return super.getVariable(name); } else { return super.getVariable(name); } } } }
termPrefix = termPrefix.substring(pos); try { Command<?> command = session.getCommand(commandName); if (command != null) { completion = command.complete(new RuntimeContextImpl(session, session.getContext().getAttributes()), termPrefix);
public void testReturnedObjectByGroovyScriptIsProduced() throws Exception { lifeCycle.bindGroovy("producer", "return 3"); lifeCycle.bindClass("consumer", Commands.ConsumeInteger.class); Commands.list.clear(); assertOk("producer | consumer"); assertEquals(Arrays.<Object>asList(3), Commands.list); Command<?> producer = session.getCommand("producer"); CommandMatch<?, ?> commandMatch = producer.resolveCommand(""); assertEquals(Object.class, commandMatch.getProducedType()); }
public void testReturnedObjectByJavaIsProduced() throws Exception { lifeCycle.bindClass("producer", Commands.ReturnInteger.class); lifeCycle.bindClass("consumer", Commands.ConsumeInteger.class); Commands.list.clear(); assertOk("producer | consumer"); assertEquals(Arrays.<Object>asList(3), Commands.list); Command<?> producer = session.getCommand("producer"); CommandMatch<?, ?> commandMatch = producer.resolveCommand(""); assertEquals(Integer.class, commandMatch.getProducedType()); }
public void testReturnedObjectByGroovyIsProduced() throws Exception { lifeCycle.bindGroovy("producer", "" + "class producer {\n" + " @Command\n" + " public Integer main() {\n" + " context.session['class'] = getClass();\n" + " return 3;\n" + " }\n" + " }\n"); lifeCycle.bindClass("consumer", Commands.ConsumeInteger.class); Commands.list.clear(); assertOk("producer | consumer"); assertEquals(Arrays.<Object>asList(3), Commands.list); Command<?> producer = session.getCommand("producer"); CommandMatch<?, ?> commandMatch = producer.resolveCommand(""); assertEquals(Integer.class, commandMatch.getProducedType()); }
public CommandInvoker<Void, Object> create(ShellSession session) throws CommandNotFoundException, CommandException { LinkedList<CommandInvoker> pipes = new LinkedList<CommandInvoker>(); for (PipeLineFactory current = this;current != null;current = current.next) { Command<?> command = session.getCommand(current.name); if (command == null) { throw new CommandNotFoundException(current.name); } CommandInvoker commandInvoker = command.resolveInvoker(current.rest); if (commandInvoker == null) { throw new CommandNotFoundException(current.name); } pipes.add(commandInvoker); } return new PipeLine(pipes.toArray(new CommandInvoker[pipes.size()])); }
public CommandInvoker<Void, Object> create(ShellSession session) throws CommandNotFoundException, CommandException { LinkedList<CommandInvoker> pipes = new LinkedList<CommandInvoker>(); for (PipeLineFactory current = this;current != null;current = current.next) { Command<?> command = session.getCommand(current.name); if (command == null) { throw new CommandNotFoundException(current.name); } CommandInvoker commandInvoker = command.resolveInvoker(current.rest); if (commandInvoker == null) { throw new CommandNotFoundException(current.name); } pipes.add(commandInvoker); } return new PipeLine(pipes.toArray(new CommandInvoker[pipes.size()])); }
@Override public Object getVariable(String name) { if (name.equals("context")) { return proxy; } else { if (session != null) { try { Command<?> cmd = session.getCommand(name); if (cmd != null) { return new PipeLineClosure(new InvocationContextImpl<Object>(proxy), name, cmd); } } catch (CommandException ignore) { // Really ? } return super.getVariable(name); } else { return super.getVariable(name); } } } }
@Override public Object getVariable(String name) { if (name.equals("context")) { return proxy; } else { if (session != null) { try { Command<?> cmd = session.getCommand(name); if (cmd != null) { return new PipeLineClosure(new InvocationContextImpl<Object>(proxy), name, cmd); } } catch (CommandException ignore) { // Really ? } return super.getVariable(name); } else { return super.getVariable(name); } } } }