Appendix B: Core Tasks

This appendix contains a reference of all core tasks, i.e. all tasks that are needed to build a basic project. If you are looking for binarycloud related tasks, look in appendix ?.

This reference lists the tasks alphabetically by the name of the classes that implement the tasks. So if you are searching for the reference to the <copy> tag, for example, you will want to look at the reference of CopyTask.

AdhocTaskdefTask

The AdhocTaskdefTask allows you to define a task within your build file.

<target name="main"
description="==>test AdhocTask ">

<adhoc-task name="foo"><![CDATA[
class FooTest extends Task {
private $bar;

function setBar($bar) {
$this->bar = $bar;
}

function main() {
$this->log("In FooTest: " . $this->bar);
}
}
]]></adhoc-task>

<foo bar="B.L.I.N.G"/>
</target>

Note that you should use <![CDATA[ ... ]]> so that you don't have to quote entities within your <adhoc-task></adhoc-task> tags.

Parameters

Name Type Description Default Required
name String Name of XML tag that will represent this task. n/a Yes

AdhocTypedefTask

The AdhocTaskdefTask allows you to define a datatype within your build file.

<target name="main"
description="==>test AdhocType">

<adhoc-type name="dsn"><![CDATA[
class CreoleDSN extends DataType {
private $url;

function setUrl($url) {
$this->url = $url;
}

function getUrl() { return $this->url; }
}
]]></adhoc-type>
<!-- creole-sql task doesn't exist; just an example --> <creole-sql file="test.sql"> <dsn url="mysql://root@localhost/test"/> </creole-sql>

</target>

Note that you should use <![CDATA[ ... ]]> so that you don't have to quote entities within your <adhoc-type></adhoc-type> tags.

Parameters

Name Type Description Default Required
name String Name of XML tag that will represent this datatype.. n/a Yes

AppendTask

The Append Task appends text or contents of files to a specified file.

<append destFile="${process.outputfile}">
  <filterchain>
    <xsltfilter style="${process.stylesheet}">
	     <param name="mode" expression="${process.xslt.mode}"/>
    </xsltfilter>
  </filterchain>
  <filelist dir="book/" listfile="book/PhingGuide.book"/>
</append>

In the example above, AppendTask is reading a filename from book/PhingGuide.book, processing the file contents with XSLT, and then appending the result to the file located at ${process.outputfile}. This is a real example from the build file used to generate this book!

Parameters

Name Type Description Default Required
destFile File Path of file to which text should be appended. n/a Yes
file File Path to file that should be appended to destFile. n/a Yes
text String Some literal text to append to file. n/a No

Supported Nested Tags

AvailableTask

Available Task tests if a resource/file is set and sets a certain property to a certain value if it exists.

<available file="/tmp/test.txt" property="test_txt_exists" value="Yes"/>

<available file="/home/foo" type="dir" property="properties.yetanother" />

<available file="/home/foo/bar" property="foo.bar" value="Well, yes" />

Here, AvailableTask first checks for the existance of either file or directory named test.txt in /tmp. Then, it checks for the directory foo in /home and then for the file or directory bar in /home/foo. If /tmp/test.txt is found, the property test_txt_exists is set to "Yes", if /home/foo is found and a directory, properties.yetanother is set to "true" (default). If /home/foo/bar exists, AvailableTask will set foo.bar to "Well, yes".

Parameters

Name Type Description Default Required
property string Name of the property that is to be set. n/a Yes
value String The value the propert is to be set to. "true" No
file String File/directory to check existance. n/a Yes (or resource)
resource String Path of the resource to look for. n/a Yes (or file)
type String (file|dir) Determines if AvailableTask should look for a file or a directory at the position set by file. If empty, it checks for either file or directory. n/a No

CallTargetTask

The CallTargetTask calls a target from the same project. A <project> tag may contain <property> tags that define new properties. In the following example, the properties property1 and foo are defined and only accessible inside the called target.

However, this will only work if the properties are not yet set outside the "phingcall" tag.

Example

<target name="foo">
    <phingcall target="bar">
        <property name="property1" value="aaaaa" />
        <property name="foo" value="baz" />
    </phingcall>
</target>

<target name="bar" depends="init">
    <echo message="prop is ${property1} ${foo}" />
</target>

Parameters

Name Type/Values Description Default Required
target string The name of the target in the same project that is to be called. n/a Yes

CopyTask

The phing Copy Task. Copies a file or directory to a new file or directory. Files are only copied if the source file is newer than the destination file, or when the destination file does not exist. It is possible to explictly overwrite existing files.

Example

On the one hand, CopyTask can be used to copy file by file:

<copy file="somefile.txt" tofile="/tmp/anotherfile.bak" overwrite="true"/>

