@@ -33,20 +33,22 @@ final case class ModuleTrees(
3333 def toNode (tree : DependencyTree , root : Boolean ): Unit = {
3434 val dep = tree.dependency
3535 val moduleOrgName = dep.module.orgName
36- val name = s " ${moduleOrgName}: ${dep.version}"
36+ val reconciledVersion = tree.reconciledVersion
37+ val name = s " ${moduleOrgName}: ${reconciledVersion}"
3738
3839 def putTogether : DependencyNode = {
3940 // TODO consider classifiers
4041 val packageUrl =
41- s " pkg:maven/ ${dep.module.organization.value}/ ${dep.module.name.value}@ ${dep.version }"
42+ s " pkg:maven/ ${dep.module.organization.value}/ ${dep.module.name.value}@ ${reconciledVersion }"
4243 val relationShip : DependencyRelationship =
4344 if (root) DependencyRelationship .direct
4445 else DependencyRelationship .indirect
4546 val dependencies = tree.children.map { child =>
46- s " ${child.dependency.module.orgName}: ${child.dependency.version }"
47+ s " ${child.dependency.module.orgName}: ${child.reconciledVersion }"
4748 }
4849 DependencyNode (
4950 Some (packageUrl),
51+ // TODO we can check if original == reconciled here and add metadata that it is a reconciled version
5052 Map .empty,
5153 Some (relationShip),
5254 None ,
@@ -57,37 +59,21 @@ final case class ModuleTrees(
5759 def verifyRelationship (node : DependencyNode ) =
5860 (root && node.isDirectDependency) || (! root && ! node.isDirectDependency)
5961
60- val getsEvicted = dep.version != tree.retainedVersion
61- // So the idea here is that if the retained version doesn't match the dep
62- // version, we know that the dep ends up getting evicted, so we don't
63- // actually need it as an entry since it won't end up on the classpath.
64- // However if it's a root node, we need to ensure we later go back and
65- // mark it as direct. We don't do it while iterating because we may have
66- // already seen the dep that evicted it. See the evicted test for an
67- // example.
68- if (getsEvicted && root) {
69- reconciledDirects += s " ${moduleOrgName}: ${tree.retainedVersion}"
70- } else if (getsEvicted) {
71- // If we know it's evicted here, but we're not at the root level, then
72- // it doesn't matter because it's still not a direct dep.
73- ()
74- } else {
75- allDependencies.get(name) match {
76- // If the node is found and the relationship is correct just do nothing
77- case Some (node) if verifyRelationship(node) => ()
78- // If the node is found and the relationship is incorrect, but it's a
79- // root node, then make sure to mark it as direct
80- case Some (node) if root =>
81- val updated =
82- node.copy(relationship = Some (DependencyRelationship .direct))
83- allDependencies += ((name, updated))
84- // Should never really happen, but it it does do nothing
85- case Some (_) => ()
86- // Unseen dependency, create a node for it
87- case None =>
88- val node = putTogether
89- allDependencies += ((name, node))
90- }
62+ allDependencies.get(name) match {
63+ // If the node is found and the relationship is correct just do nothing
64+ case Some (node) if verifyRelationship(node) => ()
65+ // If the node is found and the relationship is incorrect, but it's a
66+ // root node, then make sure to mark it as direct
67+ case Some (node) if root =>
68+ val updated =
69+ node.copy(relationship = Some (DependencyRelationship .direct))
70+ allDependencies += ((name, updated))
71+ // Should never really happen, but it it does do nothing
72+ case Some (_) => ()
73+ // Unseen dependency, create a node for it
74+ case None =>
75+ val node = putTogether
76+ allDependencies += ((name, node))
9177 }
9278
9379 tree.children.foreach(toNode(_, root = false ))
0 commit comments