Skip to content

Commit ef58233

Browse files
committed
fix(model): Stop throwing accidentally from an invariant check
The previous implementation of `Identifier.isVersionRange()` returned true if and only if the version string contained characters hard-coded to be a version range indicator, see the constant `IVY_VERSION_RANGE_INDICATORS`. This heuristic returns false positives for versions which are not a version range, but contain version range indicators, such as for the package `Crate::wasi:0.13.3+wasi-0.2.2`. Such false positives in turn make the recently introduced invariant check in the constructor of `PackageConfiguration` fail accidentally. Improve the heuristic of `Identifier.isVersionRange()` to fix that. Signed-off-by: Frank Viernau <[email protected]>
1 parent 9af797d commit ef58233

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

model/src/main/kotlin/utils/VersionUtils.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,17 @@ internal fun Identifier.isApplicableIvyVersion(pkgId: Identifier) =
5454
it.showStackTrace()
5555
}.getOrDefault(false)
5656

57-
internal fun Identifier.isVersionRange() = IVY_VERSION_RANGE_INDICATORS.any { version.contains(it, ignoreCase = true) }
57+
internal fun Identifier.isVersionRange(): Boolean {
58+
val rangesList = getVersionRange() ?: return false
59+
val ranges = rangesList.get().flatten()
60+
val rangeVersions = ranges.mapTo(mutableSetOf()) { it.rangeVersion }
61+
val isSingleVersion = rangeVersions.size <= 1 && ranges.all { range ->
62+
// Determine whether the non-accessible `Range.rangeOperator` is `RangeOperator.EQUALS`.
63+
range.toString().startsWith("=")
64+
}
65+
66+
return !isSingleVersion
67+
}
5868

5969
private fun Identifier.getVersionRange(): RangesList? {
6070
if (IVY_VERSION_RANGE_INDICATORS.none { version.contains(it, ignoreCase = true) }) return null

model/src/test/kotlin/config/PackageConfigurationTest.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,5 +208,12 @@ class PackageConfigurationTest : WordSpec({
208208
)
209209
}
210210
}
211+
212+
"not throw if a version range with a range indicator is given while having a source artifact URL" {
213+
PackageConfiguration(
214+
id = Identifier.EMPTY.copy(version = "0.13.3+wasi-0.2.2"),
215+
sourceArtifactUrl = "https://host/path/file.zip"
216+
)
217+
}
211218
}
212219
})

0 commit comments

Comments
 (0)