Saturday, 29 March 2008

Getting an overview of all targets accumulated in a Phing build file

Looking for an equivalent to Ant's -p(rojecthelp) command-line option in Phing, I dug up that you can use Phing's -l(ist) option to get a quick overview of all targets hosted in a given build file. This comes in handy when you are maintaining build files or have to get a raw picture of the provided targets of a project specific build file. The following console output shows the targets hosted in a example build file. As you will see, by using the -l command-line option you get an overview of the default target, the main targets and further subtargets.

triton:work stolt$ phing -l
Buildfile: /Volumes/USB DISK/work/build.xml
Build file for recordshelf project
Default target:
help Displays the help for this build file

Main targets:
build Builds the project
clean Removes data left over by former build
cs-coding-standard Runs the coding standard code inspection
help Display the help for this build file
init Initializes the build process
layout Creates the project layout for the build
lint-project Lints all code artifacts
test-components Runs the automated component tests
test-integration Runs the automated integration tests
test-units Runs the automated unit tests

A target becomes a main target when it has an non-empty description attribute, otherwise it will be a subtarget. This can be used to define the visibility and thereby 'callability' of targets, similar as you would do when defining access specifiers for class members of a PHP class. Main targets would become the public targets of your build file and all subtargets could be considered as private targets, which shouldn't be called directly as they might/should be used to provide specific helper functionality to public main targets or target wrappers. To definitively veto the call to a target, which never should be run directly via the Phing CLI(e.g. phing tragetname), just define an invalid target name(i.e. -build-initial-model instead of build-initial-model) so the Phing CLI will respond with an error and thereby not run the build file. The next console output shows the Phing CLI response when calling a private target.
triton:work stolt$ phing -build-initial-model
Unknown argument: -build-initial-model
phing [options] [target [target2 [target3] ...]]
-h -help print this message
-l -list list available targets in this project
-v -version print the version information and exit
-q -quiet be extra quiet
-verbose be extra verbose
-debug print debugging information
-logfile <file> use given file for log
-logger <classname> the class which is to perform logging
-f -buildfile <file> use given buildfile
-D<property>=<value> use value for given property
-find <file> search for buildfile towards the root of the
filesystem and use it
-inputhandler <file> the class to use to handle user input

Report bugs to <>
This post is somehow a partial and PHP flavoured remix of a post by Julian Simpson, who runs the build doctor blog and is also the author of the 'Refactoring Ant Build Files' contribution to the upcoming ThoughtWorks Anthology book.


Julian said...


Thanks for the link back to Build Doctor. It's the second link back from a PHP site - it must be time to have a look at Phing :)



Raphael Stolt said...

Hi Julian,

Thanks for stopping by. Recently read your essay about 'Refactoring Ant Build Files' and it turned out to be a really usefull and good one.

When looking at Phing you should feel at home right away because it's really close/similar to ANT.

Best regards,