Class MavenVersion

  • All Implemented Interfaces:
    Comparable<org.apache.maven.artifact.versioning.ArtifactVersion>, org.apache.maven.artifact.versioning.ArtifactVersion

    public class MavenVersion
    extends MavenVersionSpecification
    implements org.apache.maven.artifact.versioning.ArtifactVersion
    Provides a model of an artifact version which can be used as a maven version.

    The maven POM reference does not define a format for versions. This is presumably intentional as it allows artifacts with arbitrary versioning schemes to be referenced in a POM.

    Maven tooling, on the other hand side, defines a rather restrictive version number pattern for maven projects. Non-compliant version numbers are parsed as qualifier-only versions.

    The parsing methods of this class make an attempt to interpret a version number as a <major>/<minor>/<micro/incremental>/<qualifier> pattern, even if it does not match the restrictive maven project version number pattern. The string representation of an instance of this class is always the original, unparsed (or "literal") representation because due to the permissive parsing algorithm used, the original representation cannot faithfully be reconstructed from the parsed components.

    Contrary to bnd's MavenVersion, this implementation inherits from ArtifactVersion, i.e. from the version as implemented by maven.

    • Constructor Detail

      • MavenVersion

        public MavenVersion​(String maven)
        Creates a new instance. The maven version is parsed by an instance of DefaultArtifactVersion. The parsing is thus fully maven compliant.
        Parameters:
        maven - the version
      • MavenVersion

        public MavenVersion​(aQute.bnd.version.Version osgiVersion)
        Creates a new maven version from an osgi version. The version components are copied, the string representation is built from the components as "<major>.<minor>.<micro>.<qualifier>"
        Parameters:
        osgiVersion - the osgi version
      • MavenVersion

        public MavenVersion​(aQute.bnd.version.Version osgiVersion,
                            String literal,
                            boolean isSnapshot)
        Creates a new maven version from an osgi version and an unparsed literal. The version components are copied, the literal is used as string representation, the snapshot property is taken from the argument.
        Parameters:
        osgiVersion - the osgi version
        literal - the literal
        isSnapshot - whether it is a snapshot version
    • Method Detail

      • parseString

        public static final MavenVersion parseString​(String versionStr)
        Parses the string as a maven version, but allows a dot as separator before the qualifier.

        Leading sequences of digits followed by a dot or dash are converted to the major, minor and incremental version components. A dash or a dot that is not followed by a digit or the third dot is interpreted as the start of the qualifier.

        In particular, version numbers such as "1.2.3.4.5" are parsed as major=1, minor=2, incremental=3 and qualifier="4.5". This is closer to the (assumed) semantics of such a version number than the parsing implemented in maven tooling, which interprets the complete version as a qualifier in such cases.

        Parameters:
        versionStr - the version string
        Returns:
        the maven version
        Throws:
        IllegalArgumentException - if the version cannot be parsed
      • from

        public static final MavenVersion from​(aQute.bnd.version.MavenVersion bndVer)
        Creates a new MavenVersion from a bnd MavenVersion. Propagates null values.
        Parameters:
        bndVer - the bnd maven version
        Returns:
        the maven version
      • toBndMavenVersion

        public static aQute.bnd.version.MavenVersion toBndMavenVersion​(MavenVersion version)
        Converts this version to a bnd MavenVersion. Propagates null pointers.
        Parameters:
        version - the version
        Returns:
        the bnd maven version
      • asBndMavenVersion

        public aQute.bnd.version.MavenVersion asBndMavenVersion()
        Converts this version to a bnd MavenVersion.
        Returns:
        the a qute.bnd.version. maven version
      • parseVersion

        public void parseVersion​(String version)
        This method is required by the ArtifactVersion interface. However, because instances of this class are intended to be immutable, it is not implemented. Use one of the other parse... methods instead.
        Specified by:
        parseVersion in interface org.apache.maven.artifact.versioning.ArtifactVersion
        Parameters:
        version - the version to parse
        Throws:
        UnsupportedOperationException - in any case
      • of

        public aQute.maven.api.Revision of​(aQute.maven.api.Program program)
        Combines this version with a program to a revision.
        Parameters:
        program - the program
        Returns:
        the revision
      • getMajorVersion

        public int getMajorVersion()
        Specified by:
        getMajorVersion in interface org.apache.maven.artifact.versioning.ArtifactVersion
      • getMinorVersion

        public int getMinorVersion()
        Specified by:
        getMinorVersion in interface org.apache.maven.artifact.versioning.ArtifactVersion
      • getIncrementalVersion

        public int getIncrementalVersion()
        Specified by:
        getIncrementalVersion in interface org.apache.maven.artifact.versioning.ArtifactVersion
      • getBuildNumber

        public int getBuildNumber()
        Specified by:
        getBuildNumber in interface org.apache.maven.artifact.versioning.ArtifactVersion
      • getQualifier

        public String getQualifier()
        Specified by:
        getQualifier in interface org.apache.maven.artifact.versioning.ArtifactVersion
      • getComparable

        public org.apache.maven.artifact.versioning.ComparableVersion getComparable()
        Gets the comparable.
        Returns:
        the comparable
      • getOsgiVersion

        public aQute.bnd.version.Version getOsgiVersion()
        Gets the osgi version.
        Returns:
        the osgi version
      • isSnapshot

        public boolean isSnapshot()
        If the qualifier ends with -SNAPSHOT or for an OSGI version with a qualifier that is SNAPSHOT.
        Returns:
        true, if is snapshot
      • compareTo

        public int compareTo​(org.apache.maven.artifact.versioning.ArtifactVersion other)
        Compares maven version numbers according to the rules defined in the POM reference.
        Specified by:
        compareTo in interface Comparable<org.apache.maven.artifact.versioning.ArtifactVersion>
        Parameters:
        other - the other
        Returns:
        the int
      • toSnapshot

        public MavenVersion toSnapshot​(long epoch,
                                       String build)
        To snapshot.
        Parameters:
        epoch - the epoch
        build - the build
        Returns:
        the maven version
      • toSnapshot

        public MavenVersion toSnapshot​(String timestamp,
                                       String build)
        To snapshot.
        Parameters:
        timestamp - the timestamp
        build - the build
        Returns:
        the maven version
      • toSnapshot

        public MavenVersion toSnapshot​(String dateStamp)
        To snapshot.
        Parameters:
        dateStamp - the date stamp
        Returns:
        the maven version
      • validate

        public static String validate​(String value)
        Validate.
        Parameters:
        value - the value
        Returns:
        the string
      • toDateStamp

        public static String toDateStamp​(long epoch)
        To date stamp.
        Parameters:
        epoch - the epoch
        Returns:
        the string
      • toDateStamp

        public static String toDateStamp​(long epoch,
                                         String build)
        To date stamp.
        Parameters:
        epoch - the epoch
        build - the build
        Returns:
        the string
      • cleanupVersion

        public static String cleanupVersion​(String version)
        Cleanup version.
        Parameters:
        version - the version
        Returns:
        the string