Skip to content

io7m-com/verona

Repository files navigation

verona

Maven Central Maven Central (snapshot) Codecov Java Version

com.io7m.verona

JVM Platform Status
OpenJDK (Temurin) Current Linux Build (OpenJDK (Temurin) Current, Linux)
OpenJDK (Temurin) LTS Linux Build (OpenJDK (Temurin) LTS, Linux)
OpenJDK (Temurin) Current Windows Build (OpenJDK (Temurin) Current, Windows)
OpenJDK (Temurin) LTS Windows Build (OpenJDK (Temurin) LTS, Windows)

verona

The verona package provides types implementing the Semantic Versioning specification.

Features

  • Types for representing versions and version ranges.
  • Parsers for version numbers and version ranges.
  • Written in pure Java 17.
  • OSGi ready.
  • JPMS ready.
  • ISC license.
  • High-coverage automated test suite.

Description

Types

The verona package contains types for representing versions and version ranges.

assert Version.of(1, 0, 2).toString() == "1.0.2";
assert Version.of(2, 3, 1, "SNAPSHOT").toString() == "2.3.1-SNAPSHOT";
assert Version.of(3, 0, 0, "SNAPSHOT").toString() == "2.3.1-SNAPSHOT";

Values of type Version are comparable and are ordered such that version number components are treated as unsigned values and, for two versions x and y:

Comparator.comparing(Version::major, COMPARE_UNSIGNED)
  .thenComparing(Version::minor, COMPARE_UNSIGNED)
  .thenComparing(Version::patch, COMPARE_UNSIGNED)
  .thenComparing(Version::qualifier, COMPARE_QUALIFIER)
  .compare(x, y);

For a given version x.y.z, the version x.y.z-q is considered less than x.y.z for any q.

Parsing

Version numbers can be parsed:

assert VersionParser.parse("1.0.2").toString() == "1.0.2";

Parsing is strict by default. This means that exactly three version number components must be provided, along with an optional qualifier. Support is provided for lax parsing that allows for missing components. For example:

assert VersionParser.parse("1.2.0").toString() == "1.2.0";

VersionParser.parse("1.2"); // throws VersionException

assert VersionParser.parseLax("1.2").toString() == "1.2.0";

Additional support is provided for OSGi version numbers where the qualifier is separated with a dot instead of a hyphen:

assert VersionParser.parseOSGi("1.2.0.SNAPSHOT").toString() == "1.2.0-SNAPSHOT";