gnodet-bot commented on code in PR #13263: URL: https://github.com/apache/maven/pull/13263#discussion_r4091521395
########## maven-core/src/test/java/org/apache/maven/project/ProjectSorterDependencyManagementTest.java: ########## @@ -0,0 +1,64 @@ +/* + * 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 java.util.List; + +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; + +class ProjectSorterDependencyManagementTest { + @Test + void importedReactorBomPrecedesConsumer() throws Exception { + MavenProject bom = createProject("org.example", "test-bom", "1-SNAPSHOT"); + MavenProject consumer = createProject("org.example", "test-consumer", "1-SNAPSHOT"); + + Dependency importedBom = new Dependency(); + importedBom.setGroupId("org.example"); + importedBom.setArtifactId("test-bom"); + importedBom.setVersion("${project.version}"); + importedBom.setType("pom"); + importedBom.setScope("import"); + + DependencyManagement dependencyManagement = new DependencyManagement(); + dependencyManagement.addDependency(importedBom); + consumer.getOriginalModel().setDependencyManagement(dependencyManagement); + + 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()); Review Comment: **Missing test: generic property resolution branch in `resolveImportVersion`.** The only test exercises the `${project.version}` fast-path. The second branch — resolving an arbitrary property from `project.getProperties()` — is untested. If that lookup returns `null` (property not present), `resolveImportVersion` falls through and returns the unresolved `${someProperty}` string. `isSpecificVersion` treats that as a concrete version, so `vertices.get("${someProperty}")` returns `null` and the edge is **silently dropped** — the BOM is not added to the reactor sort order even though it's in the reactor. The master test (`List.of` variant) has the same gap. But since this backport introduces the property-resolution logic, a test covering the property-substitution case should be here. Suggested addition: ```java @Test void importedReactorBomWithPropertyVersion() throws Exception { MavenProject bom = createProject("org.example", "test-bom", "1.0"); MavenProject consumer = createProject("org.example", "test-consumer", "1.0"); // version expressed as a project property consumer.getOriginalModel().getProperties().setProperty("bom.version", "1.0"); Dependency importedBom = new Dependency(); importedBom.setGroupId("org.example"); importedBom.setArtifactId("test-bom"); importedBom.setVersion("${bom.version}"); importedBom.setType("pom"); importedBom.setScope("import"); DependencyManagement dependencyManagement = new DependencyManagement(); dependencyManagement.addDependency(importedBom); consumer.getOriginalModel().setDependencyManagement(dependencyManagement); 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]
