diff --git a/model/src/main/kotlin/PackageCuration.kt b/model/src/main/kotlin/PackageCuration.kt index 4d86ba634a4e5..52197a8567501 100644 --- a/model/src/main/kotlin/PackageCuration.kt +++ b/model/src/main/kotlin/PackageCuration.kt @@ -21,7 +21,7 @@ package org.ossreviewtoolkit.model import com.fasterxml.jackson.annotation.JsonProperty -import org.ossreviewtoolkit.model.utils.isApplicableIvyVersion +import org.ossreviewtoolkit.model.utils.isApplicableVersionRangeFor /** * Return true if this string equals the [other] string, or if either string is blank. @@ -55,11 +55,11 @@ data class PackageCuration( /** * Return true if this [PackageCuration] is applicable to the package with the given [identifier][pkgId]. The * curation's version may be an - * [Ivy version matcher](http://ant.apache.org/ivy/history/2.4.0/settings/version-matchers.html). + * [Ivy, NPM, or CocoaPods version range](https://github.com/semver4j/semver4j?tab=readme-ov-file#external). */ fun isApplicable(pkgId: Identifier): Boolean = isApplicableDisregardingVersion(pkgId) - && (id.version.equalsOrIsBlank(pkgId.version) || id.isApplicableIvyVersion(pkgId)) + && (id.version.equalsOrIsBlank(pkgId.version) || id.isApplicableVersionRangeFor(pkgId)) /** * Apply the curation [data] to the provided [basePackage] by calling [PackageCurationData.apply], if applicable. diff --git a/model/src/main/kotlin/config/PackageConfiguration.kt b/model/src/main/kotlin/config/PackageConfiguration.kt index 5f9137e3069e1..b5ca996c7d8fe 100644 --- a/model/src/main/kotlin/config/PackageConfiguration.kt +++ b/model/src/main/kotlin/config/PackageConfiguration.kt @@ -30,7 +30,7 @@ import org.ossreviewtoolkit.model.RepositoryProvenance import org.ossreviewtoolkit.model.SourceCodeOrigin import org.ossreviewtoolkit.model.VcsInfo import org.ossreviewtoolkit.model.VcsType -import org.ossreviewtoolkit.model.utils.isApplicableIvyVersion +import org.ossreviewtoolkit.model.utils.isApplicableVersionRangeFor import org.ossreviewtoolkit.model.utils.isVersionRange import org.ossreviewtoolkit.utils.common.replaceCredentialsInUri @@ -44,7 +44,7 @@ data class PackageConfiguration( /** * The [Identifier] which must match with the identifier of the package in order for this package curation to apply. * The [version][Identifier.version] can be either a plain version string matched for equality, or an - * [Ivy-style version matchers](https://ant.apache.org/ivy/history/2.5.0/settings/version-matchers.html). + * [Ivy, NPM, or CocoaPods version range](https://github.com/semver4j/semver4j?tab=readme-ov-file#external). * The other components of the [identifier][id] are matched by equality. */ val id: Identifier, @@ -98,7 +98,7 @@ data class PackageConfiguration( if (!id.type.equals(otherId.type, ignoreCase = true) || id.namespace != otherId.namespace || id.name != otherId.name || - !id.isApplicableIvyVersion(otherId) + !id.isApplicableVersionRangeFor(otherId) ) { return false } diff --git a/model/src/main/kotlin/utils/VersionUtils.kt b/model/src/main/kotlin/utils/VersionUtils.kt index be7a7c8d45b5b..10a662a0e08e5 100644 --- a/model/src/main/kotlin/utils/VersionUtils.kt +++ b/model/src/main/kotlin/utils/VersionUtils.kt @@ -28,15 +28,10 @@ import org.semver4j.RangesListFactory import org.semver4j.Semver /** - * A list of Strings that are used by Ivy-style version ranges. + * Return true if the version of this [Identifier] interpreted as an Ivy, NPM or CocoaPods version range is applicable + * to the package with the given [identifier][pkgId]. */ -private val IVY_VERSION_RANGE_INDICATORS = listOf(",", "~", "*", "+", ">", "<", "=", " - ", "^", ".x", "||") - -/** - * Return true if the version of this [Identifier] interpreted as an Ivy version matcher is applicable to the - * package with the given [identifier][pkgId]. - */ -internal fun Identifier.isApplicableIvyVersion(pkgId: Identifier) = +internal fun Identifier.isApplicableVersionRangeFor(pkgId: Identifier) = runCatching { if (version == pkgId.version) return true @@ -66,7 +61,7 @@ internal fun Identifier.isVersionRange(): Boolean { } private fun Identifier.getVersionRanges(): RangesList? { - if (IVY_VERSION_RANGE_INDICATORS.none { version.contains(it, ignoreCase = true) }) return null + if (version.isEmpty()) return null return runCatching { RangesListFactory.create(version).takeUnless { it.get().isEmpty() } diff --git a/website/docs/configuration/package-configurations.md b/website/docs/configuration/package-configurations.md index 8e0b27f195b4e..785b62a1def19 100644 --- a/website/docs/configuration/package-configurations.md +++ b/website/docs/configuration/package-configurations.md @@ -14,7 +14,7 @@ Use a package configuration file to: ## Package Configuration File Basics A package configuration applies to the packages it matches with. -It contains the mandatory `id` matcher, for matching package IDs, which allows for using [Ivy-style version matchers](https://ant.apache.org/ivy/history/2.5.0/settings/version-matchers.html). +It contains the mandatory `id` matcher, for matching package IDs, which allows for using [Ivy, NPM, or CocoaPods version ranges](https://github.com/semver4j/semver4j?tab=readme-ov-file#external). In addition to the `id`, at most one of the matchers `vcs`, `sourceArtifactUrl` or `sourceCodeOrigin` may additionally be specified, which targets the repository provenance, the source artifact provenance or just the source code origin of the package's scan result(s).