Package org.jboss.fresh.shell

Examples of org.jboss.fresh.shell.ShellException


      }

      if (job.size() > 1) {
        ProcessGroup p = sshell.createProcessGroup(job);
        if (p == null) {
          throw new ShellException("[ShellImpl][execute] Failed to create ProcessGroup.");
        }
        InBuffer ib = ((Process) job.getFirst()).getInputBuffer();
        OutBuffer ob = ((Process) job.getLast()).getOutputBuffer();
        p.setRedirected(((Process) job.getLast()).isRedirected());

//log.debug("PRocessGroup ib: " + ib);
//log.debug("PRocessGroup ob: " + ob);
        p.setInputBuffer(ib);
        p.setOutputBuffer(ob);
        p.setCommandLine(cmdline);


        if (active == null) {
          active = p;
        }

//      if(interactive) {
//        outreader.replacePrimaryBuffer(ob);
//      }

        procmap.put(p.getID(), p);
        p.setUserInitiated(ui);

        hi.setProcessID(p.getID());

                // We don't use it anywhere - WRONG - we use it when NoProcessForID Exceptions occur
                LinkedList chs = hi.getChildren();
        LinkedList ls = p.getProcessList();
        it = ls.iterator();
        while(it.hasNext()) {
          Process cp = (Process) it.next();
          chs.add(cp);
        }

        if (!prepareOnly) {
          p.start(); // We have a problem with concurrent modification on job
        } else {
          preparedProcess.set(p);
        }
       
        ProcessInfo pinfo = new ProcessInfo();
        pinfo.procid = p.getID();
        pinfo.inbuf_maxsize = ib.getMaxSize();
        pinfo.outbuf_maxsize = ob.getMaxSize();
        return pinfo;
      } else {
        Process p = (Process) job.getFirst();
//    System.out.println("Putting the process in the procmap: " + p.getID() + " : " + p);

        InBuffer ib = p.getInputBuffer();
        OutBuffer ob = p.getOutputBuffer();

//log.debug("PRocess ib: " + ib);
//log.debug("PRocess ob: " + ob);

        if (active == null) {
          active = p;
        }
//      if(interactive) {
//        outreader.replacePrimaryBuffer(ob);
//      }

//      System.out.println("ACTIVE SET: " + active);

        procmap.put(p.getID(), p);
//log.debug("***\n***[execute] Created process " + p.getID() + "\n***");
        log.debug("Created process " + p.getID());

        p.setUserInitiated(ui);

        hi.setProcessID(p.getID());
        hi.getChildren().add(p);

        if (!prepareOnly) {
          p.start();
        } else {
          preparedProcess.set(p);
        }
       
//    System.out.println("Started the process.");

        ProcessInfo pinfo = new ProcessInfo();
        pinfo.procid = p.getID();
        pinfo.inbuf_maxsize = ib.getMaxSize();
        pinfo.outbuf_maxsize = ob.getMaxSize();
        return pinfo;
      }
    } catch (SessionTimeoutException ex) {
            throw new SessionTimeoutException("Exception executing: " + cmdline + " - " + ex.getMessage());
        } catch (ParseException ex) {
      log.error("Exception occured during parsing of the command line!", ex);
      throw new ShellException("Exception occured during parsing of the command line!", ex, cmdline);
    }
    // now we have several processes in the job list.
    // we still need to run them all.
    // If

View Full Code Here


    //System.out.println("        completeExecution 1");
    Process p = (Process) preparedProcess.get();
    //System.out.println("        completeExecution 2    p == " + p);
    if(p == null) {
      //new Exception("No prepared process found").printStackTrace();
      throw new ShellException("No prepared process found - was prepareExecution() called in this thread?");
    }
    //System.out.println("        completeExecution 3");
    preparedProcess.remove();
//System.out.println("      *Calling Process.start()");
    p.start();
View Full Code Here

        try {
          InputStreamBuffer bin = new InputStreamBuffer(new FileInputStream(cmdl.getSLStdInRedir()), cmdl.isSLInObjMode());
          bin.setProperties(env);
          in = bin;
        } catch (IOException ex) {
          throw new ShellException("Exception occured while initializing input buffer: " + ex.toString());
        }

      } else if (cmdl.getStdInRedir() != null) {
        try {
          //in=new InputStreamBuffer(new VFSInputStream(new SecureVFS(vfs, uctx), cmdl.getStdInRedir()), cmdl.isInObjMode());
          if(cmdl.getStdInLines() != null) {
            String enc = env.getProperty("ENC");
            ByteArrayInputStream bain;
            if(enc != null) {
              bain = new ByteArrayInputStream(cmdl.getStdInLines().getBytes("ENC"));
            } else {
              bain = new ByteArrayInputStream(cmdl.getStdInLines().getBytes());
            }
            InputStreamBuffer bin = new InputStreamBuffer(bain, false);
            bin.setProperties(env);
            in = bin;
           
          } else {
            FileName fname = new FileName(cmdl.getStdInRedir());
            if (fname.isRelative()) {
              fname = new FileName(getEnvProperty("PWD")).absolutize(fname);
            }
            InputStreamBuffer bin = new InputStreamBuffer(new VFSInputStream(new SecureVFS(vfs, uctx), fname.toString()), cmdl.isInObjMode());
            bin.setProperties(env);
            in = bin;
          }

        } catch (IOException ex) {
          throw new ShellException("Exception occured while initializing input buffer: " + ex.toString());
        }

      }


      if (in == null) {
//log.debug("No output redirect setup...");
        if (hasin) {
          if (!"SINGLE".equals(getEnvProperty("TMODE"))) {
            in = new BufferImpl();
          } else {
            in = new MemFileBufferImpl();
          }
          // here we set whatever is maxsize for inputbuffer for this executable - we have this set
          // as attribute on the file or something ...
          // FIXME
          List input = cmdl.getStdInput();
          if(input != null) {
            in.setMaxSize(input.size());
            try {
              ((Buffer)in).putBuffer(new LinkedList(input), 1000);
              in.close();
            } catch (IOException ex) {
              throw new ShellException("Exception occured while initializing input buffer: " + ex.toString());
            }
          }
          in.setMaxSize(inbufmax); // should be a variable

        } else {
          in = new NullBuffer();
        }
      }

    } else {
//log.debug("Piping in previous out...");
      Object o_in = ((Process) joblist.getLast()).getOutputBuffer();
      if (!(o_in instanceof InBuffer)) {
        throw new ShellException("Invalid pipe chain. Trying to read from write-only buffer.");
      }
      in = (InBuffer) o_in;
    }

