Home
CVS keyword substitution
In addition to storing the history of changes to a given source code file in the CVS repository, it is also possible to store meta-information (such as author, date/time, revision and change comments) in the contents of the file. Typically a standard header template is configured in RAD v7.5, which is then applied to each file when CVS operations (usually check-in and checkout) are performed. The template can include a set of CVS keywords inside a heading, which are expanded out when a file is checked in or out. This is known as keyword expansion.
Keyword expansion is an effective mechanism for developers to quickly identify what version a resource is in the repository versus what a user has checked out locally on their workspace.
RAD v7.5, by default, has the keyword substitution set to ASCII with keyword expansion (-kkv) under the selection Windows Æ Preferences Æ Team Æ CVS and the File and Folders tab (Figure | 8-11). This setting expands out keyword substitution based on the interpretation by CVS, and is performed wherever the keywords are located in the file.
Figure 28-11 CVS Keyword expansion setting
Some of the available keywords (case sensitive) are listed in Table | 8-2.
Table 28-2
Keyword Description $Author$ Expands to the name of the author of the change in the file, for example: $Author: itsodev $ $Date$ Expands to the date and time of the change in UTC, for example:
$Date: 2008/10/14 18:21:32 $$Header$ Contains the CVS file in repository, revision, date (in UTC), author, state and locker, for example: $Header: /rep7672/XMLExample/.project,v 1.1 2008/10/14 18:21:32 itsodev Exp itso $ $Id$ Like $Header$ except without the full path of the CVS file, for example: $Id: .project,v 1.1 2008/10/14 18:21:32 itsodev Exp itso $ $Log$ The log message of this revision. This does not get replaced but gets appended to existing log messages. $Name$ Expands to the name of the sticky tag, which is a file retrieved by date or revision tags, for example: $Name: version_1_3 $ $Revision$ Expands to the revision number of the file, for example: $Revision: 1.1 $ $Source$ Expands to the full path of the RCS file in the repository, for example: $Source: /rep7672/XMLExample/.project,v $ CVS keywords
To ensure consistency between multiple users working on a team, IBM recommends that a standard header is defined for all Java source files. A simple example is shown in Example | 8-1.
Example 28-1 Example of CVS keywords used in Java
/**| Class comment goes here.|| <pre>| Date $Date| Id $Id| </pre>| @author $Author| @version $Revision| /
To ensure consistency across all files created, each user would have to cut and paste this into their document. Fortunately RAD offers a means to ensure this consistency.
To set up a standard template, do these steps:
Select Windows Æ Preferences Æ Java Æ Code Style Æ Code Templates.
Expand Comments Æ Files and click Edit.
Cut and paste or type what comment header you require (Figure | 8-12).
Figure 28-12 Setup of a common code template for Java files
Click OK to complete the editing, then click Apply followed by OK.
Note: The double dollar sign ($$) is required because Application Developer treats a single dollar ($) as one of its own variables. $$ is used as a means of escaping the single dollar so that it can be post processed by CVS.
This sets up a standard CVS template. The next time a new class is created, checked in, and then checked out, the header is displayed (Example | 8-2).
Example 28-2 Contents of Java file after check in and check out from CVS
/**| class comment goes here.|| <pre>| Date $Date: 2004/10/29 18:21:32 $| Id $Id: $Id: Example.java,v 1.1 2004/10/29 18:21:32 itsodev Exp itso $| </pre>| @author $Author: itsodev $| @version $Revision: 1.1 $| /
ibm.com/redbooks