Core task translation of phing User Manual

Source: Internet
Author: User
Tags echo message touch command

AvailableTask
Test whether a resource or file exists and set a property to a value.
Example
[Html]
<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"/>

<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 whether a file or directory named test.txt exists in the/tmpdirectory.
Then, check whether the/home directory has the directory foo. Then, check whether there is a file or directory named bar in the/home/foo directory.
If/tmp/test.txt exists, the test_txt_exists attribute is set to Yes. If/home/foo exists and is a directory, properties. yetanother is set to true (default ).
If/home/foo/bar exists, foo. bar is set to "Well, yes ".


ChmodTask
Set file or directory permissions.
Example
[Html]
<Chmod file = "test.txt" mode = "0755"/>
<Chmod file = "/home/test" mode = "0775"/>
<Chmod file = "/home/test/mine.txt" mode = "0500" verbose = "true"/>

<Chmod file = "test.txt" mode = "0755"/>
<Chmod file = "/home/test" mode = "0775"/>
<Chmod file = "/home/test/mine.txt" mode = "0500" verbose = "true"/> For more information, see chmod in the php Manual ([http://php.net/chmod]).
Supported nested labels
<Fileset>


ChownTask
Change the owner of a file or directory
Example
[Html]
<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"/>

<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"/> nested labels supported
<Fileset>


ConditionTask
Set a property value when the condition is true-equivalent to integration of Available and UpToDate.
Note:
If the condition is true, the property value is set to true by default. If the condition is false, the property value is not set. You can set the value attribute to replace the default value.
Condition is a nested element. You must specify one condition (and only one condition ).
Example
[Html]
<Condition property = "isMacOrWindows">
<Or>
<OS family = "mac"/>
<OS family = "windows"/>
</Or>
</Condition>

<Condition property = "isMacOrWindows">
<Or>
<OS family = "mac"/>
<OS family = "windows"/>
</Or>
</Condition>


CopyTask
Copy a file or directory


Note:
Only when the source file is newer than the target file or the target file does not exist will the file be copied.
You can specify file overwrite.
Example
On the one hand, CopyTask directly Copies files one by one:
[Html]
<Copy file = "somefile.txt" tofile = "/tmp/anotherfile. bak" overwrite = "true"/>

<Copy file = "somefile.txt" tofile = "/tmp/anotherfile. bak "overwrite =" true "/> In addition, CopyTask also supports Fileset. You can easily add or exclude files. For more information, see FileSet. Pay special attention to its defaultexcludes attribute. CopyTask also supports Mappers and Filters, so you can process almost any file content and file name.
[Html]
<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>

<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> supported nested labels
<Fileset>
<Filelist>
<Filterchain>
<Mapper>


DeleteTask
Delete a file or directory
Example
[Html]
<-- 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>

<-- 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> supported nested labels
<Fileset>


EchoTask
Output messages to standard output and logs
Note:
You can specify the log level.
You can directly output messages to the file. In this case, overwrite is replaced by the append option by default, and the log level option is invalid.
In addition, echotask can also output the content of the specified file in the fileset element.
[Html]
<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>

<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> supports nested labels.
<Fileset>


ExecTask
Execute shell commands
Note:
With this task, you can quickly add a new command for Phing.
If you often use a command, we recommend that you write a task for it.
Example
[Html]
<-- 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"/>

<-- 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"/> supported nested labels
<Arg>


IfTask
Execute the corresponding task based on the true and false conditions.
Attribute
Like <condition>, only one condition can be used. You can use <and> or <or> to connect them.
You can use three different sub-elements: <elseif>, <then>, and <else>. They are optional, not mandatory. <Then> and <else> can only appear once in an iftask. They can contain Phing tasks.
Example
[Html]
<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>

<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>
MkdirTask
Create a directory that contains any necessary directories (similar to shell mkdir-p)
Note:
If the directory exists, nothing will be done
Example
[Html]
<-- Create a temp directory -->
<Mkdir dir = "/tmp/foo"/>
 
<-- Using mkdir with a property -->
<Mkdir dir = "$ {dirs. install}/tmp"/>

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

<-- Using mkdir with a property -->
<Mkdir dir = "$ {dirs. install}/tmp"/>
MoveTask
Move the file or directory to a new location
Note:
By default, if the target file exists, it will be overwritten. If overwrite is set to false, the source file is moved only when the source file is newer than the target file, or the target file does not exist.
If the file is successfully moved, the source file or directory will be deleted.
Example
[Html]
<-- 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". Empty directories are also copied -->
<Move file = "/tmp" todir = "/home/default/tmp" includeemptydirs = "true"/>

<-- 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". Empty directories are also copied -->
<Move file = "/tmp" todir = "/home/default/tmp" includeemptydirs = "true"/>
PhingCallTask
Call the target in the same phing Project
Note:
<Phingcall> can contain <property> tags to define new properties.
These new property values take effect only when they are not defined outside of <phingcall>.
Example
In the following example, we define property1 And foo, which can only be accessed in the called target.
[Html]
<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>

<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>

PropertyTask
Used for custom attribute values
Example
[Html]
<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"/>

<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"/>

TouchTask
TouchTask is similar to the touch command of Unix: Set the modtime of the file.
Note:
The default value is the current time.
Example
[Html]
<Touch file = "README.txt" millis = "102134111"/>
<Touch file = "COPYING. lib" datetime = "10/10/1999 09:31 AM"/>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.