//log.debug("\n\nin = " + in);

    OutBuffer out = null;

    if (cmdl.size() == joblist.size() + 1) {

      if (cmdl.getSLStdOutRedir() != null) {
        try {
          OutputStreamBuffer bout = new OutputStreamBuffer(new FileOutputStream(cmdl.getSLStdOutRedir(), cmdl.getSLAppend()), cmdl.isSLOutObjMode());
          bout.setProperties(env);
          out = bout;
          p.setRedirected(true);
        } catch (IOException ex) {
          throw new ShellException("Exception occured while initializing output buffer: " + ex.toString());
        }

      } else if (cmdl.getStdOutRedir() != null) {
        try {
          ////out=new OutputStreamBuffer(new VFSOutputStream(new SecureVFS(vfs, uctx), cmdl.getStdOutRedir(), cmdl.getAppend()), cmdl.isOutObjMode());

          //if(TxSupport.isActive()) throw new ShellException("Illegal state - inside transaction.");
          //TxSupport.begin();
          try {
            FileName fname = new FileName(cmdl.getStdOutRedir());
            if (fname.isRelative()) {
              fname = new FileName(getEnvProperty("PWD")).absolutize(fname);
            }
            OutputStreamBuffer bout = new OutputStreamBuffer(new LazyVFSOutputStream(new SecureVFS(vfs, uctx), fname.toString(), cmdl.getAppend()), cmdl.isOutObjMode());
            bout.setProperties(env);
            out = bout;
            p.setRedirected(true);
            //TxSupport.commit();
          } catch (Exception ex) {
            //TxSupport.rollback();
            throw ex;
          }
        } catch (Exception ex) {
          log.error("Exception occured while initializing output buffer: ", ex);
          throw new ShellException("Exception occured while initializing output buffer: " + ex.toString());
        }
      }
    }
//log.debug("\n\nout = " + out);
    if (out == null) {
View Full Code Here

    } catch (ShellException ex) {
      log.error(ex.getMessage(), ex);
      throw ex;
    } catch (Throwable t) {
      log.error(t.getMessage(), t);
      throw new ShellException(t);
    }
  }
View Full Code Here

          } else {
            throw new EOFException("StdIn not available any more (process done executing)");
          }
            }
      if (list.size() > b.getMaxSize()) {
        throw new ShellException("Buffer sent by client exeeds the communicated maximum size.");
      }

      b.putBuffer(list, p.getIOTimeout());
    } catch (EOFException ex) {
      if (p.getThrowable() != null) {
View Full Code Here

    if (bufid == 0) {
      return (Buffer) p.getInputBuffer();
    } else if (bufid == 1) {
      return (Buffer) p.getOutputBuffer();
    } else {
      throw new ShellException("Illegal buffer id : " + bufid);
    }
  }
View Full Code Here

      log.debug("closing output " + b);
      // closeAndDiscard explicitly tells OutBuffer that nothing will
      // be read from it any more. Not even what it may still have inside.
      b.closeAndDiscard();
    } else {
      throw new ShellIOException(new ShellException("Wrong stream id: " + streamid));
    }
  }
View Full Code Here

                inf = shell.getVFS().getFileInfo(shell.getUserCtx(), cmdnm, false);
            }

            if (inf != null) {
                String clazz = (String) inf.getAttributes().get("Class");
                if (clazz == null) throw new ShellException("No Class attribute specified. (" + command + ")");
                command = clazz;
            }


            Executable exe = getInternal(command);
            if (exe != null) return exe;

        } catch (ShellException ex) {

            log.error(ex.getMessage(), ex);

            Executable exe = getInternal(command);
            if (exe != null) return exe;

            throw ex;

        } catch (VFSException ex) {
            log.error(ex.getMessage(), ex);
            throw new ShellException(ex.toString());
        }
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        Class execls = null;
        try {
            execls = cl.loadClass(command);
        } catch (ClassNotFoundException e) {
            throw new BadCommandException("Unknown command.", command);
        }

        Executable exe;
        try {
            exe = (Executable) execls.newInstance();
        } catch (InstantiationException e) {
            throw new ShellException("Could not instantiate class: " + execls);
        } catch (IllegalAccessException e) {
            throw new ShellException("Not allowed to instantiate class: " + execls);
        }

        exe.setFileInfo(inf);

        return exe;
View Full Code Here

  public ProcessInfo execute(String cmdline) throws ShellException {
    collide();
    try {
      return shell.execute(cmdline);
    } catch(RemoteException ex) {
      throw new ShellException(ex);
    } finally {
      done();
    }
  }
View Full Code Here

  public ProcessInfo execute(String cmdline, List input) throws ShellException {
    collide();
    try {
      return shell.execute(cmdline, input);
    } catch(RemoteException ex) {
      throw new ShellException(ex);
    } finally {
      done();
    }
  }
View Full Code Here

TOP

Related Classes of org.jboss.fresh.shell.ShellException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.