|
6.3. Working with the ServerThe 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).
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 ModulesTo 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.
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
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 CodeWhen 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 CodeAfter 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 FilesYou 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.");
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. |
|