Skip to content

Commit 90e6393

Browse files
committed
feat(tools/curations): Start categorizing license exception pairs
ScanCode does not provide categories for pairs of licenses and their belonging exceptions. In some cases the category is pretty clear. So, add a mechanism to hard-code the categories and add a first entry. Signed-off-by: Frank Viernau <[email protected]>
1 parent e78f0db commit 90e6393

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

tools/curations/buildSrc/src/main/kotlin/ScanCodeLicenseDbClassifications.kt

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,24 @@ private val JSON_MAPPER = JsonMapper().apply {
4646

4747
private const val CATEGORY_CLA = "cla"
4848
private const val CATEGORY_GENERIC = "generic"
49+
private const val CATEGORY_PERMISSIVE = "permissive"
4950
private const val CATEGORY_UNKNOWN = "unknown"
5051

5152
private val OVERRIDE_LICENSE_CATEGORIES = mapOf(
5253
// https://github.com/nexB/scancode-toolkit/issues/3317.
5354
"LicenseRef-scancode-ms-cla" to CATEGORY_CLA
5455
).mapKeys { (license, _) -> SpdxSingleLicenseExpression.parse(license) }
5556

57+
// ScanCode does not provide categories for pairs of licenses and their belonging exceptions. So, hard-code some:
58+
private val LICENSE_EXCEPTION_CATEGORIZATIONS = listOf(
59+
"Apache-2.0 WITH Swift-exception" to CATEGORY_PERMISSIVE
60+
).map { (license, category) ->
61+
LicenseCategorization(
62+
id = SpdxSingleLicenseExpression.parse(license),
63+
categories = addExtraCategories(category)
64+
)
65+
}
66+
5667
private data class License(
5768
val licenseKey: String,
5869
val spdxLicenseKey: String? = null,
@@ -170,19 +181,19 @@ private fun addExtraCategories(category: String): Set<String> =
170181
)
171182

172183
private fun getLicenseClassifications(licenseDetails: Collection<LicenseDetails>): LicenseClassifications {
173-
val categories = licenseDetails.flatMap { details ->
174-
details.getCategories()
175-
}.distinct().map { category ->
176-
LicenseCategory(category)
177-
}
178-
179184
val categorizations = licenseDetails.flatMap { details ->
180185
details.getLicenseIds().map { licenseId ->
181186
LicenseCategorization(
182187
id = licenseId,
183188
categories = details.getCategories()
184189
)
185190
}
191+
} + LICENSE_EXCEPTION_CATEGORIZATIONS
192+
193+
val categories = categorizations.flatMap { categorization ->
194+
categorization.categories
195+
}.distinct().map { category ->
196+
LicenseCategory(category)
186197
}
187198

188199
return LicenseClassifications(

0 commit comments

Comments
 (0)