You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gb...@apache.org on 2017/01/10 21:56:55 UTC

maven git commit: [MNG-6117] ${session.parallel} not correctly set

Repository: maven
Updated Branches:
  refs/heads/MNG-6117 [created] bd98ae6a3


[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/bd98ae6a
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/bd98ae6a
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/bd98ae6a

Branch: refs/heads/MNG-6117
Commit: bd98ae6a3de8d443f5b3d2f895f2348c2912ae05
Parents: e51fc87
Author: Guillaume Bou� <gb...@apache.org>
Authored: Sun Nov 13 22:46:18 2016 +0100
Committer: Guillaume Bou� <gb...@apache.org>
Committed: Mon Jan 9 21:50:07 2017 +0100

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


http://git-wip-us.apache.org/repos/asf/maven/blob/bd98ae6a/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 b3e35e0..f0fa2ac 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() );