Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to group targets in Phing?

Tags:

php

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.

like image 641
Tom Jowitt Avatar asked Jul 16 '11 12:07

Tom Jowitt


1 Answers

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

like image 172
Tom Jowitt Avatar answered Sep 19 '22 17:09

Tom Jowitt