com.perforce.p4java.ant.tasks
Class PerforceTask

java.lang.Object
  extended by org.apache.tools.ant.ProjectComponent
      extended by org.apache.tools.ant.Task
          extended by com.perforce.p4java.ant.tasks.PerforceTask
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
ServerTask

public abstract class PerforceTask
extends org.apache.tools.ant.Task

Base class for Perforce server and client tasks. It defines some common attributes and methods shared by most Perforce tasks. This class is further extended by a base server and a base client classes.

Perforce tasks requires some basic properties. These properties are respectively retrieved through individual attributes, project-wide properties and environment variables.

See Also:
ServerTask, ClientTask, AddTask, ChangeTask, ChangesTask, CounterTask, DeleteTask, Diff2Task, EditTask, FilesTask, FixTask, FstatTask, GrepTask, HaveTask, IntegrateTask, JobTask, JobsTask, LabelTask, LabelsyncTask, LockTask, MoveTask, ReopenTask, ResolveTask, RevertTask, ShelveTask, SubmitTask, SyncTask, TagTask, UnlockTask, UnshelveTask

Nested Class Summary
 class PerforceTask.Field
          This inner class is used for handling nested "field" elements.
 class PerforceTask.File
          This inner class is used for handling nested "file" elements.
 
Field Summary
protected  java.lang.String charset
          Character set used for translation of unicode files.
protected  java.lang.String client
          Perforce client workspace.
protected  boolean failOnError
          If true, it will fail on error, otherwise it will keep on going (default is to fail on error).
protected  java.util.List<PerforceTask.Field> fields
          Collection of fields (name-value pairs) contained in the "field" nested elements.
protected static java.lang.String FILE_TOKEN_REGEX_PATTERN
          Regular expression pattern for splitting a string by whitespace and sequences of characters that begin and end with a quote.
protected  java.util.List<PerforceTask.File> fileList
          Collection of file and revision specifiers contained in the "file" nested elements.
protected  java.lang.String files
          Perforce file and revision specifiers, separated by whitespace.
protected  java.util.List<IFileSpec> fileSpecs
          Collection of file and revision specifiers used as input for the Perforce command.
protected static java.lang.String LINE_PADDING
          Line padding.
protected static java.lang.String LINE_SEPARATOR
          Line separator for this system.
protected  PerforceMessages p4Messages
          Perforce message bundle.
protected  java.lang.String passwd
          Perforce user's password.
protected  java.lang.String port
          Perforce server host and port.
protected  java.lang.String protocol
          Perforce server protocol.
protected  java.util.List<IFileSpec> retFileSpecs
          Collection of file and revision specifiers returned from the Perforce command.
protected  java.lang.String retStatusMessage
          Result status message returned from the Perforce command.
protected  java.lang.String user
          Perforce user.
 
Fields inherited from class org.apache.tools.ant.Task
target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project
 
Constructor Summary
PerforceTask()
          Default constructor.
 
Method Summary
 void addFileset(org.apache.tools.ant.types.FileSet fileSet)
          This method is use for adding new "fileset" to the collection.
protected abstract  void cleanupP4()
          Cleanup Perforce server and client instances; logout, disconnect, etc.
 PerforceTask.Field createField()
          This method is called by an Ant factory method to instantiates a collection of "field" nested elements.
 PerforceTask.File createFile()
          This method is called by an Ant factory method to instantiates a collection of "file" nested elements.
protected abstract  void execP4Command()
          Execute the Perforce command.
 void execute()
          Runs the task.
protected  java.util.Map<java.lang.String,java.lang.String> getFields()
          Combine all of the fields specified by the "field" nested elements.
protected  java.lang.String[] getFiles()
          Combine all of the files specified by the "file" attribute, the "file" nested element and Ant's FileSet.
 java.util.List<IFileSpec> getFileSpecs()
          Gets the file specs.
 java.util.List<IFileSpec> getRetFileSpecs()
          Gets the ret file specs.
 java.lang.String getRetStatusMessage()
          Gets the ret status message.
 void init()
          Inits the.
protected abstract  void initP4()
          Initialize Perforce server and client instances.
protected  boolean isEmpty(java.lang.String value)
          Checks if is empty.
protected  void logChangelistSummaries(java.util.List<IChangelistSummary> changelistSummaries)
          Log the attributes of a list of changelist summaries.
protected  void logChangelistSummary(IChangelistSummary changelistSummary)
          Log the attributes of a changelist summary.
protected  void logExtendedFileSpec(IExtendedFileSpec extendedFileSpec)
          Log the attributes of an extended file spec.
protected  void logExtendedFileSpecs(java.util.List<IExtendedFileSpec> extendedFileSpecs)
          Log the attributes of a list of extended file specs.
protected  void logFileDiff(IFileDiff fileDiff)
          Log the attributes of a file diff.
protected  void logFileDiffs(java.util.List<IFileDiff> fileDiffs)
          Log the attributes of a list of file diffs.
protected  void logFileLineMatch(IFileLineMatch fileLineMatch)
          Log the attributes of a file line match.
protected  void logFileLineMatches(java.util.List<IFileLineMatch> fileLineMatches)
          Log the attributes of a list of file line matches.
