jamesfredley commented on code in PR #15467:
URL: https://github.com/apache/grails-core/pull/15467#discussion_r3342077696


##########
build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsDependencyValidatorPlugin.groovy:
##########
@@ -159,19 +161,49 @@ class GrailsDependencyValidatorPlugin implements 
Plugin<Project> {
 
     /**
      * Scans the project's configurations to find which BOM project is in use.
+     *
+     * <p>When multiple known BOMs are declared on the same project (for 
example,
+     * the {@code grails-app} plugin auto-injects {@code platform(grails-bom)} 
on
+     * every declarable configuration while a Micronaut project additionally
+     * declares {@code enforcedPlatform(grails-micronaut-bom)}), this method
+     * prefers an {@code enforcedPlatform} declaration over a regular
+     * {@code platform}. The enforced BOM is the one whose constraints actually
+     * win at resolution time, so it is the correct reference for the
+     * "expected" versions reported by the validator.</p>
      */
     static String detectBomPath(Project project) {
+        String regularPlatformBomPath = null
+
         for (Configuration config : project.configurations) {
             for (Dependency dep : config.dependencies) {
-                if (BOM_PROJECT_NAMES.contains(dep.name)) {
-                    Project bomProject = 
project.rootProject.findProject(":${dep.name}" as String)
-                    if (bomProject != null) {
-                        return bomProject.path
-                    }
+                if (!BOM_PROJECT_NAMES.contains(dep.name)) {
+                    continue
+                }
+                Project bomProject = 
project.rootProject.findProject(":${dep.name}" as String)
+                if (bomProject == null) {
+                    continue
+                }
+                if (isEnforcedPlatformDependency(dep)) {
+                    return bomProject.path
+                }
+                if (regularPlatformBomPath == null) {
+                    regularPlatformBomPath = bomProject.path
                 }
             }
         }
-        null
+
+        regularPlatformBomPath
+    }
+
+    private static boolean isEnforcedPlatformDependency(Dependency dep) {
+        if (!(dep instanceof ModuleDependency)) {
+            return false
+        }
+        Object categoryAttr = ((ModuleDependency) 
dep).attributes.getAttribute(Category.CATEGORY_ATTRIBUTE)

Review Comment:
   Done in c2ac4a6948.



##########
build-logic/docs-core/src/main/groovy/org/apache/grails/gradle/tasks/bom/ExtractDependenciesTask.groovy:
##########
@@ -259,91 +261,229 @@ abstract class ExtractDependenciesTask extends 
DefaultTask {
     Properties populatePlatformDependencies(CoordinateVersionHolder 
bomCoordinates, List<CoordinateHolder> exclusionRules, Map<CoordinateHolder, 
ExtractedDependencyConstraint> constraints, boolean error = true, int level = 
0) {
         Dependency bomDependency = 
dependencyHandler.create("${bomCoordinates.coordinates}@pom")
         Configuration dependencyConfiguration = 
configurationContainer.detachedConfiguration(bomDependency)
+        dependencyConfiguration.transitive = false
         File bomPomFile = dependencyConfiguration.singleFile
 
-        MavenXpp3Reader reader = new MavenXpp3Reader()
-        Model model = reader.read(new FileReader(bomPomFile))
-
+        Document doc = parsePom(bomPomFile)
         Properties versionProperties = new Properties()
-        if (model.parent) {
-            // Need to populate the parent bom if it's present first
-            CoordinateVersionHolder parentBom = new CoordinateVersionHolder(
-                    groupId: model.parent.groupId,
-                    artifactId: model.parent.artifactId,
-                    version: model.parent.version
-            )
+
+        // Parent POM populated first so its properties can be overridden by 
the child
+        CoordinateVersionHolder parentBom = readParentCoordinates(doc)
+        if (parentBom) {
             populatePlatformDependencies(parentBom, exclusionRules, 
constraints, false, level + 1)?.entrySet()?.each { Map.Entry<Object, Object> 
entry ->
                 versionProperties.put(entry.key, entry.value)
             }
         }
-        model.properties.entrySet().each { Map.Entry<Object, Object> entry ->
-            versionProperties.put(entry.key, entry.value)
+
+        readProperties(doc).each { String name, String value ->
+            versionProperties.put(name, value)
         }
         versionProperties.put('project.groupId', bomCoordinates.groupId)
         versionProperties.put('project.version', bomCoordinates.version)
 
-        if (model.dependencyManagement && 
model.dependencyManagement.dependencies) {
-            for 
(io.spring.gradle.dependencymanagement.org.apache.maven.model.Dependency 
depItem : model.dependencyManagement.dependencies) {
-                CoordinateHolder baseCoordinates = new CoordinateHolder(
-                        groupId: depItem.groupId,
-                        artifactId: depItem.artifactId
-                )
-
-                CoordinateHolder resolvedCoordinates = new CoordinateHolder(
-                        groupId: 
resolveMavenProperty(baseCoordinates.coordinatesWithoutVersion, 
depItem.groupId, versionProperties),
-                        artifactId: 
resolveMavenProperty(baseCoordinates.coordinatesWithoutVersion, 
depItem.artifactId, versionProperties)
-                )
-
-                if (!constraints.containsKey(resolvedCoordinates)) {
-                    boolean isExcluded = exclusionRules.any { CoordinateHolder 
excludedCoordinate ->
-                        if (excludedCoordinate.groupId && 
excludedCoordinate.artifactId) {
-                            return resolvedCoordinates == excludedCoordinate
-                        }
-
-                        if (excludedCoordinate.groupId && 
!excludedCoordinate.artifactId) {
-                            return depItem.groupId == 
excludedCoordinate.groupId
-                        }
-
-                        if (!excludedCoordinate.groupId && 
excludedCoordinate.artifactId) {
-                            return depItem.artifactId == 
excludedCoordinate.artifactId
-                        }
-
-                        false
-                    }
-
-                    if (!isExcluded) {
-                        String resolvedVersion = 
resolveMavenProperty(resolvedCoordinates.coordinatesWithoutVersion, 
depItem.version, versionProperties)
-                        String propertyName = depItem.version.contains('$') ? 
depItem.version : null
-                        ExtractedDependencyConstraint constraint = new 
ExtractedDependencyConstraint(
-                                groupId: resolvedCoordinates.groupId, 
artifactId: resolvedCoordinates.artifactId,
-                                version: resolvedVersion, 
versionPropertyReference: propertyName, source: bomCoordinates.artifactId
-                        )
-                        if (depItem.scope == 'import') {
-                            constraints.put(resolvedCoordinates, constraint)
-
-                            CoordinateVersionHolder resolvedBomCoordinates = 
new CoordinateVersionHolder(
-                                    groupId: resolvedCoordinates.groupId,
-                                    artifactId: resolvedCoordinates.artifactId,
-                                    version: resolvedVersion
-                            )
-                            
populatePlatformDependencies(resolvedBomCoordinates, exclusionRules, 
constraints, error, level + 1)
-                        } else {
-                            constraints.put(resolvedCoordinates, constraint)
-                        }
-                    }
-                }
-            }
-        } else {
+        List<ManagedDependency> managedDependencies = 
readManagedDependencies(doc)
+        if (managedDependencies.isEmpty()) {
             if (error) {
                 // only the boms we directly include need to error since we 
expect a dependency management;
                 // parent boms are sometimes use to share properties so we 
need to not error on these cases
                 throw new GradleException("BOM ${bomCoordinates.coordinates} 
has no dependencyManagement section.")
             }
+            return versionProperties
+        }
+
+        for (ManagedDependency depItem : managedDependencies) {
+            CoordinateHolder baseCoordinates = new CoordinateHolder(
+                    groupId: depItem.groupId,
+                    artifactId: depItem.artifactId
+            )
+
+            CoordinateHolder resolvedCoordinates = new CoordinateHolder(
+                    groupId: 
resolveMavenProperty(baseCoordinates.coordinatesWithoutVersion, 
depItem.groupId, versionProperties),
+                    artifactId: 
resolveMavenProperty(baseCoordinates.coordinatesWithoutVersion, 
depItem.artifactId, versionProperties)
+            )
+
+            if (constraints.containsKey(resolvedCoordinates)) {
+                continue
+            }
+
+            boolean isExcluded = exclusionRules.any { CoordinateHolder 
excludedCoordinate ->
+                if (excludedCoordinate.groupId && 
excludedCoordinate.artifactId) {
+                    return resolvedCoordinates == excludedCoordinate
+                }
+
+                if (excludedCoordinate.groupId && 
!excludedCoordinate.artifactId) {
+                    return depItem.groupId == excludedCoordinate.groupId
+                }
+
+                if (!excludedCoordinate.groupId && 
excludedCoordinate.artifactId) {
+                    return depItem.artifactId == excludedCoordinate.artifactId
+                }
+
+                false
+            }
+
+            if (isExcluded) {
+                continue
+            }
+
+            String resolvedVersion = 
resolveMavenProperty(resolvedCoordinates.coordinatesWithoutVersion, 
depItem.version, versionProperties)
+            String propertyName = depItem.version?.contains('$') ? 
depItem.version : null
+            ExtractedDependencyConstraint constraint = new 
ExtractedDependencyConstraint(
+                    groupId: resolvedCoordinates.groupId, artifactId: 
resolvedCoordinates.artifactId,
+                    version: resolvedVersion, versionPropertyReference: 
propertyName, source: bomCoordinates.artifactId
+            )
+            constraints.put(resolvedCoordinates, constraint)
+
+            if (depItem.scope == 'import') {
+                CoordinateVersionHolder resolvedBomCoordinates = new 
CoordinateVersionHolder(
+                        groupId: resolvedCoordinates.groupId,
+                        artifactId: resolvedCoordinates.artifactId,
+                        version: resolvedVersion
+                )
+                populatePlatformDependencies(resolvedBomCoordinates, 
exclusionRules, constraints, error, level + 1)
+            }
         }
 
         versionProperties
     }
 
+    /**
+     * Parses a BOM POM file using the JDK's built-in {@link 
DocumentBuilderFactory}.
+     * XML parsing is hardened against XXE / XInclude attacks.
+     */
+    private static Document parsePom(File pomFile) {
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance()
+        factory.setNamespaceAware(false)
+        factory.setValidating(false)
+        factory.setXIncludeAware(false)
+        
factory.setFeature('http://apache.org/xml/features/nonvalidating/load-external-dtd',
 false)
+        
factory.setFeature('http://xml.org/sax/features/external-general-entities', 
false)
+        
factory.setFeature('http://xml.org/sax/features/external-parameter-entities', 
false)
+        return factory.newDocumentBuilder().parse(pomFile)

Review Comment:
   Done in c2ac4a6948 - applied your `tap {}` suggestion.



##########
build-logic/docs-core/src/main/groovy/org/apache/grails/gradle/tasks/bom/ExtractDependenciesTask.groovy:
##########
@@ -259,91 +261,229 @@ abstract class ExtractDependenciesTask extends 
DefaultTask {
     Properties populatePlatformDependencies(CoordinateVersionHolder 
bomCoordinates, List<CoordinateHolder> exclusionRules, Map<CoordinateHolder, 
ExtractedDependencyConstraint> constraints, boolean error = true, int level = 
0) {
         Dependency bomDependency = 
dependencyHandler.create("${bomCoordinates.coordinates}@pom")
         Configuration dependencyConfiguration = 
configurationContainer.detachedConfiguration(bomDependency)
+        dependencyConfiguration.transitive = false
         File bomPomFile = dependencyConfiguration.singleFile
 
-        MavenXpp3Reader reader = new MavenXpp3Reader()
-        Model model = reader.read(new FileReader(bomPomFile))
-
+        Document doc = parsePom(bomPomFile)
         Properties versionProperties = new Properties()
-        if (model.parent) {
-            // Need to populate the parent bom if it's present first
-            CoordinateVersionHolder parentBom = new CoordinateVersionHolder(
-                    groupId: model.parent.groupId,
-                    artifactId: model.parent.artifactId,
-                    version: model.parent.version
-            )
+
+        // Parent POM populated first so its properties can be overridden by 
the child
+        CoordinateVersionHolder parentBom = readParentCoordinates(doc)
+        if (parentBom) {
             populatePlatformDependencies(parentBom, exclusionRules, 
constraints, false, level + 1)?.entrySet()?.each { Map.Entry<Object, Object> 
entry ->
                 versionProperties.put(entry.key, entry.value)
             }
         }
-        model.properties.entrySet().each { Map.Entry<Object, Object> entry ->
-            versionProperties.put(entry.key, entry.value)
+
+        readProperties(doc).each { String name, String value ->
+            versionProperties.put(name, value)
         }
         versionProperties.put('project.groupId', bomCoordinates.groupId)
         versionProperties.put('project.version', bomCoordinates.version)
 
-        if (model.dependencyManagement && 
model.dependencyManagement.dependencies) {
-            for 
(io.spring.gradle.dependencymanagement.org.apache.maven.model.Dependency 
depItem : model.dependencyManagement.dependencies) {
-                CoordinateHolder baseCoordinates = new CoordinateHolder(
-                        groupId: depItem.groupId,
-                        artifactId: depItem.artifactId
-                )
-
-                CoordinateHolder resolvedCoordinates = new CoordinateHolder(
-                        groupId: 
resolveMavenProperty(baseCoordinates.coordinatesWithoutVersion, 
depItem.groupId, versionProperties),
-                        artifactId: 
resolveMavenProperty(baseCoordinates.coordinatesWithoutVersion, 
depItem.artifactId, versionProperties)
-                )
-
-                if (!constraints.containsKey(resolvedCoordinates)) {
-                    boolean isExcluded = exclusionRules.any { CoordinateHolder 
excludedCoordinate ->
-                        if (excludedCoordinate.groupId && 
excludedCoordinate.artifactId) {
-                            return resolvedCoordinates == excludedCoordinate
-                        }
-
-                        if (excludedCoordinate.groupId && 
!excludedCoordinate.artifactId) {
-                            return depItem.groupId == 
excludedCoordinate.groupId
-                        }
-
-                        if (!excludedCoordinate.groupId && 
excludedCoordinate.artifactId) {
-                            return depItem.artifactId == 
excludedCoordinate.artifactId
-                        }
-
-                        false
-                    }
-
-                    if (!isExcluded) {
-                        String resolvedVersion = 
resolveMavenProperty(resolvedCoordinates.coordinatesWithoutVersion, 
depItem.version, versionProperties)
-                        String propertyName = depItem.version.contains('$') ? 
depItem.version : null
-                        ExtractedDependencyConstraint constraint = new 
ExtractedDependencyConstraint(
-                                groupId: resolvedCoordinates.groupId, 
artifactId: resolvedCoordinates.artifactId,
-                                version: resolvedVersion, 
versionPropertyReference: propertyName, source: bomCoordinates.artifactId
-                        )
-                        if (depItem.scope == 'import') {
-                            constraints.put(resolvedCoordinates, constraint)
-
-                            CoordinateVersionHolder resolvedBomCoordinates = 
new CoordinateVersionHolder(
-                                    groupId: resolvedCoordinates.groupId,
-                                    artifactId: resolvedCoordinates.artifactId,
-                                    version: resolvedVersion
-                            )
-                            
populatePlatformDependencies(resolvedBomCoordinates, exclusionRules, 
constraints, error, level + 1)
-                        } else {
-                            constraints.put(resolvedCoordinates, constraint)
-                        }
-                    }
-                }
-            }
-        } else {
+        List<ManagedDependency> managedDependencies = 
readManagedDependencies(doc)
+        if (managedDependencies.isEmpty()) {
             if (error) {
                 // only the boms we directly include need to error since we 
expect a dependency management;
                 // parent boms are sometimes use to share properties so we 
need to not error on these cases
                 throw new GradleException("BOM ${bomCoordinates.coordinates} 
has no dependencyManagement section.")
             }
+            return versionProperties
+        }
+
+        for (ManagedDependency depItem : managedDependencies) {
+            CoordinateHolder baseCoordinates = new CoordinateHolder(
+                    groupId: depItem.groupId,
+                    artifactId: depItem.artifactId
+            )
+
+            CoordinateHolder resolvedCoordinates = new CoordinateHolder(
+                    groupId: 
resolveMavenProperty(baseCoordinates.coordinatesWithoutVersion, 
depItem.groupId, versionProperties),
+                    artifactId: 
resolveMavenProperty(baseCoordinates.coordinatesWithoutVersion, 
depItem.artifactId, versionProperties)
+            )
+
+            if (constraints.containsKey(resolvedCoordinates)) {
+                continue
+            }
+
+            boolean isExcluded = exclusionRules.any { CoordinateHolder 
excludedCoordinate ->
+                if (excludedCoordinate.groupId && 
excludedCoordinate.artifactId) {
+                    return resolvedCoordinates == excludedCoordinate
+                }
+
+                if (excludedCoordinate.groupId && 
!excludedCoordinate.artifactId) {
+                    return depItem.groupId == excludedCoordinate.groupId
+                }
+
+                if (!excludedCoordinate.groupId && 
excludedCoordinate.artifactId) {
+                    return depItem.artifactId == excludedCoordinate.artifactId
+                }
+
+                false
+            }
+
+            if (isExcluded) {
+                continue
+            }
+
+            String resolvedVersion = 
resolveMavenProperty(resolvedCoordinates.coordinatesWithoutVersion, 
depItem.version, versionProperties)
+            String propertyName = depItem.version?.contains('$') ? 
depItem.version : null
+            ExtractedDependencyConstraint constraint = new 
ExtractedDependencyConstraint(
+                    groupId: resolvedCoordinates.groupId, artifactId: 
resolvedCoordinates.artifactId,
+                    version: resolvedVersion, versionPropertyReference: 
propertyName, source: bomCoordinates.artifactId
+            )
+            constraints.put(resolvedCoordinates, constraint)
+
+            if (depItem.scope == 'import') {
+                CoordinateVersionHolder resolvedBomCoordinates = new 
CoordinateVersionHolder(

Review Comment:
   Done in c2ac4a6948.



##########
build-logic/docs-core/src/main/groovy/org/apache/grails/gradle/tasks/bom/ExtractDependenciesTask.groovy:
##########
@@ -259,91 +261,229 @@ abstract class ExtractDependenciesTask extends 
DefaultTask {
     Properties populatePlatformDependencies(CoordinateVersionHolder 
bomCoordinates, List<CoordinateHolder> exclusionRules, Map<CoordinateHolder, 
ExtractedDependencyConstraint> constraints, boolean error = true, int level = 
0) {
         Dependency bomDependency = 
dependencyHandler.create("${bomCoordinates.coordinates}@pom")
         Configuration dependencyConfiguration = 
configurationContainer.detachedConfiguration(bomDependency)
+        dependencyConfiguration.transitive = false
         File bomPomFile = dependencyConfiguration.singleFile
 
-        MavenXpp3Reader reader = new MavenXpp3Reader()
-        Model model = reader.read(new FileReader(bomPomFile))
-
+        Document doc = parsePom(bomPomFile)
         Properties versionProperties = new Properties()
-        if (model.parent) {
-            // Need to populate the parent bom if it's present first
-            CoordinateVersionHolder parentBom = new CoordinateVersionHolder(
-                    groupId: model.parent.groupId,
-                    artifactId: model.parent.artifactId,
-                    version: model.parent.version
-            )
+
+        // Parent POM populated first so its properties can be overridden by 
the child
+        CoordinateVersionHolder parentBom = readParentCoordinates(doc)
+        if (parentBom) {
             populatePlatformDependencies(parentBom, exclusionRules, 
constraints, false, level + 1)?.entrySet()?.each { Map.Entry<Object, Object> 
entry ->
                 versionProperties.put(entry.key, entry.value)
             }
         }
-        model.properties.entrySet().each { Map.Entry<Object, Object> entry ->
-            versionProperties.put(entry.key, entry.value)
+
+        readProperties(doc).each { String name, String value ->
+            versionProperties.put(name, value)
         }
         versionProperties.put('project.groupId', bomCoordinates.groupId)
         versionProperties.put('project.version', bomCoordinates.version)
 
-        if (model.dependencyManagement && 
model.dependencyManagement.dependencies) {
-            for 
(io.spring.gradle.dependencymanagement.org.apache.maven.model.Dependency 
depItem : model.dependencyManagement.dependencies) {
-                CoordinateHolder baseCoordinates = new CoordinateHolder(
-                        groupId: depItem.groupId,
-                        artifactId: depItem.artifactId
-                )
-
-                CoordinateHolder resolvedCoordinates = new CoordinateHolder(
-                        groupId: 
resolveMavenProperty(baseCoordinates.coordinatesWithoutVersion, 
depItem.groupId, versionProperties),
-                        artifactId: 
resolveMavenProperty(baseCoordinates.coordinatesWithoutVersion, 
depItem.artifactId, versionProperties)
-                )
-
-                if (!constraints.containsKey(resolvedCoordinates)) {
-                    boolean isExcluded = exclusionRules.any { CoordinateHolder 
excludedCoordinate ->
-                        if (excludedCoordinate.groupId && 
excludedCoordinate.artifactId) {
-                            return resolvedCoordinates == excludedCoordinate
-                        }
-
-                        if (excludedCoordinate.groupId && 
!excludedCoordinate.artifactId) {
-                            return depItem.groupId == 
excludedCoordinate.groupId
-                        }
-
-                        if (!excludedCoordinate.groupId && 
excludedCoordinate.artifactId) {
-                            return depItem.artifactId == 
excludedCoordinate.artifactId
-                        }
-
-                        false
-                    }
-
-                    if (!isExcluded) {
-                        String resolvedVersion = 
resolveMavenProperty(resolvedCoordinates.coordinatesWithoutVersion, 
depItem.version, versionProperties)
-                        String propertyName = depItem.version.contains('$') ? 
depItem.version : null
-                        ExtractedDependencyConstraint constraint = new 
ExtractedDependencyConstraint(
-                                groupId: resolvedCoordinates.groupId, 
artifactId: resolvedCoordinates.artifactId,
-                                version: resolvedVersion, 
versionPropertyReference: propertyName, source: bomCoordinates.artifactId
-                        )
-                        if (depItem.scope == 'import') {
-                            constraints.put(resolvedCoordinates, constraint)
-
-                            CoordinateVersionHolder resolvedBomCoordinates = 
new CoordinateVersionHolder(
-                                    groupId: resolvedCoordinates.groupId,
-                                    artifactId: resolvedCoordinates.artifactId,
-                                    version: resolvedVersion
-                            )
-                            
populatePlatformDependencies(resolvedBomCoordinates, exclusionRules, 
constraints, error, level + 1)
-                        } else {
-                            constraints.put(resolvedCoordinates, constraint)
-                        }
-                    }
-                }
-            }
-        } else {
+        List<ManagedDependency> managedDependencies = 
readManagedDependencies(doc)
+        if (managedDependencies.isEmpty()) {
             if (error) {
                 // only the boms we directly include need to error since we 
expect a dependency management;
                 // parent boms are sometimes use to share properties so we 
need to not error on these cases
                 throw new GradleException("BOM ${bomCoordinates.coordinates} 
has no dependencyManagement section.")
             }
+            return versionProperties
+        }
+
+        for (ManagedDependency depItem : managedDependencies) {
+            CoordinateHolder baseCoordinates = new CoordinateHolder(
+                    groupId: depItem.groupId,
+                    artifactId: depItem.artifactId
+            )
+
+            CoordinateHolder resolvedCoordinates = new CoordinateHolder(
+                    groupId: 
resolveMavenProperty(baseCoordinates.coordinatesWithoutVersion, 
depItem.groupId, versionProperties),
+                    artifactId: 
resolveMavenProperty(baseCoordinates.coordinatesWithoutVersion, 
depItem.artifactId, versionProperties)
+            )
+
+            if (constraints.containsKey(resolvedCoordinates)) {
+                continue
+            }
+
+            boolean isExcluded = exclusionRules.any { CoordinateHolder 
excludedCoordinate ->
+                if (excludedCoordinate.groupId && 
excludedCoordinate.artifactId) {
+                    return resolvedCoordinates == excludedCoordinate
+                }
+
+                if (excludedCoordinate.groupId && 
!excludedCoordinate.artifactId) {
+                    return depItem.groupId == excludedCoordinate.groupId
+                }
+
+                if (!excludedCoordinate.groupId && 
excludedCoordinate.artifactId) {
+                    return depItem.artifactId == excludedCoordinate.artifactId
+                }
+
+                false
+            }
+
+            if (isExcluded) {
+                continue
+            }
+
+            String resolvedVersion = 
resolveMavenProperty(resolvedCoordinates.coordinatesWithoutVersion, 
depItem.version, versionProperties)
+            String propertyName = depItem.version?.contains('$') ? 
depItem.version : null
+            ExtractedDependencyConstraint constraint = new 
ExtractedDependencyConstraint(

Review Comment:
   Done in c2ac4a6948 - `resolvedVersion`, `propertyName` and `constraint` now 
use `def`.



##########
build-logic/docs-core/src/main/groovy/org/apache/grails/gradle/tasks/bom/ExtractDependenciesTask.groovy:
##########
@@ -259,91 +261,229 @@ abstract class ExtractDependenciesTask extends 
DefaultTask {
     Properties populatePlatformDependencies(CoordinateVersionHolder 
bomCoordinates, List<CoordinateHolder> exclusionRules, Map<CoordinateHolder, 
ExtractedDependencyConstraint> constraints, boolean error = true, int level = 
0) {
         Dependency bomDependency = 
dependencyHandler.create("${bomCoordinates.coordinates}@pom")
         Configuration dependencyConfiguration = 
configurationContainer.detachedConfiguration(bomDependency)
+        dependencyConfiguration.transitive = false
         File bomPomFile = dependencyConfiguration.singleFile
 
-        MavenXpp3Reader reader = new MavenXpp3Reader()
-        Model model = reader.read(new FileReader(bomPomFile))
-
+        Document doc = parsePom(bomPomFile)
         Properties versionProperties = new Properties()
-        if (model.parent) {
-            // Need to populate the parent bom if it's present first
-            CoordinateVersionHolder parentBom = new CoordinateVersionHolder(
-                    groupId: model.parent.groupId,
-                    artifactId: model.parent.artifactId,
-                    version: model.parent.version
-            )
+
+        // Parent POM populated first so its properties can be overridden by 
the child
+        CoordinateVersionHolder parentBom = readParentCoordinates(doc)
+        if (parentBom) {
             populatePlatformDependencies(parentBom, exclusionRules, 
constraints, false, level + 1)?.entrySet()?.each { Map.Entry<Object, Object> 
entry ->
                 versionProperties.put(entry.key, entry.value)
             }
         }
-        model.properties.entrySet().each { Map.Entry<Object, Object> entry ->
-            versionProperties.put(entry.key, entry.value)
+
+        readProperties(doc).each { String name, String value ->
+            versionProperties.put(name, value)
         }
         versionProperties.put('project.groupId', bomCoordinates.groupId)
         versionProperties.put('project.version', bomCoordinates.version)
 
-        if (model.dependencyManagement && 
model.dependencyManagement.dependencies) {
-            for 
(io.spring.gradle.dependencymanagement.org.apache.maven.model.Dependency 
depItem : model.dependencyManagement.dependencies) {
-                CoordinateHolder baseCoordinates = new CoordinateHolder(
-                        groupId: depItem.groupId,
-                        artifactId: depItem.artifactId
-                )
-
-                CoordinateHolder resolvedCoordinates = new CoordinateHolder(
-                        groupId: 
resolveMavenProperty(baseCoordinates.coordinatesWithoutVersion, 
depItem.groupId, versionProperties),
-                        artifactId: 
resolveMavenProperty(baseCoordinates.coordinatesWithoutVersion, 
depItem.artifactId, versionProperties)
-                )
-
-                if (!constraints.containsKey(resolvedCoordinates)) {
-                    boolean isExcluded = exclusionRules.any { CoordinateHolder 
excludedCoordinate ->
-                        if (excludedCoordinate.groupId && 
excludedCoordinate.artifactId) {
-                            return resolvedCoordinates == excludedCoordinate
-                        }
-
-                        if (excludedCoordinate.groupId && 
!excludedCoordinate.artifactId) {
-                            return depItem.groupId == 
excludedCoordinate.groupId
-                        }
-
-                        if (!excludedCoordinate.groupId && 
excludedCoordinate.artifactId) {
-                            return depItem.artifactId == 
excludedCoordinate.artifactId
-                        }
-
-                        false
-                    }
-
-                    if (!isExcluded) {
-                        String resolvedVersion = 
resolveMavenProperty(resolvedCoordinates.coordinatesWithoutVersion, 
depItem.version, versionProperties)
-                        String propertyName = depItem.version.contains('$') ? 
depItem.version : null
-                        ExtractedDependencyConstraint constraint = new 
ExtractedDependencyConstraint(
-                                groupId: resolvedCoordinates.groupId, 
artifactId: resolvedCoordinates.artifactId,
-                                version: resolvedVersion, 
versionPropertyReference: propertyName, source: bomCoordinates.artifactId
-                        )
-                        if (depItem.scope == 'import') {
-                            constraints.put(resolvedCoordinates, constraint)
-
-                            CoordinateVersionHolder resolvedBomCoordinates = 
new CoordinateVersionHolder(
-                                    groupId: resolvedCoordinates.groupId,
-                                    artifactId: resolvedCoordinates.artifactId,
-                                    version: resolvedVersion
-                            )
-                            
populatePlatformDependencies(resolvedBomCoordinates, exclusionRules, 
constraints, error, level + 1)
-                        } else {
-                            constraints.put(resolvedCoordinates, constraint)
-                        }
-                    }
-                }
-            }
-        } else {
+        List<ManagedDependency> managedDependencies = 
readManagedDependencies(doc)
+        if (managedDependencies.isEmpty()) {
             if (error) {
                 // only the boms we directly include need to error since we 
expect a dependency management;
                 // parent boms are sometimes use to share properties so we 
need to not error on these cases
                 throw new GradleException("BOM ${bomCoordinates.coordinates} 
has no dependencyManagement section.")
             }
+            return versionProperties
+        }
+
+        for (ManagedDependency depItem : managedDependencies) {

Review Comment:
   Done in c2ac4a6948.



-- 
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