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

refactor(cocoapods): Move Podspec to a dedicated file #8880

Merged
merged 4 commits into from
Jul 15, 2024

Conversation

fviernau
Copy link
Member

Separate the CocoaPods model from the analyzer.

@fviernau fviernau requested a review from a team as a code owner July 15, 2024 06:44
@fviernau fviernau enabled auto-merge (rebase) July 15, 2024 06:51
Copy link

codecov bot commented Jul 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.54%. Comparing base (25f07db) to head (59c65fa).

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #8880   +/-   ##
=========================================
  Coverage     67.54%   67.54%           
  Complexity     1166     1166           
=========================================
  Files           244      244           
  Lines          7775     7775           
  Branches        865      865           
=========================================
  Hits           5252     5252           
  Misses         2167     2167           
  Partials        356      356           
Flag Coverage Δ
funTest-non-docker 33.92% <ø> (ø)
test 37.90% <ø> (ø)

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.

Separate the CocoaPods model from the analyzer.

Signed-off-by: Frank Viernau <[email protected]>
@fviernau fviernau force-pushed the cocoapods-extract-podspec branch 2 times, most recently from d2a38fc to d4a1741 Compare July 15, 2024 07:53
@@ -211,9 +210,9 @@ class CocoaPods(
return null
}

val podspecFile = File(podspecCommand.stdout.trim())
val podspec = File(podspecCommand.stdout.trim()).readText().parsePodspec()
Copy link
Member

@sschuberth sschuberth Jul 15, 2024

Choose a reason for hiding this comment

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

Nit: I'd have a slight tendency towards keeping podspecFile as a separate variable here to not do too many conversions in this single line, and eventually ease inspecting variables when debugging.

private object LicenseSerializer : JsonTransformingSerializer<String>(String.serializer()) {
override fun transformDeserialize(element: JsonElement): JsonElement =
if (element is JsonObject) {
val type: String = (element["type"] as JsonPrimitive).content
Copy link
Member

Choose a reason for hiding this comment

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

The explicit type should be dropped, and the jsonPrimitive extension function should be used (which requires explicit handling of the null case for element["type"]).

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you please provide a rationale for the latter? (I believe it is fine to assume that type is not null here, which this code does.)

Copy link
Member

Choose a reason for hiding this comment

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

Explicit handling of the null case for element["type"] is a side effect of using jsonPrimitive, not the primary goal. But I think it's a good side effect as the original code also handled the null case explicitly via textValueOrEmpty(). If you want to document that you expect the field to exist in any case (and throw an exception otherwise), then you should use getValue() instead of [].

Copy link
Member Author

Choose a reason for hiding this comment

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

Note: I kept the explicit type for readability.

Prepare for migrating the parsing to KxS.

Signed-off-by: Frank Viernau <[email protected]>
@fviernau fviernau force-pushed the cocoapods-extract-podspec branch from 59c65fa to 8096d70 Compare July 15, 2024 12:20
@fviernau fviernau requested a review from sschuberth July 15, 2024 12:20
fviernau added 2 commits July 15, 2024 15:14
When the `source` node contains boolean properties with unquoted values,
such as [1], the deserialization of the source property to a
`Map<String, String>` with KxS fails by default. So, introduce a
dedicated data class to prepare for migrating to KxS and to improve the
readability.

[1]: "source": {
       "git": "https://github.com/AFNetworking/AFNetworking.git",
       "tag": "3.2.1",
       "submodules": true
     }

Signed-off-by: Frank Viernau <[email protected]>
@fviernau fviernau force-pushed the cocoapods-extract-podspec branch from 8096d70 to a615014 Compare July 15, 2024 13:14
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.json.JsonTransformingSerializer
import kotlinx.serialization.json.jsonPrimitive
Copy link
Member

Choose a reason for hiding this comment

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

This import is present twice now.

Copy link
Member

Choose a reason for hiding this comment

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

Not sure why Detekt did not report this, though.

Copy link
Member Author

Choose a reason for hiding this comment

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

You've overlooked that the first character differs, e.g. j vs. J.

@@ -37,6 +40,9 @@ dependencies {
implementation(projects.utils.ortUtils)
implementation(projects.utils.spdxUtils)

implementation(libs.kotlinx.serialization.core)
implementation(libs.kotlinx.serialization.json)

implementation(libs.jackson.annotations)
Copy link
Member

Choose a reason for hiding this comment

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

The Jackson dependencies should be removed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not yet. The lockfile parsing also needs to be ported.

@fviernau fviernau requested a review from sschuberth July 15, 2024 14:43
@fviernau fviernau merged commit ebc4b63 into main Jul 15, 2024
20 checks passed
@fviernau fviernau deleted the cocoapods-extract-podspec branch July 15, 2024 15:04
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