Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(PurlUtils): Add optional parameters to toPurl #7601

Merged

Conversation

nnobelis
Copy link
Member

@nnobelis nnobelis commented Sep 29, 2023

The commit boschglobal@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.

@codecov
Copy link

codecov bot commented Sep 29, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (0057704) 68.03% compared to head (a6f03c3) 68.02%.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #7601      +/-   ##
============================================
- Coverage     68.03%   68.02%   -0.01%     
  Complexity     2022     2022              
============================================
  Files           344      344              
  Lines         16724    16725       +1     
  Branches       2371     2371              
============================================
  Hits          11378    11378              
- Misses         4363     4365       +2     
+ Partials        983      982       -1     
Flag Coverage Δ
funTest-docker 69.36% <ø> (ø)
funTest-non-docker 36.44% <0.00%> (-0.01%) ⬇️
test 35.54% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
model/src/main/kotlin/utils/PurlUtils.kt 75.71% <0.00%> (-1.10%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nnobelis nnobelis force-pushed the nnobelis/toPurlChanges branch from ec7acb0 to 0f484d6 Compare September 29, 2023 10:26
@fviernau
Copy link
Member

@sschuberth , mind sharing the rationale for 7da5ae9 ?

@sschuberth
Copy link
Member

@sschuberth , mind sharing the rationale for 7da5ae9 ?

It's the same rational that you follow in similar commits like 38eacac. 0d75760 and others, to reduce visibility of functions that are only supposed to be used internally, to not make too much promises regarding the public API.

@fviernau
Copy link
Member

fviernau commented Sep 29, 2023

It's the same rational that you follow in similar commits like 38eacac. 0d75760 and others, to reduce visibility of functions that are only supposed to be used internally, to not make too much promises regarding the public API.

I've been trying to include you into the discussion to figure out whether the rationale for 7da5ae9 does still apply in context of @nnobelis change. The commits of mine are irrelevant in this context. In order to review this I would have liked your view as additional input. But it seems this was not clear to you.

@@ -91,7 +101,7 @@ fun Identifier.getPurlType() =
* [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)
fun Identifier.toPurl() = toPurl(emptyMap(), "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to, instead of an overload, just add these two parameter to this function, with default values emptyMap and "" ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's how it was before the force-push, and I also liked that better... @nnobelis why did you change it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As explained in the commit message it broke the FreeMarker templates that call toUrl (the tests failed): I guess Kotlin's implementation of extension functions with default values is not compatible with FreeMarker Java's reflection.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered annotation the function (from before) with @JvmOverloads? I might solve the problem as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can go around with @JvmOverloads. Would it be ok to put this annotation on toUrl ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does toUrl now come from? Did you maybe mean this?

@JvmOverloads
fun Identifier.toPurl(qualifiers: Map<String, String> = emptyMap(), subpath: String = "") = ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes toPurl. Sorry typo.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If above signature works, IMO it'd bee good.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nnobelis, please also explain in the commit message what @JvmOverloads is needed for.

@sschuberth
Copy link
Member

@nnobelis I guess this can be moved out of draft state?

@nnobelis nnobelis marked this pull request as ready for review September 29, 2023 12:30
@nnobelis nnobelis requested a review from a team as a code owner September 29, 2023 12:30
@nnobelis nnobelis force-pushed the nnobelis/toPurlChanges branch from 5829489 to 731a8d6 Compare October 2, 2023 08:13
@nnobelis nnobelis requested a review from fviernau October 2, 2023 08:13
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]>
@nnobelis nnobelis force-pushed the nnobelis/toPurlChanges branch from 731a8d6 to a6f03c3 Compare October 2, 2023 10:18
@nnobelis
Copy link
Member Author

nnobelis commented Oct 4, 2023

@fviernau @sschuberth can we please merge this ?

@fviernau fviernau merged commit aef4fe4 into oss-review-toolkit:main Oct 4, 2023
20 of 21 checks passed
@nnobelis nnobelis deleted the nnobelis/toPurlChanges branch November 20, 2024 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants