Class GenericVersionScheme
- java.lang.Object
-
- org.eclipse.aether.util.version.GenericVersionScheme
-
- All Implemented Interfaces:
VersionScheme
public final class GenericVersionScheme extends java.lang.Object implements VersionScheme
A version scheme using a generic version syntax and common sense sorting.This scheme accepts versions of any form, interpreting a version as a sequence of numeric and alphabetic segments. The characters '-', '_', and '.' as well as the mere transitions from digit to letter and vice versa delimit the version segments. Delimiters are treated as equivalent.
Numeric segments are compared mathematically, alphabetic segments are compared lexicographically and case-insensitively. However, the following qualifier strings are recognized and treated specially: "alpha" = "a" < "beta" = "b" < "milestone" = "m" < "cr" = "rc" < "snapshot" < "final" = "ga" < "sp". All of those well-known qualifiers are considered smaller/older than other strings. An empty segment/string is equivalent to 0.
In addition to the above mentioned qualifiers, the tokens "min" and "max" may be used as final version segment to denote the smallest/greatest version having a given prefix. For example, "1.2.min" denotes the smallest version in the 1.2 line, "1.2.max" denotes the greatest version in the 1.2 line. A version range of the form "[M.N.*]" is short for "[M.N.min, M.N.max]".
Numbers and strings are considered incomparable against each other. Where version segments of different kind would collide, comparison will instead assume that the previous segments are padded with trailing 0 or "ga" segments, respectively, until the kind mismatch is resolved, e.g. "1-alpha" = "1.0.0-alpha" < "1.0.1-ga" = "1.0.1".
-
-
Constructor Summary
Constructors Constructor Description GenericVersionScheme()
Creates a new instance of the version scheme for parsing versions.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
int
hashCode()
static void
main(java.lang.String... args)
A handy main method that behaves similarly like maven-artifact ComparableVersion is, to make possible test and possibly compare differences between the two.GenericVersion
parseVersion(java.lang.String version)
Parses the specified version string, for example "1.0".GenericVersionConstraint
parseVersionConstraint(java.lang.String constraint)
Parses the specified version constraint specification, for example "1.0" or "[1.0,2.0),(2.0,)".GenericVersionRange
parseVersionRange(java.lang.String range)
Parses the specified version range specification, for example "[1.0,2.0)".
-
-
-
Method Detail
-
parseVersion
public GenericVersion parseVersion(java.lang.String version) throws InvalidVersionSpecificationException
Description copied from interface:VersionScheme
Parses the specified version string, for example "1.0".- Specified by:
parseVersion
in interfaceVersionScheme
- Parameters:
version
- The version string to parse, must not benull
.- Returns:
- The parsed version, never
null
. - Throws:
InvalidVersionSpecificationException
- If the string violates the syntax rules of this scheme.
-
parseVersionRange
public GenericVersionRange parseVersionRange(java.lang.String range) throws InvalidVersionSpecificationException
Description copied from interface:VersionScheme
Parses the specified version range specification, for example "[1.0,2.0)".- Specified by:
parseVersionRange
in interfaceVersionScheme
- Parameters:
range
- The range specification to parse, must not benull
.- Returns:
- The parsed version range, never
null
. - Throws:
InvalidVersionSpecificationException
- If the range specification violates the syntax rules of this scheme.
-
parseVersionConstraint
public GenericVersionConstraint parseVersionConstraint(java.lang.String constraint) throws InvalidVersionSpecificationException
Description copied from interface:VersionScheme
Parses the specified version constraint specification, for example "1.0" or "[1.0,2.0),(2.0,)".- Specified by:
parseVersionConstraint
in interfaceVersionScheme
- Parameters:
constraint
- The constraint specification to parse, must not benull
.- Returns:
- The parsed version constraint, never
null
. - Throws:
InvalidVersionSpecificationException
- If the constraint specification violates the syntax rules of this scheme.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
main
public static void main(java.lang.String... args)
A handy main method that behaves similarly like maven-artifact ComparableVersion is, to make possible test and possibly compare differences between the two.To check how "1.2.7" compares to "1.2-SNAPSHOT", for example, you can issue
java -cp ${maven.repo.local}/org/apache/maven/resolver/maven-resolver-api/${resolver.version}/maven-resolver-api-${resolver.version}.jar:${maven.repo.local}/org/apache/maven/resolver/maven-resolver-util/${resolver.version}/maven-resolver-util-${resolver.version}.jar org.eclipse.aether.util.version.GenericVersionScheme "1.2.7" "1.2-SNAPSHOT"
command to command line, output is very similar to that of ComparableVersion on purpose.
-
-