Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscellaneous Bundler improvements #6039

Merged
merged 3 commits into from
Nov 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions analyzer/src/main/kotlin/managers/Bundler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ class Bundler(
private fun resolveGemsMetadata(workingDir: File): MutableMap<String, GemSpec> {
val stdout = runScriptResource(RESOLVE_DEPENDENCIES_SCRIPT, workingDir)

// The metadata produced by the "bundler_dependencies_metadata.rb" script separates specs for packages with
// the "\0" character as delimiter. Always drop the first "Fetching gem metadata from" entry.
val gemSpecs = stdout.split('\u0000').drop(1).map {
// The metadata produced by the "bundler_resolve_dependencies.rb" script separates specs for packages with the
// "\0" character as delimiter.
val gemSpecs = stdout.split('\u0000').dropWhile { it.startsWith("Fetching gem metadata") }.map {
GemSpec.createFromMetadata(yamlMapper.readTree(it))
}.associateByTo(mutableMapOf()) {
it.name
Expand Down 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