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

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


The following commit(s) were added to refs/heads/maven-3.9.x by this push:
     new 11ff947e7d [MNG-8092] Only warn about extension in reactor for 
projects actually… (#13742)
11ff947e7d is described below

commit 11ff947e7d313e50d6b4f56d99f6d571f95d068d
Author: TARUN N <[email protected]>
AuthorDate: Thu Nov 5 20:02:52 2026 +0530

    [MNG-8092] Only warn about extension in reactor for projects actually… 
(#13742)
    
    * [MNG-8092] Only warn about extension in reactor for projects actually 
built (fix #10859)
    
    Backport of #13290 to maven-3.9.x.
    
    The warning about a plugin with extensions that is built in the same 
reactor was logged for all collected projects, before the reactor was trimmed, 
so it also fired for a plugin excluded with -pl / --projects (#10859).
    
    - Move extension-in-reactor validation from build() to 
reactorDependencyGraph(), after trimming steps, so only active projects are 
checked
    - Rename method to validateExtensionIsNotPartOfReactor and simplify key 
lookup to a Set<String>
    - Add unit test coverage in DefaultGraphBuilderTest verifying that warning 
is only emitted when extension plugin is actually built in the reactor
    
    * [MNG-8092] Address review feedback: restore private logger and simplify 
test verification
---
 .../apache/maven/graph/DefaultGraphBuilder.java    |  17 ++-
 .../maven/graph/DefaultGraphBuilderTest.java       | 117 +++++++++++++++++++++
 2 files changed, 125 insertions(+), 9 deletions(-)

diff --git 
a/maven-core/src/main/java/org/apache/maven/graph/DefaultGraphBuilder.java 
b/maven-core/src/main/java/org/apache/maven/graph/DefaultGraphBuilder.java
index 67fad2b6a6..889814d709 100644
--- a/maven-core/src/main/java/org/apache/maven/graph/DefaultGraphBuilder.java
+++ b/maven-core/src/main/java/org/apache/maven/graph/DefaultGraphBuilder.java
@@ -23,11 +23,11 @@
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
-import java.util.Map;
+import java.util.Set;
 
 import org.apache.maven.DefaultMaven;
 import org.apache.maven.MavenExecutionException;
@@ -74,7 +74,6 @@ public Result<ProjectDependencyGraph> build(MavenSession 
session) {
 
             if (result == null) {
                 final List<MavenProject> projects = 
getProjectsForMavenReactor(session);
-                validateProjects(projects);
                 result = reactorDependencyGraph(session, projects);
             }
 
@@ -113,6 +112,8 @@ private Result<ProjectDependencyGraph> 
reactorDependencyGraph(MavenSession sessi
         activeProjects = trimExcludedProjects(activeProjects, 
session.getRequest());
         activeProjects = trimResumedProjects(activeProjects, 
session.getRequest());
 
+        validateExtensionIsNotPartOfReactor(activeProjects);
+
         if (activeProjects.size() != 
projectDependencyGraph.getSortedProjects().size()) {
             projectDependencyGraph = new 
FilteredProjectDependencyGraph(projectDependencyGraph, activeProjects);
         }
@@ -380,13 +381,11 @@ private void collectProjects(List<MavenProject> projects, 
List<File> files, Mave
         }
     }
 
-    private void validateProjects(List<MavenProject> projects) {
-        Map<String, MavenProject> projectsMap = new HashMap<>();
+    private void validateExtensionIsNotPartOfReactor(List<MavenProject> 
projects) {
+        Set<String> projectKeys = new HashSet<>();
 
         for (MavenProject p : projects) {
-            String projectKey = ArtifactUtils.key(p.getGroupId(), 
p.getArtifactId(), p.getVersion());
-
-            projectsMap.put(projectKey, p);
+            projectKeys.add(ArtifactUtils.key(p.getGroupId(), 
p.getArtifactId(), p.getVersion()));
         }
 
         for (MavenProject project : projects) {
@@ -396,7 +395,7 @@ private void validateProjects(List<MavenProject> projects) {
                     String pluginKey =
                             ArtifactUtils.key(plugin.getGroupId(), 
plugin.getArtifactId(), plugin.getVersion());
 
-                    if (projectsMap.containsKey(pluginKey)) {
+                    if (projectKeys.contains(pluginKey)) {
                         logger.warn(project.getName() + " uses " + 
plugin.getKey()
                                 + " as extensions, which is not possible 
within the same reactor build. "
                                 + "This plugin was pulled from the local 
repository!");
diff --git 
a/maven-core/src/test/java/org/apache/maven/graph/DefaultGraphBuilderTest.java 
b/maven-core/src/test/java/org/apache/maven/graph/DefaultGraphBuilderTest.java
new file mode 100644
index 0000000000..4ca41a392f
--- /dev/null
+++ 
b/maven-core/src/test/java/org/apache/maven/graph/DefaultGraphBuilderTest.java
@@ -0,0 +1,117 @@
+/*
+ * 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.graph;
+
+import java.io.File;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.maven.execution.DefaultMavenExecutionRequest;
+import org.apache.maven.execution.DefaultMavenExecutionResult;
+import org.apache.maven.execution.MavenExecutionRequest;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Build;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.building.ModelProblem;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuilder;
+import org.apache.maven.project.ProjectBuildingRequest;
+import org.apache.maven.project.ProjectBuildingResult;
+import org.codehaus.plexus.logging.Logger;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.ArgumentMatchers.anyString;
+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 DefaultGraphBuilderTest {
+
+    /**
+     * The warning about a plugin with extensions that is built in the same 
reactor is only for projects which are
+     * built, not for the ones excluded from the reactor (MNG-8092).
+     */
+    @Test
+    void warnsAboutExtensionInReactorOnlyWhenItIsBuilt() throws Exception {
+        Logger warnings = mock(Logger.class);
+        buildReactor(warnings, Collections.<String>emptyList());
+        verify(warnings, times(1)).warn(anyString());
+
+        Logger noWarnings = mock(Logger.class);
+        buildReactor(noWarnings, 
Collections.singletonList("org.apache.maven:test-0"));
+        verify(noWarnings, never()).warn(anyString());
+    }
+
+    private void buildReactor(Logger logger, List<String> excludedProjects) 
throws Exception {
+        Model pluginModel = new Model();
+        pluginModel.setGroupId("org.apache.maven");
+        pluginModel.setArtifactId("test-0");
+        pluginModel.setVersion("1");
+
+        Plugin plugin = new Plugin();
+        plugin.setGroupId("org.apache.maven");
+        plugin.setArtifactId("test-0");
+        plugin.setVersion("1");
+        plugin.setExtensions(true);
+        Build build = new Build();
+        build.addPlugin(plugin);
+        Model consumerModel = new Model();
+        consumerModel.setGroupId("org.apache.maven");
+        consumerModel.setArtifactId("test-1");
+        consumerModel.setVersion("1");
+        consumerModel.setBuild(build);
+
+        List<ProjectBuildingResult> results = new ArrayList<>();
+        for (Model model : Arrays.asList(pluginModel, consumerModel)) {
+            MavenProject project = new MavenProject(model);
+            ProjectBuildingResult result = mock(ProjectBuildingResult.class);
+            when(result.getProject()).thenReturn(project);
+            when(result.getProjectId()).thenReturn(project.getId());
+            
when(result.getProblems()).thenReturn(Collections.<ModelProblem>emptyList());
+            results.add(result);
+        }
+
+        ProjectBuilder projectBuilder = mock(ProjectBuilder.class);
+        when(projectBuilder.build(anyList(), anyBoolean(), 
any(ProjectBuildingRequest.class)))
+                .thenReturn(results);
+
+        MavenExecutionRequest request = new DefaultMavenExecutionRequest();
+        request.setPom(new File("pom.xml"));
+        request.setExcludedProjects(excludedProjects);
+        MavenSession session = new MavenSession(null, null, request, new 
DefaultMavenExecutionResult());
+
+        DefaultGraphBuilder graphBuilder = new DefaultGraphBuilder();
+        graphBuilder.projectBuilder = projectBuilder;
+        Field loggerField = 
DefaultGraphBuilder.class.getDeclaredField("logger");
+        loggerField.setAccessible(true);
+        loggerField.set(graphBuilder, logger);
+
+        assertFalse(graphBuilder.build(session).hasErrors());
+    }
+}

Reply via email to