Skip to content

Commit

Permalink
refactor(bower): Reword obsolete uses of the terminology of nodes
Browse files Browse the repository at this point in the history
A preceding commit refactored Bower to use data classes and a model
mapper for the deserilation. So, it now operates on `PackageInfo`
instances instead of on `JsonNode`s.

Align variable names, function names and comments with that change,
to make things consistent again.

Signed-off-by: Frank Viernau <[email protected]>
  • Loading branch information
fviernau committed Jul 18, 2024
1 parent 3c3b42a commit 8fff913
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions plugins/package-managers/bower/src/main/kotlin/Bower.kt
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private val PackageInfo.key: String?
"$name:$version".takeUnless { name.isEmpty() || version.isEmpty() }
}

private fun getNodesWithCompleteDependencies(info: PackageInfo): Map<String, PackageInfo> {
private fun getPackageInfosWithCompleteDependencies(info: PackageInfo): Map<String, PackageInfo> {
val result = mutableMapOf<String, PackageInfo>()

val stack = Stack<PackageInfo>().apply { push(info) }
Expand All @@ -217,26 +217,27 @@ private fun getNodesWithCompleteDependencies(info: PackageInfo): Map<String, Pac
private fun parseDependencyTree(
info: PackageInfo,
scopeName: String,
alternativeNodes: Map<String, PackageInfo> = getNodesWithCompleteDependencies(info)
alternativeInfos: Map<String, PackageInfo> = getPackageInfosWithCompleteDependencies(info)
): Set<PackageReference> {
val result = mutableSetOf<PackageReference>()

if (!hasCompleteDependencies(info, scopeName)) {
// Bower leaves out a dependency entry for a child if there exists a similar node to its parent node
// Bower leaves out a dependency entry for a child if there exists a similar entry to its parent entry
// with the exact same name and resolved target. This makes it necessary to retrieve the information
// about the subtree rooted at the parent from that other node containing the full dependency
// about the subtree rooted at the parent from that other entry containing the full dependency
// information.
// See https://github.com/bower/bower/blob/6bc778d/lib/core/Manager.js#L557 and below.
val alternativeNode = alternativeNodes.getValue(info.key!!)
return parseDependencyTree(alternativeNode, scopeName, alternativeNodes)

val alternativeInfo = alternativeInfos.getValue(info.key!!)

Check warning

Code scanning / detekt

Unsafe calls on nullable types detected. These calls will throw a NullPointerException in case the nullable value is null. Warning

Calling !! on a nullable type will throw a NullPointerException at runtime in case the value is null. It should be avoided.
return parseDependencyTree(alternativeInfo, scopeName, alternativeInfos)
}

info.pkgMeta.getDependencies(scopeName).keys.forEach {
val childNode = info.dependencies.getValue(it)
val childInfo = info.dependencies.getValue(it)
val childScope = SCOPE_NAME_DEPENDENCIES
val childDependencies = parseDependencyTree(childNode, childScope, alternativeNodes)
val childDependencies = parseDependencyTree(childInfo, childScope, alternativeInfos)
val packageReference = PackageReference(
id = parsePackageId(childNode),
id = parsePackageId(childInfo),
dependencies = childDependencies
)
result += packageReference
Expand Down

0 comments on commit 8fff913

Please sign in to comment.