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 MavenVersion
HIGHEST
The Constant HIGHEST.static MavenVersion
LOWEST
The Constant LOWEST.static String
SNAPSHOT
The snapshot identifier.static SimpleDateFormat
SNAPSHOT_TIMESTAMP
The usual format for a snapshot timestamp.static String
VERSION_STRING
The 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.MavenVersion
asBndMavenVersion()
Converts this version to a bndMavenVersion
.static String
cleanupVersion(String version)
Cleanup version.int
compareTo(org.apache.maven.artifact.versioning.ArtifactVersion other)
Compares maven version numbers according to the rules defined in the POM reference.boolean
equals(Object obj)
static MavenVersion
from(aQute.bnd.version.MavenVersion bndVer)
Creates a newMavenVersion
from a bndMavenVersion
.static MavenVersion
from(String maven)
Creates a newMavenVersion
from a the given representation, seeMavenVersion(String)
.int
getBuildNumber()
org.apache.maven.artifact.versioning.ComparableVersion
getComparable()
Gets the comparable.int
getIncrementalVersion()
int
getMajorVersion()
int
getMinorVersion()
aQute.bnd.version.Version
getOsgiVersion()
Gets the osgi version.String
getQualifier()
int
hashCode()
boolean
isSnapshot()
If the qualifier ends with -SNAPSHOT or for an OSGI version with a qualifier that is SNAPSHOT.aQute.maven.api.Revision
of(aQute.maven.api.Program program)
Combines this version with a program to a revision.static MavenVersion
parseMavenString(String versionStr)
Similar toparseString(String)
, but returnsnull
if the version cannot be parsed.static MavenVersion
parseString(String versionStr)
Parses the string as a maven version, but allows a dot as separator before the qualifier.void
parseVersion(String version)
This method is required by theArtifactVersion
interface.static aQute.bnd.version.MavenVersion
toBndMavenVersion(MavenVersion version)
Converts this version to a bndMavenVersion
.static String
toDateStamp(long epoch)
To date stamp.static String
toDateStamp(long epoch, String build)
To date stamp.MavenVersion
toSnapshot()
To snapshot.MavenVersion
toSnapshot(long epoch, String build)
To snapshot.MavenVersion
toSnapshot(String dateStamp)
To snapshot.MavenVersion
toSnapshot(String timestamp, String build)
To snapshot.String
toString()
static String
validate(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 returnsnull
if the version cannot be parsed.- Parameters:
versionStr
- the version string- Returns:
- the maven version
-
from
public static final MavenVersion from(String maven)
Creates a newMavenVersion
from 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
. Propagatesnull
pointers.- 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 theArtifactVersion
interface. However, because instances of this class are intended to be immutable, it is not implemented. Use one of the otherparse...
methods instead.- Specified by:
parseVersion
in 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:
getMajorVersion
in interfaceorg.apache.maven.artifact.versioning.ArtifactVersion
-
getMinorVersion
public int getMinorVersion()
- Specified by:
getMinorVersion
in interfaceorg.apache.maven.artifact.versioning.ArtifactVersion
-
getIncrementalVersion
public int getIncrementalVersion()
- Specified by:
getIncrementalVersion
in interfaceorg.apache.maven.artifact.versioning.ArtifactVersion
-
getBuildNumber
public int getBuildNumber()
- Specified by:
getBuildNumber
in interfaceorg.apache.maven.artifact.versioning.ArtifactVersion
-
getQualifier
public String getQualifier()
- Specified by:
getQualifier
in 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:
compareTo
in 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
-
-