Skip to content

Commit

Permalink
feat(ort-utils): Find names even if the version has an (ignorable) su…
Browse files Browse the repository at this point in the history
…ffix

So far ignorable suffixes were only ignored from the given (tag) names.
Extend the logic to also ignore them from the given version.

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Dec 15, 2023
1 parent 96d87c0 commit cd8e1bf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion utils/ort/src/main/kotlin/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ var printStackTrace = false
private val versionSeparators = listOf('-', '_', '.')
private val versionSeparatorsPattern = versionSeparators.joinToString("", "[", "]")

private val ignorablePrefixSuffixPattern = listOf("rel", "release", "final").joinToString("|", "(", ")")
private val ignorablePrefixSuffix = listOf("rel", "release", "final")
private val ignorablePrefixSuffixPattern = ignorablePrefixSuffix.joinToString("|", "(", ")")
private val ignorablePrefixSuffixRegex = Regex(
"(^$ignorablePrefixSuffixPattern$versionSeparatorsPattern|$versionSeparatorsPattern$ignorablePrefixSuffixPattern$)"
)
Expand All @@ -63,6 +64,10 @@ fun filterVersionNames(version: String, names: List<String>, project: String? =
VersionVariant(versionLower.replace(separatorRegex, it.toString()), listOf(it))
}

ignorablePrefixSuffix.mapTo(versionVariants) {
VersionVariant(versionLower.removeSuffix(it).trimEnd(*versionSeparators.toCharArray()), versionSeparators)
}

// The list of supported version separators.
val versionHasSeparator = versionSeparators.any { it in version }

Expand Down
10 changes: 10 additions & 0 deletions utils/ort/src/test/kotlin/UtilsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,16 @@ class UtilsTest : WordSpec({

filterVersionNames("3.9.0.99", names).shouldContainExactly("3.9.0.99-a3d9827", "sdk-3.9.0.99", "v3.9.0.99")
}

"find names that match the version without an ignorable suffix" {
val names = listOf(
"6.2.8",
"6.2.9",
"6.2.10"
)

filterVersionNames("6.2.9.Final", names).shouldContainExactly("6.2.9")
}
}

"normalizeVcsUrl" should {
Expand Down

0 comments on commit cd8e1bf

Please sign in to comment.