A few Phing tips
Following on from my last post, here’s a few other Phing things that I’ve found helps me.
Hiding targets from Phing -l
I have a number of dependent targets in my build.xml that I don’t want listed when I run phing -l. The easiest way to do this is to add the hidden="true" property to the targets I want to hide:
<?xml version="1.0"?> <project name="buildfile" default="foo"> <target name="foo" depends="bar,baz" /> <target name="bar" hidden="true"> <!-- tasks --> </target> <target name="baz" hidden="true"> <!-- tasks --> </target> </project>
The output of phing -l now shows just the foo target as I want:
$ phing -l Buildfile: /Users/rob/tmp/build.xml Default target: ------------------------------------------------------------------------------- foo Subtargets: ------------------------------------------------------------------------------- foo
Main target vs subtarget
If you set a description on a target, then it becomes a Main target:
<?xml version="1.0"?> <project name="buildfile" default="foo"> <target name="foo" depends="bar,baz" description="Run foo to do stuff" /> <!-- other hidden targets --> </project>
The output is now:
$ phing -l Buildfile: /Users/rob/tmp/build.xml Default target: ------------------------------------------------------------------------------- foo Main targets: ------------------------------------------------------------------------------- foo Run foo to do stuff
It just looks better and provides additional information as well.
List available targets by default
If you run phing without a target, then the default target runs. If you’ve forgotten what that is, then this may not be the safest thing to happen. Ideally, the default target should do no harm and I’ve found it helpful to make the default target display a list of the available targets within the build file.
This is done by adding a hidden “list_targets” target and making it the default:
<?xml version="1.0"?> <project name="buildfile" default="list_targets"> <target name="list_targets" hidden="true"> <exec command="phing -q -f ${phing.file} -l" passthru="true"/> </target> <target name="foo" depends="bar,baz" description="Run foo to do stuff" /> <!-- other hidden targets --> </project>
Essentially, we run phing -l against our current build file and set the passthru property so that the output is displayed. This gives us:
$ phing Buildfile: /Users/rob/tmp/build.xml buildfile > list: Default target: ------------------------------------------------------------------------------- list Main targets: ------------------------------------------------------------------------------- foo Run foo to do stuff BUILD FINISHED Total time: 0.2176 seconds
List available targets by default is slick