| 1 | package com.depanalyzer.core.graph | |
| 2 | ||
| 3 | import com.depanalyzer.parser.ParsedDependency | |
| 4 | import com.depanalyzer.report.Vulnerability | |
| 5 | ||
| 6 | class DependencyGraphBuilder { | |
| 7 | ||
| 8 | fun buildGraph( | |
| 9 | directDependencies: List<ParsedDependency>, | |
| 10 | allDependencies: List<ParsedDependency>, | |
| 11 | vulnerabilities: Map<String, List<Vulnerability>> = emptyMap() | |
| 12 | ): DependencyGraph { | |
| 13 | val directCoordinates = directDependencies.map { "${it.groupId}:${it.artifactId}:${it.version}" }.toSet() | |
| 14 | ||
| 15 | val nodeMap = mutableMapOf<String, DependencyNode>() | |
| 16 | ||
| 17 | allDependencies.forEach { dep -> | |
| 18 | val coordinate = "${dep.groupId}:${dep.artifactId}:${dep.version}" | |
| 19 |
1
1. buildGraph : negated conditional → NO_COVERAGE |
val vulns = vulnerabilities[coordinate] ?: emptyList() |
| 20 | | |
| 21 | val node = DependencyNode( | |
| 22 | id = coordinate, | |
| 23 | groupId = dep.groupId, | |
| 24 | artifactId = dep.artifactId, | |
| 25 |
1
1. buildGraph : negated conditional → NO_COVERAGE |
version = dep.version ?: "unknown", |
| 26 | vulnerabilities = vulns, | |
| 27 | ecosystem = dep.ecosystem | |
| 28 | ) | |
| 29 | nodeMap[coordinate] = node | |
| 30 | } | |
| 31 | ||
| 32 | val rootNodes = mutableListOf<DependencyNode>() | |
| 33 | ||
| 34 | directDependencies.forEach { dep -> | |
| 35 | val coordinate = "${dep.groupId}:${dep.artifactId}:${dep.version}" | |
| 36 |
1
1. buildGraph : negated conditional → NO_COVERAGE |
nodeMap[coordinate]?.let { rootNodes.add(it) } |
| 37 | } | |
| 38 | ||
| 39 | val transitiveDeps = allDependencies.filterNot { dep -> | |
| 40 | directCoordinates.contains("${dep.groupId}:${dep.artifactId}:${dep.version}") | |
| 41 | } | |
| 42 | ||
| 43 | transitiveDeps.forEach { transitiv -> | |
| 44 | val transitiveCoord = "${transitiv.groupId}:${transitiv.artifactId}:${transitiv.version}" | |
| 45 |
1
1. buildGraph : negated conditional → NO_COVERAGE |
val transitiveNode = nodeMap[transitiveCoord] ?: return@forEach |
| 46 | ||
| 47 | directDependencies.forEach { direct -> | |
| 48 | val directCoord = "${direct.groupId}:${direct.artifactId}:${direct.version}" | |
| 49 |
2
1. buildGraph : negated conditional → NO_COVERAGE 2. buildGraph : removed call to com/depanalyzer/core/graph/DependencyNode::addChild → NO_COVERAGE |
nodeMap[directCoord]?.addChild(transitiveNode) |
| 50 | } | |
| 51 | } | |
| 52 | ||
| 53 | return DependencyGraph(rootNodes) | |
| 54 | } | |
| 55 | ||
| 56 | } | |
Mutations | ||
| 19 |
1.1 |
|
| 25 |
1.1 |
|
| 36 |
1.1 |
|
| 45 |
1.1 |
|
| 49 |
1.1 2.2 |
|
| 68 |
1.1 |