Skip to content

Commit

Permalink
Bundler: Discard empty authors and licenses in all places
Browse files Browse the repository at this point in the history
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 <sschuberth@gmail.com>
  • Loading branch information
sschuberth committed Nov 6, 2022
1 parent 809de61 commit fbe3029
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions analyzer/src/main/kotlin/managers/Bundler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ data class GemSpec(
node["name"].textValue(),
node["version"]["version"].textValue(),
homepage,
node["authors"]?.asIterable()?.mapTo(sortedSetOf()) { it.textValue() } ?: sortedSetOf(),
node["licenses"]?.asIterable()?.mapTo(sortedSetOf()) { it.textValue() } ?: sortedSetOf(),
node["authors"]?.toList().mapToSortedSetOfNotEmptyStrings(),
node["licenses"]?.toList().mapToSortedSetOfNotEmptyStrings(),
node["description"].textValueOrEmpty(),
runtimeDependencies.orEmpty(),
VcsHost.parseUrl(homepage),
Expand All @@ -417,27 +417,28 @@ data class GemSpec(
RemoteArtifact.EMPTY
}

val authors = node["authors"]
.textValueOrEmpty()
.split(',')
.mapNotNullTo(sortedSetOf()) { author ->
author.trim().takeIf {
it.isNotEmpty()
}
}

return GemSpec(
node["name"].textValue(),
node["version"].textValue(),
node["homepage_uri"].textValueOrEmpty(),
authors,
node["licenses"]?.asIterable()?.mapTo(sortedSetOf()) { it.textValue() } ?: sortedSetOf(),
node["authors"].textValueOrEmpty().split(',').mapToSortedSetOfNotEmptyStrings(),
node["licenses"]?.toList().mapToSortedSetOfNotEmptyStrings(),
node["description"].textValueOrEmpty(),
runtimeDependencies.orEmpty(),
vcs,
artifact
)
}

private inline fun <reified T> Collection<T>?.mapToSortedSetOfNotEmptyStrings(): SortedSet<String> =
this?.mapNotNullTo(sortedSetOf()) { entry ->
val text = when (T::class) {
JsonNode::class -> (entry as JsonNode).textValue()
else -> entry.toString()
}

text?.trim()?.takeIf { it.isNotEmpty() }
} ?: sortedSetOf()
}

fun merge(other: GemSpec): GemSpec {
Expand Down

0 comments on commit fbe3029

Please sign in to comment.