Skip to content

Version handling#277

Merged
davexparker merged 7 commits into
prismmodelchecker:masterfrom
davexparker:versions
Apr 10, 2026
Merged

Version handling#277
davexparker merged 7 commits into
prismmodelchecker:masterfrom
davexparker:versions

Conversation

@davexparker
Copy link
Copy Markdown
Member

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

  • Introduced a new VersionUtils class (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 .dev vs -dev distinctions and supporting both dot and dash separators.
  • Refactored PrismUtils.compareVersions to delegate to VersionUtils.compareVersions, removing the old, complex in-line logic.
  • Updated and expanded unit tests in PrismUtilsTest to cover new and legacy versioning cases, including dash vs dot separators, .dev vs .post, and more nuanced scenarios.

Versioning Scheme and Automation

  • Changed the version suffix separator in Prism.java from a dot (.) to a dash (-), aligning with standard semantic versioning practices (e.g., 4.10.2-alpha instead of 4.10.2.alpha).
  • Bumped the version in Version.java to 4.10.2 with the suffix dev.
  • Added a new script bump_version.sh to automate updating the version and suffix in Version.java.

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
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 switched PrismUtils.compareVersions() to delegate to it.
  • Updated version formatting to use -<suffix> and bumped Version.versionString to 4.10.2 (suffix dev).
  • Expanded PrismUtilsTest version comparison coverage and introduced a bump_version.sh helper 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.

Comment thread prism/src/prism/VersionUtils.java Outdated
VersionPart p2 = parseVersionPart(i < ss2.length ? ss2[i] : "");
int cmp = p1.compareTo(p2);
if (cmp != 0) {
return cmp;
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)).

Suggested change
return cmp;
return Integer.signum(cmp);

Copilot uses AI. Check for mistakes.

NEW_VERSION=$1
NEW_SUFFIX=$2
FILE="src/prism/Version.java"
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
FILE="src/prism/Version.java"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
FILE="$SCRIPT_DIR/../prism/Version.java"

Copilot uses AI. Check for mistakes.
Comment on lines +21 to +26
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"

Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines 829 to 835
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;
}
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
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).
@davexparker davexparker merged commit 3023ec1 into prismmodelchecker:master Apr 10, 2026
6 checks passed
@davexparker davexparker deleted the versions branch April 10, 2026 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants