Class MavenVersion
- java.lang.Object
 - 
- de.mnl.osgi.bnd.maven.MavenVersionSpecification
 - 
- de.mnl.osgi.bnd.maven.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 fromArtifactVersion, i.e. from the version as implemented by maven. 
- 
- 
Field Summary
Fields Modifier and Type Field Description static MavenVersionHIGHESTThe Constant HIGHEST.static MavenVersionLOWESTThe Constant LOWEST.static StringSNAPSHOTThe snapshot identifier.static SimpleDateFormatSNAPSHOT_TIMESTAMPThe usual format for a snapshot timestamp.static StringVERSION_STRINGThe usual format of a verson string. 
- 
Constructor Summary
Constructors Constructor Description MavenVersion(aQute.bnd.version.Version osgiVersion)Creates a new maven version from an osgi version.MavenVersion(aQute.bnd.version.Version osgiVersion, String literal, boolean isSnapshot)Creates a new maven version from an osgi version and an unparsed literal.MavenVersion(String maven)Creates a new instance. 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description aQute.bnd.version.MavenVersionasBndMavenVersion()Converts this version to a bndMavenVersion.static StringcleanupVersion(String version)Cleanup version.intcompareTo(org.apache.maven.artifact.versioning.ArtifactVersion other)Compares maven version numbers according to the rules defined in the POM reference.booleanequals(Object obj)static MavenVersionfrom(aQute.bnd.version.MavenVersion bndVer)Creates a newMavenVersionfrom a bndMavenVersion.static MavenVersionfrom(String maven)Creates a newMavenVersionfrom a the given representation, seeMavenVersion(String).intgetBuildNumber()org.apache.maven.artifact.versioning.ComparableVersiongetComparable()Gets the comparable.intgetIncrementalVersion()intgetMajorVersion()intgetMinorVersion()aQute.bnd.version.VersiongetOsgiVersion()Gets the osgi version.StringgetQualifier()inthashCode()booleanisSnapshot()If the qualifier ends with -SNAPSHOT or for an OSGI version with a qualifier that is SNAPSHOT.aQute.maven.api.Revisionof(aQute.maven.api.Program program)Combines this version with a program to a revision.static MavenVersionparseMavenString(String versionStr)Similar toparseString(String), but returnsnullif the version cannot be parsed.static MavenVersionparseString(String versionStr)Parses the string as a maven version, but allows a dot as separator before the qualifier.voidparseVersion(String version)This method is required by theArtifactVersioninterface.static aQute.bnd.version.MavenVersiontoBndMavenVersion(MavenVersion version)Converts this version to a bndMavenVersion.static StringtoDateStamp(long epoch)To date stamp.static StringtoDateStamp(long epoch, String build)To date stamp.MavenVersiontoSnapshot()To snapshot.MavenVersiontoSnapshot(long epoch, String build)To snapshot.MavenVersiontoSnapshot(String dateStamp)To snapshot.MavenVersiontoSnapshot(String timestamp, String build)To snapshot.StringtoString()static Stringvalidate(String value)Validate.- 
Methods inherited from class de.mnl.osgi.bnd.maven.MavenVersionSpecification
isRange 
 - 
 
 - 
 
- 
- 
Field Detail
- 
VERSION_STRING
public static final String VERSION_STRING
The usual format of a verson string.- See Also:
 - Constant Field Values
 
 
- 
SNAPSHOT_TIMESTAMP
public static final SimpleDateFormat SNAPSHOT_TIMESTAMP
The usual format for a snapshot timestamp. 
- 
SNAPSHOT
public static final String SNAPSHOT
The snapshot identifier.- See Also:
 - Constant Field Values
 
 
- 
HIGHEST
public static final MavenVersion HIGHEST
The Constant HIGHEST. 
- 
LOWEST
public static final MavenVersion LOWEST
The Constant LOWEST. 
 - 
 
- 
Constructor Detail
- 
MavenVersion
public MavenVersion(String maven)
Creates a new instance. The maven version is parsed by an instance ofDefaultArtifactVersion. 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 versionliteral- the literalisSnapshot- 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
 
- 
parseMavenString
public static final MavenVersion parseMavenString(String versionStr)
Similar toparseString(String), but returnsnullif the version cannot be parsed.- Parameters:
 versionStr- the version string- Returns:
 - the maven version
 
 
- 
from
public static final MavenVersion from(String maven)
Creates a newMavenVersionfrom a the given representation, seeMavenVersion(String).- Parameters:
 maven- the maven version string- Returns:
 - the maven version
 
 
- 
from
public static final MavenVersion from(aQute.bnd.version.MavenVersion bndVer)
- 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 bndMavenVersion. Propagatesnullpointers.- Parameters:
 version- the version- Returns:
 - the bnd maven version
 
 
- 
asBndMavenVersion
public aQute.bnd.version.MavenVersion asBndMavenVersion()
Converts this version to a bndMavenVersion.- Returns:
 - the a qute.bnd.version. maven version
 
 
- 
parseVersion
public void parseVersion(String version)
This method is required by theArtifactVersioninterface. However, because instances of this class are intended to be immutable, it is not implemented. Use one of the otherparse...methods instead.- Specified by:
 parseVersionin interfaceorg.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:
 getMajorVersionin interfaceorg.apache.maven.artifact.versioning.ArtifactVersion
 
- 
getMinorVersion
public int getMinorVersion()
- Specified by:
 getMinorVersionin interfaceorg.apache.maven.artifact.versioning.ArtifactVersion
 
- 
getIncrementalVersion
public int getIncrementalVersion()
- Specified by:
 getIncrementalVersionin interfaceorg.apache.maven.artifact.versioning.ArtifactVersion
 
- 
getBuildNumber
public int getBuildNumber()
- Specified by:
 getBuildNumberin interfaceorg.apache.maven.artifact.versioning.ArtifactVersion
 
- 
getQualifier
public String getQualifier()
- Specified by:
 getQualifierin interfaceorg.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:
 compareToin interfaceComparable<org.apache.maven.artifact.versioning.ArtifactVersion>- Parameters:
 other- the other- Returns:
 - the int
 
 
- 
toSnapshot
public MavenVersion toSnapshot()
To snapshot.- Returns:
 - the maven version
 
 
- 
toSnapshot
public MavenVersion toSnapshot(long epoch, String build)
To snapshot.- Parameters:
 epoch- the epochbuild- the build- Returns:
 - the maven version
 
 
- 
toSnapshot
public MavenVersion toSnapshot(String timestamp, String build)
To snapshot.- Parameters:
 timestamp- the timestampbuild- 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 epochbuild- the build- Returns:
 - the string
 
 
- 
cleanupVersion
public static String cleanupVersion(String version)
Cleanup version.- Parameters:
 version- the version- Returns:
 - the string
 
 
 - 
 
 -