Skip to content

Commit 431abea

Browse files
committedFeb 19, 2025
chore(spdx-utils): Say "simple mapping" instead of "custom mapping"
Match the name of the file containing the mapping by calling variables after "simple mapping", which also is a bit more specific than "custom mapping". While at it, also distinguish between mapping to licenses or expressions. For consistency this is also done for the mapping of deprecated expressions. Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
1 parent 4ee1030 commit 431abea

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed
 

‎utils/spdx/src/main/kotlin/SpdxSimpleLicenseMapping.kt

+9-8
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,38 @@ import com.fasterxml.jackson.module.kotlin.readValue
2828
*/
2929
object SpdxSimpleLicenseMapping {
3030
/**
31-
* The raw map which associates custom license IDs with their corresponding SPDX license ID.
31+
* The map of simple license names associated with their corresponding [SPDX license][SpdxLicense].
3232
*/
33-
internal val customLicenseIdsMap by lazy {
33+
internal val simpleLicenseMapping by lazy {
3434
val resource = checkNotNull(javaClass.getResource("/simple-license-mapping.yml"))
3535
yamlMapper.readValue<Map<String, SpdxLicense>>(resource)
3636
}
3737

3838
/**
39-
* The map of custom license ids associated with their corresponding SPDX expression.
39+
* The map of simple license names associated with their corresponding [SPDX expression][SpdxLicenseIdExpression].
4040
*/
41-
internal val customLicenseIds = customLicenseIdsMap.mapValues { (_, v) -> v.toExpression() }
41+
internal val simpleExpressionMapping = simpleLicenseMapping.mapValues { (_, v) -> v.toExpression() }
4242
.toSortedMap(String.CASE_INSENSITIVE_ORDER)
4343

4444
/**
45-
* The map of deprecated SPDX license ids associated with their current SPDX expression.
45+
* The map of deprecated SPDX license IDs associated with their current [SPDX expression]
46+
* [SpdxSingleLicenseExpression].
4647
*/
47-
private val deprecatedLicenseIds by lazy {
48+
private val deprecatedExpressionMapping by lazy {
4849
val resource = checkNotNull(javaClass.getResource("/deprecated-license-mapping.yml"))
4950
yamlMapper.readValue<Map<String, SpdxSingleLicenseExpression>>(resource)
5051
}
5152

5253
/**
5354
* The map of varied SPDX license ids associated with their corresponding SPDX expression.
5455
*/
55-
val mapping = (customLicenseIds + deprecatedLicenseIds).toSortedMap(String.CASE_INSENSITIVE_ORDER)
56+
val mapping = (simpleExpressionMapping + deprecatedExpressionMapping).toSortedMap(String.CASE_INSENSITIVE_ORDER)
5657

5758
/**
5859
* Return the [SpdxExpression] the [license] id maps to, or null if there is no corresponding expression. If
5960
* [mapDeprecated] is true, license ids marked as deprecated in the SPDX standard are mapped to their
6061
* corresponding current expression, otherwise they are mapped to their corresponding deprecated expression.
6162
*/
6263
fun map(license: String, mapDeprecated: Boolean = true) =
63-
(if (mapDeprecated) mapping else customLicenseIds)[license] ?: SpdxLicense.forId(license)?.toExpression()
64+
(if (mapDeprecated) mapping else simpleExpressionMapping)[license] ?: SpdxLicense.forId(license)?.toExpression()
6465
}

‎utils/spdx/src/test/kotlin/SpdxSimpleLicenseMappingTest.kt

+7-7
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ import org.ossreviewtoolkit.utils.spdx.parser.SpdxExpressionParser
3636
import org.ossreviewtoolkit.utils.spdx.parser.Token
3737

3838
class SpdxSimpleLicenseMappingTest : WordSpec({
39-
"The raw map" should {
39+
"The license map" should {
4040
"not contain any duplicate keys with respect to capitalization" {
41-
val keys = SpdxSimpleLicenseMapping.customLicenseIdsMap.keys.toMutableList()
42-
val uniqueKeys = SpdxSimpleLicenseMapping.customLicenseIds.keys
41+
val keys = SpdxSimpleLicenseMapping.simpleLicenseMapping.keys.toMutableList()
42+
val uniqueKeys = SpdxSimpleLicenseMapping.simpleExpressionMapping.keys
4343

4444
// Remove keys one by one as calling "-" would remove all occurrences of a key.
4545
uniqueKeys.forEach { uniqueKey -> keys.remove(uniqueKey) }
@@ -48,13 +48,13 @@ class SpdxSimpleLicenseMappingTest : WordSpec({
4848
}
4949

5050
"not contain any deprecated values" {
51-
SpdxSimpleLicenseMapping.customLicenseIdsMap.values.forAll {
51+
SpdxSimpleLicenseMapping.simpleLicenseMapping.values.forAll {
5252
it.deprecated shouldBe false
5353
}
5454
}
5555

5656
"not associate licenses without a version to *-only" {
57-
SpdxSimpleLicenseMapping.customLicenseIdsMap.forAll { (key, license) ->
57+
SpdxSimpleLicenseMapping.simpleLicenseMapping.forAll { (key, license) ->
5858
if (license.id.endsWith("-only")) key should containADigit()
5959
}
6060
}
@@ -76,13 +76,13 @@ class SpdxSimpleLicenseMappingTest : WordSpec({
7676
}
7777

7878
"not contain plain SPDX license ids" {
79-
SpdxSimpleLicenseMapping.customLicenseIds.keys.forAll { declaredLicense ->
79+
SpdxSimpleLicenseMapping.simpleExpressionMapping.keys.forAll { declaredLicense ->
8080
SpdxLicense.forId(declaredLicense) should beNull()
8181
}
8282
}
8383

8484
"be case-insensitive" {
85-
SpdxSimpleLicenseMapping.customLicenseIds.forAll { (key, license) ->
85+
SpdxSimpleLicenseMapping.simpleExpressionMapping.forAll { (key, license) ->
8686
SpdxSimpleLicenseMapping.map(key.lowercase(), mapDeprecated = false) shouldBe license
8787
SpdxSimpleLicenseMapping.map(key.uppercase(), mapDeprecated = false) shouldBe license
8888
SpdxSimpleLicenseMapping.map(key.titlecase(), mapDeprecated = false) shouldBe license

0 commit comments

Comments
 (0)
Please sign in to comment.