Repository: maven
Updated Branches:
  refs/heads/master f381cd4f2 -> dfb4a7b7f


[MNG-6117] ${session.parallel} not correctly set

MultiThreadedBuilder must set parallel to true when it's using more than
1 thread to build: i.e. a degree of concurrency greater than 1 (-T) and
more than 1 project to build. Since each ProjectSegment works on a
cloned session instance (see
BuildListCalculator#calculateProjectBuilds), the flag must be also set
on each cloned session.

Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/dfb4a7b7
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/dfb4a7b7
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/dfb4a7b7

Branch: refs/heads/master
Commit: dfb4a7b7f4225bc32385da139679e189a2aeb79a
Parents: f381cd4
Author: Guillaume Boué <gb...@apache.org>
Authored: Sun Nov 13 22:46:18 2016 +0100
Committer: Guillaume Boué <gb...@apache.org>
Committed: Sun Nov 13 22:46:18 2016 +0100

----------------------------------------------------------------------
 .../multithreaded/MultiThreadedBuilder.java       | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/dfb4a7b7/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/multithreaded/MultiThreadedBuilder.java
----------------------------------------------------------------------
diff --git 
a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/multithreaded/MultiThreadedBuilder.java
 
b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/multithreaded/MultiThreadedBuilder.java
index b24d785..14bf13b 100644
--- 
a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/multithreaded/MultiThreadedBuilder.java
+++ 
b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/multithreaded/MultiThreadedBuilder.java
@@ -44,7 +44,11 @@ import org.codehaus.plexus.component.annotations.Requirement;
 import org.codehaus.plexus.logging.Logger;
 
 /**
- * Builds the full lifecycle in weave-mode (phase by phase as opposed to 
project-by-project)
+ * Builds the full lifecycle in weave-mode (phase by phase as opposed to 
project-by-project).
+ * <p>
+ * This builder uses a number of threads equal to the minimum of the degree of 
concurrency (which is the thread count
+ * set with <code>-T</code> on the command-line) and the number of projects to 
build. As such, building a single project
+ * will always result in a sequential build, regardless of the thread count.
  *
  * @since 3.0
  * @author Kristian Rosenvold
@@ -73,9 +77,15 @@ public class MultiThreadedBuilder
                        List<TaskSegment> taskSegments, ReactorBuildStatus 
reactorBuildStatus )
         throws ExecutionException, InterruptedException
     {
-        ExecutorService executor =
-            Executors.newFixedThreadPool( Math.min( 
session.getRequest().getDegreeOfConcurrency(),
-                                                    
session.getProjects().size() ), new BuildThreadFactory() );
+        int nThreads = Math.min( 
session.getRequest().getDegreeOfConcurrency(), session.getProjects().size() );
+        boolean parallel = nThreads >= 2;
+        // Propagate the parallel flag to the root session and all of the 
cloned sessions in each project segment
+        session.setParallel( parallel );
+        for ( ProjectSegment segment : projectBuilds )
+        {
+            segment.getSession().setParallel( parallel );
+        }
+        ExecutorService executor = Executors.newFixedThreadPool( nThreads, new 
BuildThreadFactory() );
         CompletionService<ProjectSegment> service = new 
ExecutorCompletionService<>( executor );
         ConcurrencyDependencyGraph analyzer =
             new ConcurrencyDependencyGraph( projectBuilds, 
session.getProjectDependencyGraph() );

Reply via email to