ohmm
Class Version

java.lang.Object
  extended by ohmm.Version

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.

Author:
Marsette A. Vona

Field Summary
 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 Summary
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.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

svnid

private static final java.lang.String svnid
See Also:
Constant Field Values

DEFAULT_VERSION_FILE

public static final java.lang.String DEFAULT_VERSION_FILE
the name of the default version file, see class header doc

See Also:
Constant Field Values

UNKNOWN

public static final java.lang.String UNKNOWN
unknown version fields are set to this value

See Also:
Constant Field Values

SVN_ID_FIELD

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.

See Also:
Constant Field Values

CVS_ID_FIELD

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.

See Also:
Constant Field Values

svnVersion

public final java.lang.String svnVersion

Version string in the format produced by svnversion, or UNKNOWN.


earliestRevision

public final java.lang.String earliestRevision

Version string in the format produced by svnversion before any colon, or UNKNOWN.


latestRevision

public final java.lang.String latestRevision

Version string in the format produced by svnversion after any colon, or UNKNOWN.


versionDate

public final java.lang.String versionDate

A string identifying the version by date or UNKNOWN.


className

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.


versionFileName

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.

Constructor Detail

Version

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.

Parameters:
clazz - see className, not null
versionFileName - see versionFileName

Version

public Version(java.lang.Class clazz)

Covers Version(Class, String), uses DEFAULT_VERSION_FILE.


Version

public Version(java.lang.String versionFileName)

Covers Version(Class, String), uses this class.


Version

public Version()

Covers Version(Class, String), uses this class and DEFAULT_VERSION_FILE.

Method Detail

dump

public void dump(java.io.PrintStream s)
dumps all version info


dump

public void dump()
dump(PrintStream) to System.out


main

public static void main(java.lang.String[] arg)

Test driver.

USAGE:

Version
invokes Version()
Version classname
invokes Version(Class, String) with null versionFileName
Version classname filename
invokes Version(Class, String)