com.tek42.perforce.parse
Class AbstractPerforceTemplate

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

public abstract class AbstractPerforceTemplate
extends Object

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

Author:
Mike Wille

Nested Class Summary
static class AbstractPerforceTemplate.ResponseFilter
          Used to filter the response from perforce so the API can throw out useless lines and thus save memory during large operations.
 
Constructor Summary
AbstractPerforceTemplate(Depot depot)
           
 
Method Summary
protected  String[] getExtraParams(String[] cmd)
          Adds any extra parameters that need to be applied to all perforce commands.
 org.slf4j.Logger getLogger()
           
protected  String getP4Exe()
           
protected  StringBuilder getPerforceResponse(String[] cmd)
          Executes a perforce command and returns the output as a StringBuilder.
protected  StringBuilder getPerforceResponse(String[] cmd, AbstractPerforceTemplate.ResponseFilter filter)
           
protected  byte[] getRawPerforceResponseBytes(String[] cmd)
          Used by calls that make use of p4.exe's python dictionary output format.
protected  List<String> getRawPerforceResponseLines(String[] cmd)
          Executes a p4 command and returns the output as list of lines.
protected  boolean hitMax(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  List<String> parseList(StringBuilder response, int index)
          Parses lines of formatted text for a list of values.
protected  void saveToPerforce(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 List<String> parseList(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(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 String[] getExtraParams(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(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 StringBuilder getPerforceResponse(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

getPerforceResponse

protected StringBuilder getPerforceResponse(String[] cmd,
                                            AbstractPerforceTemplate.ResponseFilter filter)
                                     throws PerforceException
Throws:
PerforceException

getRawPerforceResponseLines

protected List<String> getRawPerforceResponseLines(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

getRawPerforceResponseBytes

protected byte[] getRawPerforceResponseBytes(String[] cmd)
                                      throws PerforceException
Used by calls that make use of p4.exe's python dictionary output format.

Parameters:
cmd -
Returns:
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 String getP4Exe()


Copyright © 2004-2012 Hudson. All Rights Reserved.