Skip to content

Commit

Permalink
refactor(reporter): Extract function for resolving copyrights
Browse files Browse the repository at this point in the history
Refactor the code to improve reusability and
maintainability by extracting the functionality for resolving
copyright statements from package authors into a separate
function. The extracted function encapsulates the existing logic,
making it easier to call from multiple places while reducing
duplication.

The refactor does not introduce any changes to the
existing behavior and serves purely as a structural improvement.

Signed-off-by: Wolfgang Klenk <[email protected]>
  • Loading branch information
wkl3nk authored and sschuberth committed Dec 19, 2024
1 parent f0b825b commit 14b2d68
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions model/src/main/kotlin/licenses/LicenseInfoResolver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,7 @@ class LicenseInfoResolver(
}.keys

licenseInfo.declaredLicenseInfo.authors.takeIf { it.isNotEmpty() && addAuthorsToCopyrights }?.also {
locations += ResolvedLicenseLocation(
provenance = UnknownProvenance,
location = UNDEFINED_TEXT_LOCATION,
appliedCuration = null,
matchingPathExcludes = emptyList(),
copyrights = it.mapTo(mutableSetOf()) { author ->
val statement = "Copyright (C) $author".takeUnless {
author.contains("Copyright", ignoreCase = true)
} ?: author

ResolvedCopyrightFinding(
statement = statement,
location = UNDEFINED_TEXT_LOCATION,
matchingPathExcludes = emptyList()
)
}
)
locations += resolveCopyrightFromAuthors(it)
}
}
}
Expand Down Expand Up @@ -287,6 +271,25 @@ class LicenseInfoResolver(

return ResolvedLicenseFileInfo(id, licenseFiles)
}

private fun resolveCopyrightFromAuthors(authors: Set<String>): ResolvedLicenseLocation =
ResolvedLicenseLocation(
provenance = UnknownProvenance,
location = UNDEFINED_TEXT_LOCATION,
appliedCuration = null,
matchingPathExcludes = emptyList(),
copyrights = authors.mapTo(mutableSetOf()) { author ->
val statement = "Copyright (C) $author".takeUnless {
author.contains("Copyright", ignoreCase = true)
} ?: author

ResolvedCopyrightFinding(
statement = statement,
location = UNDEFINED_TEXT_LOCATION,
matchingPathExcludes = emptyList()
)
}
)
}

private class ResolvedLicenseBuilder(val license: SpdxSingleLicenseExpression) {
Expand Down

0 comments on commit 14b2d68

Please sign in to comment.