Skip to content

Commit fbe3029

Browse files
committed
Bundler: Discard empty authors and licenses in all places
Introduce a generic function to map a collection of things that represent text to a sorted set of not empty strings, and make use of that function in all relevant places. Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent 809de61 commit fbe3029

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

analyzer/src/main/kotlin/managers/Bundler.kt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,8 @@ data class GemSpec(
390390
node["name"].textValue(),
391391
node["version"]["version"].textValue(),
392392
homepage,
393-
node["authors"]?.asIterable()?.mapTo(sortedSetOf()) { it.textValue() } ?: sortedSetOf(),
394-
node["licenses"]?.asIterable()?.mapTo(sortedSetOf()) { it.textValue() } ?: sortedSetOf(),
393+
node["authors"]?.toList().mapToSortedSetOfNotEmptyStrings(),
394+
node["licenses"]?.toList().mapToSortedSetOfNotEmptyStrings(),
395395
node["description"].textValueOrEmpty(),
396396
runtimeDependencies.orEmpty(),
397397
VcsHost.parseUrl(homepage),
@@ -417,27 +417,28 @@ data class GemSpec(
417417
RemoteArtifact.EMPTY
418418
}
419419

420-
val authors = node["authors"]
421-
.textValueOrEmpty()
422-
.split(',')
423-
.mapNotNullTo(sortedSetOf()) { author ->
424-
author.trim().takeIf {
425-
it.isNotEmpty()
426-
}
427-
}
428-
429420
return GemSpec(
430421
node["name"].textValue(),
431422
node["version"].textValue(),
432423
node["homepage_uri"].textValueOrEmpty(),
433-
authors,
434-
node["licenses"]?.asIterable()?.mapTo(sortedSetOf()) { it.textValue() } ?: sortedSetOf(),
424+
node["authors"].textValueOrEmpty().split(',').mapToSortedSetOfNotEmptyStrings(),
425+
node["licenses"]?.toList().mapToSortedSetOfNotEmptyStrings(),
435426
node["description"].textValueOrEmpty(),
436427
runtimeDependencies.orEmpty(),
437428
vcs,
438429
artifact
439430
)
440431
}
432+
433+
private inline fun <reified T> Collection<T>?.mapToSortedSetOfNotEmptyStrings(): SortedSet<String> =
434+
this?.mapNotNullTo(sortedSetOf()) { entry ->
435+
val text = when (T::class) {
436+
JsonNode::class -> (entry as JsonNode).textValue()
437+
else -> entry.toString()
438+
}
439+
440+
text?.trim()?.takeIf { it.isNotEmpty() }
441+
} ?: sortedSetOf()
441442
}
442443

443444
fun merge(other: GemSpec): GemSpec {

0 commit comments

Comments
 (0)