开发者

How to group targets in Phing?

Is there a way to group targets in Phing? I have a number of targets that can be reused by running them in different orders and combinations. For example to create a new dev build:

$ phing clean
$ phing prepare
$ phing build
$ phing runtests

Or to update a dev build from a repo:

$ phing update
$ phing runtests

Is there a way to group these targets to run them as single command? I'm aware that you can chain targets eg:

$ phing clean prepare build runtests
$ phing update runtests

But ideally I'd like to run a command such as:

$ phing cleanbuild

This would run all four targets. This way the build file can separated out into reusable targets. Creating a new target that does this will result in duplication of code from the existing targets. I know that you can use the depends parameter to execute other targets but I want each target to be independent of each other.

The Phing documentation doesn't seem to be very clear on how to do this but I'm sure it's possible to call targets within other开发者_如何学编程 targets as it must be a pretty common way of doing things. Many thanks.


OK, after a hunting around a bit I found the answer. You can call targets from inside other targets by using the PhingCallTask task. An example of a composite task:

<target name="cleanbuild" description="Runs a clean dev build">
    <phingcall target="clean" />
    <phingcall target="prepare" />
    <phingcall target="build" />
    <phingcall target="runtests" />
</target>

Documentation is here:

http://www.phing.info/docs/guide/stable/apbs25.html


Your own answer is fine. Or you can use the depends attribute and make it even shorter:

<target name="cleanbuild" description="Runs a clean dev build" depends="clean, prepare, build, runtests"></target>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