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

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/master by this push:
     new 6d22ed20fd Wait for a standalone goal before concurrent project 
teardown (#14121)
6d22ed20fd is described below

commit 6d22ed20fd15a228fe5358a155b26b9b7495217b
Author: kayokoi Zhang <[email protected]>
AuthorDate: Thu Nov 26 15:41:14 2026 -0800

    Wait for a standalone goal before concurrent project teardown (#14121)
    
    Fixes #14120.
---
 .../internal/concurrent/BuildPlanExecutor.java     |  3 +-
 .../internal/concurrent/BuildPlanExecutorTest.java | 62 ++++++++++++++++++++++
 2 files changed, 64 insertions(+), 1 deletion(-)

diff --git 
a/impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/concurrent/BuildPlanExecutor.java
 
b/impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/concurrent/BuildPlanExecutor.java
index 0461cb11a0..bcadcc0ba6 100644
--- 
a/impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/concurrent/BuildPlanExecutor.java
+++ 
b/impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/concurrent/BuildPlanExecutor.java
@@ -361,7 +361,8 @@ public BuildPlan buildInitialPlan(List<TaskSegment> 
taskSegments) {
                 plan.steps(project).forEach(step -> {
                     if (step.predecessors.stream().noneMatch(s -> s.project == 
project)) {
                         step.executeAfter(setup);
-                    } else if (step.successors.stream().noneMatch(s -> 
s.project == project)) {
+                    }
+                    if (step.successors.stream().noneMatch(s -> s.project == 
project)) {
                         teardown.executeAfter(step);
                     }
                 });
diff --git 
a/impl/maven-core/src/test/java/org/apache/maven/lifecycle/internal/concurrent/BuildPlanExecutorTest.java
 
b/impl/maven-core/src/test/java/org/apache/maven/lifecycle/internal/concurrent/BuildPlanExecutorTest.java
index 5705e254e4..56469ebdf8 100644
--- 
a/impl/maven-core/src/test/java/org/apache/maven/lifecycle/internal/concurrent/BuildPlanExecutorTest.java
+++ 
b/impl/maven-core/src/test/java/org/apache/maven/lifecycle/internal/concurrent/BuildPlanExecutorTest.java
@@ -35,12 +35,18 @@
 import org.apache.maven.internal.impl.DefaultLifecycleRegistry;
 import org.apache.maven.internal.transformation.TransformerManager;
 import org.apache.maven.lifecycle.LifecycleExecutionException;
+import org.apache.maven.lifecycle.internal.GoalTask;
 import org.apache.maven.lifecycle.internal.LifecycleTask;
+import org.apache.maven.lifecycle.internal.MojoDescriptorCreator;
 import org.apache.maven.lifecycle.internal.ReactorBuildStatus;
 import org.apache.maven.lifecycle.internal.ReactorContext;
 import org.apache.maven.lifecycle.internal.TaskSegment;
 import org.apache.maven.lifecycle.internal.stub.ExecutionEventCatapultStub;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.plugin.descriptor.MojoDescriptor;
+import org.apache.maven.plugin.descriptor.PluginDescriptor;
 import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
 import org.eclipse.aether.DefaultRepositorySystemSession;
 import org.eclipse.aether.RepositorySystemSession;
 import org.eclipse.aether.deployment.DeployRequest;
@@ -52,6 +58,12 @@
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
 import static org.junit.jupiter.api.Assertions.assertSame;
 import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.ArgumentMatchers.same;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 class BuildPlanExecutorTest {
 
@@ -260,6 +272,56 @@ private BuildStep addStep(BuildPlan plan, MavenProject 
project, String name) {
         return step;
     }
 
+    @Test
+    void teardownWaitsForAnOrdinaryDirectGoalFailure() throws Exception {
+        String goal = "test:example-plugin:1:run";
+        MavenProject project = newProject();
+        MavenSession session = newSession(project);
+        session.getRequest().setGoals(List.of(goal));
+
+        PluginDescriptor plugin = new PluginDescriptor();
+        plugin.setPlugin(new Plugin());
+        MojoDescriptor descriptor = new MojoDescriptor();
+        descriptor.setGoal("run");
+        descriptor.setPluginDescriptor(plugin);
+        descriptor.setMojoConfiguration(new 
XmlPlexusConfiguration("configuration"));
+        MojoDescriptorCreator descriptors = mock(MojoDescriptorCreator.class);
+        when(descriptors.getMojoDescriptor(goal, session, 
project)).thenReturn(descriptor);
+        MojoExecutor mojoExecutor = mock(MojoExecutor.class);
+        LifecycleExecutionException failure = new 
LifecycleExecutionException("goal failed");
+        doThrow(failure).when(mojoExecutor).execute(same(session), anyList());
+
+        TaskSegment segment = new TaskSegment(false);
+        segment.getTasks().add(new GoalTask(goal));
+        try (BuildPlanExecutor.BuildContext context = 
newDirectGoalExecutor(mojoExecutor, descriptors)
+        .new BuildContext(session, newReactorContext(session), 
List.of(segment))) {
+            BuildStep goalStep = context.plan.requiredStep(project, goal);
+            
assertTrue(goalStep.isSuccessorOf(context.plan.requiredStep(project, 
BuildStep.SETUP)));
+            assertTrue(
+                    context.plan.requiredStep(project, 
BuildStep.TEARDOWN).isSuccessorOf(goalStep),
+                    "project teardown must wait for the direct goal");
+            context.execute();
+        }
+
+        verify(mojoExecutor).execute(same(session), anyList());
+        assertEquals(List.of(failure), session.getResult().getExceptions());
+        assertTrue(session.getResult().getBuildSummary(project) instanceof 
org.apache.maven.execution.BuildFailure);
+    }
+
+    private BuildPlanExecutor newDirectGoalExecutor(MojoExecutor mojoExecutor, 
MojoDescriptorCreator descriptors) {
+        return new BuildPlanExecutor(
+                mojoExecutor,
+                new ExecutionEventCatapultStub(),
+                List.of(),
+                new NoopTransformerManager(),
+                new BuildPlanLogger(),
+                Map.of("default", (buildProject, execution, usePluginConfig) 
-> {}),
+                null,
+                descriptors,
+                new DefaultLifecycleRegistry(Collections.emptyList()),
+                Collections.emptyList());
+    }
+
     /**
      * A build step that throws an {@link Error} must be reported as a build 
failure, the same way the
      * single threaded builder reports it. Otherwise the build ends with no 
exception at all and Maven

Reply via email to