Additionally, CopyTask supports Filesets, i.e. you can easily include/exclude one or more files. For more information, see Appendix C. Mappers and Filterchains are also supported by CopyTask, so you can do almost everything that needs processing the content of the files or the filename.

Notice: CopyTask does not allow self copying, i.e. copying a file to the same name for security reasons.

<copy todir="/tmp/backup" >
  <fileset dir=".">
    <include name="**/*.txt">
    <include name="**/*.doc">
    <include name="**/*.swx">
  </fileset>
</copy>

Attributes

Name Type Description Default Required
file String The source file. Yes
tofile String

The destination the file is to be written to. tofile specifies a full filename. If you only want to specify a directory to copy to, use todir.

Either this or the todir attribute is required.

n/a Yes (or todir)
todir String The directory the file is to be copied to. The file will have the same name of the source file. If you want to specify a different name, use tofile. n/a Yes (or tofile)
overwrite Boolean If set to true, the target file will be overwritten. false No
tstamp Boolean If set to true, the new file will have the same mtime as the old one. false No
includeemptydirs Boolean If set to true, also empty directories are copied. true No

Supported Nested Tags

DeleteTask

Deletes a file or directory, or set of files defined by a fileset. See Appendix C for information on Filesets.

Example

<-- Delete a specific file from a directory -->
<delete file="foo.bar" dir="/tmp" />

<-- Delete a directory -->
<delete dir="/tmp/darl" includeemptydirs="true" verbose="true" failonerror="true" />

Attributes

Name Type Description Default Required
file String The file that is to be deleted. You either have to specify this attribute, or dir or both. n/a Yes
dir String The directory that is to be deleted. You either have to specify this attribute, or file or both. n/a Yes (or file)
verbose Boolean Used to force listing of all names of deleted files. n/a Yes
quiet Boolean

If the file does not exist, do not display a diagnostic message or modify the exit status to reflect an error. This means that if a file or directory cannot be deleted, then no error is reported.

This setting emulates the -f option to the Unix rm command. Default is false meaning things are verbose

n/a Yes
failonerror Boolean If this attribute is set to true, DeleteTask will verbose on errors but the build process will not be stopped. true Yes
includeemptydirs Boolean Determines if empty directories are also to be deleted. false False

Supported Nested Tags

EchoTask

This task simply verboses a string.

Example

<echo msg="Phing rocks!" />

<echo message="Binarycloud, too." />

<echo>And don't forget Propel.</echo>

Attributes

Name Type Description Default Required
msg String The string that is to be send to the output. n/a Yes
message String Alias for msg. n/a Yes

ExecTask

Executes a shell command. You can use this to quickly add a new command to Phing. However, if you want to use this regularly, you should think about writing a Task for it.

Example

<-- List the contents of "/home". -->
<exec command="ls -l" dir="/home" />

<-- Start the make process in "/usr/src/php-4.0". -->
<exec command="make" dir="/usr/src/php-4.0" />

<-- List the contents of "/tmp" out to a file. -->
<exec command="ls -l" "/tmp > foo.out" escape="false" />

Attributes

Name Type Description Default Required
command String The command that is to be executed. n/a Yes
dir String The directory the command is to be executed in. n/a Yes
os String Only execute if os.name contains specified text. n/a No
escape Boolean By default, we escape shell metacharacters before executing. Setting this to false will disable this precaution. TRUE No

ExitTask

Causes the current build script execution to fail and the script to exit with an (optional) error message.

Example

<-- Exit w/ message -->
<fail message="Failed for some reason!" />

<--  Exit if ${errorprop} is defined -->
<fail if="errorprop" message="Detected error!" />

<-- Exit unless ${dontfail} prop is defined. -->
<fail unless="dontfail" message="Detected error!" />

Attributes

Name Type Description Default Required
message String The message to display (reason for script abort). "No Message" No
if String Name of property that must be set for script to exit. n/a No
os String Name of property that must not be set in order for script to exit. n/a No

ForeachTask

The foreach task iterates over a list, a list of paths, or both. If both, list and paths, are specified, the list will be evaluated first. Nested paths are evaluated in the order they appear in the task.

Example

<!-- loop through languages, and call buildlang task with setted param -->
<property name="langauges" value="en,fr,de" />
<foreach list="${languages}" param="lang" target="buildlang" />

Attributes

Name Type Description Default Required
list string The list of values to process, with the delimiter character, indicated by the "delimiter" attribute, separating each value. n/a Yes
target string The target to call for each token, passing the token as the parameter with the name indicated by the "param" attribute. n/a Yes
param string The name of the parameter to pass the tokens in as to the target. n/a Yes
delimiter string The delimiter string that separates the values in the "list" parameter. The default is ",". , No

InputTask

The InputTask can be used to interactively set property values based on input from the console (or other Reader).

Example

<echo>HTML pages installing to: ${documentRoot}</echo>
<echo>PHP classes installing to: ${servletDirectory}</echo>

<input propertyname="documentRoot">Web application document root</input>
<input propertyname="servletDirectory"
  defaultValue="/usr/servlets" promptChar="?">PHP classes install dir</input>

<echo>HTML pages installed to ${documentRoot}</echo>
<echo>PHP classes installed to ${servletDirectory}</echo>

Attributes

Name Type Description Default Required
propertyName String The name of the property to set. n/a Yes
defaultValue String The default value to be set if no new value is provided. n/a Yes
message String Prompt text (same as CDATA). n/a No
promptChar String The prompt character to follow prompt text. n/a No

MkdirTask

Create a directory.

Example

<-- Create a temp directory -->
<mkdir dir="/tmp/foo" />

<-- Using mkdir with a property -->
<mkdir dir="{$dirs.install}/tmp" />

Attributes

Name Type Description Default Required
dir String The directory that is to be created. n/a Yes

MoveTask

Moves a file or directory to a new file or directory. By default, the destination file is overwritten if it already exists. When overwrite is turned off, then files are only moved if the source file is newer than the destination file, or when the destination file does not exist.

Source files and directories are only deleted if the file or directory has been copied to the destination successfully.

Example

<-- The following will move the file "somefile.txt" to "/tmp" and
    change its filename to "anotherfile.bak". It will overwrite
    an existing file. -->
<move file="somefile.txt" tofile="/tmp/anotherfile.bak" overwrite="true"/>

<-- This will move the "/tmp" directory to "/home/default/tmp",
    preserving the directory name. So the final name is
    "/home/default/tmp/tmp". Empty directories are also copied -->
<move file="/tmp" todir="/home/default/tmp" includeemptydirs="true" />

Attributes and Nested Elements

For further documentation, see CopyTask, since MoveTask only is a child of CopyTask and inherits all attributes.

PhingTask

This task calls another build file. You may specify the target that is to be called within the build file. Additionally, the <phing> Tag may contain <property> Tags (see PropertyTask).

Example

<-- Call target "xslttest" from buildfile "alternativebuildfile.xml" -->
 <phing phingfile="alternativebuild.xml" inheritRefs="true" target="xslttest" />

<-- Do a more complex call -->
<phing phingfile="somebuild.xml" target="sometarget">
  <property name="foo" value="bar">
  <property name="anotherone" value="32">
</phing>

Attributes

Name Type Description Default Required
inheritAll Boolean If true, pass all properties to the new phing project. true No
inheritRefs Boolean If true, pass all references to the new phing project. false No
dir String The directory to use as a base directory for the new phing project. Default is the current project's basedir, unless inheritall has been set to false, in which case it doesn't have a default value. This will override the basedir setting of the called project. n/a No
phingFile String The build file to use. Defaults to "build.xml". This file is expected to be a filename relative to the dir attribute given. n/a Yes
target String The target of the new Phing project to execute. Default is the new project's default target. n/a No

Supported Nested Tags

Base directory of the new project

The base directory of the new project is set dependant on the dir and the inheritAll attribute. This is important to keep in mind or else you might run into bugs in your build.xml's. The following table shows when which value is used:

