Section 6.1. Source Control and Ant

6.1. Source Control and Ant

When you work in teams, you have to coordinate your efforts. That means discussing and planning, but even with the best of intentions, you can still end up with unintentional conflicts. You may have made some brilliant changes to the code, only to find them wiped out by mistake when another programmer uploads his own version of the same file.

Source control helps prevent these problems by controlling access to code and by maintaining a history of the changes made so things aren't destroyed unintentionally. Storing a history of your code is powerful; you can compare a new (buggy) file against an older one, and you can revert to a previous version in case things have gone bad.

Ant has several source control tasks, shown in Table 6-1.

Table 6-1. Source control tasks

Task name



Tasks for ClearCase cleartool checkin, checkout, uncheckout, update, lock, unlock, mklbtype, rmtype, mklabel, mkattr, mkdir, mkelem, and mkbl commands

Continuus/Synergy tasks

Tasks for Continuus ccmcheckin, ccmcheckout, ccmcheckintask, ccmreconfigure, and ccmcreateTask commands


Specifies how to work with packages and modules retrieved from a CVS repository


Creates change reports from a CVS repository


Adds entries to a .cvspass file


Creates an XML-formatted report of the changes between two tags or dates recorded in a CVS repository

Microsoft Visual Sourcesafe tasks

Tasks for Visual SourceSafe vssget, vsslabel, vsshistory, vsscheckin, vsscheckout, vssadd, vsscp, and vsscreate commands


Tasks for Perforce p4sync, p4change, p4edit, p4submit, p4have, p4label, p4counter, p4reopen, p4revert, and p4add commands


Retrieves and handles source code from a PVCS repository


Tasks for SourceOffSite sosget, soslabel, soscheckin, and soscheckout commands


Tasks for StarTeam stcheckout, stcheckin, stlabel, and stlist commands

Though Ant lets you work with various source control systems, most of its support revolves around CVS, which is used throughout this chapter. CVS is an open source project that started as a set of Unix shell scripts in 1986 and came into its own with dedicated software in 1989. Support for CVS is available on many operating systems: Unix, Linux, Windows, Mac, and others. For the full CVS story, look at

To work with CVS using Ant, you need access to a CVS server. Most Linux and Unix installations come with a built-in CVS server. To test if you have a working CVS installation, type cvs --help at the prompt; you should see a list of help items. If you can't find a CVS server, you can download what you need from Many CVS servers are available for Windows, such as CVSNT, available for free from To install CVSNT, download the executable file and run it.

The idea behind CVS, as with any repository software, is to manage and record changes to source code. What corresponds to a project for Ant is a module in CVS. Modules are represented by directories in CVS; the files you share are stored in the CVS repository. When you retrieve a file from the repository, you check the file out. After you've modified the file, you commit the file, checking it back in and sending those changes to the repository. If you want to refresh your own copy of a file, you update it from the repository.

Because each file must be independently tracked, CVS gives the individual files a version number automatically. Each time a file is committed, its version number is incremented. When you commit files to the repository, they'll get a new version number as well.

Using the cvs task, you communicate with the CVS server using CVS commands, which appear in Table 6-2.

Read more about these commands in the CVS guide at

Table 6-2. CVS commands

CVS command

Does this


Specifies you want to add a new file or directory to the CVS repository


Lets you work with administrative commands


Specifies the revision where each line was modified


Specifies authentication mode for the server


Specifies the access list for a directory


Checks out source code from the repository


Changes the owner of a directory in the repository


Checks source code files into the repository


Displays the differences between source code revisions


Specifies you want to edit a file


Specifies you want to watch who has been editing a particular file


Exports source code from a CVS repository (similar to checkout)


Displays the CVS repository access history


Imports source code into a CVS repository


Displays information about the CVS repository and its supported protocols


Creates a CVS repository and initializes it


Displays information on file history


Asks for a password, if needed


Logs out of a server


Lists the files in the CVS repository


Lists the CVS directories access control list


Sets a user's CVS password


Displays the revision in which source lines were modified


Creates patch files by comparing two files and outputting a file that be used to update one into the other


Specifies that a module will not be used anymore


Removes an item from a CVS repository


Displays CVS history information for a module


Adds a tag to a CVS module


Lets you set server modes for access


Displays checked-out file information


Adds a tag to checked-out files


Undoes an edit command that's been executed


Updates local copies of a file with those in the CVS repository


Shows the CVS version


Watches a file or files


Displays which users are watching a file or files

The first step in working with CVS is to log into the CVS server, typically done with the cvspass task.

    Ant. The Definitive Guide
    Ant: The Definitive Guide, 2nd Edition
    ISBN: 0596006098
    EAN: 2147483647
    Year: 2003
    Pages: 115
    Authors: Steve Holzner © 2008-2017.
    If you may any questions please contact us: