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.