public class Version
extends java.lang.Object
Version utility.
This class provides several ways to determine version information for
some particular codebase. The version may have a number of components:
svnVersion
, earliestRevision
, latestRevision
, and
versionDate
; see which. Any component(s) which cannot be
determined are set to the value UNKNOWN
.
The version info can either be taken from a version file which is
read as a resouce associated with a particular version class, or it
can be read from an SVN or CVS Id keyword expansion stored in a static field
(SVN_ID_FIELD
or CVS_ID_FIELD
) of the version class.
If a version file is specified, or if DEFAULT_VERSION_FILE
is
implied, and the file is not present or there was a problem reading it then
the version fields are left UNKNOWN
. Only in the case that the
version file is explicitly specified as null
is any attempt made to
read the version info from an Id keyword field.
The format of the version file is an svn ID string in the format produced
by the standard svnversion utility, followed by whitespace,
followed by a date string, followed by whitespace. Everything is optional
and elements that are not present will be left as UNKNOWN
. The
super-ninja makefile includes targets to auto-generate version files in this
format.
Using a version file is generally better than relying on an Id keyword expansion, as the file can be generated to reflect the overall version of an entire svn tree, whereas the Id keyword only gives the version for that particular class.
Modifier and Type | Field and Description |
---|---|
java.lang.String |
className
The name of the class for which versioning was computed.
|
static java.lang.String |
CVS_ID_FIELD
Field name searched when attempting to read an SVN or CVS Id keyword
expansion from a class.
|
static java.lang.String |
DEFAULT_VERSION_FILE
the name of the default version file, see class header doc
|
java.lang.String |
earliestRevision
Version string in the format produced by svnversion before any
colon, or
UNKNOWN . |
java.lang.String |
latestRevision
Version string in the format produced by svnversion after any
colon, or
UNKNOWN . |
static java.lang.String |
SVN_ID_FIELD
Field name searched when attempting to read an SVN or CVS Id keyword
expansion from a class.
|
private static java.lang.String |
svnid |
java.lang.String |
svnVersion
Version string in the format produced by svnversion, or
UNKNOWN . |
static java.lang.String |
UNKNOWN
unknown version fields are set to this value
|
java.lang.String |
versionDate
A string identifying the version by date or
UNKNOWN . |
java.lang.String |
versionFileName
The name of the file from which version info was read or null if
version info was parsed from an SVN or CVS Id keyword expansion.
|
Constructor and Description |
---|
Version()
Covers
Version(Class, String) , uses this class and DEFAULT_VERSION_FILE . |
Version(java.lang.Class clazz)
Covers
Version(Class, String) , uses DEFAULT_VERSION_FILE . |
Version(java.lang.Class clazz,
java.lang.String versionFileName)
Parse version info.
|
Version(java.lang.String versionFileName)
Covers
Version(Class, String) , uses this class. |
Modifier and Type | Method and Description |
---|---|
void |
dump()
dump(PrintStream) to System.out |
void |
dump(java.io.PrintStream s)
dumps all version info
|
static void |
main(java.lang.String[] arg)
Test driver.
|
private static final java.lang.String svnid
public static final java.lang.String DEFAULT_VERSION_FILE
public static final java.lang.String UNKNOWN
public static final java.lang.String SVN_ID_FIELD
Field name searched when attempting to read an SVN or CVS Id keyword expansion from a class.
See header doc for details.
If such a field is found it will only be respected if it is a class field of type String.
public static final java.lang.String CVS_ID_FIELD
Field name searched when attempting to read an SVN or CVS Id keyword expansion from a class.
See header doc for details.
If such a field is found it will only be respected if it is a class field of type String.
public final java.lang.String svnVersion
Version string in the format produced by svnversion, or UNKNOWN
.
public final java.lang.String earliestRevision
Version string in the format produced by svnversion before any
colon, or UNKNOWN
.
public final java.lang.String latestRevision
Version string in the format produced by svnversion after any
colon, or UNKNOWN
.
public final java.lang.String versionDate
A string identifying the version by date or UNKNOWN
.
public final java.lang.String className
The name of the class for which versioning was computed.
In the case that the version info was read from a version file, this class was used as the reference to acquire the file as a resource.
In the case that the version info was read from a class field containing an SVN or CVS Id keyword expansion, this class was searched for the field.
public final java.lang.String versionFileName
The name of the file from which version info was read or null if version info was parsed from an SVN or CVS Id keyword expansion.
public Version(java.lang.Class clazz, java.lang.String versionFileName)
Parse version info.
Specifying versionFileName other than null triggers version
parsing from file. If null version info is parsed from SVN_ID_FIELD
or CVS_ID_FIELD
, if present.
clazz
- see className
, not nullversionFileName
- see versionFileName
public Version(java.lang.Class clazz)
Covers Version(Class, String)
, uses DEFAULT_VERSION_FILE
.
public Version(java.lang.String versionFileName)
Covers Version(Class, String)
, uses this class.
public Version()
Covers Version(Class, String)
, uses this class and DEFAULT_VERSION_FILE
.
public void dump(java.io.PrintStream s)
public void dump()
dump(PrintStream)
to System.out
public static void main(java.lang.String[] arg)
Test driver.
USAGE:
Version()
Version(Class, String)
with
null versionFileNameVersion(Class,
String)