gnodet commented on code in PR #2139:
URL: https://github.com/apache/maven/pull/2139#discussion_r1978116969


##########
impl/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomBuilder.java:
##########
@@ -193,72 +202,72 @@ private ModelBuilderResult 
buildModel(RepositorySystemSession session, Path src)
         return result;
     }
 
-    static Model transform(Model model, MavenProject project) {
-        String packaging = model.getPackaging();
+    static Model transformNonPom(Model model, MavenProject project) {
         boolean preserveModelVersion = model.isPreserveModelVersion();
-        if (POM_PACKAGING.equals(packaging)) {
-            // raw to consumer transform
-            model = 
model.withRoot(false).withModules(null).withSubprojects(null);
-            if (model.getParent() != null) {
-                model = 
model.withParent(model.getParent().withRelativePath(null));
-            }
 
-            if (!preserveModelVersion) {
-                model = model.withPreserveModelVersion(false);
-                String modelVersion = new 
MavenModelVersion().getModelVersion(model);
-                model = model.withModelVersion(modelVersion);
-            }
-        } else if (BOM_PACKAGING.equals(packaging)) {
-            DependencyManagement dependencyManagement =
-                    
project.getOriginalModel().getDependencyManagement().getDelegate();
-            List<Dependency> dependencies = new ArrayList<>();
-            String version = model.getVersion();
-
-            dependencyManagement
-                    .getDependencies()
-                    .forEach((dependency) -> 
dependencies.add(dependency.withVersion(version)));
-            Model.Builder builder = prune(
-                    Model.newBuilder(model, true)
-                            .preserveModelVersion(false)
-                            .root(false)
-                            .parent(null)
-                            
.dependencyManagement(dependencyManagement.withDependencies(dependencies))
-                            .build(null),
-                    model);
-            builder.packaging(POM_PACKAGING);
-            builder.profiles(prune(model.getProfiles()));
-
-            model = builder.build();
-            String modelVersion = new 
MavenModelVersion().getModelVersion(model);
-            if (!ModelBuilder.MODEL_VERSION_4_0_0.equals(modelVersion) && 
!preserveModelVersion) {
-                warnNotDowngraded(project);
-            }
-            model = model.withModelVersion(modelVersion);
-        } else {
-            Model.Builder builder = prune(
-                            Model.newBuilder(model, true)
-                                    .preserveModelVersion(false)
-                                    .root(false)
-                                    .parent(null)
-                                    .build(null),
-                            model)
-                    .mailingLists(null)
-                    .issueManagement(null)
-                    .scm(
-                            model.getScm() != null
-                                    ? Scm.newBuilder(model.getScm(), true)
-                                            
.childScmConnectionInheritAppendPath(null)
-                                            .childScmUrlInheritAppendPath(null)
-                                            
.childScmDeveloperConnectionInheritAppendPath(null)
-                                            .build()
-                                    : null);
-            builder.profiles(prune(model.getProfiles()));
-
-            model = builder.build();
+        Model.Builder builder = prune(
+                        Model.newBuilder(model, true)
+                                .preserveModelVersion(false)
+                                .root(false)
+                                .parent(null)
+                                .build(null),
+                        model)
+                .mailingLists(null)
+                .issueManagement(null)
+                .scm(
+                        model.getScm() != null
+                                ? Scm.newBuilder(model.getScm(), true)
+                                        
.childScmConnectionInheritAppendPath(null)
+                                        .childScmUrlInheritAppendPath(null)
+                                        
.childScmDeveloperConnectionInheritAppendPath(null)
+                                        .build()
+                                : null);
+        builder.profiles(prune(model.getProfiles()));
+
+        model = builder.build();
+        String modelVersion = new MavenModelVersion().getModelVersion(model);
+        if (!ModelBuilder.MODEL_VERSION_4_0_0.equals(modelVersion) && 
!preserveModelVersion) {
+            warnNotDowngraded(project);
+        }
+        model = model.withModelVersion(modelVersion);
+        return model;
+    }
+
+    static Model transformBom(Model model, MavenProject project) {
+        boolean preserveModelVersion = model.isPreserveModelVersion();
+
+        Model.Builder builder = prune(
+                Model.newBuilder(model, true)
+                        .preserveModelVersion(false)
+                        .root(false)
+                        .parent(null)
+                        // 
.dependencyManagement(dependencyManagement.withDependencies(dependencies))

Review Comment:
   The problem is that the consumer POM for the BOM was originally created like 
a POM, i.e. from the raw model, and it was missing some versions for managed 
dependencies.  The fix was overwriting the dependency version with the model 
version.  This is now correctly implemented by using the effective model 
instead of the raw model.



-- 
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: issues-unsubscr...@maven.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to