protected  void logFileSpec(IFileSpec fileSpec)
          Log the attributes of a file spec.
protected  void logFileSpecs(java.util.List<IFileSpec> fileSpecs)
          Log the attributes of a list of file specs.
protected  void logFix(IFix fix)
          Log the attributes of a fix.
protected  void logFixes(java.util.List<IFix> fixes)
          Log the attributes of a list of fixes.
protected  void logJob(IJob job)
          Log the attributes of a job.
protected  void logJobs(java.util.List<IJob> jobs)
          Log the attributes of a list of jobs.
protected  int parseChangelist(java.lang.String changelist)
          Parse the changelist string to a changelist number.
 void setCharset(java.lang.String charset)
          Sets the charset.
 void setClient(java.lang.String client)
          Sets the client.
 void setFailOnError(boolean failOnError)
          Sets the fail on error.
 void setFiles(java.lang.String files)
          Sets the files.
 void setPasswd(java.lang.String passwd)
          Sets the passwd.
 void setPort(java.lang.String port)
          Sets the port.
 void setProtocol(java.lang.String protocol)
          Sets the protocol.
 void setUser(java.lang.String user)
          Sets the user.
 
Methods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fields

protected java.util.List<PerforceTask.Field> fields
Collection of fields (name-value pairs) contained in the "field" nested elements.


fileList

protected java.util.List<PerforceTask.File> fileList
Collection of file and revision specifiers contained in the "file" nested elements.


p4Messages

protected PerforceMessages p4Messages
Perforce message bundle.


LINE_SEPARATOR

protected static final java.lang.String LINE_SEPARATOR
Line separator for this system.


LINE_PADDING

protected static final java.lang.String LINE_PADDING
Line padding.

See Also:
Constant Field Values

FILE_TOKEN_REGEX_PATTERN

protected static final java.lang.String FILE_TOKEN_REGEX_PATTERN
Regular expression pattern for splitting a string by whitespace and sequences of characters that begin and end with a quote.

See Also:
Constant Field Values

protocol

protected java.lang.String protocol
Perforce server protocol. Initialize to default protocol.


port

protected java.lang.String port
Perforce server host and port.


client

protected java.lang.String client
Perforce client workspace.


user

protected java.lang.String user
Perforce user.


passwd

protected java.lang.String passwd
Perforce user's password.


charset

protected java.lang.String charset
Character set used for translation of unicode files. P4CHARSET only affects files of type unicode and utf16; non-unicode files are never translated. For servers operating in the default (non-Unicode mode), P4CHARSET must be left unset on client machines. If P4CHARSET is set, but the server is not operating in internationalized mode, the server returns the following error message: "Unicode clients require a unicode enabled server". For servers operating in Unicode mode, P4CHARSET must be set on client machines. If P4CHARSET is unset, but the server is operating in Unicode mode, client programs return the following error message: "Unicode server permits only unicode enabled clients". Note that the names below are not actually the standard name for the charset in some cases: e.g. UTF-8 should be "utf-8" not "utf8", but we follow the Perforce server's rules here.

"none", "utf8", "iso8859-1", "shiftjis", "eucjp", "winansi", "cp949", "macosroman", "iso8859-15", "iso8859-5", "koi8-r", "cp1251", "utf16le", "utf16be", "utf16"


files

protected java.lang.String files
Perforce file and revision specifiers, separated by whitespace. If the path contains whitespace, it must be double-quoted.


failOnError

protected boolean failOnError
If true, it will fail on error, otherwise it will keep on going (default is to fail on error).


fileSpecs

protected java.util.List<IFileSpec> fileSpecs
Collection of file and revision specifiers used as input for the Perforce command.


retFileSpecs

protected java.util.List<IFileSpec> retFileSpecs
Collection of file and revision specifiers returned from the Perforce command.


retStatusMessage

protected java.lang.String retStatusMessage
Result status message returned from the Perforce command.

Constructor Detail

PerforceTask

public PerforceTask()
Default constructor.

Method Detail

createField

public PerforceTask.Field createField()
This method is called by an Ant factory method to instantiates a collection of "field" nested elements. It saves the reference to the collection and returns it to Ant Core.

Returns:
the field

createFile

public PerforceTask.File createFile()
This method is called by an Ant factory method to instantiates a collection of "file" nested elements. It saves the reference to the list and returns it to Ant Core.

Returns:
the files

addFileset

public void addFileset(org.apache.tools.ant.types.FileSet fileSet)
This method is use for adding new "fileset" to the collection.

Parameters:
fileSet - the file set

setProtocol

public void setProtocol(java.lang.String protocol)
Sets the protocol.

Parameters:
protocol - the new protocol

setPort

public void setPort(java.lang.String port)
Sets the port.

Parameters:
port - the new port

setClient

public void setClient(java.lang.String client)
Sets the client.

Parameters:
client - the new client

setUser

public void setUser(java.lang.String user)
Sets the user.

Parameters:
user - the new user

setPasswd

public void setPasswd(java.lang.String passwd)
Sets the passwd.

Parameters:
passwd - the new passwd

