elharo commented on code in PR #2058:
URL: https://github.com/apache/maven/pull/2058#discussion_r1929532595
##########
impl/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomBuilder.java:
##########
@@ -77,20 +83,88 @@ public Model build(RepositorySystemSession session,
MavenProject project, Path s
protected Model buildPom(RepositorySystemSession session, MavenProject
project, Path src)
throws ModelBuilderException {
- ModelBuilderResult result = buildModel(session, project, src);
+ ModelBuilderResult result = buildModel(session, src);
Model model = result.getRawModel();
return transform(model, project);
}
protected Model buildNonPom(RepositorySystemSession session, MavenProject
project, Path src)
throws ModelBuilderException {
- ModelBuilderResult result = buildModel(session, project, src);
- Model model = result.getEffectiveModel();
+ Model model = buildEffectiveModel(session, src);
return transform(model, project);
}
- private ModelBuilderResult buildModel(RepositorySystemSession session,
MavenProject project, Path src)
- throws ModelBuilderException {
+ private Model buildEffectiveModel(RepositorySystemSession session, Path
src) throws ModelBuilderException {
+ InternalSession iSession = InternalSession.from(session);
+ ModelBuilderResult result = buildModel(session, src);
+ Model model = result.getEffectiveModel();
+
+ if (model.getDependencyManagement() != null
+ &&
!model.getDependencyManagement().getDependencies().isEmpty()) {
+ ArtifactCoordinates artifact = iSession.createArtifactCoordinates(
+ model.getGroupId(), model.getArtifactId(),
model.getVersion(), null);
+ DependencyCoordinates dependency =
iSession.createDependencyCoordinates(artifact);
+ Node node = iSession.collectDependencies(dependency,
PathScope.TEST_RUNTIME);
+
+ Map<String, Node> nodes =
+ node.stream().collect(Collectors.toMap(n ->
getDependencyKey(n.getDependency()), n -> n));
+ Map<String, Dependency> directDeps =
model.getDependencies().stream()
+ .collect(Collectors.toMap(d -> getDependencyKey(d), d ->
d, this::merge, LinkedHashMap::new));
+ Map<String, Dependency> managedDeps =
model.getDependencyManagement().getDependencies().stream()
+ .filter(d -> nodes.containsKey(getDependencyKey(d)))
+ .collect(Collectors.toMap(d -> getDependencyKey(d), d ->
d, this::merge, LinkedHashMap::new));
+
+ // for each managed dep in the model:
+ // * if there is no corresponding node in the tree, discard the
managed dep
+ // * if there's a direct dependency, apply the managed dependency
to it and discard the managed dep
+ // * else keep the managed dep
+ managedDeps.keySet().retainAll(nodes.keySet());
+
+ directDeps.replaceAll((key, dep) -> {
+ var managedDep = managedDeps.get(key);
Review Comment:
dep --> dependency here and elsewhere. In general, avoiding abbreviations in
variable names and elsewhere improves readability.
--
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]