Class ComparableVersion

  • All Implemented Interfaces:
    java.lang.Comparable<ComparableVersion>

    public class ComparableVersion
    extends java.lang.Object
    implements java.lang.Comparable<ComparableVersion>

    Generic implementation of version comparison.

    Features:
    • mixing of '-' (hyphen) and '.' (dot) separators,
    • transition between characters and digits also constitutes a separator: 1.0alpha1 => [1, 0, alpha, 1]
    • unlimited number of version components,
    • version components in the text can be digits or strings,
    • strings are checked for well-known qualifiers and the qualifier ordering is used for version ordering. Well-known qualifiers (case insensitive) are:
      • alpha or a
      • beta or b
      • milestone or m
      • rc or cr
      • snapshot
      • (the empty string) or ga or final
      • sp
      Unknown qualifiers are considered after known qualifiers, with lexical order (always case insensitive),
    • a hyphen usually precedes a qualifier, and is always less important than something preceded with a dot.
    Author:
    Kenney Westerhof, Hervé Boutemy
    See Also:
    "Versioning" on Maven Wiki
    • Constructor Detail

      • ComparableVersion

        public ComparableVersion​(java.lang.String version)
    • Method Detail

      • parseVersion

        public final void parseVersion​(java.lang.String version)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getCanonical

        public java.lang.String getCanonical()
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • main

        public static void main​(java.lang.String... args)
        Main to test version parsing and comparison.

        To check how "1.2.7" compares to "1.2-SNAPSHOT", for example, you can issue

        java -jar ${maven.repo.local}/org/apache/maven/maven-artifact/${maven.version}/maven-artifact-${maven.version}.jar "1.2.7" "1.2-SNAPSHOT"
        command to command line. Result of given command will be something like this:
         Display parameters as parsed by Maven (in canonical form) and comparison result:
         1. 1.2.7 == 1.2.7
            1.2.7 > 1.2-SNAPSHOT
         2. 1.2-SNAPSHOT == 1.2-snapshot
         
        Parameters:
        args - the version strings to parse and compare. You can pass arbitrary number of version strings and always two adjacent will be compared