jjkester commented on a change in pull request #603:
URL: https://github.com/apache/maven/pull/603#discussion_r745993959



##########
File path: 
maven-model-builder/src/main/java/org/apache/maven/model/composition/DefaultDependencyManagementImporter.java
##########
@@ -83,4 +90,43 @@ public void importManagement( Model target, List<? extends 
DependencyManagement>
         }
     }
 
+    static void updateDependencyHierarchy( Dependency dependency, 
DependencyManagement bom )
+    {
+        // We are only interested in the InputSource, so the location of the 
<dependency> element is sufficient
+        InputLocation dependencyLocation = dependency.getLocation( "" );
+        InputLocation bomLocation = bom.getLocation( "" );
+
+        if ( dependencyLocation == null || bomLocation == null )
+        {
+            return;
+        }
+
+        InputSource hierarchicalSource = dependencyLocation.getSource();
+        InputSource bomSource = bomLocation.getSource();
+
+        // Skip if the dependency and bom have the same source
+        if ( hierarchicalSource == null || bomSource == null || 
Objects.equals( hierarchicalSource.getModelId(),
+                bomSource.getModelId() ) )
+        {
+            return;
+        }
+
+        while ( hierarchicalSource.getImportedBy() != null )

Review comment:
       I had the impression while testing that in long chains (e.g. `pom - bom1 
- bom2 - bom3 - bom4`) parts of the objects defined in `bom4` are copied to 
`bom3`, then `bom2`, etc. This loop ensures that we set a new location at the 
right place, without overwriting any existing. I will however investigate this. 
Also, I expect this code to be quite different if we decide to go with 
`InputLocation` (see 
[here](https://github.com/apache/maven/pull/603#discussion_r745439915)) so I'll 
look into that first.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to