Class DefaultVersionInfo
- java.lang.Object
-
- org.apache.maven.shared.release.versions.DefaultVersionInfo
-
- All Implemented Interfaces:
java.lang.Comparable<VersionInfo>,VersionInfo
public class DefaultVersionInfo extends java.lang.Object implements VersionInfo
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- Terms:
- component - name of the versioned component (log4j, commons-lang, etc)
- digits - Numeric digits with at least one "." period. (1.0, 1.1, 1.01, 1.2.3, etc)
- annotationRevision - Integer qualifier for the annotation. (4 as in RC-4)
- buildSpecifier - Additional specifier for build. (SNAPSHOT, or build number like "20041114.081234-2")
The separators "_" and "-" between components are also optional (though they are usually recommended).
Example:
log4j-1.2.9-beta-9-SNAPSHOT == log4j1.2.9beta9SNAPSHOT == log4j_1.2.9_beta_9_SNAPSHOTLeading zeros are significant when performing comparisons. TODO: this parser is better than DefaultArtifactVersion - replace it with this (but align naming) and then remove this from here.
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.regex.PatternALTERNATE_PATTERNprivate java.lang.Stringannotationprivate static intANNOTATION_INDEXprivate static intANNOTATION_REV_SEPARATOR_INDEXprivate static intANNOTATION_REVISION_INDEXprivate static intANNOTATION_SEPARATOR_INDEXprivate java.lang.StringannotationRevisionprivate java.lang.StringannotationRevSeparatorprivate java.lang.StringannotationSeparatorprivate static intBUILD_SEPARATOR_INDEXprivate static intBUILD_SPECIFIER_INDEXprivate java.lang.StringbuildSeparatorprivate java.lang.StringbuildSpecifierprivate static java.lang.StringDIGIT_SEPARATOR_STRINGprivate java.util.List<java.lang.String>digitsprivate static intDIGITS_INDEXprivate static java.lang.StringSNAPSHOT_IDENTIFIERstatic java.util.regex.PatternSTANDARD_PATTERNprivate java.lang.StringstrVersion
-
Constructor Summary
Constructors Constructor Description DefaultVersionInfo(java.lang.String version)Constructs this object and parses the supplied version string.DefaultVersionInfo(java.util.List<java.lang.String> digits, java.lang.String annotation, java.lang.String annotationRevision, java.lang.String buildSpecifier, java.lang.String annotationSeparator, java.lang.String annotationRevSeparator, java.lang.String buildSeparator)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(VersionInfo obj)Compares thisDefaultVersionInfoto the suppliedDefaultVersionInfoto determine which version is greater.booleanequals(java.lang.Object obj)java.lang.StringgetAnnotation()java.lang.StringgetAnnotationRevision()java.lang.StringgetBuildSpecifier()java.util.List<java.lang.String>getDigits()VersionInfogetNextVersion()Returns aVersionInfoobject which represents the next version of this object.java.lang.StringgetReleaseVersionString()Returns a string representing the version without a snapshot specification.java.lang.StringgetSnapshotVersionString()Returns a string representing the version with a snapshot specificationprotected static java.lang.StringgetVersionString(DefaultVersionInfo info, java.lang.String buildSpecifier, java.lang.String buildSeparator)inthashCode()protected java.lang.StringincrementVersionString(java.lang.String s)Takes a string and increments it as an integer.booleanisSnapshot()Returns whether this represents a snapshot version.protected static java.lang.StringjoinDigitString(java.util.List<java.lang.String> digits)Simply joins the items in the list with "." periodprivate static java.lang.StringnullIfEmpty(java.lang.String s)private java.util.List<java.lang.String>parseDigits(java.lang.String strDigits)Splits the string on "." and returns a list containing each digit.java.lang.StringtoString()
-
-
-
Field Detail
-
strVersion
private final java.lang.String strVersion
-
digits
private final java.util.List<java.lang.String> digits
-
annotation
private java.lang.String annotation
-
annotationRevision
private java.lang.String annotationRevision
-
buildSpecifier
private final java.lang.String buildSpecifier
-
annotationSeparator
private java.lang.String annotationSeparator
-
annotationRevSeparator
private java.lang.String annotationRevSeparator
-
buildSeparator
private final java.lang.String buildSeparator
-
DIGITS_INDEX
private static final int DIGITS_INDEX
- See Also:
- Constant Field Values
-
ANNOTATION_SEPARATOR_INDEX
private static final int ANNOTATION_SEPARATOR_INDEX
- See Also:
- Constant Field Values
-
ANNOTATION_INDEX
private static final int ANNOTATION_INDEX
- See Also:
- Constant Field Values
-
ANNOTATION_REV_SEPARATOR_INDEX
private static final int ANNOTATION_REV_SEPARATOR_INDEX
- See Also:
- Constant Field Values
-
ANNOTATION_REVISION_INDEX
private static final int ANNOTATION_REVISION_INDEX
- See Also:
- Constant Field Values
-
BUILD_SEPARATOR_INDEX
private static final int BUILD_SEPARATOR_INDEX
- See Also:
- Constant Field Values
-
BUILD_SPECIFIER_INDEX
private static final int BUILD_SPECIFIER_INDEX
- See Also:
- Constant Field Values
-
SNAPSHOT_IDENTIFIER
private static final java.lang.String SNAPSHOT_IDENTIFIER
- See Also:
- Constant Field Values
-
DIGIT_SEPARATOR_STRING
private static final java.lang.String DIGIT_SEPARATOR_STRING
- See Also:
- Constant Field Values
-
STANDARD_PATTERN
public static final java.util.regex.Pattern STANDARD_PATTERN
-
ALTERNATE_PATTERN
public static final java.util.regex.Pattern ALTERNATE_PATTERN
-
-
Constructor Detail
-
DefaultVersionInfo
public DefaultVersionInfo(java.lang.String version) throws VersionParseExceptionConstructs this object and parses the supplied version string.- Parameters:
version-- Throws:
VersionParseException
-
DefaultVersionInfo
public DefaultVersionInfo(java.util.List<java.lang.String> digits, java.lang.String annotation, java.lang.String annotationRevision, java.lang.String buildSpecifier, java.lang.String annotationSeparator, java.lang.String annotationRevSeparator, java.lang.String buildSeparator)
-
-
Method Detail
-
isSnapshot
public boolean isSnapshot()
Description copied from interface:VersionInfoReturns whether this represents a snapshot version.- Specified by:
isSnapshotin interfaceVersionInfo- Returns:
trueif the original value was a snapshot, otherwisefalse
-
getNextVersion
public VersionInfo getNextVersion()
Description copied from interface:VersionInfoReturns aVersionInfoobject which represents the next version of this object.- Specified by:
getNextVersionin interfaceVersionInfo- Returns:
- the next VersionInfo
-
compareTo
public int compareTo(VersionInfo obj)
Compares thisDefaultVersionInfoto the suppliedDefaultVersionInfoto determine which version is greater.- Specified by:
compareToin interfacejava.lang.Comparable<VersionInfo>- Parameters:
obj- the comparison version- Returns:
- the comparison value
- Throws:
java.lang.IllegalArgumentException- if the components differ between the objects or if either of the annotations can not be determined.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
incrementVersionString
protected java.lang.String incrementVersionString(java.lang.String s)
Takes a string and increments it as an integer. Preserves any lpad of "0" zeros.- Parameters:
s-
-
getSnapshotVersionString
public java.lang.String getSnapshotVersionString()
Description copied from interface:VersionInfoReturns a string representing the version with a snapshot specification- Specified by:
getSnapshotVersionStringin interfaceVersionInfo- Returns:
- the snapshot version transformation of the original value
-
getReleaseVersionString
public java.lang.String getReleaseVersionString()
Description copied from interface:VersionInfoReturns a string representing the version without a snapshot specification.- Specified by:
getReleaseVersionStringin interfaceVersionInfo- Returns:
- the final version transformation of the original value
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getVersionString
protected static java.lang.String getVersionString(DefaultVersionInfo info, java.lang.String buildSpecifier, java.lang.String buildSeparator)
-
joinDigitString
protected static java.lang.String joinDigitString(java.util.List<java.lang.String> digits)
Simply joins the items in the list with "." period- Parameters:
digits-
-
parseDigits
private java.util.List<java.lang.String> parseDigits(java.lang.String strDigits)
Splits the string on "." and returns a list containing each digit.- Parameters:
strDigits-
-
nullIfEmpty
private static java.lang.String nullIfEmpty(java.lang.String s)
-
getDigits
public java.util.List<java.lang.String> getDigits()
-
getAnnotation
public java.lang.String getAnnotation()
-
getAnnotationRevision
public java.lang.String getAnnotationRevision()
-
getBuildSpecifier
public java.lang.String getBuildSpecifier()
-
-