Skip to content

Commit

Permalink
feat(PurlUtils): Add optional parameters to toPurl
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
nnobelis committed Oct 2, 2023
1 parent 0057704 commit a6f03c3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion model/src/main/kotlin/utils/PurlUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]?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<String, String> = emptyMap(), subpath: String = "") =

Check warning on line 99 in model/src/main/kotlin/utils/PurlUtils.kt

View check run for this annotation

Codecov / codecov/patch

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

Added line #L99 was not covered by tests
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:
Expand Down

0 comments on commit a6f03c3

Please sign in to comment.