You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mt...@apache.org on 2021/03/22 08:18:00 UTC

[maven] branch MNG-7102-exclude-projects-recursively created (now 7c4d2aa)

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

mthmulders pushed a change to branch MNG-7102-exclude-projects-recursively
in repository https://gitbox.apache.org/repos/asf/maven.git.


      at 7c4d2aa  [MNG-7102] The child modules of excluded projects are now excluded as well, making the behavior consistent with MNG-6981.

This branch includes the following new commits:

     new 7c4d2aa  [MNG-7102] The child modules of excluded projects are now excluded as well, making the behavior consistent with MNG-6981.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[maven] 01/01: [MNG-7102] The child modules of excluded projects are now excluded as well, making the behavior consistent with MNG-6981.

Posted by mt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mthmulders pushed a commit to branch MNG-7102-exclude-projects-recursively
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 7c4d2aa2c66e403523a38a21fd34b9c2a8d71e9f
Author: Martin Kanters <ma...@apache.org>
AuthorDate: Sat Feb 20 11:37:17 2021 +0100

    [MNG-7102] The child modules of excluded projects are now excluded as well, making the behavior consistent with MNG-6981.
---
 .../apache/maven/graph/DefaultGraphBuilder.java    | 23 ++++++++++++++++++----
 .../maven/graph/DefaultGraphBuilderTest.java       | 11 +++++++++++
 2 files changed, 30 insertions(+), 4 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 797cbe2..cad12db 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
@@ -140,7 +140,7 @@ public class DefaultGraphBuilder
         activeProjects = trimProjectsToRequest( activeProjects, projectDependencyGraph, session.getRequest() );
         activeProjects = trimSelectedProjects( activeProjects, projectDependencyGraph, session.getRequest() );
         activeProjects = trimResumedProjects( activeProjects, projectDependencyGraph, session.getRequest() );
-        activeProjects = trimExcludedProjects( activeProjects, session.getRequest() );
+        activeProjects = trimExcludedProjects( activeProjects, projectDependencyGraph, session.getRequest() );
 
         if ( activeProjects.size() != projectDependencyGraph.getSortedProjects().size() )
         {
@@ -237,7 +237,8 @@ public class DefaultGraphBuilder
         return result;
     }
 
-    private List<MavenProject> trimExcludedProjects( List<MavenProject> projects, MavenExecutionRequest request )
+    private List<MavenProject> trimExcludedProjects( List<MavenProject> projects, ProjectDependencyGraph graph,
+                                                     MavenExecutionRequest request )
         throws MavenExecutionException
     {
         List<MavenProject> result = projects;
@@ -250,12 +251,26 @@ public class DefaultGraphBuilder
 
             for ( String selector : request.getExcludedProjects() )
             {
-                MavenProject excludedProject = projects.stream()
+                // Instead of looking for the project inside the activeProjects, we should rather look inside the
+                // original list of projects. When someone excludes a project again which has been excluded by one of
+                // the earlier reactor filters (e.g. --resume-from) already, then we should not throw an error.
+                List<MavenProject> allProjects = graph.getSortedProjects();
+                MavenProject excludedProject = allProjects.stream()
                         .filter( project -> isMatchingProject( project, selector, reactorDirectory ) )
                         .findFirst()
                         .orElseThrow( () -> new MavenExecutionException( "Could not find the selected project in "
                                 + "the reactor: " + selector, request.getPom() ) );
-                result.remove( excludedProject );
+
+                boolean isExcludedProjectRemoved = result.remove( excludedProject );
+
+                if ( isExcludedProjectRemoved )
+                {
+                    List<MavenProject> children = excludedProject.getCollectedProjects();
+                    if ( children != null )
+                    {
+                        result.removeAll( children );
+                    }
+                }
             }
         }
 
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
index 4a8f9c0..d5a1811 100644
--- a/maven-core/src/test/java/org/apache/maven/graph/DefaultGraphBuilderTest.java
+++ b/maven-core/src/test/java/org/apache/maven/graph/DefaultGraphBuilderTest.java
@@ -147,6 +147,13 @@ public class DefaultGraphBuilderTest
                         .excludedProjects( MODULE_B )
                         .makeBehavior( REACTOR_MAKE_UPSTREAM )
                         .expectResult( PARENT_MODULE, MODULE_C, MODULE_A, MODULE_C_2 ),
+                scenario( "Excluding a project additionally excludes its children" )
+                        .excludedProjects( MODULE_C )
+                        .expectResult( PARENT_MODULE, MODULE_A, MODULE_B, INDEPENDENT_MODULE ),
+                scenario( "Excluding a project additionally excludes its children, but a child can be selected separately" )
+                        .selectedProjects( MODULE_C_1 )
+                        .excludedProjects( MODULE_C )
+                        .expectResult( MODULE_C_1 ),
                 scenario( "Excluding an also make dependency from resumeFrom does take its transitive dependency" )
                         .resumeFrom( MODULE_C_2 )
                         .excludedProjects( MODULE_B )
@@ -156,6 +163,10 @@ public class DefaultGraphBuilderTest
                         .resumeFrom( MODULE_A )
                         .excludedProjects( MODULE_B )
                         .expectResult( MODULE_A, MODULE_C_2, INDEPENDENT_MODULE ),
+                scenario( "Resume from exclude project upstream (should not fail)" )
+                        .resumeFrom( MODULE_B )
+                        .excludedProjects( MODULE_A )
+                        .expectResult( MODULE_B, MODULE_C_2, INDEPENDENT_MODULE ),
                 scenario( "Exclude the project we are resuming from (as proposed in MNG-6676)" )
                         .resumeFrom( MODULE_B )
                         .excludedProjects( MODULE_B )