com.perforce.p4java.ant.tasks
Class GrepTask

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
              extended by com.perforce.p4java.ant.tasks.ServerTask
                  extended by com.perforce.p4java.ant.tasks.ClientTask
                      extended by com.perforce.p4java.ant.tasks.GrepTask
All Implemented Interfaces:
java.lang.Cloneable

public class GrepTask
extends ClientTask

Grep searches files for lines matching a given regular expression, the expression (or pattern) can contain wild cards. The parser used internally is based on V8 regexp and might not be compatible with later parsers, however the majority of functionality is available.

If the file argument has a revision, then all files as of that revision are searched. If the file argument has a revision range, then only files selected by that revision range are listed, and the highest revision in the range is used for each file. Normally, the head revision is searched. See 'p4 help revisions' for help specifying revisions.

See Also:
PerforceTask, ServerTask

Nested Class Summary
 
Nested classes/interfaces inherited from class com.perforce.p4java.ant.tasks.ServerTask
ServerTask.GlobalOption
 
Nested classes/interfaces inherited from class com.perforce.p4java.ant.tasks.PerforceTask
PerforceTask.Field, PerforceTask.File
 
Field Summary
protected  boolean allRevisions
          Search all revisions within the specified range, rather than only the highest revision in the range.
protected  boolean caseInsensitive
          Perform case-insensitive pattern matching.
protected  java.util.List<IFileLineMatch> fileLineMatches
          Collection of file line matches returned from the Perforce command.
protected  boolean fixedPattern
          If true, interpret the pattern as a fixed string.
protected  boolean includeLineNumbers
          Display a matching line number after the file revision number.
protected  int leadingContext
          Display num lines of trailing context before matching lines.
protected  boolean nonMatchingLines
          Display files with non-matching lines.
protected  int outputContext
          Display num lines of output context.
protected  java.lang.String pattern
          The patterns used by p4 grep are regular expressions comparable to those used in UNIX.
protected  boolean searchBinaries
          Treat binary files as text.
protected  int trailingContext
          Display num lines of trailing context after matching lines.
 
Fields inherited from class com.perforce.p4java.ant.tasks.ClientTask
p4Client
 
Fields inherited from class com.perforce.p4java.ant.tasks.ServerTask
allHosts, commandOptions, globaloptions, hostName, P4_SERVER_PROTOCOL_PROPERTIES_FILE, P4_SERVER_USAGE_PROPERTIES_FILE, p4Server, programName, programVersion, protocolPropertiesFile, protocolProps, textLanguage, unsetClientName, unsetUserName, usagePropertiesFile, usageProps, workingDirectory
 
Fields inherited from class com.perforce.p4java.ant.tasks.PerforceTask
charset, client, failOnError, fields, FILE_TOKEN_REGEX_PATTERN, fileList, files, fileSpecs, LINE_PADDING, LINE_SEPARATOR, p4Messages, passwd, port, protocol, retFileSpecs, retStatusMessage, 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
GrepTask()
          Default constructor.
 
Method Summary
protected  void execP4Command()
          Execute the Perforce grep command with file specs, pattern and options.
 java.util.List<IFileLineMatch> getFileLineMatches()
          Gets the file line matches.
 void setAllRevisions(boolean allRevisions)
          Sets the all revisions.
 void setCaseInsensitive(boolean caseInsensitive)
          Sets the case insensitive.
 void setFixedPattern(boolean fixedPattern)
          Sets the fixed pattern.
 void setIncludeLineNumbers(boolean includeLineNumbers)
          Sets the include line numbers.
 void setLeadingContext(int leadingContext)
          Sets the leading context.
 void setNonMatchingLines(boolean nonMatchingLines)
          Sets the non matching lines.
 void setOutputContext(int outputContext)
          Sets the output context.
 void setPattern(java.lang.String pattern)
          Sets the pattern.
 void setSearchBinaries(boolean searchBinaries)
          Sets the search binaries.
 void setTrailingContext(int trailingContext)
          Sets the trailing context.
 
Methods inherited from class com.perforce.p4java.ant.tasks.ClientTask
cleanupP4, getP4Client, initP4, setP4Client
 
Methods inherited from class com.perforce.p4java.ant.tasks.ServerTask
cleanupP4Server, createGlobalOption, getGlobalOptions, getP4Server, initP4Server, initP4ServerOptions, setAllHosts, setHostName, setP4Server, setProgramName, setProgramVersion, setProtocolPropertiesFile, setProtocolProps, setTextLanguage, setUnsetClientName, setUnsetUserName, setUsagePropertiesFile, setUsageProps, setWorkingDirectory
 
Methods inherited from class com.perforce.p4java.ant.tasks.PerforceTask
addFileset, createField, createFile, execute, getFields, getFiles, getFileSpecs, getRetFileSpecs, getRetStatusMessage, init, isEmpty, logChangelistSummaries, logChangelistSummary, logExtendedFileSpec, logExtendedFileSpecs, logFileDiff, logFileDiffs, logFileLineMatch, logFileLineMatches, logFileSpec, logFileSpecs, logFix, logFixes, logJob, logJobs, parseChangelist, setCharset, setClient, setFailOnError, setFiles, setPasswd, setPort, setProtocol, setUser
 
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

pattern

protected java.lang.String pattern
The patterns used by p4 grep are regular expressions comparable to those used in UNIX. Corresponds to the p4 grep -e pattern option.


allRevisions

protected boolean allRevisions
Search all revisions within the specified range, rather than only the highest revision in the range. Corresponds to the p4 grep -a option.


caseInsensitive

protected boolean caseInsensitive
Perform case-insensitive pattern matching. (By default, matching is case-sensitive.). Corresponds to the p4 grep -i option.


includeLineNumbers

protected boolean includeLineNumbers
Display a matching line number after the file revision number. Corresponds to the p4 grep -n option.


nonMatchingLines

protected boolean nonMatchingLines
Display files with non-matching lines. Corresponds to the p4 grep -v option.


searchBinaries

protected boolean searchBinaries
Treat binary files as text. (By default, only files of type text are selected for pattern matching.). Corresponds to the p4 grep -t option.


outputContext

protected int outputContext
Display num lines of output context. Corresponds to the p4 grep -C num option; if zero, option is off.


trailingContext

protected int trailingContext
Display num lines of trailing context after matching lines. Corresponds to the p4 grep -A num option; if zero, option is off.


leadingContext

protected int leadingContext
Display num lines of trailing context before matching lines. Corresponds to the p4 grep -B num option; if zero, option is off.


fixedPattern

protected boolean fixedPattern
If true, interpret the pattern as a fixed string. If false, interpret the pattern as a regular expression. Corresponds to the p4 grep -F and -G options: if true, corresponds to -F; if false, to -G.


fileLineMatches

protected java.util.List<IFileLineMatch> fileLineMatches
Collection of file line matches returned from the Perforce command.

Constructor Detail

GrepTask

public GrepTask()
Default constructor.

Method Detail

setPattern

public void setPattern(java.lang.String pattern)
Sets the pattern.

Parameters:
pattern - the new pattern

setAllRevisions

public void setAllRevisions(boolean allRevisions)
Sets the all revisions.

Parameters:
allRevisions - the new all revisions

setCaseInsensitive

public void setCaseInsensitive(boolean caseInsensitive)
Sets the case insensitive.

Parameters:
caseInsensitive - the new case insensitive

setIncludeLineNumbers

public void setIncludeLineNumbers(boolean includeLineNumbers)
Sets the include line numbers.

Parameters:
includeLineNumbers - the new include line numbers

setNonMatchingLines

public void setNonMatchingLines(boolean nonMatchingLines)
Sets the non matching lines.

Parameters:
nonMatchingLines - the new non matching lines

setSearchBinaries

public void setSearchBinaries(boolean searchBinaries)
Sets the search binaries.

Parameters:
searchBinaries - the new search binaries

setOutputContext

public void setOutputContext(int outputContext)
Sets the output context.

Parameters:
outputContext - the new output context

setTrailingContext

public void setTrailingContext(int trailingContext)
Sets the trailing context.

Parameters:
trailingContext - the new trailing context

setLeadingContext

public void setLeadingContext(int leadingContext)
Sets the leading context.

Parameters:
leadingContext - the new leading context

setFixedPattern

public void setFixedPattern(boolean fixedPattern)
Sets the fixed pattern.

Parameters:
fixedPattern - the new fixed pattern

getFileLineMatches

public java.util.List<IFileLineMatch> getFileLineMatches()
Gets the file line matches.

Returns:
the file line matches

execP4Command

protected void execP4Command()
                      throws org.apache.tools.ant.BuildException
Execute the Perforce grep command with file specs, pattern and options. Log the returned line matches.

Get list of matching lines in the specified file specs. This method implements the p4 grep command; for full semantics, see the separate p4 documentation and / or the GrepOptions Javadoc.

Specified by:
execP4Command in class PerforceTask
Throws:
org.apache.tools.ant.BuildException - the build exception
See Also:
PerforceTask.execP4Command()


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