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

Miscellaneous smaller Pub serialization improvements #9287

Merged
merged 8 commits into from
Oct 21, 2024
Merged

Conversation

sschuberth
Copy link
Member

Please have a look at the individual commit messages for the details.

@sschuberth sschuberth requested a review from a team as a code owner October 15, 2024 20:31
@sschuberth sschuberth enabled auto-merge (rebase) October 15, 2024 20:31
Copy link

codecov bot commented Oct 15, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 2 lines in your changes missing coverage. Please review.

Project coverage is 67.49%. Comparing base (ed4bccf) to head (c643da0).
Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
...kage-managers/pub/src/main/kotlin/model/Pubspec.kt 83.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #9287      +/-   ##
============================================
+ Coverage     66.29%   67.49%   +1.20%     
+ Complexity     1201     1198       -3     
============================================
  Files           239      241       +2     
  Lines          8446     8494      +48     
  Branches        905      899       -6     
============================================
+ Hits           5599     5733     +134     
+ Misses         2478     2399      -79     
+ Partials        369      362       -7     
Flag Coverage Δ
funTest-docker 60.63% <50.00%> (+0.55%) ⬆️
funTest-non-docker 33.63% <ø> (-1.08%) ⬇️
test 37.48% <78.57%> (+0.11%) ⬆️

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

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

@@ -77,7 +77,7 @@ internal data class Pubspec(
@Serializable
data class HostedDependency(
val version: String,
val url: String? = null
val hosted: String? = null
Copy link
Member

Choose a reason for hiding this comment

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

Hosted packages can be represented in multiple ways.
The link above only points to one of the representations.
There is a way to specify a url for hosted dependencies.
So, the data class should IMO remain as-is.

Copy link
Member

Choose a reason for hiding this comment

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

copied from the docs:

environment:
  sdk: '>=2.14.0 < 3.0.0'

dependencies:
  transmogrify:
    hosted:
      name: transmogrify
      url: https://some-package-server.com
    version: ^1.4.0

Copy link
Member

Choose a reason for hiding this comment

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

The link you provided points to the short form, which uses a primitive type to specify the url in a more compact way.

Copy link
Member Author

@sschuberth sschuberth Oct 17, 2024

Choose a reason for hiding this comment

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

Hmm. The link IMO documents three forms of hosted packages:

  1. With a scalar value:
dependencies:
  transmogrify: ^1.4.0
  1. With a map value that contains hosted and version on the same level, while hosted having a scalar value:
dependencies:
  transmogrify:
    hosted: https://some-package-server.com
    version: ^1.4.0
  1. With a map value where also hosted is a map (only relevant for an SDK version earlier than 2.15):
dependencies:
  transmogrify:
    hosted:
      name: transmogrify
      url: https://some-package-server.com
    version: ^1.4.0

My goal was to support case 2 where hosted and version are siblings as I did not see this case being covered. Am I missing something?

Copy link
Member Author

Choose a reason for hiding this comment

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

To add to that, the naming in this case actually does not matter too much as these classes are not directly used via their auto-generated serializers, but the DependencyMapSerializer constructs these classes manually, and takes care about the 3. case by explicitly looking for hosted.get<YamlScalar>("url").

Anyway, if the classes were deserialized directly, I believe naming the property hosted instead of url to be more correct.

Copy link
Member

@fviernau fviernau Oct 17, 2024

Choose a reason for hiding this comment

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

I would prefer to keep url, because

  1. In the most detailed representation the name is url
  2. Hosted is name of the class. So it's kind of Hosted.hosted which seems a tad odd
  3. Considering the values, url seems to fit better.
  4. It's debatable whether the version values are actually part of the hosted object. It seems to rather be a sibling. Anyhow, it's in the same data class.

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 still don't believe it makes sense to stick with url in the longer term as it would break as soon as we'd be able to deserialize classes directly (see charleskorn/kaml#29 and / or charleskorn/kaml#612), but for the sake of moving things forward I'll drop that commit.

plugins/package-managers/pub/src/main/kotlin/Pubspec.kt Outdated Show resolved Hide resolved
@sschuberth sschuberth force-pushed the pub-imps branch 2 times, most recently from 3aa5736 to a8c986f Compare October 17, 2024 11:05
@sschuberth sschuberth requested review from fviernau and a team October 17, 2024 11:06
@@ -41,8 +39,6 @@ import kotlinx.serialization.encoding.Decoder

import org.ossreviewtoolkit.plugins.packagemanagers.pub.model.PackageInfo.Description

private val YAML = Yaml(configuration = YamlConfiguration(strictMode = false))
Copy link
Member

Choose a reason for hiding this comment

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

Hm, personally sacrificing encapsulation for these few bytes of memory is not worth it.
What do you think about the middle ground of keeping it private, but turning it into a function?

Copy link
Member Author

@sschuberth sschuberth Oct 18, 2024

Choose a reason for hiding this comment

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

Why would encapsulation even be required here? I mean, these two files are supposed to be deserialized in exactly the same way, so it makes sense and is correct to share the same Yaml instance, or?

Background: I was originally doing this in the context of adding more tests for deserialization (which turned out to be unnecessary). As part of that, I needed access to YAML, but I couldn't make either instance internal as it would then have conflicted with the other private one.

This is a follow-up to 9607cd0 for code that was merged in parallel.

Signed-off-by: Sebastian Schuberth <[email protected]>
Signed-off-by: Sebastian Schuberth <[email protected]>
The dependencies node itself is never a scalar, so the code can be
simplified.

Signed-off-by: Sebastian Schuberth <[email protected]>
Remove the `utils` package and move its only class to the root. In
exchange, group the `Lockfile` and `Pubspec` classes in a new `model`
package.

Signed-off-by: Sebastian Schuberth <[email protected]>
@sschuberth sschuberth merged commit 201e0de into main Oct 21, 2024
23 checks passed
@sschuberth sschuberth deleted the pub-imps branch October 21, 2024 07:26
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.

2 participants