gnodet-bot commented on code in PR #13263: URL: https://github.com/apache/maven/pull/13263#discussion_r4091586129
########## maven-core/src/test/java/org/apache/maven/project/ProjectSorterDependencyManagementTest.java: ########## @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.project; + +import java.util.Arrays; + +import org.apache.maven.model.Dependency; +import org.apache.maven.model.DependencyManagement; +import org.apache.maven.model.Model; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class ProjectSorterDependencyManagementTest { + + /** + * Verifies that a BOM module imported via {@code <dependencyManagement>} is treated as a + * reactor graph edge: the BOM must be sorted before its consumer (-am direction). + */ + @Test + void importedReactorBomPrecedesConsumer() throws Exception { + MavenProject bom = createProject("org.example", "test-bom", "1-SNAPSHOT"); + MavenProject consumer = createProject("org.example", "test-consumer", "1-SNAPSHOT"); + + addBomImport(consumer, "org.example", "test-bom", "${project.version}"); + + ProjectSorter sorter = new ProjectSorter(Arrays.asList(consumer, bom)); + + assertEquals(Arrays.asList(ProjectSorter.getId(bom)), sorter.getDependencies(ProjectSorter.getId(consumer))); + assertEquals(Arrays.asList(bom, consumer), sorter.getSortedProjects()); + } + + /** + * Verifies the reverse direction (-amd): the consumer is a downstream dependent of the BOM, + * so the BOM knows about the consumer as one of its dependents. + */ + @Test + void importedReactorBomKnowsItsDependents() throws Exception { + MavenProject bom = createProject("org.example", "test-bom", "1-SNAPSHOT"); + MavenProject consumer = createProject("org.example", "test-consumer", "1-SNAPSHOT"); + + addBomImport(consumer, "org.example", "test-bom", "${project.version}"); + + ProjectSorter sorter = new ProjectSorter(Arrays.asList(consumer, bom)); + + assertTrue( + sorter.getDependents(ProjectSorter.getId(bom)).contains(ProjectSorter.getId(consumer)), + "BOM should list the importing consumer as a dependent"); + } + + // ------------------------------------------------------------------------- Review Comment: **Prior finding not addressed: generic property resolution branch in `resolveImportVersion` is still untested.** Both `importedReactorBomPrecedesConsumer` and `importedReactorBomKnowsItsDependents` use `${project.version}`, which hits the fast-path (`project.getVersion()` return). The second branch — resolving an arbitrary property via `project.getProperties().getProperty(...)` — has no test coverage. The failure mode if the property is absent: `resolveImportVersion` returns the unresolved placeholder (`${bom.version}`). `isSpecificVersion` returns `true` for it (non-empty, no `[` or `(`), so `vertices.get("${bom.version}")` is called, returns `null`, and the edge is silently dropped — the BOM is excluded from the reactor sort even though it's in the reactor. Add a test that covers this path: ```java @Test void importedReactorBomWithPropertyVersion() throws Exception { MavenProject bom = createProject("org.example", "test-bom", "1.0"); MavenProject consumer = createProject("org.example", "test-consumer", "1.0"); // Resolve via project.getProperties() — exercises the second branch of resolveImportVersion consumer.getOriginalModel().getProperties().setProperty("bom.version", "1.0"); addBomImport(consumer, "org.example", "test-bom", "${bom.version}"); ProjectSorter sorter = new ProjectSorter(Arrays.asList(consumer, bom)); assertEquals(Arrays.asList(ProjectSorter.getId(bom)), sorter.getDependencies(ProjectSorter.getId(consumer))); assertEquals(Arrays.asList(bom, consumer), sorter.getSortedProjects()); } ``` -- 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]
