PHP DevCenter
oreilly.comSafari Books Online.Conferences.

advertisement


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




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: