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

Description

clearcase

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

cvs

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

cvschangelog

Creates change reports from a CVS repository

cvspass

Adds entries to a .cvspass file

cvstagdiff

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

perforce

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

pvcs

Retrieves and handles source code from a PVCS repository

sourceoffsite

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

starteam

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 http://www.cvshome.org.

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 http://www.cvshome.org. Many CVS servers are available for Windows, such as CVSNT, available for free from http://www.cvsnt.org. 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 https://www.cvshome.org/docs/manual/cvs-1.11.7/cvs_16.html.


Table 6-2. CVS commands

CVS command

Does this

add

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

admin

Lets you work with administrative commands

annotate

Specifies the revision where each line was modified

authserver

Specifies authentication mode for the server

chacl

Specifies the access list for a directory

checkout

Checks out source code from the repository

chown

Changes the owner of a directory in the repository

commit

Checks source code files into the repository

diff

Displays the differences between source code revisions

edit

Specifies you want to edit a file

editors

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

export

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

history

Displays the CVS repository access history

import

Imports source code into a CVS repository

info

Displays information about the CVS repository and its supported protocols

init

Creates a CVS repository and initializes it

log

Displays information on file history

login

Asks for a password, if needed

logout

Logs out of a server

ls

Lists the files in the CVS repository

lsacl

Lists the CVS directories access control list

passwd

Sets a user's CVS password

rannotate

Displays the revision in which source lines were modified

rdiff

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

release

Specifies that a module will not be used anymore

remove

Removes an item from a CVS repository

rlog

Displays CVS history information for a module

rtag

Adds a tag to a CVS module

server

Lets you set server modes for access

status

Displays checked-out file information

tag

Adds a tag to checked-out files

unedit

Undoes an edit command that's been executed

update

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

version

Shows the CVS version

watch

Watches a file or files

watchers

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

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net