org.codehaus.mojo.pomtools.versioning
Class DefaultVersionInfo

java.lang.Object
  extended by org.codehaus.mojo.pomtools.versioning.DefaultVersionInfo
All Implemented Interfaces:
Cloneable, Comparable, VersionInfo

public class DefaultVersionInfo
extends Object
implements VersionInfo, Cloneable

This compares and increments versions for a common java versioning scheme.

The supported version scheme has the following parts.
component-digits-annotation-annotationRevision-buildSpecifier
Example:
my-component-1.0.1-alpha-2-SNAPSHOT

Digits is the only required piece of the version string, and must contain at lease one "." period.

Implementation details:
The separators "_" and "-" between components are also optional (though they are usually reccommended).
Example:
log4j-1.2.9-beta-9-SNAPSHOT == log4j1.2.9beta9SNAPSHOT == log4j_1.2.9_beta_9_SNAPSHOT

All numbers in the "digits" part of the version are considered Integers. Therefore 1.01.01 is the same as 1.1.1 Leading zeros are ignored when performing comparisons.

Version:
$Id: DefaultVersionInfo.java 2166 2006-07-18 21:32:16Z carlos $
Author:
David Hawkins

Field Summary
protected static Pattern DATESTAMP_PATTERN
           
static String[] DEFAULT_ANNOTATION_ORDER
          Default order of annotations to consider in compareTo(Object).
protected static Pattern DIGIT_SEPARATOR_PATTERN
           
protected static String DIGIT_SEPARATOR_STRING
           
protected static Pattern OPTIONAL_DIGIT_SEPARATOR_PATTERN
           
static String SNAPSHOT_IDENTIFIER
           
protected static Pattern STANDARD_PATTERN
           
 
Constructor Summary
DefaultVersionInfo(String version)
          Constructs this object and parses the supplied version string.
 
Method Summary
 int compareTo(Object obj)
          Compares this DefaultVersionInfo to the supplied DefaultVersionInfo to determine which version is greater.
 boolean equals(Object obj)
           
 String getAnnotation()
           
 List getAnnotationOrder()
           
 String getAnnotationRevision()
           
 org.apache.maven.artifact.versioning.ArtifactVersion getArtifactVersion()
           
 String getBuildSpecifier()
           
 String getComponent()
           
 List getDigits()
           
 VersionInfo getNextVersion()
          Returns a VersionInfo object which represents the next version of this object.
 String getReleaseVersionString()
          Returns a string representing the version without a snapshot specification.
 String getSnapshotVersionString()
          Returns a string representing the version with a snapshot specification
 String getVersionString()
          Returns a string representing the version without modification.
protected static String getVersionString(DefaultVersionInfo info, String buildSpecifier, String buildSeparator)
           
 int hashCode()
           
protected  String incrementVersionString(String s)
          Takes a string and increments it as an integer.
 boolean isParsed()
           
 boolean isSnapshot()
          Returns whether this represents a snapshot version.
protected static String joinDigitString(List digits)
          Simply joins the items in the list with "." period
protected  List parseDigits(String strDigits)
          Splits the string on "." and returns a list containing each digit.
protected  void parseVersion(String version)
          Internal routine for parsing the supplied version string into its parts.
protected  void setAnnotation(String annotation)
           
protected  void setAnnotationOrder(List annotationOrder)
           
protected  void setAnnotationRevision(String annotationRevision)
           
protected  void setBuildSpecifier(String buildSpecifier)
           
protected  void setComponent(String component)
           
protected  void setDigits(List digits)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SNAPSHOT_IDENTIFIER

public static final String SNAPSHOT_IDENTIFIER
See Also:
Constant Field Values

DIGIT_SEPARATOR_STRING

protected static final String DIGIT_SEPARATOR_STRING
See Also:
Constant Field Values

DEFAULT_ANNOTATION_ORDER

public static final String[] DEFAULT_ANNOTATION_ORDER
Default order of annotations to consider in compareTo(Object). null denotes a version without an annotation. Therefore, a "SP" or Service Pack build is considered to be greater than a version without an annotation.


