com.tek42.perforce.parse
Class AbstractPerforceTemplate

java.lang.Object
  extended by com.tek42.perforce.parse.AbstractPerforceTemplate
Direct Known Subclasses:
Changes, Counters, Groups, Labels, Status, Users, Workspaces

public abstract class AbstractPerforceTemplate
extends java.lang.Object

Provides default functionality for interacting with Perforce using the template design pattern.

Author:
Mike Wille

Constructor Summary
AbstractPerforceTemplate(Depot depot)
           
 
Method Summary
protected  java.lang.String[] getExtraParams(java.lang.String[] cmd)
          Adds any extra parameters that need to be applied to all perforce commands.
 org.slf4j.Logger getLogger()
           
protected  java.lang.String getP4Exe()
           
protected  java.lang.StringBuilder getPerforceResponse(java.lang.String[] cmd)
          Executes a perforce command and returns the output as a StringBuilder.
protected  java.util.List<java.lang.String> getRawPerforceResponseLines(java.lang.String[] cmd)
          Executes a p4 command and returns the output as list of lines.
protected  boolean hitMax(java.lang.StringBuilder response)
          Check to see if the perforce request resulted in a "too many results" error.
protected  void login()
          Tries to perform a p4 login if the security level on the server is set to level 3 and no ticket was set via depot.setP4Ticket().
protected  java.util.List<java.lang.String> parseList(java.lang.StringBuilder response, int index)
          Parses lines of formatted text for a list of values.
protected  void saveToPerforce(java.lang.Object object, Builder builder)
          Handles the IO for opening a process, writing to it, flushing, closing, and then handling any errors.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractPerforceTemplate

public AbstractPerforceTemplate(Depot depot)
Method Detail

getLogger

public org.slf4j.Logger getLogger()

parseList

protected java.util.List<java.lang.String> parseList(java.lang.StringBuilder response,
                                                     int index)
Parses lines of formatted text for a list of values. Tokenizes each line into columns and adds the column specified by index to the list.

Parameters:
response - The response from perforce to parse
index - The column index to add to the list
Returns:
A List of strings parsed from the response

hitMax

protected boolean hitMax(java.lang.StringBuilder response)
Check to see if the perforce request resulted in a "too many results" error. If so, special handling needs to happen.

Parameters:
response - The response from perforce
Returns:
True if the limit was reached, false otherwise.

getExtraParams

protected java.lang.String[] getExtraParams(java.lang.String[] cmd)
Adds any extra parameters that need to be applied to all perforce commands. For example, adding the login ticket to authenticate with.

Parameters:
cmd - String array that will be executed
Returns:
A (possibly) modified string array to be executed in place of the original.

saveToPerforce

protected void saveToPerforce(java.lang.Object object,
                              Builder builder)
                       throws PerforceException
Handles the IO for opening a process, writing to it, flushing, closing, and then handling any errors.

Parameters:
object - The perforce object to save
builder - The builder responsible for saving the object
Throws:
PerforceException - If there is any errors thrown from perforce

getPerforceResponse

protected java.lang.StringBuilder getPerforceResponse(java.lang.String[] cmd)
                                               throws PerforceException
Executes a perforce command and returns the output as a StringBuilder.

Parameters:
cmd - The perforce commands to execute. Each command and argument is it's own array element
Returns:
The response from perforce as a stringbuilder
Throws:
PerforceException - If perforce throws any errors

getRawPerforceResponseLines

protected java.util.List<java.lang.String> getRawPerforceResponseLines(java.lang.String[] cmd)
                                                                throws PerforceException
Executes a p4 command and returns the output as list of lines. TODO Introduce a method that handles prefixed messages (i.e. "p4 -s "), and can thus stop reading once if reads the "exit: " line, which should avoid the "expected" Exception at EOF.

Parameters:
cmd - The perforce command to execute. The command and arguments are each in their own array element (e.g. cmd = {"p4", "info"}).
Returns:
The response from perforce as a list
Throws:
PerforceException

login

protected void login()
              throws PerforceException
Tries to perform a p4 login if the security level on the server is set to level 3 and no ticket was set via depot.setP4Ticket().

Unfortunately, this likely doesn't work on windows.

Throws:
PerforceException - If perforce throws any errors

getP4Exe

protected java.lang.String getP4Exe()


Copyright © 2010. All Rights Reserved.