setCharset

public void setCharset(java.lang.String charset)
Sets the charset.

Parameters:
charset - the new charset

setFiles

public void setFiles(java.lang.String files)
Sets the files.

Parameters:
files - the new files

setFailOnError

public void setFailOnError(boolean failOnError)
Sets the fail on error.

Parameters:
failOnError - the new fail on error

getFileSpecs

public java.util.List<IFileSpec> getFileSpecs()
Gets the file specs.

Returns:
the file specs

getRetFileSpecs

public java.util.List<IFileSpec> getRetFileSpecs()
Gets the ret file specs.

Returns:
the ret file specs

getRetStatusMessage

public java.lang.String getRetStatusMessage()
Gets the ret status message.

Returns:
the ret status message

init

public void init()
Inits the.

Overrides:
init in class org.apache.tools.ant.Task
See Also:
Task.init()

execute

public void execute()
             throws org.apache.tools.ant.BuildException
Runs the task.

Overrides:
execute in class org.apache.tools.ant.Task
Throws:
org.apache.tools.ant.BuildException - the build exception
See Also:
Task.execute()

initP4

protected abstract void initP4()
                        throws org.apache.tools.ant.BuildException
Initialize Perforce server and client instances. This should be implemented in the Perforce server and client subclasses.

Throws:
org.apache.tools.ant.BuildException - the build exception

cleanupP4

protected abstract void cleanupP4()
                           throws org.apache.tools.ant.BuildException
Cleanup Perforce server and client instances; logout, disconnect, etc. This should be implemented by the Perforce server and client subclasses.

Throws:
org.apache.tools.ant.BuildException - the build exception

execP4Command

protected abstract void execP4Command()
                               throws org.apache.tools.ant.BuildException
Execute the Perforce command. This should be implemented by the task subclasses handling specific Perforce commands. Please refer to individual Perforce commands for definitions and details.

Throws:
org.apache.tools.ant.BuildException - the build exception

logFileSpecs

protected void logFileSpecs(java.util.List<IFileSpec> fileSpecs)
Log the attributes of a list of file specs.

Parameters:
fileSpecs - the file specs

logFileSpec

protected void logFileSpec(IFileSpec fileSpec)
Log the attributes of a file spec.

Parameters:
fileSpec - the file spec

logExtendedFileSpecs

protected void logExtendedFileSpecs(java.util.List<IExtendedFileSpec> extendedFileSpecs)
Log the attributes of a list of extended file specs.

Parameters:
extendedFileSpecs - the extended file specs

logExtendedFileSpec

protected void logExtendedFileSpec(IExtendedFileSpec extendedFileSpec)
Log the attributes of an extended file spec.

Parameters:
extendedFileSpec - the extended file spec

logFileDiffs

protected void logFileDiffs(java.util.List<IFileDiff> fileDiffs)
Log the attributes of a list of file diffs.

Parameters:
fileDiffs - the file diffs

logFileDiff

protected void logFileDiff(IFileDiff fileDiff)
Log the attributes of a file diff.

Parameters:
fileDiff - the file diff

logChangelistSummaries

protected void logChangelistSummaries(java.util.List<IChangelistSummary> changelistSummaries)
Log the attributes of a list of changelist summaries.

Parameters:
changelistSummaries - the changelist summaries

logChangelistSummary

protected void logChangelistSummary(IChangelistSummary changelistSummary)
Log the attributes of a changelist summary.

Parameters:
changelistSummary - the changelist summary

logFixes

protected void logFixes(java.util.List<IFix> fixes)
Log the attributes of a list of fixes.

Parameters:
fixes - the fixes

logFix

protected void logFix(IFix fix)
Log the attributes of a fix.

Parameters:
fix - the fix

logFileLineMatches

protected void logFileLineMatches(java.util.List<IFileLineMatch> fileLineMatches)
Log the attributes of a list of file line matches.

Parameters:
fileLineMatches - the file line matches

logFileLineMatch

protected void logFileLineMatch(IFileLineMatch fileLineMatch)
Log the attributes of a file line match.

Parameters:
fileLineMatch - the file line match

logJobs

protected void logJobs(java.util.List<IJob> jobs)
Log the attributes of a list of jobs.

Parameters:
jobs - the jobs

logJob

protected void logJob(IJob job)
Log the attributes of a job.

Parameters:
job - the job

getFields

protected java.util.Map<java.lang.String,java.lang.String> getFields()
Combine all of the fields specified by the "field" nested elements.

Returns:
the map

getFiles

protected java.lang.String[] getFiles()
Combine all of the files specified by the "file" attribute, the "file" nested element and Ant's FileSet.

Returns:
the files

parseChangelist

protected int parseChangelist(java.lang.String changelist)
Parse the changelist string to a changelist number. Convert the "default" changelist string to the default changelist number. If it is negative return unknown changelist. Otherwise, return the converted changelist number.

Parameters:
changelist - the changelist
Returns:
the int

isEmpty

protected boolean isEmpty(java.lang.String value)
Checks if is empty.

Parameters:
value - the value
Returns:
true, if is empty


Copyright (c) 2010 Perforce Software. All rights reserved.