From a6f03c3fe56a62bb8e88427f6b66577f00cee019 Mon Sep 17 00:00:00 2001 From: Nicolas Nobelis Date: Fri, 29 Sep 2023 11:20:09 +0200 Subject: [PATCH] feat(PurlUtils): Add optional parameters to `toPurl` The commit 7da5ae93 changed the visibility of `createPurl`, `toPurl` has become the only public ORT function for plugins to generate Purls. Since this function does not support qualifiers nor subpath, these two parameters have to be added to the function signature with default values. The `JvmOverloads` annotation is used to make this function with default parameters compatible with calls coming from FreeMarker templates. Signed-off-by: Nicolas Nobelis --- model/src/main/kotlin/utils/PurlUtils.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/model/src/main/kotlin/utils/PurlUtils.kt b/model/src/main/kotlin/utils/PurlUtils.kt index 448b922890d07..987ed8609a46e 100644 --- a/model/src/main/kotlin/utils/PurlUtils.kt +++ b/model/src/main/kotlin/utils/PurlUtils.kt @@ -86,12 +86,18 @@ fun Identifier.getPurlType() = * Create the canonical [package URL](https://github.com/package-url/purl-spec) ("purl") based on the properties of * the [Identifier]. Some issues remain with this specification * (see e.g. https://github.com/package-url/purl-spec/issues/33). + * Optional [qualifiers] may be given and will be appended to the purl as query parameters e.g. + * pkg:deb/debian/curl@7.50.3-1?arch=i386&distro=jessie + * Optional [subpath] may be given and will be appended to the purl e.g. + * pkg:golang/google.golang.org/genproto#googleapis/api/annotations * * This implementation uses the package type as 'type' purl element as it is used * [in the documentation](https://github.com/package-url/purl-spec/blob/master/README.rst#purl). * E.g. 'maven' for Gradle projects. */ -fun Identifier.toPurl() = if (this == Identifier.EMPTY) "" else createPurl(getPurlType(), namespace, name, version) +@JvmOverloads +fun Identifier.toPurl(qualifiers: Map = emptyMap(), subpath: String = "") = + if (this == Identifier.EMPTY) "" else createPurl(getPurlType(), namespace, name, version, qualifiers, subpath) /** * Create the canonical [package URL](https://github.com/package-url/purl-spec) ("purl") based on given properties: