Section 6.3. Working with the Server


6.3. Working with the Server

The cvs task lets you interact with the CVS server after you've logged in. The attributes of this task appear in Table 6-4; to use this task, the cvs command must work on the command line (ie., the cvs binary must be in your path).

Table 6-4. The cvs attributes

Attribute

Description

Required

Default

append

Specifies whether you want to append output when redirecting text to a file.

No

false

command

Specifies the CVS command you want to execute.

No

"checkout"

compression

The same as compressionlevel="3".

No

false

compressionlevel

Specifies the compression level you want to use, via a number between 1 and 9. Any other value sets compression="false".

No

false

cvsRoot

Specifies the CVSROOT variable.

No

 

cvsRsh

Specifies the CVS_RSH variable.

No

 

date

Specifies that you want to use the most recent revision, as long as it is no later than the given date.

No

 

dest

Specifies the directory where you want checked-out files to be placed.

No

The project's basedir.

error

Specifies the file where you want error messages stored.

No

Sends errors to the Ant Log as MSG_WARN.

failonerror

Stops the build if the task encounters an error.

No

false

noexec

Specifies that CVS actions should report only, without changing any files.

No

false

output

Specifies the file to which standard output should be directed.

No

Sends output to the Ant Log as MSG_INFO.

package

Specifies the module you want to check out.

No

 

passfile

Specifies a password file you want to have the task read passwords from.

No

~/.cvspass.

port

Specifies the port used by the task to communicate with the CVS server.

No

Port 2401

quiet

Suppresses messages. This is the same as using -q on the command line.

No

false

reallyquiet

Suppresses all messages. This is the same as using -Q on the command line. Since Ant 1.6.

No

false

tag

Specifies the module to check out by tag name.

No

 


This task is designed to pass commands on to CVS verbatim. For example, here's how you'd pass a CVS diff command to the CVS server:

<cvs command="diff -u -N" output="diff.txt"/>

You can nest commandline elements and use the value attribute of argument elements to pass arguments to the CVS server; you can pass the diff command this way:

<cvs output="patch">     <commandline>         <argument value="diff"/>         <argument value="-u"/>         <argument value="-N"/>     </commandline> </cvs>

or this way, using the argument element's line attribute:

<cvs output="patch">     <commandline>         <argument line="-q diff -u -N"/>     </commandline> </cvs>

6.3.1. Checking Out Modules

To check out a module from the CVS server, you can use the cvs task without specifying a CVS command; the default for the command attribute is "checkout." In Example 6-1, a module named GreetingApp is checked out and stored in a directory named project.

In this and the following CVS-related build files, you can omit the cvspass task if you've stored your password in the .cvspass file (which is what cvspass does). If you omit cvspass, set the cvsroot attribute in the cvs task, or set the CVSROOT environment variable.


Example 6-1. Checking out a CVS module (ch06/checkout/build.xml)
<?xml version="1.0"?> <project default="checkout" basedir=".">     <property name="cvs.dir" value="project" />     <target name="checkout" >         <cvspass cvsroot=":pserver:steven@STEVE:/home/steven/repository"              password="opensesame" />         <cvs package="GreetingApp" dest="${cvs.dir}" />     </target> </project>

Here's what this build file looks like in action:

%ant Buildfile: build.xml checkout:       [cvs] Using cvs passfile: /home/.cvspasss       [cvs] cvs server: Updating GreetingApp       [cvs] U GreetingApp/.classpath       [cvs] U GreetingApp/.project       [cvs] cvs server: Updating GreetingApp/org       [cvs] cvs server: Updating GreetingApp/org/antbook       [cvs] cvs server: Updating GreetingApp/org/antbook/ch06       [cvs] U GreetingApp/org/antbook/ch06/GreetingClass.java BUILD SUCCESSFUL Total time: 2 seconds

Before using the build files for this chapter in the downloadable code, make sure you replace the cvsroot attribute value or the CVSROOT environment variable with an appropriate value for your CVS server.


After running this build file, the project directory will hold the checked-out module, including a CVS .project file and a CVS directory, which holds logging and tracking information. You're free to work with the code that's been downloaded, and when you want to commit the project back to the CVS server, specify the same directory you downloaded the project to.

6.3.2. Updating Shared Code

When you want to update your local copy of a module from the CVS repository, you can use the update command. You can see how that works in Example 6-2; as before, you can omit the cvspass task if your password is in the .cvspass file though it causes no harm to leave it in.

