| java.lang.Object org.apache.commons.jrcs.util.ToString org.apache.commons.jrcs.rcs.Archive
Archive | public class Archive extends ToString (Code) | | Handling of RCS/CVS style version control archives.
JRCS is a library that knows how to manipulate the archive files produced
by the RCS and CVS version control systems. JRCS is not intended to replace
neither tool. JRCS was written to be able create archive analysis tools
that can do things like identify hot spots in the source code,
measure the contributions by each developer,
or assess how bugs make it in.
The reasons why JRCS has the ability do do check-ins and save archives
is API symmetry, and to simplify the writing of unit tests.
CAVEAT UTILITOR: Do not make modifications to your archives with JRCS.
There needs to be an important amount of additional testing
before it's safe to do that.
The
org.apache.commons.jrcs.rcs rcs package implements the
archive handling functionality. The entry point to the library is class
org.apache.commons.jrcs.rcs.Archive Archive .
The
org.apache.commons.jrcs.diff diff package implements
the differencing engine that JRCS uses. The engine has the power of Unix diff,
is simple to understand, and can be used independently of the archive handling
functionality. The entry point to the differencing engine is class
org.apache.commons.jrcs.diff.Diff Diff .
Within this library, the word text means a unit of information
subject to version control. The word revision means a particular
version of a text. Each revision has a version number
associated to it. Version numbers are dot-separated lists of numbers.
Version numbers with an odd number of dots indicate revisions, while those
with an even number of dots (including zero dots) designate branches.
Revisions of a text are represented as Object[] because
the diff engine is capable of handling more than plain text. In fact,
arrays of any type that implements
java.lang.Object.hashCode hashCode() and
java.lang.Object.equals equals() correctly can be subject to differencing and version control using this
library.
To create an empty archive use:
Archive archive = new Archive();
To read an archive from the file system, use:
Archive archive = new Archive("/path/to/archive,v");
You can also initialize archives from streams.
To retreive a revision from an archive use:
String versionNumber = "1.2";
Object[] text = archive.getRevision(versionNumber);
You can also retreive revisions in such a way that each item
is annotated with the version number of the revision in which it was
last changed or added. To retrieve annotated text use:
String versionNumber = "1.2";
Line Line[] text = archive.getRevision(versionNumber);
for(int i = 0; i < text.length(); i++)
System.out.println(text[i].revision.version);
This class is NOT thread safe.
See Also: org.apache.commons.jrcs.diff version: $Id: Archive.java 2967 2005-10-26 10:52:33Z ian@caret.cam.ac.uk $ author: Juanco Anez |
Constructor Summary | |
public | Archive(Object[] text, String desc) Creates a new archive and sets the text of the initial revision. | public | Archive(Object[] text, String desc, String vernum) Creates a new archive with the specified initial version number
and sets the text of the initial revision.
The initial revision must be of the form "n.m" (i.e. | public | Archive(Object[] text, String desc, Version vernum) Creates a new archive with the specified initial version number
and sets the text of the initial revision.
The initial revision must be of the form "n.m" (i.e. | public | Archive(String fname, InputStream input) Load an archive from an input stream. | public | Archive(String path) Load an archive from an a file given by name. | | Archive() Create an unitialized Archive. |
Method Summary | |
public void | addLock(String user, Version vernum) Add a lock over a revison. | public void | addPhrase(String key, Collection values) Add a new phrase to the archive. | public Version | addRevision(Object[] text, String log) Add the given revision to the active branch on the archive.
Parameters: text - the text of the revision. Parameters: log - the log: a short note explaining what the revision is. | public Version | addRevision(Object[] text, String vernum, String log) Add the given revision to the the archive using the given version
number.
The version number may be partial. | public Version | addRevision(Object[] text, Version vernum, String log) Add the given revision to the the archive using the given version
number.
The version number may be partial. | public void | addSymbol(String sym, Version vernum) Tag a given version with a symbol. | public void | addUser(String name) Add a user name to the list of archive users. | public Node[] | changeLog() Return the list of nodes between the head revision and
the root revision. | public Node[] | changeLog(Version latest) Return the list of nodes between the the given revision
and the root revision. | public Node[] | changeLog(Version latest, Version earliest) Return the list of nodes between the the given two revisions. | public Object[] | doKeywords(Object[] text, Node rev) Returns the given text with values added to CVS-style keywords.
Parameters: text - the text on which substitutions will be applied. Parameters: rev - a node that identifies the revision to which thegiven text belongs. | public Node | findNode(Version vernum) Return the node with the version number that matches the one provided.
The given version number may be partial.
Parameters: vernum - the version number to match. | public String | getDesc() Returns the description associated with the archive. | public String | getLog(Version version) Returns the log message associated with the given revision.
Parameters: version - - the version to get the log message for the log message for the version. | public String | getLog(String vernum) Returns the log message associated with the given revision.
Parameters: version - - the version to get the log message for the log message for the version. | protected Node | getNode(Version vernum) | public Object[] | getRevision() Get the text belonging to the head revision. | public Object[] | getRevision(boolean annotate) Get the text belonging to the head revision. | public Object[] | getRevision(String vernum) Get the text belonging to the revision identified by the
given version number.
Partial version numbers are OK.
Parameters: vernum - the version number. | public Object[] | getRevision(String vernum, boolean annotate) Get the text belonging to the revision identified by the
given version number. | public Object[] | getRevision(Version vernum) Get the text belonging to the revision identified by the
given version number.
Partial version numbers are OK.
Parameters: vernum - the version number. | public Object[] | getRevision(Version vernum, boolean annotate) Get the text belonging to the revision identified by the
given version number. | protected Path | getRevisionPath(Version vernum) Returns the path from the head node to the node identified
by the given version number.
Parameters: vernum - The version number that identifies the final node.Partial version numbers are OK. | public Version | getRevisionVersion(Version vernum) Return the actual revision number of the node identified
by the given version number.
Parameters: vernum - The version number that identifies the node.Partial version numbers are OK. | public Version | getRevisionVersion(String vernum) Return the actual revision number of the node identified
by the given version number.
Parameters: vernum - The version number that identifies the node.Partial version numbers are OK. | public Version | getRevisionVersion() Return the actual revision number of the active revision. | public Map | getSymbols() Returns a Map of the symbols (tags) associated with each revision. | protected BranchNode | newBranchNode(Version vernum) | protected Node | newNode(Version vernum) | protected Node | newNode(Version vernum, Node prev) | protected TrunkNode | newTrunkNode(Version vernum) | public static String | quoteString(String s) Quote a string.
RCS strings are quoted using @. | protected static Object[] | removeKeywords(Object[] text) Returns the given text removing the values of any CVS-style
keywords.
Parameters: text - the text on which substitutions will be applied. | public void | save(OutputStream output) Save the archive to the provided stream. | public void | save(String path) Save the archive to a file and the the Archives filename
accordingly. | public void | setBranch(String v) Set the active branch to the one identified by the given version number. | public void | setBranch(Version vernum) Set the active branch to the one identified by the given version number. | public void | setComment(String value) Set the archive's comment. | public void | setDesc(String value) Set the archives description. | public void | setExpand(String value) Set the keyword expansion flag for the archive.
Parameters: value - The keyword expansion value. | public void | setFileName(String path) | protected void | setHead(Version vernum) Add a head node with the given version number. | public void | setStrictLocking(boolean value) Set the strict locking flag for the archive. | public byte[] | toByteArray() Return a text image of the archive as a char array. | public char[] | toCharArray() Return a text image of the archive as a char array. | public void | toString(StringBuffer s) Place a string image of the archive in the given StringBuffer. | public String | toString(String EOL) Return a text image of the archive.
Parameters: EOL - The token to use as line separator. | public void | toString(StringBuffer s, String EOL) Append a text image of the archive to the given buffer using
the given token as line separator. | public static String | unquoteString(String s) Unquote a string quoted in RCS style.
Parameters: s - the quoted string. | public static String | unquoteString(String s, boolean removeExtremes) Unquote a string quoted in RCS style.
Parameters: s - the quoted string. Parameters: removeExtremes - Determines if the enclosing @ quotesshould be removed. |
strictLocking | protected boolean strictLocking(Code) | | |
Archive | public Archive(Object[] text, String desc)(Code) | | Creates a new archive and sets the text of the initial revision.
Parameters: text - The text of the initial revision. Parameters: desc - The archives description (not the log message). |
Archive | public Archive(Object[] text, String desc, String vernum)(Code) | | Creates a new archive with the specified initial version number
and sets the text of the initial revision.
The initial revision must be of the form "n.m" (i.e. a trunk revision).
Parameters: text - The text of the initial revision. Parameters: desc - The archives description (not the log message). Parameters: vernum - The initial revision number. |
Archive | public Archive(Object[] text, String desc, Version vernum)(Code) | | Creates a new archive with the specified initial version number
and sets the text of the initial revision.
The initial revision must be of the form "n.m" (i.e. a trunk revision).
Parameters: text - The text of the initial revision. Parameters: desc - The archives description (not the log message). Parameters: vernum - The initial revision number. |
Archive | public Archive(String fname, InputStream input) throws ParseException(Code) | | Load an archive from an input stream.
Parses the archive given by the input stream, and gives it the provided name.
Parameters: fname - The name to give to the archive. Parameters: input - Where to read the archive from |
Archive | Archive()(Code) | | Create an unitialized Archive.
Used internally by the ArchiveParser.
See Also: ArchiveParser |
addPhrase | public void addPhrase(String key, Collection values)(Code) | | Add a new phrase to the archive.
Phrases are used to provide for extensions of the archive format.
Each phrase has a key and a list of values associated with it.
Parameters: key - The phrases key. Parameters: values - The values under the key. |
addRevision | public Version addRevision(Object[] text, String vernum, String log) throws InvalidFileFormatException, DiffException, InvalidVersionNumberException, NodeNotFoundException(Code) | | Add the given revision to the the archive using the given version
number.
The version number may be partial. If so, the rules used by RCS/CVS
are used to decide which branch the revision should be added to. A
new branch may be created if required.
Parameters: text - the text of the revision. Parameters: vernum - is the version number wanted, or, if partial, identifiesthe target branch. Parameters: log - the log: a short note explaining what the revision is. The version number assigned to the revision. |
addRevision | public Version addRevision(Object[] text, Version vernum, String log) throws InvalidFileFormatException, DiffException, NodeNotFoundException, InvalidVersionNumberException(Code) | | Add the given revision to the the archive using the given version
number.
The version number may be partial. If so, the rules used by RCS/CVS
are used to decide which branch the revision should be added to. A
new branch may be created if required.
Parameters: text - the text of the revision. Parameters: vernum - is the version number wanted, or, if partial, identifiesthe target branch. Parameters: log - the log: a short note explaining what the revision is. The version number assigned to the revision. |
addUser | public void addUser(String name)(Code) | | Add a user name to the list of archive users.
Parameters: name - The user name. |
changeLog | public Node[] changeLog()(Code) | | Return the list of nodes between the head revision and
the root revision.
|
changeLog | public Node[] changeLog(Version latest)(Code) | | Return the list of nodes between the the given revision
and the root revision.
Parameters: latest - the version of the last revision in the log. |
changeLog | public Node[] changeLog(Version latest, Version earliest)(Code) | | Return the list of nodes between the the given two revisions.
Parameters: latest - the version of the last revision in the log. Parameters: earliest - the version of the first revision in the log. |
doKeywords | public Object[] doKeywords(Object[] text, Node rev) throws PatchFailedException(Code) | | Returns the given text with values added to CVS-style keywords.
Parameters: text - the text on which substitutions will be applied. Parameters: rev - a node that identifies the revision to which thegiven text belongs. the text with substitutions performed. |
findNode | public Node findNode(Version vernum)(Code) | | Return the node with the version number that matches the one provided.
The given version number may be partial.
Parameters: vernum - the version number to match. the node, or null if no match found. |
getDesc | public String getDesc()(Code) | | Returns the description associated with the archive.
the description |
getLog | public String getLog(Version version) throws NodeNotFoundException(Code) | | Returns the log message associated with the given revision.
Parameters: version - - the version to get the log message for the log message for the version. - if the version does not exist for the archive. |
getRevisionPath | protected Path getRevisionPath(Version vernum)(Code) | | Returns the path from the head node to the node identified
by the given version number.
Parameters: vernum - The version number that identifies the final node.Partial version numbers are OK. The path to the node, or null if not found. |
getRevisionVersion | public Version getRevisionVersion(Version vernum)(Code) | | Return the actual revision number of the node identified
by the given version number.
Parameters: vernum - The version number that identifies the node.Partial version numbers are OK. The actual version, or null if a node is not found. |
getRevisionVersion | public Version getRevisionVersion(String vernum)(Code) | | Return the actual revision number of the node identified
by the given version number.
Parameters: vernum - The version number that identifies the node.Partial version numbers are OK. The actual version, or null if a node is not found. |
getRevisionVersion | public Version getRevisionVersion()(Code) | | Return the actual revision number of the active revision.
The revision will be the tip of the branch identified as
active, or the head revision of the trunk if no branch is set
as active.
The version number of the active revision, or null ifthere is none. |
getSymbols | public Map getSymbols()(Code) | | Returns a Map of the symbols (tags) associated with each revision.
The symbols are the keys and the revision numbers are the values.
A map of symbol/revision number pairs. |
quoteString | public static String quoteString(String s)(Code) | | Quote a string.
RCS strings are quoted using @. Any @ in the original
string is doubled to @@.
Parameters: s - the string to quote. The string quoted in RCS style. |
removeKeywords | protected static Object[] removeKeywords(Object[] text) throws PatchFailedException(Code) | | Returns the given text removing the values of any CVS-style
keywords.
Parameters: text - the text on which substitutions will be applied. the text with substitutions performed. |
save | public void save(OutputStream output) throws IOException(Code) | | Save the archive to the provided stream.
Parameters: output - The stream to save the archive to. |
save | public void save(String path) throws IOException(Code) | | Save the archive to a file and the the Archives filename
accordingly.
Parameters: path - The file's path. |
setBranch | public void setBranch(String v) throws InvalidBranchVersionNumberException(Code) | | Set the active branch to the one identified by the given version number.
Incomplete version numbers of the form "1" or "2.1.3" are accepted.
Parameters: v - The version number. |
setComment | public void setComment(String value)(Code) | | Set the archive's comment.
Parameters: value - The comment. |
setDesc | public void setDesc(String value)(Code) | | Set the archives description.
Parameters: value - The descriptions text. |
setExpand | public void setExpand(String value)(Code) | | Set the keyword expansion flag for the archive.
Parameters: value - The keyword expansion value. It should be one of:- kv (Default) Substitue keyword and value.
- kvl Substitute keyword, value, and locker (if any).
- k Substitute keyword only.
- o Preserve original string.
- b Like o, but mark file as binary.
- v Substitue value only.
|
setFileName | public void setFileName(String path)(Code) | | Set the name of the file for this archive
Parameters: path - The full path name. |
setStrictLocking | public void setStrictLocking(boolean value)(Code) | | Set the strict locking flag for the archive.
Parameters: value - Indicates if strict locking should be on or off. |
toByteArray | public byte[] toByteArray()(Code) | | Return a text image of the archive as a char array.
This is useful for writing the archive to a file without
having the characters be interpreted by the writer.
The archive image. |
toCharArray | public char[] toCharArray()(Code) | | Return a text image of the archive as a char array.
This is useful for writing the archive to a file without
having the characters be interpreted by the writer.
The archive image. |
toString | public void toString(StringBuffer s)(Code) | | Place a string image of the archive in the given StringBuffer.
Parameters: s - Where the image shoul go. |
toString | public String toString(String EOL)(Code) | | Return a text image of the archive.
Parameters: EOL - The token to use as line separator. The text image of the archive. |
toString | public void toString(StringBuffer s, String EOL)(Code) | | Append a text image of the archive to the given buffer using
the given token as line separator.
Parameters: s - where to append the image. Parameters: EOL - the line separator. |
unquoteString | public static String unquoteString(String s)(Code) | | Unquote a string quoted in RCS style.
Parameters: s - the quoted string. s the string unquoted. |
unquoteString | public static String unquoteString(String s, boolean removeExtremes)(Code) | | Unquote a string quoted in RCS style.
Parameters: s - the quoted string. Parameters: removeExtremes - Determines if the enclosing @ quotesshould be removed. s the string unquoted. |
|
|