gnodet-bot commented on code in PR #13612:
URL: https://github.com/apache/maven/pull/13612#discussion_r4517247506


##########
impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLifecycleExecutor.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.internal.impl;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Predicate;
+
+import org.apache.maven.api.LifecyclePlan;
+import org.apache.maven.api.MojoExecution;
+import org.apache.maven.api.Service;
+import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.services.LifecycleExecutionRequest;
+import org.apache.maven.api.services.LifecycleExecutionResult;
+import org.apache.maven.api.services.LifecycleExecutor;
+import org.apache.maven.api.services.LifecycleExecutorException;
+import org.apache.maven.api.services.LifecyclePlanRequest;
+import org.apache.maven.api.services.LifecyclePlanResult;
+import org.apache.maven.api.services.MavenException;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.lifecycle.LifecycleExecutionException;
+import org.apache.maven.lifecycle.internal.LifecycleTaskSegmentCalculator;
+import org.apache.maven.lifecycle.internal.TaskSegment;
+import org.apache.maven.lifecycle.internal.concurrent.BuildPlan;
+import org.apache.maven.lifecycle.internal.concurrent.BuildPlanExecutor;
+import org.apache.maven.lifecycle.internal.concurrent.BuildStep;
+import org.apache.maven.project.MavenProject;
+import org.eclipse.sisu.Typed;
+
+import static java.util.Objects.requireNonNull;
+import static org.apache.maven.internal.impl.CoreUtils.cast;
+
+@Named
+@Typed({LifecycleExecutor.class, Service.class})
+@Singleton
+public class DefaultLifecycleExecutor implements LifecycleExecutor {
+
+    private final LifecycleTaskSegmentCalculator taskSegmentCalculator;
+    private final BuildPlanExecutor buildPlanExecutor;
+
+    @Inject
+    public DefaultLifecycleExecutor(
+            LifecycleTaskSegmentCalculator taskSegmentCalculator, 
BuildPlanExecutor buildPlanExecutor) {
+        this.taskSegmentCalculator = taskSegmentCalculator;
+        this.buildPlanExecutor = buildPlanExecutor;
+    }
+
+    @Nonnull
+    @Override
+    public LifecyclePlanResult plan(@Nonnull LifecyclePlanRequest request) {
+        requireNonNull(request, "request");
+        InternalMavenSession internalSession = 
InternalMavenSession.from(request.getSession());
+        MavenSession mavenSession = internalSession.getMavenSession();
+        MavenProject mavenProject =
+                cast(DefaultProject.class, request.project(), 
"project").getProject();
+        MavenProject previousProject = mavenSession.getCurrentProject();
+
+        mavenSession.setCurrentProject(mavenProject);
+        try {
+            List<TaskSegment> taskSegments = 
taskSegmentCalculator.calculateTaskSegments(mavenSession, request.tasks());
+            BuildPlan buildPlan = 
buildPlanExecutor.calculateProjectPlan(mavenSession, mavenProject, 
taskSegments);
+
+            List<org.apache.maven.plugin.MojoExecution> internalExecutions = 
buildPlan.sortedNodes().stream()
+                    .flatMap(BuildStep::executions)
+                    .toList();
+            List<MojoExecution> executions = internalExecutions.stream()
+                    .map(execution -> (MojoExecution) new 
DefaultMojoExecution(internalSession, execution))
+                    .toList();
+            Map<org.apache.maven.plugin.MojoExecution, MojoExecution> mapping =
+                    DefaultLifecyclePlan.buildMapping(internalExecutions, 
executions);
+
+            DefaultLifecyclePlan plan =
+                    new DefaultLifecyclePlan(request.project(), 
request.tasks(), executions, buildPlan, mapping);
+            return new DefaultLifecyclePlanResult(request, plan);
+        } catch (MavenException e) {
+            throw new LifecycleExecutorException("Unable to calculate 
lifecycle plan", e);
+        } catch (Exception e) {
+            throw new LifecycleExecutorException("Unable to calculate 
lifecycle plan", e);
+        } finally {
+            mavenSession.setCurrentProject(previousProject);
+        }
+    }
+
+    @Nonnull
+    @Override
+    public LifecycleExecutionResult execute(@Nonnull LifecycleExecutionRequest 
request) {
+        requireNonNull(request, "request");
+        InternalMavenSession internalSession = 
InternalMavenSession.from(request.getSession());
+        MavenSession mavenSession = internalSession.getMavenSession();
+        if (!(request.plan() instanceof DefaultLifecyclePlan plan)) {
+            throw new IllegalArgumentException("plan was not produced by this 
lifecycle executor");
+        }
+        MavenProject mavenProject =
+                cast(DefaultProject.class, plan.project(), 
"project").getProject();
+        MavenProject previousProject = mavenSession.getCurrentProject();
+
+        mavenSession.setCurrentProject(mavenProject);
+        try {
+            Predicate<MojoExecution> filter = request.filter();
+            Map<org.apache.maven.plugin.MojoExecution, MojoExecution> mapping 
= plan.internalToApiMap();
+
+            // Determine which v4 executions pass the filter
+            Set<MojoExecution> accepted = new HashSet<>();
+            List<MojoExecution> submittedExecutions = new ArrayList<>();
+            for (MojoExecution apiExecution : plan.executions()) {
+                if (filter == null || filter.test(apiExecution)) {
+                    accepted.add(apiExecution);
+                    submittedExecutions.add(apiExecution);
+                }
+            }
+
+            // Walk the BuildPlan steps in topological order, executing 
filtered mojos
+            List<MojoExecution> succeeded = new ArrayList<>();
+            MojoExecution failed = null;
+            Throwable failureCause = null;
+
+            for (BuildStep step : plan.buildPlan().sortedNodes()) {
+                List<org.apache.maven.plugin.MojoExecution> stepExecutions = 
step.executions()
+                        .filter(internal -> 
accepted.contains(mapping.get(internal)))
+                        .toList();
+                if (!stepExecutions.isEmpty()) {
+                    try {
+                        buildPlanExecutor.configureAndExecute(mavenSession, 
mavenProject, stepExecutions);
+                        for (org.apache.maven.plugin.MojoExecution internal : 
stepExecutions) {
+                            succeeded.add(mapping.get(internal));
+                        }
+                    } catch (LifecycleExecutionException e) {
+                        // Determine which mojo failed (last in the batch that 
was executing)
+                        failed = 
mapping.get(stepExecutions.get(stepExecutions.size() - 1));
+                        failureCause = e;
+                        throw new LifecycleExecutorException("Unable to 
execute lifecycle plan", e);

Review Comment:
   ⚠️ **`executedSuccessfully()` / `failedExecution()` / `failureCause()` are 
unreachable after failure.**
   
   `failed` and `failureCause` are set on lines 153–154, but the `throw` on 
line 155 discards them — `DefaultLifecycleExecutionResult` is only constructed 
on the success path (line 159). `LifecycleExecutorException` carries no result 
object. IDE embedders cannot access `failedExecution()` or 
`executedSuccessfully()` after a mojo failure — which is precisely when they 
need them.
   
   **Fix A** (preferred — matches `ProjectBuildingException` carrying results): 
attach the partial result to the exception.
   
   Add a constructor and accessor to `LifecycleExecutorException`:
   ```java
   public class LifecycleExecutorException extends MavenException {
       private final LifecycleExecutionResult result;
   
       public LifecycleExecutorException(String message, Throwable cause, 
LifecycleExecutionResult result) {
           super(message, cause);
           this.result = result;
       }
   
       /** {@return the partial execution result available at the time of 
failure, or empty} */
       public Optional<LifecycleExecutionResult> result() {
           return Optional.ofNullable(result);
       }
       // ... existing constructors unchanged
   }
   ```
   Then in `execute()`:
   ```java
   } catch (LifecycleExecutionException e) {
       failed = mapping.get(stepExecutions.get(stepExecutions.size() - 1));
       failureCause = e;
       DefaultLifecycleExecutionResult partialResult =
               new DefaultLifecycleExecutionResult(request, plan, 
submittedExecutions, succeeded, failed, failureCause);
       throw new LifecycleExecutorException("Unable to execute lifecycle plan", 
e, partialResult);
   }
   ```
   
   **Fix B** (simpler API, different contract): don't throw — always return a 
result. Callers check `failedExecution().isPresent()`. Requires documenting 
that the calling thread's build may be in a failed state.
   
   The `reportsPerExecutionStatus` test must also be updated to assert on the 
partial result (see separate comment).



##########
impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLifecycleExecutor.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.internal.impl;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Predicate;
+
+import org.apache.maven.api.LifecyclePlan;
+import org.apache.maven.api.MojoExecution;
+import org.apache.maven.api.Service;
+import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.services.LifecycleExecutionRequest;
+import org.apache.maven.api.services.LifecycleExecutionResult;
+import org.apache.maven.api.services.LifecycleExecutor;
+import org.apache.maven.api.services.LifecycleExecutorException;
+import org.apache.maven.api.services.LifecyclePlanRequest;
+import org.apache.maven.api.services.LifecyclePlanResult;
+import org.apache.maven.api.services.MavenException;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.lifecycle.LifecycleExecutionException;
+import org.apache.maven.lifecycle.internal.LifecycleTaskSegmentCalculator;
+import org.apache.maven.lifecycle.internal.TaskSegment;
+import org.apache.maven.lifecycle.internal.concurrent.BuildPlan;
+import org.apache.maven.lifecycle.internal.concurrent.BuildPlanExecutor;
+import org.apache.maven.lifecycle.internal.concurrent.BuildStep;
+import org.apache.maven.project.MavenProject;
+import org.eclipse.sisu.Typed;
+
+import static java.util.Objects.requireNonNull;
+import static org.apache.maven.internal.impl.CoreUtils.cast;
+
+@Named
+@Typed({LifecycleExecutor.class, Service.class})
+@Singleton
+public class DefaultLifecycleExecutor implements LifecycleExecutor {
+
+    private final LifecycleTaskSegmentCalculator taskSegmentCalculator;
+    private final BuildPlanExecutor buildPlanExecutor;
+
+    @Inject
+    public DefaultLifecycleExecutor(
+            LifecycleTaskSegmentCalculator taskSegmentCalculator, 
BuildPlanExecutor buildPlanExecutor) {
+        this.taskSegmentCalculator = taskSegmentCalculator;
+        this.buildPlanExecutor = buildPlanExecutor;
+    }
+
+    @Nonnull
+    @Override
+    public LifecyclePlanResult plan(@Nonnull LifecyclePlanRequest request) {
+        requireNonNull(request, "request");
+        InternalMavenSession internalSession = 
InternalMavenSession.from(request.getSession());
+        MavenSession mavenSession = internalSession.getMavenSession();
+        MavenProject mavenProject =
+                cast(DefaultProject.class, request.project(), 
"project").getProject();
+        MavenProject previousProject = mavenSession.getCurrentProject();
+
+        mavenSession.setCurrentProject(mavenProject);
+        try {
+            List<TaskSegment> taskSegments = 
taskSegmentCalculator.calculateTaskSegments(mavenSession, request.tasks());
+            BuildPlan buildPlan = 
buildPlanExecutor.calculateProjectPlan(mavenSession, mavenProject, 
taskSegments);
+
+            List<org.apache.maven.plugin.MojoExecution> internalExecutions = 
buildPlan.sortedNodes().stream()
+                    .flatMap(BuildStep::executions)
+                    .toList();
+            List<MojoExecution> executions = internalExecutions.stream()
+                    .map(execution -> (MojoExecution) new 
DefaultMojoExecution(internalSession, execution))
+                    .toList();
+            Map<org.apache.maven.plugin.MojoExecution, MojoExecution> mapping =
+                    DefaultLifecyclePlan.buildMapping(internalExecutions, 
executions);
+
+            DefaultLifecyclePlan plan =
+                    new DefaultLifecyclePlan(request.project(), 
request.tasks(), executions, buildPlan, mapping);
+            return new DefaultLifecyclePlanResult(request, plan);
+        } catch (MavenException e) {
+            throw new LifecycleExecutorException("Unable to calculate 
lifecycle plan", e);
+        } catch (Exception e) {

Review Comment:
   💡 **Redundant `catch` block.** `MavenException` extends `RuntimeException`, 
so `catch (Exception e)` on line 101 already subsumes it — both branches 
produce identical `LifecycleExecutorException`. Drop the first catch:
   
   ```suggestion
           } catch (Exception e) {
               throw new LifecycleExecutorException("Unable to calculate 
lifecycle plan", e);
   ```



##########
api/maven-api-core/src/main/java/org/apache/maven/api/MojoExecution.java:
##########
@@ -82,4 +82,11 @@ public interface MojoExecution {
     /** {@return the merged configuration for this execution, if any} */
     @Nonnull
     Optional<XmlNode> configuration();
+
+    /** {@return true if this mojo triggers a forked lifecycle execution} */

Review Comment:
   💡 **Missing `@since` on new default method.** `MojoExecution` is `@since 
4.0.0`. Methods added after the initial release need their own `@since` so API 
consumers know the minimum version.
   
   ```suggestion
       /**
        * {@return true if this mojo triggers a forked lifecycle execution}
        *
        * @since 4.2.0
        */
   ```



##########
impl/maven-core/src/test/java/org/apache/maven/internal/impl/DefaultLifecycleExecutorTest.java:
##########
@@ -0,0 +1,246 @@
+/*
+ * 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.internal.impl;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.api.LifecyclePlan;
+import org.apache.maven.api.services.LifecycleExecutionRequest;
+import org.apache.maven.api.services.LifecycleExecutionResult;
+import org.apache.maven.api.services.LifecycleExecutorException;
+import org.apache.maven.api.services.LifecyclePlanRequest;
+import org.apache.maven.api.services.LifecyclePlanResult;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.lifecycle.LifecycleExecutionException;
+import org.apache.maven.lifecycle.internal.LifecycleTask;
+import org.apache.maven.lifecycle.internal.LifecycleTaskSegmentCalculator;
+import org.apache.maven.lifecycle.internal.TaskSegment;
+import org.apache.maven.lifecycle.internal.concurrent.BuildPlan;
+import org.apache.maven.lifecycle.internal.concurrent.BuildPlanExecutor;
+import org.apache.maven.lifecycle.internal.concurrent.BuildStep;
+import org.apache.maven.plugin.MojoExecution;
+import org.apache.maven.plugin.descriptor.MojoDescriptor;
+import org.apache.maven.plugin.descriptor.PluginDescriptor;
+import org.apache.maven.project.MavenProject;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.same;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+class DefaultLifecycleExecutorTest {
+
+    private InternalMavenSession session;
+    private MavenSession mavenSession;
+    private LifecycleTaskSegmentCalculator taskSegmentCalculator;
+    private BuildPlanExecutor buildPlanExecutor;
+    private MavenProject project;
+    private MavenProject previousProject;
+    private DefaultProject apiProject;
+    private MojoExecution compile;
+    private MojoExecution test;
+    private DefaultLifecycleExecutor executor;
+    private BuildPlan buildPlan;
+
+    @BeforeEach
+    void setUp() throws Exception {
+        session = mock(InternalMavenSession.class);
+        mavenSession = mock(MavenSession.class);
+        taskSegmentCalculator = mock(LifecycleTaskSegmentCalculator.class);
+        buildPlanExecutor = mock(BuildPlanExecutor.class);
+        project = new MavenProject();
+        previousProject = new MavenProject();
+        apiProject = mock(DefaultProject.class);
+        compile = execution("compile", "compile");
+        test = execution("test", "test");
+        TaskSegment segment = new TaskSegment(false, new 
LifecycleTask("verify"));
+
+        when(session.getMavenSession()).thenReturn(mavenSession);
+        when(mavenSession.getCurrentProject()).thenReturn(previousProject);
+        when(apiProject.getProject()).thenReturn(project);
+        when(taskSegmentCalculator.calculateTaskSegments(mavenSession, 
List.of("verify")))
+                .thenReturn(List.of(segment));
+
+        // Create a BuildPlan with steps containing the mojos
+        buildPlan = new BuildPlan(Collections.singletonMap(project, 
Collections.emptyList()));
+        Map<String, BuildStep> steps = new java.util.LinkedHashMap<>();
+        BuildStep compileStep = new BuildStep("compile", project, null);
+        compileStep.addMojo(compile, 0);
+        steps.put("compile", compileStep);
+        BuildStep testStep = new BuildStep("test", project, null);
+        testStep.addMojo(test, 0);
+        compileStep.executeBefore(testStep);
+        steps.put("test", testStep);
+        buildPlan.addProject(project, steps);
+
+        when(buildPlanExecutor.calculateProjectPlan(same(mavenSession), 
same(project), anyList()))
+                .thenReturn(buildPlan);
+
+        executor = new DefaultLifecycleExecutor(taskSegmentCalculator, 
buildPlanExecutor);
+    }
+
+    @Test
+    void plansInspectsAndExecutesFilteredMojos() throws Exception {
+        LifecyclePlanResult planResult =
+                executor.plan(LifecyclePlanRequest.build(session, apiProject, 
List.of("verify")));
+        LifecyclePlan plan = planResult.plan();
+
+        assertSame(apiProject, plan.project());
+        assertEquals(List.of("verify"), plan.tasks());
+        assertEquals(
+                List.of("compile", "test"),
+                plan.executions().stream()
+                        .map(org.apache.maven.api.MojoExecution::goal)
+                        .toList());
+
+        LifecycleExecutionResult result = 
executor.execute(LifecycleExecutionRequest.build(
+                session, plan, execution -> execution.goal().equals("test")));
+
+        assertEquals(
+                List.of("test"),
+                result.executions().stream()
+                        .map(org.apache.maven.api.MojoExecution::goal)
+                        .toList());
+        verify(mavenSession, times(2)).setCurrentProject(same(project));
+        verify(mavenSession, 
times(2)).setCurrentProject(same(previousProject));
+    }
+
+    @Test
+    void executesAllMojosWhenFilterIsAbsent() throws Exception {
+        LifecyclePlan plan = executor.plan(LifecyclePlanRequest.build(session, 
apiProject, List.of("verify")))
+                .plan();
+
+        LifecycleExecutionResult result = 
executor.execute(LifecycleExecutionRequest.build(session, plan));
+
+        assertEquals(2, result.executions().size());
+        assertEquals(2, result.executedSuccessfully().size());
+        assertTrue(result.failedExecution().isEmpty());
+        assertTrue(result.failureCause().isEmpty());
+    }
+
+    @Test
+    void restoresCurrentProjectOnExecutionFailure() throws Exception {
+        LifecyclePlan plan = executor.plan(LifecyclePlanRequest.build(session, 
apiProject, List.of("verify")))
+                .plan();
+        doThrow(new LifecycleExecutionException("boom"))
+                .when(buildPlanExecutor)
+                .configureAndExecute(eq(mavenSession), eq(project), anyList());
+
+        assertThrows(
+                LifecycleExecutorException.class,
+                () -> 
executor.execute(LifecycleExecutionRequest.build(session, plan)));
+
+        verify(mavenSession, 
times(2)).setCurrentProject(same(previousProject));
+    }
+
+    @Test
+    void doesNotWrapFilterFailures() throws Exception {
+        LifecyclePlan plan = executor.plan(LifecyclePlanRequest.build(session, 
apiProject, List.of("verify")))
+                .plan();
+        IllegalStateException filterFailure = new 
IllegalStateException("broken filter");
+
+        IllegalStateException thrown = assertThrows(
+                IllegalStateException.class,
+                () -> 
executor.execute(LifecycleExecutionRequest.build(session, plan, execution -> {
+                    throw filterFailure;
+                })));
+
+        assertSame(filterFailure, thrown);
+        verify(buildPlanExecutor, never()).configureAndExecute(any(), any(), 
anyList());
+        verify(mavenSession, 
times(2)).setCurrentProject(same(previousProject));
+    }
+
+    @Test
+    void 
rejectsPlansNotProducedByThisServiceWithoutLeakingImplementationDetails() {
+        LifecyclePlan externalPlan = mock(LifecyclePlan.class);
+
+        IllegalArgumentException thrown = assertThrows(
+                IllegalArgumentException.class,
+                () -> 
executor.execute(LifecycleExecutionRequest.build(session, externalPlan)));
+
+        assertEquals("plan was not produced by this lifecycle executor", 
thrown.getMessage());
+        
assertFalse(thrown.getMessage().contains(DefaultLifecyclePlan.class.getName()));
+        verify(mavenSession, never()).setCurrentProject(project);
+    }
+
+    @Test
+    void reportsPerExecutionStatus() throws Exception {
+        LifecyclePlan plan = executor.plan(LifecyclePlanRequest.build(session, 
apiProject, List.of("verify")))
+                .plan();
+
+        // Make the second step (test) fail
+        doAnswer(inv -> {
+                    List<MojoExecution> execs = inv.getArgument(2);
+                    if (execs.stream().anyMatch(e -> 
"test".equals(e.getGoal()))) {
+                        throw new LifecycleExecutionException("test failed");
+                    }
+                    return null;
+                })
+                .when(buildPlanExecutor)
+                .configureAndExecute(eq(mavenSession), eq(project), anyList());
+
+        LifecycleExecutorException ex = assertThrows(
+                LifecycleExecutorException.class,
+                () -> 
executor.execute(LifecycleExecutionRequest.build(session, plan)));
+
+        assertTrue(ex.getMessage().contains("Unable to execute lifecycle 
plan"));
+    }

Review Comment:
   💡 **`reportsPerExecutionStatus` only checks the exception message, not the 
partial results.** Once `LifecycleExecutorException` carries the result (Fix A 
above), this test should validate:
   - `ex.result().orElseThrow().executedSuccessfully()` contains the `compile` 
goal
   - `ex.result().orElseThrow().failedExecution()` is present with goal `test`
   - `ex.result().orElseThrow().failureCause()` is present
   
   As written, a regression removing `executedSuccessfully` or 
`failedExecution` from the implementation would not be caught.



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