Skip to content

Semver: accept globs in metadataPattern; fix backpatch-style upgrades#7731

Merged
jkschneider merged 1 commit into
mainfrom
semver-glob-metadata-pattern
May 19, 2026
Merged

Semver: accept globs in metadataPattern; fix backpatch-style upgrades#7731
jkschneider merged 1 commit into
mainfrom
semver-glob-metadata-pattern

Conversation

@jkschneider
Copy link
Copy Markdown
Member

Summary

  • Semver.validate accepts glob syntax for metadataPattern. Previously the pattern was compiled as a regex only, so simple inputs like +backpatch* failed validation. Now the validator tries regex first and, on failure, converts the pattern from glob (*.*, ?., everything else Pattern.quoted) via the new StringUtils.globToRegex. Pure literals and existing regex patterns are unaffected.
  • MavenDependency.findNewerVersion no longer short-circuits when the source version doesn't match the metadata pattern. The pattern is meant to filter target candidates, not the source. The semver-only base-version sanity check is preserved via new LatestPatch(null).isValid(...).
  • LatestRelease.compare breaks ties lexicographically when both candidates' originals match the metadata pattern, so 1.2.3+backpatch.001 < 1.2.3+backpatch.002 instead of comparing equal. The HyphenRange behaviour where 28-jre and 28 are equivalent under pattern -jre is preserved by the both-match guard.

Together these three fixes unblock recipes that upgrade dependencies from a base version with no build metadata to a M.N.P+suffix artifact (e.g. emergency backpatch releases that retain the upstream patch level but add a build-metadata identifier for ordering).

Test plan

  • New SemverGlobMetadataTest covers +backpatch* glob, +backpatch.00? glob, literal -jre, regex \\+backpatch\\..*, and a mixed regex/glob fallback case.
  • Existing LatestRelease, LatestPatch, HyphenRange, TildeRange, CaretRange, XRange, SetRange, LatestMinor, LatestIntegration, and Semver tests pass unchanged.
  • rewrite-maven UpgradeDependencyVersion / UpgradeTransitiveDependencyVersion test suites pass.

`Semver.validate` interpreted `metadataPattern` as a regex only, so simple
patterns like `+backpatch*` failed validation (`+` is a quantifier without
preceding atom). Now patterns are tried as regex first and, on failure,
converted from glob via the new `StringUtils.globToRegex`. Pure literal
patterns and existing regex patterns keep working unchanged.

Two related bugs blocking upgrades that *introduce* a build-metadata
suffix (e.g. `1.2.3` → `1.2.3+backpatch.001`) are fixed alongside:

- `MavenDependency.findNewerVersion` short-circuited via
  `versionComparator.isValid(currentVersion, currentVersion)`. Under
  `LatestPatch("+backpatch*")` that returns false because the *source*
  carries no metadata — but the pattern is meant to filter *target*
  candidates, not the source. Re-check using a metadata-pattern-free
  `LatestPatch(null)` so the source sanity-check stays semver-only.

- `LatestRelease.compare` returned 0 for any pair of metadata-stripped-
  equal versions, so `1.2.3+backpatch.001` and `1.2.3+backpatch.002`
  compared equal and no "latest" could be selected. When both originals
  match the metadata pattern, fall back to lexicographic comparison of
  the un-stripped strings. The HyphenRange behaviour where `28-jre` and
  `28` are equivalent under pattern `-jre` is preserved by the
  both-match guard.
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite May 19, 2026
@jkschneider jkschneider merged commit 4f40402 into main May 19, 2026
1 check failed
@jkschneider jkschneider deleted the semver-glob-metadata-pattern branch May 19, 2026 14:33
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant