PHP DevCenter

oreilly.comSafari Books Online.Conferences.

We've expanded our LAMP news coverage and improved our search! Search for all things LAMP across O'Reilly!

Search
Search Tips

advertisement

Listen Print Discuss Subscribe to PHP Subscribe to Newsletters

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
package.name    = logicampus-1.1.0
overlay.dir     = overlay
<?xml version="1.0"?>
<project name="Sample Project" default="init" basedir=".">

        <description>Example project</description>

        <property file="config.properties"/>

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

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

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

updateoverlay:
    [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

BUILD SUCCESSFUL
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




Tagged Articles

Be the first to post this article to del.icio.us

Sponsored Resources

  • Inside Lightroom
Advertisement

Sponsored by:

O'Reilly Media

©2009, O'Reilly Media, Inc.
(707) 827-7000 / (800) 998-9938
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
About O'Reilly
Academic Solutions
Authors
Contacts
Customer Service
Jobs
Newsletters
O'Reilly Labs
Press Room
Privacy Policy
RSS Feeds
Terms of Service
User Groups
Writing for O'Reilly
Content Archive
Business Technology
Computer Technology
Google
Microsoft
Mobile
Network
Operating System
Digital Photography
Programming
Software
Web
Web Design
More O'Reilly Sites
O'Reilly Radar
Ignite
Tools of Change for Publishing
Digital Media
Inside iPhone
O'Reilly FYI
makezine.com
craftzine.com
hackszine.com
perl.com
xml.com

Partner Sites
InsideRIA
java.net
O'Reilly Insights on Forbes.com