Package com.tek42.perforce.model

Examples of com.tek42.perforce.model.Workspace


    List<String> lines = null;
    int totalLength = 0;
               
    do {
      int mesgIndex = -1, count = 0;
      Executor p4 = depot.getExecFactory().newExecutor();
                       
      String debugCmd = "";
      // get entire cmd to execute
                        String cmd[] = getExtraParams(origcmd);
                       
      // setup information for logging...
      for(String cm : cmd) {
        debugCmd += cm + " ";
      }

      // Perform execution and IO
      p4.exec(cmd);
      BufferedReader reader = p4.getReader();
      String line = null;
      totalLength = 0;
      lines = new ArrayList<String>(1024);
                        TimedStreamCloser timedStreamCloser=null;
      try
      {
                             PerforceSCM.PerforceSCMDescriptor scmDescr = PerforceSCM.getInstance();
                             p4.getWriter().close();
                             int timeout = -1;
                             if(scmDescr.hasP4ReadlineTimeout()) { // Implementation with timeout
                               timeout = scmDescr.getP4ReadLineTimeout();
                            
                             timedStreamCloser = new TimedStreamCloser(p4.getInputStream(), timeout);
                             timedStreamCloser.start();

                             while((line = reader.readLine()) != null) {
                                timedStreamCloser.reset();
                                // only check for errors if we have not found one already
                                if (mesgIndex == -1)
                                    mesgIndex = checkAuthnErrors(line);
                                if(filter.reject(line)) continue;
                                lines.add(line);
                                totalLength += line.length();
                                count++;
                            }
                            if(timedStreamCloser.timedOut()) {
                                throw new PerforceException("Perforce operation timed out after " + timeout + " seconds.");
                            }
      }
      catch(IOException ioe)
      {
        //this is generally not anything to worry about.  The underlying
        //perforce process terminated and that causes java to be angry
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw, true);
        ioe.printStackTrace(pw);
        pw.flush();
        sw.flush();
        getLogger().warn("Perforce process terminated suddenly");
        getLogger().warn(sw.toString());
      }
      finally{
                            if(timedStreamCloser!=null) timedStreamCloser.interrupt();
                            try{
                                p4.getWriter().close();
                            } catch (IOException e) {
                                getLogger().warn("Write pipe failed to close.");
                            }
                            try{
                                p4.getReader().close();
                            } catch (IOException e) {
                                getLogger().warn("Read pipe failed to close.");
                            }
                            p4.close();
      }
      loop = false;
      // If we failed to execute because of an authentication issue, try a p4 login.
      if(attemptLogin && (mesgIndex == 1 || mesgIndex == 2 || mesgIndex == 6 || mesgIndex == 9)) {
        // password is unset means that perforce isn't using the environment var P4PASSWD
        // Instead it is using tickets. We must attempt to login via p4 login, then
        // retry this cmd.
        p4.close();
                                trustIfSSL();
        login();
        loop = true;
        attemptLogin = false;
        continue;
View Full Code Here


     * @throws PerforceException
     */
    protected List<String> getRawPerforceResponseLines(String cmd[]) throws PerforceException {
        List<String> lines = new ArrayList<String>(1024);

        Executor p4 = depot.getExecFactory().newExecutor();
        String debugCmd = "";
        // get entire cmd to execute
        cmd = getExtraParams(cmd);

        // setup information for logging...
        for(String cm : cmd) {
            debugCmd += cm + " ";
        }

        // Perform execution and IO
        p4.exec(cmd);

        try
        {
            BufferedReader reader = p4.getReader();
            p4.getWriter().close();
            String line = null;
            while((line = reader.readLine()) != null) {
                lines.add(line);
            }
        }
        catch(IOException ioe)
        {
            //this is generally not anything to worry about.  The underlying
            //perforce process terminated and that causes java to be angry.

            // TODO Given the above comment, should we bother to log a warning?
            // See this blog for a discussion of IOException with message "Write end dead" from pipes:
            //      http://techtavern.wordpress.com/2008/07/16/whats-this-ioexception-write-end-dead/

            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw, true);
            ioe.printStackTrace(pw);
            pw.flush();
            sw.flush();
            getLogger().warn("IOException reading from Perforce process (may just be EOF)");
            getLogger().warn(sw.toString());
        }
        finally{
            try{
                p4.getWriter().close();
            } catch (IOException e) {
                getLogger().warn("Write pipe failed to close.");
            }
            try{
                p4.getReader().close();
            } catch (IOException e) {
                getLogger().warn("Read pipe failed to close.");
            }
            p4.close();
        }

        return lines;
    }
View Full Code Here

     */

    protected byte[] getRawPerforceResponseBytes(String cmd[]) throws PerforceException {
        List<Byte> bytes = new ArrayList<Byte>(1024);

        Executor p4 = depot.getExecFactory().newExecutor();
        String debugCmd = "";
        // get entire cmd to execute
        cmd = getExtraParams(cmd);

        // setup information for logging...
        for(String cm : cmd) {
            debugCmd += cm + " ";
        }

        // Perform execution and IO
        p4.exec(cmd);

        try
        {
            byte[] cbuf = new byte[1024];
            InputStream input = p4.getInputStream();
            p4.getWriter().close();
            int readCount = -1;
            while((readCount = input.read(cbuf, 0, 1024)) != -1) {
                for(int i=0; i<readCount; i++){
                    bytes.add(new Byte((byte)(cbuf[i]&0xff)));
                }
            }
        }
        catch(IOException ioe)
        {
            //this is generally not anything to worry about.  The underlying
            //perforce process terminated and that causes java to be angry.

            // TODO Given the above comment, should we bother to log a warning?
            // See this blog for a discussion of IOException with message "Write end dead" from pipes:
            //      http://techtavern.wordpress.com/2008/07/16/whats-this-ioexception-write-end-dead/

            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw, true);
            ioe.printStackTrace(pw);
            pw.flush();
            sw.flush();
            getLogger().warn("IOException reading from Perforce process (may just be EOF)");
            getLogger().warn(sw.toString());
        }
        finally{
            try{
                p4.getWriter().close();
            } catch (IOException e) {
                getLogger().warn("Write pipe failed to close.");
            }
            try{
                p4.getReader().close();
            } catch (IOException e) {
                getLogger().warn("Read pipe failed to close.");
            }
            p4.close();
        }
        byte[] byteArray = new byte[bytes.size()];
        for(int i=0; i<bytes.size(); i++){
            byteArray[i] = bytes.get(i).byteValue();
        }
View Full Code Here

     * @return the p4 ticket
     * @throws IOException if an I/O error prevents this from working
     * @throws PerforceException if the execution of the p4Exe fails
     */
    private String p4Login(String p4Exe) throws IOException, PerforceException {
        Executor login = depot.getExecFactory().newExecutor();
        login.exec(new String[] { p4Exe, "login", "-a", "-p" });

        try {
            // "echo" the password for the p4 process to read
            BufferedWriter writer = login.getWriter();
            try {
                writer.write(depot.getPassword() + "\n");
            } finally {
                // help the writer move the data
                writer.flush();
            }
            // read the ticket from the output
            String ticket = null;
            BufferedReader reader = login.getReader();
            String line;
            // The line matching ^[0-9A-F]{32}$ will be the ticket
            while ((line = reader.readLine()) != null) {
                int error = checkAuthnErrors(line);
                if (error != -1)
                    throw new PerforceException("Login attempt failed: " + line);
                if (line.trim().matches("^[0-9A-F]{32}$"))
                    ticket = line;
            }
           
            return ticket;
        } finally {
            login.close();
        }
    }
View Full Code Here

   
    /**
     * Trust the perforce server if using SSL
     */
    private void trustIfSSL() throws PerforceException {
        Executor trust = depot.getExecFactory().newExecutor();
        String p4Port = depot.getPort();
        if(p4Port.toLowerCase().startsWith("ssl:")){
            trust.exec(new String[] { getP4Exe(), "-p", depot.getPort(), "trust", "-y" });
            try{
                trust.getWriter().close();
                BufferedReader reader = trust.getReader();
                String line;
                // The line matching ^[0-9A-F]{32}$ will be the ticket
                while ((line = reader.readLine()) != null) {
                    int error = checkAuthnErrors(line);
                    if (error != -1)
                        throw new PerforceException("Trust attempt failed: " + line);
                }
            } catch (IOException e) {
                throw new PerforceException("Could not establish ssl trust with perforce server", e);
            }
            trust.close();
        }
    }
View Full Code Here

TOP

Related Classes of com.tek42.perforce.model.Workspace

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.