DATESTAMP_PATTERN

protected static final Pattern DATESTAMP_PATTERN

STANDARD_PATTERN

protected static final Pattern STANDARD_PATTERN

OPTIONAL_DIGIT_SEPARATOR_PATTERN

protected static final Pattern OPTIONAL_DIGIT_SEPARATOR_PATTERN

DIGIT_SEPARATOR_PATTERN

protected static final Pattern DIGIT_SEPARATOR_PATTERN
Constructor Detail

DefaultVersionInfo

public DefaultVersionInfo(String version)
Constructs this object and parses the supplied version string.

Parameters:
version -
Method Detail

parseVersion

protected void parseVersion(String version)
Internal routine for parsing the supplied version string into its parts.

Parameters:
version -

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

isParsed

public boolean isParsed()
Specified by:
isParsed in interface VersionInfo

isSnapshot

public boolean isSnapshot()
Description copied from interface: VersionInfo
Returns whether this represents a snapshot version. ("xxx-SNAPSHOT");

Specified by:
isSnapshot in interface VersionInfo
Returns:

getNextVersion

public VersionInfo getNextVersion()
Description copied from interface: VersionInfo
Returns a VersionInfo object which represents the next version of this object.

Specified by:
getNextVersion in interface VersionInfo
Returns:

compareTo

public int compareTo(Object obj)
Compares this DefaultVersionInfo to the supplied DefaultVersionInfo to determine which version is greater.

Decision order is: digits, annotation, annotationRev, buildSpecifier.

Presence of an annotation is considered to be less than an equivalent version without an annotation.
Example: 1.0 is greater than 1.0-alpha.

The getAnnotationOrder() is used in determining the rank order of annotations.
For example: alpha < beta < RC < release

Specified by:
compareTo in interface Comparable
Parameters:
that -
Returns:
Throws:
IllegalArgumentException - if the components differ between the objects or if either of the annotations can not be determined.

incrementVersionString

protected String incrementVersionString(String s)
Takes a string and increments it as an integer. Preserves any lpad of "0" zeros.

Parameters:
s -
Returns:

getSnapshotVersionString

public String getSnapshotVersionString()
Description copied from interface: VersionInfo
Returns a string representing the version with a snapshot specification

Specified by:
getSnapshotVersionString in interface VersionInfo
Returns:

getReleaseVersionString

public String getReleaseVersionString()
Description copied from interface: VersionInfo
Returns a string representing the version without a snapshot specification.

Specified by:
getReleaseVersionString in interface VersionInfo
Returns:

getArtifactVersion

public org.apache.maven.artifact.versioning.ArtifactVersion getArtifactVersion()
Specified by:
getArtifactVersion in interface VersionInfo

toString

public String toString()
Overrides:
toString in class Object

getVersionString

public String getVersionString()
Description copied from interface: VersionInfo
Returns a string representing the version without modification.

Specified by:
getVersionString in interface VersionInfo
Returns:

getVersionString

protected static String getVersionString(DefaultVersionInfo info,
                                         String buildSpecifier,
                                         String buildSeparator)

joinDigitString

protected static String joinDigitString(List digits)
Simply joins the items in the list with "." period

Parameters:
digits -
Returns:

parseDigits

protected List parseDigits(String strDigits)
Splits the string on "." and returns a list containing each digit.

Parameters:
strDigits -
Returns:

getAnnotation

public String getAnnotation()

setAnnotation

protected void setAnnotation(String annotation)

getAnnotationRevision

public String getAnnotationRevision()

setAnnotationRevision

protected void setAnnotationRevision(String annotationRevision)

getComponent

public String getComponent()

setComponent

protected void setComponent(String component)

getDigits

public List getDigits()

setDigits

protected void setDigits(List digits)

getBuildSpecifier

public String getBuildSpecifier()

setBuildSpecifier

protected void setBuildSpecifier(String buildSpecifier)

getAnnotationOrder

public List getAnnotationOrder()

setAnnotationOrder

protected void setAnnotationOrder(List annotationOrder)


Copyright © 2011 The Codehaus. All Rights Reserved.