PHP DevCenter
oreilly.comSafari Books Online.Conferences.


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

Reconcilable Differences

A big problem many developers face is keeping track of custom changes for specific clients. Many of you have installed various CMS packages for people and needed to make small tweaks, whether code or templates or whatever. How do you keep track of those changes in a sane way? This next Ant technique shows how to handle these very situations.

Assume that you've installed the LogiCampus system in the install directory and are doing some work for a particular client. For argument's sake, suppose that this client wants the time and date displayed at the bottom of every page. You can simply update the public_html/index.php page to add this information at the end of the page request.

Think about this a bit more: what are you trying to accomplish? You're trying to determine the differences between this client-specific version and the core package file you started with. If you can determine just those files that have changed, you can import them into CVS on their own without having to import the entire code base. You can then rebuild by simply untarring the original package file and overlaying the changed files from CVS on top of the original files. The following properties and build files illustrate setting up an Ant task to do just this.

install.dir     = install
temp.dir        = temp    = logicampus-1.1.0
overlay.dir     = overlay
<?xml version="1.0"?>
<project name="Sample Project" default="init" basedir=".">

        <description>Example project</description>

        <property file=""/>

        <target name="init">
                <mkdir dir="${install.dir}"/>
                <!-- don't forget the compression attr -->
                <untar src="${}tar.gz" dest="${install.dir}"

        <target name="updateoverlay">
                <mkdir dir="${temp.dir}"/>
                <mkdir dir="${overlay.dir}"/>
                <untar src="${}.tar.gz" dest="${temp.dir}"
                <copy todir="${overlay.dir}/">
                        <!-- find files in install that have a modified
                                timestamp later than those in overaly -->
                        <fileset dir="${install.dir}">
                                        <different targetdir="${temp.dir}"/>
                                        <type type="file"/>
                <delete dir="${temp.dir}"/>

If you remember, I mentioned that you changed the public_html/index.php file in the install directory. Running ant updateoverlay to call the new Ant task, you should get the output:

Buildfile: build.xml

    [mkdir] Created dir: /home/user/temp
    [mkdir] Created dir: /home/user/overlay
    [untar] Expanding: /home/user/logicampus-1.1.0.tar.gz into /home/user/temp
     [copy] Copying 1 file to /home/user/overlay
   [delete] Deleting directory /home/user/temp

Total time: 5 seconds

If you dig into the overlay directory, you'll find just the one file that you changed (index.php) sitting in the public_html directory. There are no other files or directories copied over into this overlay area--only the differences between the original tar.gz file and the installed version's changes. It's simply a matter of adding or updating these changed files in your overlay directory to CVS or whatever version-control program you use.

Pages: 1, 2, 3, 4

Next Pagearrow

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: