Skip to content

Commit aef4fe4

Browse files
nnobelisfviernau
authored andcommitted
feat(PurlUtils): Add optional parameters to toPurl
The commit 7da5ae9 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 <[email protected]>
1 parent 7d67ffb commit aef4fe4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,18 @@ fun Identifier.getPurlType() =
8686
* Create the canonical [package URL](https://github.com/package-url/purl-spec) ("purl") based on the properties of
8787
* the [Identifier]. Some issues remain with this specification
8888
* (see e.g. https://github.com/package-url/purl-spec/issues/33).
89+
* Optional [qualifiers] may be given and will be appended to the purl as query parameters e.g.
90+
* pkg:deb/debian/[email protected]?arch=i386&distro=jessie
91+
* Optional [subpath] may be given and will be appended to the purl e.g.
92+
* pkg:golang/google.golang.org/genproto#googleapis/api/annotations
8993
*
9094
* This implementation uses the package type as 'type' purl element as it is used
9195
* [in the documentation](https://github.com/package-url/purl-spec/blob/master/README.rst#purl).
9296
* E.g. 'maven' for Gradle projects.
9397
*/
94-
fun Identifier.toPurl() = if (this == Identifier.EMPTY) "" else createPurl(getPurlType(), namespace, name, version)
98+
@JvmOverloads
99+
fun Identifier.toPurl(qualifiers: Map<String, String> = emptyMap(), subpath: String = "") =
100+
if (this == Identifier.EMPTY) "" else createPurl(getPurlType(), namespace, name, version, qualifiers, subpath)
95101

96102
/**
97103
* Create the canonical [package URL](https://github.com/package-url/purl-spec) ("purl") based on given properties:

0 commit comments

Comments
 (0)