-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.in
70 lines (50 loc) · 1.96 KB
/
README.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
## verona
The `verona` package provides types implementing the
[Semantic Versioning](https://www.semver.org) specification.
## Features
* Types for representing versions and version ranges.
* Parsers for version numbers and version ranges.
* Written in pure Java 17.
* [OSGi](https://www.osgi.org/) ready.
* [JPMS](https://en.wikipedia.org/wiki/Java_Platform_Module_System) 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](https://www.osgi.org) 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";
```