-
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
chore(opossum reporter): Migrate serialization to kotlinx #9484
base: main
Are you sure you want to change the base?
chore(opossum reporter): Migrate serialization to kotlinx #9484
Conversation
7b1a948
to
b3aefdb
Compare
fun create( | ||
source: String, | ||
id: Identifier? = null, | ||
url: String? = null, | ||
license: SpdxExpression? = null, | ||
copyright: String? = null, | ||
comment: String? = null, | ||
preSelected: Boolean = false, | ||
followUp: Boolean = false, | ||
excludeFromNotice: Boolean = false | ||
): OpossumSignal { |
Check warning
Code scanning / detekt
The more parameters a function has the more complex it is. Long parameter lists are often used to control complex algorithms and violate the Single Responsibility Principle. Prefer functions with short parameter lists.
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.
You may suppress this via @Suppress("LongParameterList")
.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #9484 +/- ##
============================================
- Coverage 67.93% 67.64% -0.30%
Complexity 1289 1289
============================================
Files 249 249
Lines 8792 8830 +38
Branches 913 926 +13
============================================
Hits 5973 5973
- Misses 2433 2471 +38
Partials 386 386
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
b3aefdb
to
98ee401
Compare
98ee401
to
91b1609
Compare
Migrates the OpossumReporter plugin away from Jackson serialization to use kotlinx serialization. To get properly typed data structures for serialization the previous untyped Map<*, *> are substituted by properly typed data classes. This leads to the creation of an OpossumInputCreator class that holds intermediate data structures needed for processing of the Reporter input. Signed-off-by: alexzurbonsen <[email protected]>
Put public method at the top, put caller above callees etc. Signed-off-by: alexzurbonsen <[email protected]>
91b1609
to
4bf27e2
Compare
opossumInput.packageToRoot.values.forAll { levelForPath -> | ||
levelForPath.keys.forAll { path -> | ||
fileList shouldContain resolvePath(path) | ||
} | ||
} |
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.
Deleting this because otherwise I would have to write a separate test for OpossumInputCreator
(and make the property packageToRoot
non private, I guess).
But it seems like this test does not add much value. The same file paths are in resourcesToAttributions
, via addSignal
and later processing of pathToSignals
. And we have a test for paths in resourcesToAttributions
against the same list.
Hi @sschuberth, it is ready for review now. Let me know what you think. Removed the untyped maps. Serialization of the recursive data structure |
@@ -563,3 +622,31 @@ private fun DependencyNode.getDependencies(): List<DependencyNode> = | |||
this += dependencyNodes.map { it.getStableReference() } | |||
} | |||
} | |||
|
|||
private object UUIDSerializer : KSerializer<UUID> { |
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.
There wasn't a UUID serializer yet and only few other usages of UUIDs. So I put it here as a private class for now. But let me know if you want to see this somewhere else.
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.
Again Ks3 comes to the rescue 😉 It already provides a UUID serializer:
https://github.com/Kantis/ks3/blob/f2ec0f5811c73ce140718b355ec61ddf751eaec5/doc/jdk.md?plain=1#L42
@@ -20,6 +20,9 @@ | |||
plugins { | |||
// Apply precompiled plugins. | |||
id("ort-plugin-conventions") | |||
|
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.
Commit message nits:
- We prefer imperative mood, i.e. "Migrates" should say "Migrate".
- We usually start capitalized after ":" in the title.
val followUp: Boolean = false, | ||
val excludeFromNotice: Boolean = false, | ||
val uuid: UUID = UUID.randomUUID() | ||
@Transient |
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.
Is this a left-over from not having an UUID serializer yet?
fun create( | ||
source: String, | ||
id: Identifier? = null, | ||
url: String? = null, | ||
license: SpdxExpression? = null, | ||
copyright: String? = null, | ||
comment: String? = null, | ||
preSelected: Boolean = false, | ||
followUp: Boolean = false, | ||
excludeFromNotice: Boolean = false | ||
): OpossumSignal { |
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.
You may suppress this via @Suppress("LongParameterList")
.
followUp: Boolean = false, | ||
excludeFromNotice: Boolean = false | ||
): OpossumSignal { | ||
return OpossumSignal( |
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.
Nit: You could turn this into a function expression via =
instead of return
.
preSelected = preSelected, | ||
followUp = OpossumFollowUp.FOLLOW_UP.takeIf { followUp }, | ||
excludeFromNotice = excludeFromNotice, | ||
comment = comment, |
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.
Nit: Please avoid trailing commas.
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.
Same in other places.
val json = Json { | ||
explicitNulls = false | ||
encodeDefaults = true | ||
} |
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.
This should probably be made available as an internal top-level property for other places like tests to use. When doing that, please name the property JSON
.
explicitNulls = false | ||
encodeDefaults = true | ||
} | ||
jsonFile.writeText(json.encodeToString(OpossumInput.serializer(), opossumInput)) |
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.
If files may get big, maybe better use a streaming approach like at
internal fun File.writeReport(model: AOSD20): File = apply { outputStream().use { JSON.encodeToStream(model, it) } } |
|
||
return opossumInput | ||
internal fun createOpossumInput(input: ReporterInput, maxDepth: Int = Int.MAX_VALUE): OpossumInput { | ||
return OpossumInputCreator().create(input, maxDepth) |
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.
This could as well be a function expression.
@@ -563,3 +622,31 @@ private fun DependencyNode.getDependencies(): List<DependencyNode> = | |||
this += dependencyNodes.map { it.getStableReference() } | |||
} | |||
} | |||
|
|||
private object UUIDSerializer : KSerializer<UUID> { |
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.
Again Ks3 comes to the rescue 😉 It already provides a UUID serializer:
https://github.com/Kantis/ks3/blob/f2ec0f5811c73ce140718b355ec61ddf751eaec5/doc/jdk.md?plain=1#L42
@@ -213,18 +201,18 @@ class OpossumReporterTest : WordSpec({ | |||
|
|||
"create issues containing all issues" { | |||
val issuesFromFirstPackage = | |||
opossumInput.getSignalsForFile("/pom.xml/compile/first-package-group/[email protected]") | |||
opossumInput.getSignalsForFile("/pom.xml/compile/first-package-group/[email protected]/") |
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 guess the trailing slash is not needed and could be removed again to reduce the diff?
[FOR REVIEW]: Best reviewed commit by commit. First commit of this PR contains the actual changes. Second commit just moves code around to improve readability.
Context
Closes #8839
Summary
Migrates the
OpossumReporter
plugin away from Jackson serialization to use kotlinx serialization.To get properly typed data structures for serialization the previous untyped
Map<*, *>
s are substituted by properly typed data classes. This leads to the creation of anOpossumInputCreator
class that holds intermediate data structures needed for processing of the Reporter input.Test Plan
OpossumReporterTest
OpossumReporterFunTest
repeat for each branch:
Unzip
report.opossum
files and validate the input.json s with this little python script:https://gist.github.com/alexzurbonsen/69e38586dcffbb6b988b010bbd096759