Version handling#277
Conversation
PrismUtils.compareVersions now respects standard semantic versioning, e.g., 2 < 2.1 < 2.1.1-dev < 2.1.1-alpha < 2.1.1-beta < 2.1.1. Previously . was parsed but not - Comparison also respects legacy PRISM use of ".dev" where 2.1.1 < 2.1.1.dev.
Usage: src/scripts/bump_version.sh 4.10.2 "" (for a clean release) Usage: src/scripts/bump_version.sh 4.10.2 dev
There was a problem hiding this comment.
Pull request overview
This PR refactors PRISM version-string comparison into a dedicated VersionUtils helper, updates the displayed version suffix separator to -, bumps the PRISM version, and adds a script to automate version updates.
Changes:
- Added
VersionUtils.compareVersions()and switchedPrismUtils.compareVersions()to delegate to it. - Updated version formatting to use
-<suffix>and bumpedVersion.versionStringto4.10.2(suffixdev). - Expanded
PrismUtilsTestversion comparison coverage and introduced abump_version.shhelper script.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| prism/unit-tests/prism/PrismUtilsTest.java | Updates version comparison tests to cover new dash/dot and legacy .dev behaviors. |
| prism/src/scripts/bump_version.sh | Adds a script to update Version.java version/suffix values. |
| prism/src/prism/VersionUtils.java | Introduces the new version parsing/comparison implementation. |
| prism/src/prism/Version.java | Bumps the version number to 4.10.2. |
| prism/src/prism/PrismUtils.java | Replaces the old inline version comparison logic with a call to VersionUtils. |
| prism/src/prism/Prism.java | Changes version suffix separator from . to - in getVersion(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| VersionPart p2 = parseVersionPart(i < ss2.length ? ss2[i] : ""); | ||
| int cmp = p1.compareTo(p2); | ||
| if (cmp != 0) { | ||
| return cmp; |
There was a problem hiding this comment.
compareVersions is documented to return only -1/0/1, but it currently returns the raw VersionPart.compareTo() result. If any unrecognised segment falls back to TEXT, String.compareTo() can return values other than -1/0/1, which can break callers that check for == -1 (e.g. settings version checks). Normalize the result before returning (e.g. Integer.compare(cmp, 0) / Integer.signum(cmp)).
| return cmp; | |
| return Integer.signum(cmp); |
|
|
||
| NEW_VERSION=$1 | ||
| NEW_SUFFIX=$2 | ||
| FILE="src/prism/Version.java" |
There was a problem hiding this comment.
The script assumes it is run with the working directory set so that src/prism/Version.java resolves correctly. Consider resolving Version.java relative to the script location (and/or accepting an optional PRISM src dir argument like printversion.sh) so it works reliably when invoked from other directories (e.g. repo root/CI).
| FILE="src/prism/Version.java" | |
| SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | |
| FILE="$SCRIPT_DIR/../prism/Version.java" |
| echo "Bumping $FILE to $NEW_VERSION (suffix: '$NEW_SUFFIX')..." | ||
|
|
||
| sed -i "" "s/public static String $VERSION_STRING = \".*\";/public static String $VERSION_STRING = \"$NEW_VERSION\";/" "$FILE" | ||
|
|
||
| sed -i "" "s/public static String $SUFFIX_STRING = \".*\";/public static String $SUFFIX_STRING = \"$NEW_SUFFIX\";/" "$FILE" | ||
|
|
There was a problem hiding this comment.
sed -i "" usage is not consistently portable across sed implementations, and the script doesn’t fail fast if the substitutions don’t match. Consider using a more portable in-place edit approach (e.g. create a temp file / use a backup suffix and remove it), and check the exit status so version bumps don’t silently do nothing.
| public static String getVersion() | ||
| { | ||
| String v = version; | ||
| // Append version suffix (e.g. "dev", "beta") if non-empty | ||
| if (versionSuffix.length() > 0) { | ||
| v += "." + versionSuffix; | ||
| v += "-" + versionSuffix; | ||
| } |
There was a problem hiding this comment.
getVersion() now uses - as the suffix separator, but src/scripts/printversion.sh still appends suffixes using . even though it claims to mirror prism.getVersion(). This will cause inconsistent version strings between the Java runtime and the helper script; update printversion.sh (or its comment/output format) to match the new scheme.
compareVersions is documented to return only -1/0/1, but it currently returns the raw VersionPart.compareTo() result. If any unrecognised segment falls back to TEXT, String.compareTo() can return values other than -1/0/1, which can break callers that check for == -1 (e.g. settings version checks). Normalize the result before returning with Integer.signum(cmp).
This pull request introduces a new, robust implementation for PRISM version string comparison, refactoring the old logic into a dedicated utility class and expanding test coverage. It also updates the versioning scheme to use a dash (
-) separator for suffixes, bumps the version, and adds a script to automate version updates.Key changes:
Version Comparison Refactor and Improvements
VersionUtilsclass (prism/src/prism/VersionUtils.java) that implements a comprehensive and semver-inspired algorithm for comparing PRISM version strings, handling both legacy and modern conventions, including.devvs-devdistinctions and supporting both dot and dash separators.PrismUtils.compareVersionsto delegate toVersionUtils.compareVersions, removing the old, complex in-line logic.PrismUtilsTestto cover new and legacy versioning cases, including dash vs dot separators,.devvs.post, and more nuanced scenarios.Versioning Scheme and Automation
Prism.javafrom a dot (.) to a dash (-), aligning with standard semantic versioning practices (e.g.,4.10.2-alphainstead of4.10.2.alpha).Version.javato4.10.2with the suffixdev.bump_version.shto automate updating the version and suffix inVersion.java.