This is an automated email from the ASF dual-hosted git repository.

slawekjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-help-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new 14a2570  Report parent POM profiles as inactive (#441)
14a2570 is described below

commit 14a257091fcc1024929d2794085951b0af4de431
Author: Efe <[email protected]>
AuthorDate: Sat Nov 14 13:22:15 2026 +0300

    Report parent POM profiles as inactive (#441)
    
    * Fix parent profile activity reporting
    
    * Handle inherited active parent profiles
    
    * Use injected model IDs for parent profile activity
    
    Keep all-profiles consistent with active-profiles for parent and 
grandparent profiles, including CI-friendly versions. Restore the original 
parent-profile integration test.
    
    Generated-by: OpenAI
    
    * Simplify injected profile matching without losing settings attribution
    
    Collect injected POM profile IDs without reconstructing model coordinates.
    Exclude the documented external-profile entry so inactive ancestor profiles
    do not overwrite an active settings profile's source. Retain POM activity
    when the same ID is genuinely injected from both sources.
    
    Add settings-only and dual-active collision unit tests and a real parent-POM
    integration regression. Validated with Maven 3.10.0 (35 unit, 37 
integration)
    and Maven 4.0.0-rc-7 (35 unit, 34 integration, 3 version skips) on JDK 17.
    
    Generated-by: OpenAI
---
 src/it/projects/all-profiles-parent-pom/pom.xml    |   4 +
 .../projects/all-profiles-parent-pom/verify.groovy |   3 +-
 .../apache/maven/plugins/help/AllProfilesMojo.java |  21 ++++-
 .../maven/plugins/help/AllProfilesMojoTest.java    | 101 +++++++++++++++++++--
 4 files changed, 118 insertions(+), 11 deletions(-)

diff --git a/src/it/projects/all-profiles-parent-pom/pom.xml 
b/src/it/projects/all-profiles-parent-pom/pom.xml
index d329159..cda313f 100644
--- a/src/it/projects/all-profiles-parent-pom/pom.xml
+++ b/src/it/projects/all-profiles-parent-pom/pom.xml
@@ -30,6 +30,10 @@ under the License.
     <module>child</module>
   </modules>
   <profiles>
+    <!-- An inactive POM profile must not change the active settings profile 
source. -->
+    <profile>
+      <id>it-repo</id>
+    </profile>
     <profile>
       <id>profile-active-from-parent-pom</id>
       <activation>
diff --git a/src/it/projects/all-profiles-parent-pom/verify.groovy 
b/src/it/projects/all-profiles-parent-pom/verify.groovy
index 14ab135..d0c5e48 100644
--- a/src/it/projects/all-profiles-parent-pom/verify.groovy
+++ b/src/it/projects/all-profiles-parent-pom/verify.groovy
@@ -22,7 +22,8 @@ assert buildLog.exists()
 
 // 2 = parent + child
 assert 2 == buildLog.text.count( '  Profile Id: it-repo (Active: true, Source: 
settings.xml)' )
-assert 2 == buildLog.text.count( '  Profile Id: profile-active-from-parent-pom 
(Active: true, Source: pom)' ) 
+assert !buildLog.text.contains( '  Profile Id: it-repo (Active: true, Source: 
pom)' )
+assert 2 == buildLog.text.count( '  Profile Id: profile-active-from-parent-pom 
(Active: true, Source: pom)' )
 assert 2 == buildLog.text.count( '  Profile Id: 
profile-inactive-from-parent-pom (Active: false, Source: pom)' )
 assert 1 == buildLog.text.count( '  Profile Id: profile-active-from-child-pom 
(Active: true, Source: pom)' ) 
 assert 1 == buildLog.text.count( '  Profile Id: 
profile-inactive-from-child-pom (Active: false, Source: pom)' )
diff --git a/src/main/java/org/apache/maven/plugins/help/AllProfilesMojo.java 
b/src/main/java/org/apache/maven/plugins/help/AllProfilesMojo.java
index c2b4310..6127ee2 100644
--- a/src/main/java/org/apache/maven/plugins/help/AllProfilesMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/AllProfilesMojo.java
@@ -22,8 +22,10 @@ import javax.inject.Inject;
 
 import java.io.IOException;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.maven.model.Profile;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -152,12 +154,25 @@ public class AllProfilesMojo extends AbstractHelpMojo {
 
         getLog().debug("Attempting to read profiles from pom.xml...");
 
+        // Keep the current project's activation context while walking its 
parent models.
+        Set<String> injectedProfileIds = new HashSet<>();
+        for (Map.Entry<String, List<String>> entry :
+                project.getInjectedProfileIds().entrySet()) {
+            // External profiles come from settings.xml, not an ancestor POM.
+            if (!"external".equals(entry.getKey())) {
+                injectedProfileIds.addAll(entry.getValue());
+            }
+        }
+        if (project.getActiveProfiles() != null) {
+            for (Profile profile : project.getActiveProfiles()) {
+                activeProfiles.put(profile.getId(), profile);
+            }
+        }
+
         while (project != null) {
             for (Profile profile : project.getModel().getProfiles()) {
                 allProfiles.put(profile.getId(), profile);
-            }
-            if (project.getActiveProfiles() != null) {
-                for (Profile profile : project.getActiveProfiles()) {
+                if (injectedProfileIds.contains(profile.getId())) {
                     activeProfiles.put(profile.getId(), profile);
                 }
             }
diff --git 
a/src/test/java/org/apache/maven/plugins/help/AllProfilesMojoTest.java 
b/src/test/java/org/apache/maven/plugins/help/AllProfilesMojoTest.java
index e416cc2..424e482 100644
--- a/src/test/java/org/apache/maven/plugins/help/AllProfilesMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/help/AllProfilesMojoTest.java
@@ -25,7 +25,9 @@ import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.maven.api.di.Provides;
 import org.apache.maven.api.plugin.testing.InjectMojo;
@@ -44,6 +46,7 @@ import org.junit.jupiter.api.io.TempDir;
 import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 
+import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
@@ -83,6 +86,7 @@ class AllProfilesMojoTest {
 
     private final List<Profile> projectProfiles = new ArrayList<>();
     private final List<Profile> projectActiveProfiles = new ArrayList<>();
+    private final Map<String, List<String>> projectInjectedProfileIds = new 
HashMap<>();
     private final List<org.apache.maven.settings.Profile> settingsProfiles = 
new ArrayList<>();
     private final List<String> activeSettingsProfiles = new ArrayList<>();
 
@@ -94,6 +98,7 @@ class AllProfilesMojoTest {
         when(settings.getActiveProfiles()).thenReturn(activeSettingsProfiles);
 
         when(project.getActiveProfiles()).thenReturn(projectActiveProfiles);
+        
when(project.getInjectedProfileIds()).thenReturn(projectInjectedProfileIds);
         when(project.getModel()).thenReturn(projectModel);
         when(projectModel.getProfiles()).thenReturn(projectProfiles);
 
@@ -143,25 +148,68 @@ class AllProfilesMojoTest {
     }
 
     /**
-     * Tests the case when active profiles are present in the parent POM.
+     * Tests that a parent profile injected into the current project is active.
      *
      * @throws Exception in case of errors.
      */
     @Test
     @InjectMojo(goal = "all-profiles")
     @MojoParameter(name = "output", value = "${outputPath}")
-    void testProfileFromParentPom(AllProfilesMojo mojo) throws Exception {
-        Model parentModel = mock(Model.class);
-        
when(parentModel.getProfiles()).thenReturn(Collections.singletonList(newPomProfile("pro-1",
 "pom")));
-        MavenProject parentProject = mock(MavenProject.class);
-        when(parentProject.getModel()).thenReturn(parentModel);
-        
when(parentProject.getActiveProfiles()).thenReturn(Collections.singletonList(newPomProfile("pro-1",
 "pom")));
+    void testInjectedProfileFromParentPom(AllProfilesMojo mojo) throws 
Exception {
+        MavenProject parentProject = newParentProject("parent", "pro-1");
         when(project.getParent()).thenReturn(parentProject);
+        projectInjectedProfileIds.put("org.apache.maven.its.help:parent:1.0", 
Collections.singletonList("pro-1"));
 
         mojo.execute();
 
         String file = readOutput();
         assertTrue(file.contains("Profile Id: pro-1 (Active: true, Source: 
pom)"));
+        assertFalse(file.contains("Profile Id: pro-1 (Active: false, Source: 
pom)"));
+    }
+
+    /**
+     * Tests that a profile active only in the parent's build context is 
inactive for the current project.
+     *
+     * @throws Exception in case of errors.
+     */
+    @Test
+    @InjectMojo(goal = "all-profiles")
+    @MojoParameter(name = "output", value = "${outputPath}")
+    void testParentActiveProfileNotInjectedIntoProject(AllProfilesMojo mojo) 
throws Exception {
+        MavenProject parentProject = newParentProject("parent", "pro-1");
+        
parentProject.setActiveProfiles(parentProject.getModel().getProfiles());
+        when(project.getParent()).thenReturn(parentProject);
+
+        mojo.execute();
+
+        String file = readOutput();
+        assertTrue(file.contains("Profile Id: pro-1 (Active: false, Source: 
pom)"));
+        assertFalse(file.contains("Profile Id: pro-1 (Active: true, Source: 
pom)"));
+    }
+
+    /**
+     * Tests that only injected profiles of more distant ancestors are active.
+     *
+     * @throws Exception in case of errors.
+     */
+    @Test
+    @InjectMojo(goal = "all-profiles")
+    @MojoParameter(name = "output", value = "${outputPath}")
+    void testInjectedProfileFromGrandparentPom(AllProfilesMojo mojo) throws 
Exception {
+        MavenProject parentProject = newParentProject("parent", 
"parent-profile");
+        MavenProject grandparentProject = newParentProject("grandparent", 
"grandparent-profile");
+        parentProject.setParent(grandparentProject);
+        when(project.getParent()).thenReturn(parentProject);
+        projectInjectedProfileIds.put(
+                "org.apache.maven.its.help:grandparent:1.0", 
Collections.singletonList("grandparent-profile"));
+
+        mojo.execute();
+
+        String file = readOutput();
+        assertTrue(file.contains("Profile Id: grandparent-profile (Active: 
true, Source: pom)"));
+        assertFalse(file.contains("Profile Id: grandparent-profile (Active: 
false, Source: pom)"));
+        assertTrue(file.contains("Profile Id: parent-profile (Active: false, 
Source: pom)"));
+        assertFalse(file.contains("Profile Id: parent-profile (Active: true, 
Source: pom)"));
     }
 
     /**
@@ -185,6 +233,45 @@ class AllProfilesMojoTest {
         verify(settings).getActiveProfiles();
     }
 
+    private MavenProject newParentProject(String artifactId, String profileId) 
{
+        Model model = new Model();
+        model.setGroupId("org.apache.maven.its.help");
+        model.setArtifactId(artifactId);
+        model.setVersion("1.0");
+        model.setPackaging("pom");
+        model.addProfile(newPomProfile(profileId, "pom"));
+        return new MavenProject(model);
+    }
+
+    @Test
+    @InjectMojo(goal = "all-profiles")
+    @MojoParameter(name = "output", value = "${outputPath}")
+    void testActiveSettingsProfileWithInactiveParentProfile(AllProfilesMojo 
mojo) throws Exception {
+        when(project.getParent()).thenReturn(newParentProject("parent", 
"collision"));
+        settingsProfiles.add(newSettingsProfile("collision"));
+        projectActiveProfiles.add(newPomProfile("collision", "settings.xml"));
+        projectInjectedProfileIds.put("external", 
Collections.singletonList("collision"));
+        mojo.execute();
+        String file = readOutput();
+        assertTrue(file.contains("Profile Id: collision (Active: true, Source: 
settings.xml)"));
+        assertFalse(file.contains("Profile Id: collision (Active: true, 
Source: pom)"));
+    }
+
+    @Test
+    @InjectMojo(goal = "all-profiles")
+    @MojoParameter(name = "output", value = "${outputPath}")
+    void testActiveSettingsProfileWithActiveParentProfile(AllProfilesMojo 
mojo) throws Exception {
+        when(project.getParent()).thenReturn(newParentProject("parent", 
"collision"));
+        settingsProfiles.add(newSettingsProfile("collision"));
+        projectActiveProfiles.add(newPomProfile("collision", "settings.xml"));
+        projectInjectedProfileIds.put("external", 
Collections.singletonList("collision"));
+        projectInjectedProfileIds.put("org.apache.maven.its.help:parent:1.0", 
Collections.singletonList("collision"));
+        mojo.execute();
+        String file = readOutput();
+        assertTrue(file.contains("Profile Id: collision (Active: true, Source: 
pom)"));
+        assertFalse(file.contains("Profile Id: collision (Active: true, 
Source: settings.xml)"));
+    }
+
     private Profile newPomProfile(String id, String source) {
         Profile profile = new Profile();
         profile.setId(id);

Reply via email to