PHP DevCenter
oreilly.comSafari Books Online.Conferences.


Improve Your Build Process with Ant
Pages: 1, 2, 3, 4

How about going in reverse? How would you copy the entire overlay directory into the install/ directory? A simple copy command might work, but assuming you were using CVS, you'd copy over a whole mess of those pesky CVS directories. Ant has a way to exclude those from the copy. Add another target to your build.xml file:

<target name="applyoverlay"
            description="Copy the contents of overlay/ onto the installed core.">
            <copy todir="${install.dir}/" overwrite="true">
                    <fileset dir="overlay/">
                            <include name="**"/>
                            <exclude name="**/CVS" />
                            <exclude name="**/CVS/**"/>

You Might Say the Secret Ingredient Is ...

It's not salt but the fileset tag (apologies to Marge Simpson). This tag is at the heart of how Ant deals with a group of files. Ant evaluates the tag to determine which files from a directory to include. Ant will look at several attributes, such as includes, excludes, and followsymlinks in the fileset tag's children, then will process all matching files by passing them to the tag above the fileset tag for specific processing. In this case, it copies the files to the directory specified in the todir attribute of the copy tag.

Notice the fileset tag has other tags below it. The and tag does just what it says--it performs an and operation on the contents of the indicated set of files and the nested tags below. The nested tags are selector tags. Use them to perform logical conditional checks on the files in the fileset group. Again, the case above uses a selector tag to indicate that you want to copy only files that differ from the files in the same relative location of the temp.dir area.

The Ant manual web site has much more information about the ins and outs of fileset and selector tags. This process is just a small indication of what combining fileset and selector tags can do for you.


What have you ended up with? You can now:

  • Install a given tar.gz file
  • Work on those files directly
  • Determine and extract only the changed files to a separate area
  • Manage only the changed files in a version-control system
  • Reapply the same changed files back on the original installation files as needed

I've seen many techniques for managing multiple clients from one code base, but most techniques took that too literally and tried to do things with symlinks. With that technique, if you need to change one file for one client (perhaps a different authentication system), you have an uphill battle with keeping those changes from affecting other clients using--literally--the same code.

With this approach, you can know that you build each client from the same core system, but you are free to make any required changes or additions to the code, and you know you have a standard mechanism for resolving the changes you've made--even if it's days later.

I've only touched on the idea of making custom changes against one version of a core package. With a little tweaking, the build file could resolve differences between two versions of a package (1.1.0 and 1.1.1, for example) and place those files in a separate area for review. This can be a great alternative to reviewing a changelog on a project you're joining.

Certainly Ant offers more than this--I've barely scratched the surface. I hope this has opened some eyes as to what non-PHP technologies can accomplish, and maybe made Ant a bit more accessible to some of you.

Alternatives to Ant?

As an aside, there are some alternatives to XML-based build tools such as Ant. NAnt and phing are two I've come across. NAnt is a .NET-based version of Ant, and phing is a PHP tool modeled on Ant. I don't use these tools, but from what I can tell in the documentation, neither one supports the concept of the selector tags inside the fileset tag, which is what's at the heart of the diffing technique of this article.

This article was originally inspired by Mark Kimsal from

Michael Kimsal is the host of

Return to the PHP DevCenter.

Valuable Online Certification Training

Online Certification for Your Career
Earn a Certificate for Professional Development from the University of Illinois Office of Continuing Education upon completion of each online certificate program.

PHP/SQL Programming Certificate — The PHP/SQL Programming Certificate series is comprised of four courses covering beginning to advanced PHP programming, beginning to advanced database programming using the SQL language, database theory, and integrated Web 2.0 programming using PHP and SQL on the Unix/Linux mySQL platform.

Enroll today!

Sponsored by: