gnodet commented on code in PR #1774:
URL: https://github.com/apache/maven/pull/1774#discussion_r4291704171


##########
api/maven-api-spi/src/main/java/org/apache/maven/api/services/model/ProfileActivationContext.java:
##########
@@ -142,4 +145,12 @@ public interface ProfileActivationContext {
      * @throws InterpolatorException if an error occurs during interpolation
      */
     boolean exists(@Nullable String path, boolean glob);
+
+    /**
+     * Inject properties from newly activated profiles in order to trigger the 
cascading mechanism.
+     * This method allows profiles to contribute properties that can trigger 
the activation of other profiles.
+     *
+     * @param activatedProfiles The collection of profiles that have been 
activated that may trigger the cascading effect.
+     */
+    void addProfileProperties(Collection<Profile> activatedProfiles);

Review Comment:
   _Claude Code on behalf of Guillaume Nodet_
   
   Fixed — `addProfileProperties` now has a `default` no-op implementation, 
preserving binary compatibility for external implementations of 
`ProfileActivationContext`.



##########
impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultProfileSelector.java:
##########
@@ -63,32 +63,54 @@ public DefaultProfileSelector 
addProfileActivator(ProfileActivator profileActiva
     @Override
     public List<Profile> getActiveProfiles(
             Collection<Profile> profiles, ProfileActivationContext context, 
ModelProblemCollector problems) {
-        List<Profile> activeProfiles = new ArrayList<>(profiles.size());
+
+        List<Profile> activeSettingsProfiles = new ArrayList<>();
+        List<Profile> activePomProfiles = new ArrayList<>();
         List<Profile> activePomProfilesByDefault = new ArrayList<>();
-        boolean activatedPomProfileNotByDefault = false;
 
-        for (Profile profile : profiles) {
-            if (!context.isProfileInactive(profile.getId())) {
-                if (context.isProfileActive(profile.getId()) || 
isActive(profile, context, problems)) {
-                    activeProfiles.add(profile);
-                    if (Profile.SOURCE_POM.equals(profile.getSource())) {
-                        activatedPomProfileNotByDefault = true;
-                    }
-                } else if (isActiveByDefault(profile)) {
-                    if (Profile.SOURCE_POM.equals(profile.getSource())) {
-                        activePomProfilesByDefault.add(profile);
-                    } else {
-                        activeProfiles.add(profile);
+        // Cascading mode: iterate until no more profiles are activated
+        List<Profile> remainingProfiles = new ArrayList<>(profiles);
+        List<Profile> activatedProfiles;
+        do {
+            activatedProfiles = new ArrayList<>();
+            for (Profile profile : List.copyOf(remainingProfiles)) {
+                if (!context.isProfileInactive(profile.getId())) {
+                    boolean activated = 
context.isProfileActive(profile.getId());
+                    boolean active = isActive(profile, context, problems);
+                    boolean activeByDefault = isActiveByDefault(profile);
+                    if (activated || active || activeByDefault) {
+                        if (Profile.SOURCE_POM.equals(profile.getSource())) {
+                            if (activated || active) {
+                                activePomProfiles.add(profile);
+                            } else {
+                                activePomProfilesByDefault.add(profile);
+                            }
+                        } else {
+                            activeSettingsProfiles.add(profile);
+                        }
+                        remainingProfiles.remove(profile);
+                        activatedProfiles.add(profile);

Review Comment:
   _Claude Code on behalf of Guillaume Nodet_
   
   Fixed — `activeByDefault` profiles are now excluded from `activatedProfiles` 
(and thus from `addProfileProperties`). Only genuinely activated profiles 
(`activated || active`) contribute to the cascade. Added a test 
`testActiveByDefaultDoesNotCascade()` covering the scenario described.



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