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

Migrate the Opossum reporter to KxS #9484

Conversation

alexzurbonsen
Copy link

@alexzurbonsen alexzurbonsen commented Nov 21, 2024

[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 an OpossumInputCreator class that holds intermediate data structures needed for processing of the Reporter input.

Test Plan

  1. Automated tests:

OpossumReporterTest
OpossumReporterFunTest

  1. Manual test: Compare two opossum files with ORT builds from main and this branch

repeat for each branch:

./gradlew installDist
cli/build/install/ort/bin/ort analyze -i <INPUT_PROJECT> -o ./RESULT -f JSON 
cli/build/install/ort/bin/ort report -i /path/to/analyzer-result.json -o ./RESULT -f Opossum 

Unzip report.opossum files and validate the input.json s with this little python script:
https://gist.github.com/alexzurbonsen/69e38586dcffbb6b988b010bbd096759

@alexzurbonsen alexzurbonsen force-pushed the migrate-opossum-reporter-to-kotlinx-serialization branch 3 times, most recently from 7b1a948 to b3aefdb Compare November 21, 2024 18:26
Copy link

codecov bot commented Nov 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.96%. Comparing base (1f76243) to head (df473e8).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #9484   +/-   ##
=========================================
  Coverage     67.96%   67.96%           
  Complexity     1290     1290           
=========================================
  Files           249      249           
  Lines          8810     8810           
  Branches        915      915           
=========================================
  Hits           5988     5988           
  Misses         2433     2433           
  Partials        389      389           
Flag Coverage Δ
funTest-docker 64.82% <ø> (ø)
funTest-non-docker 33.25% <ø> (ø)

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.

@alexzurbonsen alexzurbonsen force-pushed the migrate-opossum-reporter-to-kotlinx-serialization branch from b3aefdb to 98ee401 Compare November 21, 2024 19:50
@alexzurbonsen alexzurbonsen changed the title chore(opossum reporter): migrate serialization to kotlinx chore(opossum reporter): Migrate serialization to kotlinx Nov 21, 2024
@alexzurbonsen alexzurbonsen force-pushed the migrate-opossum-reporter-to-kotlinx-serialization branch 2 times, most recently from 91b1609 to 4bf27e2 Compare November 22, 2024 18:04
Comment on lines -139 to -142
opossumInput.packageToRoot.values.forAll { levelForPath ->
levelForPath.keys.forAll { path ->
fileList shouldContain resolvePath(path)
}
}
Copy link
Author

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.

@alexzurbonsen alexzurbonsen marked this pull request as ready for review November 22, 2024 18:16
@alexzurbonsen alexzurbonsen requested a review from a team as a code owner November 22, 2024 18:16
@alexzurbonsen
Copy link
Author

Hi @sschuberth, it is ready for review now. Let me know what you think. Removed the untyped maps.

Serialization of the recursive data structure OpossumResources was a bit tricky and I decided to not support deserialization. I assume there is no use case for it anyways.

@@ -20,6 +20,9 @@
plugins {
// Apply precompiled plugins.
id("ort-plugin-conventions")

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

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

The commit message body still uses simple present instead of imperative mood.

val followUp: Boolean = false,
val excludeFromNotice: Boolean = false,
val uuid: UUID = UUID.randomUUID()
@Transient
Copy link
Member

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?

Copy link
Author

Choose a reason for hiding this comment

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

No, but it can be solved differently, I realized. I removed the property and collect the signals in a map uuidToSignals now. We could also collect them in a map signalsToUUID but that would require to replace the current matches method by overriding the equals and hashCode methods, I suppose. Would you prefer that? For now I didn't do it in the interest of keeping the diff smaller.

Copy link
Member

Choose a reason for hiding this comment

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

but that would require to replace the current matches method by overriding the equals and hashCode methods, I suppose. Would you prefer that?

I guess not. In Kotlin, I try to avoid overriding equals and hashCode as much as possible in favor of auto-generate code.

But couldn't @Transient then simply have been dropped and the original code be kept? Anyway, go for whatever causes less work for you.

preSelected = preSelected,
followUp = OpossumFollowUp.FOLLOW_UP.takeIf { followUp },
excludeFromNotice = excludeFromNotice,
comment = comment,
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

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

Same in other places.

@sschuberth
Copy link
Member

PS: @alexzurbonsen please also rebase to resolve conflicts.

@alexzurbonsen alexzurbonsen force-pushed the migrate-opossum-reporter-to-kotlinx-serialization branch from 4bf27e2 to abcdc42 Compare November 25, 2024 10:26
@alexzurbonsen alexzurbonsen force-pushed the migrate-opossum-reporter-to-kotlinx-serialization branch from 3fe68ab to 503fd35 Compare November 25, 2024 12:39
@alexzurbonsen
Copy link
Author

Sorry for the detekt noise. Should be fixed now, I hope.


addResource(pathPieces)
}
internal fun createOpossumInput(input: ReporterInput, maxDepth: Int = Int.MAX_VALUE): OpossumInput =

Check notice

Code scanning / QDJVMC

Class member can have 'private' visibility Note

Function 'createOpossumInput' could be private
@alexzurbonsen alexzurbonsen force-pushed the migrate-opossum-reporter-to-kotlinx-serialization branch from 503fd35 to cba08df Compare November 25, 2024 14:10
@alexzurbonsen
Copy link
Author

Fixed the failing workflow. PR is ready for review again.

@sschuberth
Copy link
Member

sschuberth commented Nov 25, 2024

Fixed the failing workflow. PR is ready for review again.

Thanks a lot @alexzurbonsen! There are a bunch of more things I'd like to address, e.g. regarding the Git history as we do not allow catch-all "Add review feedback" commit but want the review comments address in the commit the review comments was made on.

But I'll address these myself and take over your branch. Thanks again for all your work!

@alexzurbonsen
Copy link
Author

@sschuberth Okay, thank you! If I can be of any help, let me know.

I just saw that now detekt is failing on the functional test. May be it didn't get there before. But the fix is easy at least.

Migrate 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]>
Signed-off-by: Sebastian Schuberth <[email protected]>
@sschuberth sschuberth force-pushed the migrate-opossum-reporter-to-kotlinx-serialization branch from cba08df to df473e8 Compare November 25, 2024 20:04
@@ -20,6 +20,9 @@
plugins {
// Apply precompiled plugins.
id("ort-plugin-conventions")

Copy link
Member

Choose a reason for hiding this comment

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

The commit message body still uses simple present instead of imperative mood.

import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldContain
import kotlinx.serialization.json.jsonArray
Copy link
Member

Choose a reason for hiding this comment

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

This needs an empty line before to group top-level imports. (Our custom Detekt rule would complain.)

@sschuberth sschuberth enabled auto-merge (rebase) November 25, 2024 20:07
@sschuberth sschuberth changed the title chore(opossum reporter): Migrate serialization to kotlinx Migrate the Opossum reporter to KxS Nov 25, 2024
val baseUrlsForSources: Map<String, String>,
val externalAttributionSources: Map<String, OpossumExternalAttributionSource>
) {
fun getSignalsForFile(file: String): List<OpossumSignalFlat> =

Check warning

Code scanning / QDJVMC

Unused symbol Warning

Function "getSignalsForFile" is never used
internal data class OpossumResources(
val tree: MutableMap<String, OpossumResources> = mutableMapOf()
) {
fun addResource(pathPieces: List<String>) {

Check notice

Code scanning / QDJVMC

Class member can have 'private' visibility Note

Function 'addResource' could be private
return isPathAFile(pathPieces)
}

fun isPathAFile(pathPieces: List<String>): Boolean {

Check notice

Code scanning / QDJVMC

Class member can have 'private' visibility Note

Function 'isPathAFile' could be private
return head !in tree || tree.getValue(head).isPathAFile(tail)
}

fun toFileList(): Set<String> =

Check notice

Code scanning / QDJVMC

Class member can have 'private' visibility Note

Function 'toFileList' could be private
return head !in tree || tree.getValue(head).isPathAFile(tail)
}

fun toFileList(): Set<String> =

Check warning

Code scanning / QDJVMC

Unused symbol Warning

Function "toFileList" is never used
@sschuberth sschuberth merged commit 99e611b into oss-review-toolkit:main Nov 25, 2024
21 checks passed
@alexzurbonsen
Copy link
Author

Thanks for finishing this. I like the idea of extracting the data model and creating a full functional test.

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.

Migrate the Opossum reporter from Jackson to kotlinx-serialization (KxS)
2 participants