@@ -21,17 +21,7 @@ package org.ossreviewtoolkit.model
21
21
22
22
import com.fasterxml.jackson.annotation.JsonProperty
23
23
24
- import org.apache.logging.log4j.kotlin.logger
25
-
26
- import org.ossreviewtoolkit.utils.ort.showStackTrace
27
-
28
- import org.semver4j.RangesListFactory
29
- import org.semver4j.Semver
30
-
31
- /* *
32
- * A list of Strings that are used to identify a version string as a version range in the [PackageCuration]'s version.
33
- */
34
- private val versionRangeIndicators = listOf (" ," , " ~" , " *" , " +" , " >" , " <" , " =" , " - " , " ^" , " .x" , " ||" )
24
+ import org.ossreviewtoolkit.model.utils.isApplicableIvyVersion
35
25
36
26
/* *
37
27
* Return true if this string equals the [other] string, or if either string is blank.
@@ -62,45 +52,14 @@ data class PackageCuration(
62
52
&& id.namespace == pkgId.namespace
63
53
&& id.name.equalsOrIsBlank(pkgId.name)
64
54
65
- /* *
66
- * Return true if the version of this [PackageCuration] interpreted as an Ivy version matcher is applicable to the
67
- * package with the given [identifier][pkgId].
68
- */
69
- private fun isApplicableIvyVersion (pkgId : Identifier ) =
70
- runCatching {
71
- if (id.version == pkgId.version) return true
72
-
73
- if (id.version.isVersionRange()) {
74
- // `Semver.satisfies(String)` requires a valid version range to work as expected, see:
75
- // https://github.com/semver4j/semver4j/issues/132.
76
- val range = RangesListFactory .create(id.version)
77
- require(range.get().isNotEmpty()) {
78
- " '${id.version} ' is not a valid version range."
79
- }
80
-
81
- return Semver .coerce(pkgId.version)?.satisfies(range) == true
82
- }
83
-
84
- return false
85
- }.onFailure {
86
- logger.warn {
87
- " Failed to check if package curation version '${id.version} ' is applicable to package version " +
88
- " '${pkgId.version} ' of package '${pkgId.toCoordinates()} '."
89
- }
90
-
91
- it.showStackTrace()
92
- }.getOrDefault(false )
93
-
94
- private fun String.isVersionRange () = versionRangeIndicators.any { contains(it, ignoreCase = true ) }
95
-
96
55
/* *
97
56
* Return true if this [PackageCuration] is applicable to the package with the given [identifier][pkgId]. The
98
57
* curation's version may be an
99
58
* [Ivy version matcher](http://ant.apache.org/ivy/history/2.4.0/settings/version-matchers.html).
100
59
*/
101
60
fun isApplicable (pkgId : Identifier ): Boolean =
102
61
isApplicableDisregardingVersion(pkgId)
103
- && (id.version.equalsOrIsBlank(pkgId.version) || isApplicableIvyVersion(pkgId))
62
+ && (id.version.equalsOrIsBlank(pkgId.version) || id. isApplicableIvyVersion(pkgId))
104
63
105
64
/* *
106
65
* Apply the curation [data] to the provided [basePackage] by calling [PackageCurationData.apply], if applicable.
0 commit comments