private boolean isTrue(Object result) throws InterruptedException { checkInterrupt(); if (result == null) return false; if (result instanceof Boolean) return (Boolean) result; if (result instanceof Number) { if (0 == ((Number) result).intValue()) return false; } if ("".equals(result)) return false; return !"0".equals(result); }
public boolean not(CommandSession session, Function condition) throws Exception { if (null == condition) { return true; } return !isTrue(condition.execute(session, null)); }
private void startShell(BundleContext context, CommandProcessor processor) { Dictionary<String, Object> dict = new Hashtable<String, Object>(); dict.put(CommandProcessor.COMMAND_SCOPE, "gogo"); // register converters regs.add(context.registerService(Converter.class.getName(), new Converters(context), null)); // register commands dict.put(CommandProcessor.COMMAND_FUNCTION, Builtin.functions); regs.add(context.registerService(Builtin.class.getName(), new Builtin(), dict)); dict.put(CommandProcessor.COMMAND_FUNCTION, Procedural.functions); regs.add(context.registerService(Procedural.class.getName(), new Procedural(), dict)); dict.put(CommandProcessor.COMMAND_FUNCTION, Posix.functions); regs.add(context.registerService(Posix.class.getName(), new Posix(), dict)); dict.put(CommandProcessor.COMMAND_FUNCTION, Telnet.functions); regs.add(context.registerService(Telnet.class.getName(), new Telnet(processor), dict)); shell = new Shell(context, processor); dict.put(CommandProcessor.COMMAND_FUNCTION, Shell.functions); regs.add(context.registerService(Shell.class.getName(), shell, dict)); // start shell session = processor.createSession(System.in, System.out, System.err); thread = new Thread(this, "Gogo shell"); thread.start(); }
private void startShell(BundleContext context, CommandProcessor processor) { Dictionary<String, Object> dict = new Hashtable<String, Object>(); dict.put(CommandProcessor.COMMAND_SCOPE, "gogo"); // register converters regs.add(context.registerService(Converter.class.getName(), new Converters(context), null)); // register commands dict.put(CommandProcessor.COMMAND_FUNCTION, Builtin.functions); regs.add(context.registerService(Builtin.class.getName(), new Builtin(), dict)); dict.put(CommandProcessor.COMMAND_FUNCTION, Procedural.functions); regs.add(context.registerService(Procedural.class.getName(), new Procedural(), dict)); dict.put(CommandProcessor.COMMAND_FUNCTION, Posix.functions); regs.add(context.registerService(Posix.class.getName(), new Posix(), dict)); dict.put(CommandProcessor.COMMAND_FUNCTION, Telnet.functions); regs.add(context.registerService(Telnet.class.getName(), new Telnet(processor), dict)); shell = new Shell(context, processor); dict.put(CommandProcessor.COMMAND_FUNCTION, Shell.functions); regs.add(context.registerService(Shell.class.getName(), shell, dict)); // start shell session = processor.createSession(System.in, System.out, System.err); thread = new Thread(this, "Gogo shell"); thread.start(); }
public boolean not(CommandSession session, Function condition) throws Exception { if (null == condition) { return true; } return !isTrue(condition.execute(session, null)); }
private void startShell(BundleContext context, CommandProcessor processor) { Dictionary<String, Object> dict = new Hashtable<>(); dict.put(CommandProcessor.COMMAND_SCOPE, "gogo"); Set<ServiceRegistration<?>> currentRegs = new HashSet<>(); // register converters currentRegs.add(context.registerService(Converter.class.getName(), new Converters(context.getBundle(0).getBundleContext()), null)); // register commands dict.put(CommandProcessor.COMMAND_FUNCTION, Builtin.functions); currentRegs.add(context.registerService(Builtin.class.getName(), new Builtin(), dict)); dict.put(CommandProcessor.COMMAND_FUNCTION, Procedural.functions); currentRegs.add(context.registerService(Procedural.class.getName(), new Procedural(), dict)); dict.put(CommandProcessor.COMMAND_FUNCTION, Posix.functions); currentRegs.add(context.registerService(Posix.class.getName(), new Posix(), dict)); dict.put(CommandProcessor.COMMAND_FUNCTION, Telnet.functions); currentRegs.add(context.registerService(Telnet.class.getName(), new Telnet(processor), dict)); Shell shell = new Shell(context, processor); dict.put(CommandProcessor.COMMAND_FUNCTION, Shell.functions); currentRegs.add(context.registerService(Shell.class.getName(), shell, dict)); synchronized (regs) { regs.addAll(currentRegs); currentRegs.clear(); } // start shell on a separate thread... executor = Executors.newSingleThreadExecutor(runnable -> new Thread(runnable, "Gogo shell")); shellJob = new StartShellJob(context, processor); executor.submit(shellJob); }
private boolean isTrue(Object result) throws InterruptedException { checkInterrupt(); if (result == null) return false; if (result instanceof Boolean) return (Boolean) result; if (result instanceof Number) { if (0 == ((Number) result).intValue()) return false; } if ("".equals(result)) return false; return !"0".equals(result); }
public boolean not(CommandSession session, Function condition) throws Exception { if (null == condition) { return true; } return !isTrue(condition.execute(session, null)); }
private void startShell(BundleContext context, CommandProcessor processor) { Dictionary<String, Object> dict = new Hashtable<>(); dict.put(CommandProcessor.COMMAND_SCOPE, "gogo"); Set<ServiceRegistration<?>> currentRegs = new HashSet<>(); // register converters currentRegs.add(context.registerService(Converter.class.getName(), new Converters(context.getBundle(0).getBundleContext()), null)); // register commands dict.put(CommandProcessor.COMMAND_FUNCTION, Builtin.functions); currentRegs.add(context.registerService(Builtin.class.getName(), new Builtin(), dict)); dict.put(CommandProcessor.COMMAND_FUNCTION, Procedural.functions); currentRegs.add(context.registerService(Procedural.class.getName(), new Procedural(), dict)); dict.put(CommandProcessor.COMMAND_FUNCTION, Posix.functions); currentRegs.add(context.registerService(Posix.class.getName(), new Posix(), dict)); dict.put(CommandProcessor.COMMAND_FUNCTION, Telnet.functions); currentRegs.add(context.registerService(Telnet.class.getName(), new Telnet(processor), dict)); Shell shell = new Shell(context, processor); dict.put(CommandProcessor.COMMAND_FUNCTION, Shell.functions); currentRegs.add(context.registerService(Shell.class.getName(), shell, dict)); synchronized (regs) { regs.addAll(currentRegs); currentRegs.clear(); } // start shell on a separate thread... executor = Executors.newSingleThreadExecutor(runnable -> new Thread(runnable, "Gogo shell")); shellJob = new StartShellJob(context, processor); executor.submit(shellJob); }
private boolean isTrue(Object result) throws InterruptedException { checkInterrupt(); if (result == null) return false; if (result instanceof Boolean) return ((Boolean) result).booleanValue(); if (result instanceof Number) { if (0 == ((Number) result).intValue()) return false; } if ("".equals(result)) return false; if ("0".equals(result)) return false; return true; }
public boolean not(CommandSession session, Function condition) throws Exception { if (null == condition) { return true; } return !isTrue(condition.execute(session, null)); }
registrations.add(context.registerService(Procedural.class.getName(), new Procedural(), dict));
private boolean isTrue(Object result) throws InterruptedException { checkInterrupt(); if (result == null) return false; if (result instanceof Boolean) return ((Boolean) result).booleanValue(); if (result instanceof Number) { if (0 == ((Number) result).intValue()) return false; } if ("".equals(result)) return false; if ("0".equals(result)) return false; return true; }
public void _while(CommandSession session, Function condition, Function ifTrue) throws Exception { while (isTrue(condition.execute(session, null))) { ifTrue.execute(session, null); } }
public List<Object> each(CommandSession session, Collection<Object> list, Function closure) throws Exception { List<Object> args = new ArrayList<Object>(); List<Object> results = new ArrayList<Object>(); args.add(null); for (Object x : list) { checkInterrupt(); args.set(0, x); results.add(closure.execute(session, args)); } return results; }
public void until(CommandSession session, Function condition, Function ifTrue) throws Exception { while (!isTrue(condition.execute(session, null))) { ifTrue.execute(session, null); } }
public List<Object> each(CommandSession session, Collection<Object> list, Function closure) throws Exception { List<Object> args = new ArrayList<>(); List<Object> results = new ArrayList<>(); args.add(null); for (Object x : list) { checkInterrupt(); args.set(0, x); results.add(closure.execute(session, args)); } return results; }
public void until(CommandSession session, Function condition, Function ifTrue) throws Exception { while (!isTrue(condition.execute(session, null))) { ifTrue.execute(session, null); } }
public List<Object> each(CommandSession session, Collection<Object> list, Function closure) throws Exception { List<Object> args = new ArrayList<Object>(); List<Object> results = new ArrayList<Object>(); args.add(null); for (Object x : list) { checkInterrupt(); args.set(0, x); results.add(closure.execute(session, args)); } return results; }
public void until(CommandSession session, Function condition, Function ifTrue) throws Exception { while (!isTrue(condition.execute(session, null))) { ifTrue.execute(session, null); } }