Semver: accept globs in metadataPattern; fix backpatch-style upgrades#7731
Merged
Conversation
`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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Semver.validateaccepts glob syntax formetadataPattern. 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 elsePattern.quoted) via the newStringUtils.globToRegex. Pure literals and existing regex patterns are unaffected.MavenDependency.findNewerVersionno 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 vianew LatestPatch(null).isValid(...).LatestRelease.comparebreaks ties lexicographically when both candidates' originals match the metadata pattern, so1.2.3+backpatch.001<1.2.3+backpatch.002instead of comparing equal. The HyphenRange behaviour where28-jreand28are equivalent under pattern-jreis 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+suffixartifact (e.g. emergency backpatch releases that retain the upstream patch level but add a build-metadata identifier for ordering).Test plan
SemverGlobMetadataTestcovers+backpatch*glob,+backpatch.00?glob, literal-jre, regex\\+backpatch\\..*, and a mixed regex/glob fallback case.LatestRelease,LatestPatch,HyphenRange,TildeRange,CaretRange,XRange,SetRange,LatestMinor,LatestIntegration, andSemvertests pass unchanged.rewrite-mavenUpgradeDependencyVersion/UpgradeTransitiveDependencyVersiontest suites pass.