dir attribute inheritAll attribute new project's basedir
value provided true value of dir attribute
value provided false value of dir attribute
omitted true basedir of calling task (the build file containing the <phing> call.
omitted false basedir attribute of the <project> element of the new project

PhpEvalTask

With the PhpEvalTask, you can set a property to the results of evaluating a PHP expression or the result returned by a function/method call.

Examples

<php function="crypt" returnProperty="enc_passwd">
  <param value="${auth.root_passwd}"/>
</php>
<php expression="3 + 4" returnProperty="sum"/>

Attributes

Name Type Description Default Required
function String The name of the Property. n/a One of these is required.
expression String The expression to evaluate. n/a
class String The static class which contains function. n/a No
returnProperty String The name of the property to set with result of expression or function call. n/a No

Supported Nested Tags

PropertyTask

With PropertyTask, you can define user properties in your build file.

Example

<property name="strings.test" value="Harr harr, more power!" />
<echo message="{$strings.text}" />

<property name="foo.bar" value="Yet another property..." />
<echo message="{$foo.bar}" />

Attributes

Name Type Description Default Required
name String The name of the Property. n/a Yes
value String The value of the Property. n/a Yes
override Boolean Whether to force override of existing value. false No

ReflexiveTask

The ReflexiveTask performs operations on files. It is essentially a convenient way to transform (using filter chains) files without copying them.

Example

<reflexive>
  <fileset dir=".">
    <include pattern="*.html">
  </fileset>
  <filterchain>
    <replaceregexp>
      <regexp pattern="\n\r" replace="\n"/>
    </replaceregexp>
  </filterchain>
</reflexive>

Attributes

Name Type Description Default Required
file String A single file to be processed. n/a Yes (unless <fileset> provided)

Supported Nested Tags:

ResolvePathTask

The ResolvePathTask turns a relative path into an absolute path, with respect to specified directory or the project basedir (if no dir attribute specified).

This task is useful for turning a user-defined relative path into an absolute path in cases where buildfiles will be called in different directories. Without this task, buildfiles lower in the directory tree would mis-interpret the user-defined relative paths.

Example

<property name="relative_path" value="./dirname"/>

<resolve propertyName="absolute_path" file="${relative_path}"/>

<echo>Resolved [absolute] path: ${absolute_path}</echo>

Attributes

Name Type Description Default Required
file String The file or directory path to resolve. n/a Yes
dir File The base directory to use when resolving "file". project.basedir No
propertyName String The name of the property to set with resolved (absolute) path. n/a Yes

TaskdefTask

With the TaskdefTask you can import a user task into your buildfile.

Example

<!-- Includes the Task named "ValidateHTMLTask" and makes it available by
     <validatehtml> -->
<taskdef classname="user.tasks.ValidateHTMLTask" name="validatehtml" />

<!-- Includes the Task "RebootTask" from "user/sometasks" somewhere inside
     the $PHP_CLASSPATH -->
<taskdef classname="user.sometasks.RebootTask" name="reboot" />

Attributes

Name Type Description Default Required
classname String The path to the class that defines the TaskClass. n/a Yes
name String The name the task is available as after importing. If you specify "validate", for example, you can access the task imported here with <validate>. n/a Yes
classpath String The classpath to use when including classes. This is added to PHP's include_path. n/a No
classpathref String Reference to classpath to use when including classes. This is added to PHP's include_path. n/a No

Supported Nested Tags

TouchTask

The TouchTask works like the Unix touch command: It sets the modtime of a file to a specific time. Default is the current time.

Example

<touch file="README.txt" millis="102134111" />

<touch file="COPYING.lib" datetime="10/10/1999 09:31 AM" />

Attributes

Name Type Description Default Required
file String The file which time is to be changed. n/a No
datetime DateTime The date and time the mtime of the file is to be set to. The format is "MM/DD/YYYY HH:MM AM or PM" now No
millis Integer The millisecons since midnight Jan 1 1970 (Unix epoche). now No

TypedefTask

With the TypedefTask you can import a user task into your buildfile.

Example

<!-- Includes the Type named "CustomProject" and makes it available by
     <cproject> -->
<taskdef classname="user.types.CustomProject" name="cproject" />

Attributes

Name Type Description Default Required
classname String The path to the class that defines the type class. n/a Yes
name String The name the type is available as after importing. If you specify "cproject", for example, you can access the type imported here with <cproject>. n/a Yes
classpath String The classpath to use when including classes. This is added to PHP's include_path. n/a No
classpathref String Reference to classpath to use when including classes. This is added to PHP's include_path. n/a No

Supported Nested Tags

UpToDateTask

Available Task tests if a resource/file is set and sets a certain property to a certain value if it exists.

<uptodate property="propelBuild.notRequired" targetfile="${deploy}\propelClasses.tgz" >
  <srcfiles dir= "${src}/propel" includes="**/*.php"/>
</uptodate>

sets the property propelBuild.notRequired to true if the ${deploy}/propelClasses.tgz file is more up-to-date than any of the PHP class files in the ${src}/propel directory.

Parameters

Name Type Description Default Required
property string Name of the property that is to be set. n/a Yes
value String The value the propert is to be set to. "true" No
srcfile String The file to check against target file(s). n/a Yes (or nested srcfiles)
targetfile String The file for which we want to determine the status. n/a Yes (or nested mapper)

Supported Nested Tags

 

XsltTask

With XsltTask, you can run a XSLT tranformation on an XML file. Actually, XsltTask extends CopyTask, so you can use all the elements allowed there.

Example

<!-- Transform docbook with an imaginary XSLT file -->
<xslt todir="/srv/docs/phing"tyle="dbk2html.xslt" >
  <fileset dir=".">
    <include name="**/*.xml" />
  </fileset>
</xslt>

Attributes

Name Type Description Default Required
style String The path where the Xslt file is located n/a Yes

Note: You can also use all the attributes available for CopyTask.

Suppported Nested Elements

Note: You can use all the elements also available for CopyTask.

Additionally, you can use <param> tags with a name and a value attribute. These parameters are then available from within the xsl style sheet.