Chapter 4. Ant DataTypes

In the previous chapter’s buildfile example, you saw the fileset DataType being used to identify groups of files to copy in order to deploy the irssibot application. DataTypes are important when using Ant, and fileset is just one of the many available to you:

argument

Passes command-line arguments to programs that you invoke from an Ant buildfile.

environment

Specifies environment variables to pass to an external command or program that you execute from an Ant buildfile.

filelist

Defines a named list of files that do not necessarily need to actually exist.

fileset

Defines a named list of files that must actually exist.

patternset

Groups a set of patterns together.

filterset

Groups a set of filters together.

path

Specifies paths (such as a classpath) in a way that is portable between operating systems.

mapper

Defines a complex relationship between a set of input files and a set of output files.

Let’s dig in and learn more about these fundamental Ant DataTypes. They are building blocks used by tasks and are essential to using Ant effectively. In this chapter, we’ll talk about each DataType in detail. Before doing that, however, we discuss briefly how DataTypes fit into Ant’s overall design, and explain the notation used in this chapter to describe the attributes for the different DataTypes.

DataTypes Defined

Ant DataTypes are found in the org.apache.tools.ant.types package, usually extending from the org.apache.tools.ant.types.DataType base class. EnumeratedAttribute, Commandline, Environment, and Reference are also treated as DataTypes, although they do not extend from DataType. Figure 4-1 contains a basic UML class diagram illustrating this aspect of Ant’s design.

Ant DataTypes

Figure 4-1. Ant DataTypes

The base class, org.apache.tools.ant.ProjectComponent, provides logging functionality as well as access to the Project object. Not shown here, ProjectComponent is also the base class for every Ant task. These tasks are detailed in Chapter 7 and Chapter 8.

While the class diagram helps to explain what DataTypes are, understanding the internal structure of Ant is rarely necessary. In most cases you simply want to write buildfiles and use Ant. For this reason, the remainder of this chapter focuses on how these types are used, rather than how their internal implementation works.

Get Ant: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.