EN · DE · RU · FR · ES

#1874: Version.java

projectforge-common/src/main/java/org/projectforge/Version.java Domain class — org.projectforge package, projectforge-common/src/main/java/org/projectforge/Version.java 314 lines · 223 code · 63 comments · 28 blank
Semantic version number representation and comparison class. Parses version strings in formats #.#.#.# with optional b{beta}, rc{release-candidate}, and -SNAPSHOT suffixes. Implements Comparable<Version> for correct ordering (release > RC > beta, with numeric sub-comparison). Used throughout ProjectForge for plugin compatibility checks and database migration versioning.

Architecture

Imports

Class Hierarchy

Version implements Comparable<Version>, Serializable

Version Components

ComponentFieldDefault/Unset ValueExample
Major releasemajorRelease03.5.4.2 → major=3
Minor releaseminorRelease03.5.4.2 → minor=5
Patch levelpatchLevel03.5.4.2 → patch=4
Build numberbuildNumber03.5.4.2 → build=2
Beta versionbetaVersionInteger.MAX_VALUE (not beta)3.5b2 → beta=2
RC versionreleaseCandidateVersionInteger.MAX_VALUE (not RC)3.5rc1 → rc=1
Snapshot flagsnapshotfalse3.5-SNAPSHOT

Parsing Format

The string constructor accepts these patterns (case-insensitive for suffixes):

Comparison Logic (compareTo)

The comparison follows a strict hierarchy:

  1. Major release → Minor release → Patch level → Build number (numeric comparison)
  2. Release vs Pre-release: If versions differ in pre-release status:
    • Normal release is HIGHER than RC
    • RC is HIGHER than beta
    • Beta is LOWER than normal release
  3. If both are RC: compare RC version numbers
  4. If both are beta: compare beta version numbers

This ordering ensures: 3.5b1 < 3.5rc1 < 3.5 — critical for determining whether a database migration or plugin upgrade is needed.

Special Handling: Gradle Placeholder

The parseInt() method detects the Gradle unexpanded token "gradle.version" and treats it as 0, logging a warning. This handles the case where version information is compiled into a JAR at build time and the Gradle version property hasn't been resolved yet (e.g., in IDE test runs).

toString() Format

The use of Integer.MAX_VALUE as the sentinel for "not beta/RC" is an elegant design decision. It ensures that in numeric comparison, a non-beta version always compares as higher than any beta version (since MAX_VALUE is the largest possible integer), while still allowing direct numeric comparison when both are beta/RC.
The compareTo method does NOT consider the snapshot flag in ordering. Two versions differing only by snapshot status (e.g., "3.5" vs "3.5-SNAPSHOT") would compare as equal. This may be intentional — snapshots indicate build-time metadata rather than semantic version differences.

Git History

868d6abb7 2025 -> 2026
63081666f Source file headers: 2024-> 2025.
0237d5eba Json serialization refactored: IdOnlySerializer and IdsOnlySerializer introduced.
6f7e0fbc7 Migration stuff in progress...
b6092df09 Copyright 2023 -> 2024
ab45d51fa Copyright 2001-2022 -> 2001-2023.
5f7ef41b8 Copyright 2021 -> 2022
ceb63e8a1 Source code header: (C) 2001-2021.