[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.
This commit is contained in:
Guillaume Boué 2016-11-13 22:46:18 +01:00
parent c6c5192d4b
commit d413296cf3
1 changed files with 14 additions and 4 deletions

View File

@ -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() );