本文并没有翻译core task中的所有内容,而是选择了常用task进行翻译。查看原文请猛击这里。
<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" />这里,AvailableTask首先检查/tmp目录下是否存在名为test.txt的文件或目录。
<chmod file="test.txt" mode="0755" /> <chmod file="/home/test" mode="0775" /> <chmod file="/home/test/mine.txt" mode="0500" verbose="true" />更多信息可参见php手册中的chmod([http://php.net/chmod])
<chown file="my-file.txt" user="foo" /> <chown file="my-file.txt" user="username.groupname" /> <chown file="/home/test/my-directory" user="bar" /> <chown file="/home/test/my-file.txt" user="foo" verbose="true" failonerror="false" />支持的嵌套标签
<condition property="isMacOrWindows"> <or> <os family="mac"/> <os family="windows"/> </or> </condition>
<copy file="somefile.txt" tofile="/tmp/anotherfile.bak" overwrite="true"/>除此之外,CopyTask还支持Fileset,你可以很方便的加入或排除文件。或多信息可参考FileSet--特别要注意它的defaultexcludes属性。CopyTask还支持Mappers和Filters,所以你几乎可以完成任何对文件内容和文件名的处理。
<copy todir="/tmp/backup" > <fileset dir="."> <include name="**/*.txt" /> <include name="**/*.doc" /> <include name="**/*.swx" /> </fileset> <filelist dir="." files="test.html"/> </copy> <copy todir="build" > <fileset defaultexcludes="false" expandsymboliclinks="true" dir="."> <include name="**/*.php" /> </fileset> </copy>支持的嵌套标签
<-- Delete a specific file --> <delete file="/tmp/foo.bar" /> <-- Delete a directory --> <delete dir="/tmp/darl" includeemptydirs="true" verbose="true" failonerror="true" /> <-- Delete using a fileset --> <delete> <fileset dir="/tmp"> <include name="*.bar" /> </fileset> </delete>支持的嵌套标签
<echo msg="Phing rocks!" /> <echo message="Binarycloud, too." /> <echo>And don't forget Propel.</echo> <echo file="test.txt" append="false">This is a test message</echo>支持的嵌套标签
<-- 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" />支持的嵌套标签
<if> <equals arg1="${foo}" arg2="bar" /> <then> <echo message="The value of property foo is bar" /> </then> <else> <echo message="The value of property foo is not bar" /> </else> </if> <if> <equals arg1="${foo}" arg2="bar" /> <then> <echo message="The value of property foo is 'bar'" /> </then> <elseif> <equals arg1="${foo}" arg2="foo" /> <then> <echo message="The value of property foo is 'foo'" /> </then> </elseif> <else> <echo message="The value of property foo is not 'foo' or 'bar'" /> </else> </if>
<-- Create a temp directory --> <mkdir dir="/tmp/foo" /> <-- Using mkdir with a property --> <mkdir dir="${dirs.install}/tmp" />
<-- 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" />
<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>
<property name="strings.test" value="Harr harr, more power!" /> <echo message="${strings.test}" /> <property name="foo.bar" value="Yet another property..." /> <echo message="${foo.bar}" /> <property file="build.properties" />
<touch file="README.txt" millis="102134111" /> <touch file="COPYING.lib" datetime="10/10/1999 09:31 AM" />