-
Notifications
You must be signed in to change notification settings - Fork 313
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
Conversation
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@@ -77,7 +77,7 @@ internal data class Pubspec( | |||
@Serializable | |||
data class HostedDependency( | |||
val version: String, | |||
val url: String? = null | |||
val hosted: String? = null |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
- With a scalar value:
dependencies:
transmogrify: ^1.4.0
- With a map value that contains
hosted
andversion
on the same level, whilehosted
having a scalar value:
dependencies:
transmogrify:
hosted: https://some-package-server.com
version: ^1.4.0
- 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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
- In the most detailed representation the name is
url
- Hosted is name of the class. So it's kind of
Hosted.hosted
which seems a tad odd - Considering the values,
url
seems to fit better. - 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.
There was a problem hiding this comment.
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.
3aa5736
to
a8c986f
Compare
@@ -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)) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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]>
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]>
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]>
Signed-off-by: Sebastian Schuberth <[email protected]>
Please have a look at the individual commit messages for the details.