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

Building from a Basic Package

Here's another interesting thing Ant can provide--tar and gzip features. tar, short for "tape archive," is a standard way of packaging groups of files for later untarring. gzip is a GNU utility that compresses a file. Many others distribute much software, including PHP itself, as .tar.gz--gzipped tar--files.



Nothing shows this off as well as a real-life example of using Ant to install a tar.gz file. For this example, I'll use the LogiCampus project. Using this build.xml file:

<?xml version="1.0"?>
<project name="Sample Project" default="init" basedir=".">

        <description>Example project</description>

        <target name="init">
                <mkdir dir="install"/>
                <!-- don't forget the compression attr -->
                <untar src="logicampus-1.1.0.tar.gz" dest="install"
                          compression="gzip"/>
        </target>
</project>

and running ant I get the output:

Buildfile: build.xml

init:
    [mkdir] Created dir: /home/user/install
    [untar] Expanding: /home/user/logicampus-1.1.0.tar.gz into
        /home/user/install

BUILD SUCCESSFUL
Total time: 1 second

The above file told Ant to make a directory called install and unpack the original LogiCampus project into that directory.

I'm hoping that you can already see the need for the variables introduced in the first example. Ant also provides a simple way of including files that contain your variables. Ant refers to these variables as properties and uses the property tag to include these files.

Consider now two files, config.properties and build.xml, respectively:

#########################################################
install.dir  = install
temp.dir     = temp
package.name = logicampus-1.1.0
#########################################################
<?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>
</project>

Notice the separation of the installation directory and package name into the properties file. As you do more configuration with Ant, keep your configurations in a separate file. So far, this is fairly basic, admittedly. This is just a small script that will untar a file into a directory.

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