Example #1
0
  public IStatus service(Command command, IProcess context)
      throws InterruptedException, CoreException {
    if (!(command instanceof RepeatWith)) {
      return Status.CANCEL_STATUS;
    }

    RepeatWith repeatWith = (RepeatWith) command;
    Command todo = repeatWith.getCommand();
    ISession session = context.getSession();
    for (Object cmd : repeatWith.getCommands()) {
      Command prefix = getCommand(cmd);
      IPipe pipe = session.createPipe();
      IStatus status = session.execute(prefix, null, pipe).waitFor();
      if (!status.isOK()) {
        return status;
      }
      IPipe output = session.createPipe();
      status = session.execute(todo, pipe, output).waitFor();
      if (!status.isOK()) {
        return status;
      }
      for (Object obj : CoreUtils.readPipeContent(output)) {
        context.getOutput().write(obj);
      }
    }
    return Status.OK_STATUS;
  }
Example #2
0
 public IStatus service(Command command, IProcess process)
     throws InterruptedException, CoreException {
   Try t = (Try) command;
   Integer times = t.getTimes();
   Integer delay = t.getDelay();
   if (delay == null) delay = 100;
   if (delay < 0)
     return new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, "Illegal parameter 'delay'");
   if (times != null && times <= 0)
     return new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, "Illegal parameter 'times'");
   List<Object> content = CoreUtils.readPipeContent(process.getInput());
   IStatus status = Status.OK_STATUS;
   try {
     for (int i = 0; times == null || i < times; i++) {
       IPipe input = process.getSession().createPipe();
       for (Object o : content) input.write(o);
       input.close(Status.OK_STATUS);
       IPipe output = process.getSession().createPipe();
       IProcess doProcess = process.getSession().execute(t.getCommand(), input, output);
       status = doProcess.waitFor();
       if (status.isOK()) {
         content = CoreUtils.readPipeContent(output);
         for (Object o : content) process.getOutput().write(o);
         // return status;
         break;
       }
       if (delay > 0) {
         Thread.sleep(delay);
       }
     }
     // Do catch
     if (!status.isOK()) {
       if (t.getCatch() != null) {
         IPipe input = process.getSession().createPipe();
         for (Object o : content) input.write(o);
         input.close(Status.OK_STATUS);
         IPipe output = process.getSession().createPipe();
         IProcess doProcess = process.getSession().execute(t.getCatch(), input, output);
         IStatus status2 = doProcess.waitFor();
         if (status2.isOK()) {
           CoreUtils.readPipeContent(output);
           status = status2;
         } else {
           status = status2;
         }
       }
     }
   } finally {
     if (t.getFinally() != null) {
       IPipe input = process.getSession().createPipe();
       for (Object o : content) input.write(o);
       input.close(Status.OK_STATUS);
       IPipe output = process.getSession().createPipe();
       IProcess doProcess = process.getSession().execute(t.getFinally(), input, output);
       IStatus status2 = doProcess.waitFor();
       if (status2.isOK()) {
         CoreUtils.readPipeContent(output);
       } else {
         status = status2;
       }
     }
   }
   return status;
 }