Example 6-2. Updating a CVS module ch06/update/build.xml
<?xml version="1.0"?> <project default="main" basedir=".">     <property name="cvs.dir" value="project" />     <target name="main" depends="login, update">         <echo>             Updating....         </echo>     </target>     <target name="login">         <cvspass cvsroot=":pserver:steven@STEVE:/home/steven/repository"              password="opensesame" />     </target>     <target name="update" depends="login">         <cvs dest="${cvs.dir}" command="update"/>     </target> </project>

Here's what you see when running this build file:

%ant Buildfile: build.xml login:       [cvs] Using cvs passfile: /home/.cvspass update:       [cvs] Using cvs passfile: /home/.cvspass       [cvs] cvs server: Updating GreetingApp       [cvs] cvs server: Updating GreetingApp/org       [cvs] cvs server: Updating GreetingApp/org/antbook       [cvs] cvs server: Updating GreetingApp/org/antbook/ch06 main:      [echo]      [echo]             Updating....      [echo] BUILD SUCCESSFUL Total time: 3 seconds

This updates your local copy of a module with what's currently in the CVS repository.

6.3.3. Committing Source Code

After you've made changes to the code in a checked-out module, you can send the revised module back to the CVS repository by setting the command attribute to "commit", as shown in Example 6-3. In this example, the build file commits a new version of a checked-out module, adding the comment "New Version."

Example 6-3. Committing a CVS module ch06/commit/build.xml
<?xml version="1.0"?> <project default="main" basedir=".">     <property name="cvs.dir" value="project" />     <target name="main" depends="login, commit">         <echo>             Committing....         </echo>     </target>     <target name="login">         <cvspass cvsroot=":pserver:steven@STEVE:/home/steven/repository"              password="opensesame" />     </target>     <target name="commit" depends="login">         <cvs dest="${cvs.dir}/GreetingApp" command="commit -m 'New Version'"/>     </target> </project>

Here's what this build file gives you when you run it and the CVS server commits the new code:

%ant Buildfile: build.xml login: commit:       [cvs] Using cvs passfile: /home/.cvspass       [cvs] cvs commit: Examining .       [cvs] cvs commit: Examining org       [cvs] cvs commit: Examining org/antbook       [cvs] cvs commit: Examining org/antbook/ch06       [cvs] Checking in org/antbook/ch06/GreetingClass.java;       [cvs] /home/steven/repository/GreetingApp/org       /antbook/ch06/GreetingClass.java,v         <--  GreetingClass.java       [cvs] new revision: 1.5; previous revision: 1.4       [cvs] done main:      [echo]      [echo]             Committing....      [echo] BUILD SUCCESSFUL Total time: 1 second

6.3.4. Comparing Files

You can compare local files to those in the CVS repository with the CVS diff command. For example, say that the module you've been working with, GreetingApp, contains GreetingClass.java, which holds these contents (presumably committed earlier by you or another developer):

package org.antbook.ch06; public class GreetingClass {     public static void main(String[] args)     {         System.out.println("No problems here.");     } }

Then suppose you change the displayed message from "No problems here." to "No problems at all." in the local version of the file:

package org.antbook.ch06; public class GreetingClass {     public static void main(String[] args)     {         System.out.println("No problems at all.");     } }

The CVS diff command finds the difference between your local copy and the server's version. You can see a build file using this command in Example 6-4; in this case, the differences are written to a file named patch.txt.

Example 6-4. Finding differences in a CVS module ch06/diff/build.xml
<?xml version="1.0"?> <project default="main" basedir=".">     <property name="cvs.dir" value="project" />     <target name="main" >         <cvspass cvsroot=":pserver:steven@STEVE:/home/steven/repository"              password="opensesame" />         <cvs command="diff" dest="${cvs.dir}/GreetingApp" output="patch.txt"/>     </target> </project>

Here's what the build process looks like at work:

%ant Buildfile: build.xml main:       [cvs] Using cvs passfile: /home/.cvspass       [cvs] cvs server: Diffing .       [cvs] cvs server: Diffing org       [cvs] cvs server: Diffing org/antbook       [cvs] cvs server: Diffing org/antbook/ch06 BUILD SUCCESSFUL Total time: 1 second

In patch.txt, the diff command caught the difference between the local copy of the file and the version in the CVS repository:

Index: org/antbook/ch06/GreetingClass.java =================================================================== RCS file: /home/steven/repository/GreetingApp/org/antbook/ch06/GreetingClass.java,v retrieving revision 1.6 diff -r1.6 GreetingClass.java 20c20 <         System.out.println("No problems at all."); --- >         System.out.println("No problems here.");

If you want to create a patch file that you can, with the patch utility, update code files with, use the CVS rdiff command, not diff.


That's how the cvs task works; you pass the CVS command, along with any command-line options, in the command attribute or a commandline element. You can extrapolate from the CVS examples given here to other CVS commands easily.



    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