Another Semantic Versioning 2.0.0 implementation for Java.
- implement lax parser
- validate pre-release & build identifiers
Version version = new Release(1, 0, 0); // creates 1.0.0
Given a current version v
, new versions are derived by
applying a decorator. The following matrix show the result of
each decorator for a given version (click the links on the decorators for more examples).
Decorator | 1.0.0 | 1.1.0 | 1.0.1 | 2.0.0-beta.1 | 1.1.0-beta.1 | 1.0.1-beta.1 |
---|---|---|---|---|---|---|
new NextMajor(v) |
2.0.0 | 2.0.0 | 2.0.0 | 2.0.0 | 2.0.0 | 2.0.0 |
new NextMinor(v) |
1.1.0 | 1.2.0 | 1.1.0 | 2.0.0 | 1.1.0 | 1.1.0 |
new NextPatch(v) |
1.0.1 | 1.1.1 | 1.0.2 | 2.0.0 | 1.1.0 | 1.0.1 |
new MajorPreRelease(v) |
2.0.0-alpha | 2.0.0-alpha | 2.0.0-alpha | 3.0.0-alpha | 2.0.0-alpha | 2.0.0-alpha |
new MinorPreRelease(v) |
1.1.0-alpha | 1.2.0-alpha | 1.1.0-alpha | 2.1.0-alpha | 1.2.0-alpha | 1.1.0-alpha |
new PatchPreRelease(v) |
1.0.1-alpha | 1.1.1-alpha | 1.0.2-alpha | 2.0.1-alpha | 1.1.1-alpha | 1.0.2-alpha |
new NextPreRelease(v) |
1.1.0-alpha | 1.2.0-alpha | 1.1.0-alpha | 2.0.0-beta.2 | 1.1.0-beta.2 | 1.0.1-beta.2 |
new MajorPreRelease(v, "beta") |
2.0.0-beta | 2.0.0-beta | 2.0.0-beta | 2.0.0-beta.2 | 2.0.0-beta | 2.0.0-beta |
new MinorPreRelease(v, "beta") |
1.1.0-beta | 1.2.0-beta | 1.1.0-beta | 2.0.0-beta.2 | 1.1.0-beta.2 | 1.1.0-beta.1 |
new PatchPreRelease(v, "beta") |
1.0.1-beta | 1.1.1-beta | 1.0.2-beta | 2.0.0-beta.2 | 1.1.0-beta.2 | 1.0.1-beta.2 |
new NextPreRelease(v, "beta") |
1.1.0-beta | 1.2.0-beta | 1.1.0-beta | 2.0.0-beta.2 | 1.1.0-beta.2 | 1.0.1-beta.2 |
Note, that some of these decorators exist in other variants with slightly different behavior. The Matrix shows the most common ones.
Also note, NextPreRelease
increases the pre-release version if there is one and creates a pre-release for the next
minor version otherwise.
The Version
implementations do only a single thing, represent a version. To get a CharSequence
representation you use a dedicated adapter class called VersionSequence
, on which you can call toString()
if you
need a String
CharSequence ver = new VersionSequence(version);
String verString = new VersionSequence(version).toString();
Copyright 2024 dmfs GmbH
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.