o Refactoring: Moved one incorrectly placed method from BuildListCalculator to TaskSegmentCalculator

This method was creating a lot of strange internal dependencies since it was mis-placed

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@935741 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Kristian Rosenvold 2010-04-19 20:57:44 +00:00
parent b329fdb4e5
commit 2339e16750
10 changed files with 183 additions and 139 deletions

View File

@ -62,7 +62,7 @@ import java.util.concurrent.ExecutorService;
* @author Benjamin Bentmann * @author Benjamin Bentmann
* @author Kristian Rosenvold * @author Kristian Rosenvold
*/ */
@Component(role = LifecycleExecutor.class) @Component( role = LifecycleExecutor.class )
public class DefaultLifecycleExecutor public class DefaultLifecycleExecutor
implements LifecycleExecutor implements LifecycleExecutor
{ {
@ -126,7 +126,7 @@ public class DefaultLifecycleExecutor
boolean isThreaded = executionRequest.isThreadConfigurationPresent(); boolean isThreaded = executionRequest.isThreadConfigurationPresent();
session.setParallel( isThreaded ); session.setParallel( isThreaded );
List<TaskSegment> taskSegments = buildListCalculator.calculateTaskSegments( session ); List<TaskSegment> taskSegments = lifecycleTaskSegmentCalculator.calculateTaskSegments( session );
ProjectBuildList projectBuilds = buildListCalculator.calculateProjectBuilds( session, taskSegments ); ProjectBuildList projectBuilds = buildListCalculator.calculateProjectBuilds( session, taskSegments );
@ -256,7 +256,7 @@ public class DefaultLifecycleExecutor
// USED BY MAVEN HELP PLUGIN // USED BY MAVEN HELP PLUGIN
@SuppressWarnings({"UnusedDeclaration"}) @SuppressWarnings( { "UnusedDeclaration" } )
@Deprecated @Deprecated
public Map<String, Lifecycle> getPhaseToLifecycleMap() public Map<String, Lifecycle> getPhaseToLifecycleMap()
{ {
@ -265,7 +265,7 @@ public class DefaultLifecycleExecutor
// NOTE: Backward-compat with maven-help-plugin:2.1 // NOTE: Backward-compat with maven-help-plugin:2.1
@SuppressWarnings({"UnusedDeclaration"}) @SuppressWarnings( { "UnusedDeclaration" } )
MojoDescriptor getMojoDescriptor( String task, MavenSession session, MavenProject project, String invokedVia, MojoDescriptor getMojoDescriptor( String task, MavenSession session, MavenProject project, String invokedVia,
boolean canUsePrefix, boolean isOptionalMojo ) boolean canUsePrefix, boolean isOptionalMojo )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
@ -277,7 +277,7 @@ public class DefaultLifecycleExecutor
// Used by m2eclipse // Used by m2eclipse
@SuppressWarnings({"UnusedDeclaration"}) @SuppressWarnings( { "UnusedDeclaration" } )
public MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks ) public MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException, MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
@ -285,7 +285,7 @@ public class DefaultLifecycleExecutor
PluginVersionResolutionException PluginVersionResolutionException
{ {
List<TaskSegment> taskSegments = buildListCalculator.calculateTaskSegments( session ); List<TaskSegment> taskSegments = lifecycleTaskSegmentCalculator.calculateTaskSegments( session );
TaskSegment mergedSegment = new TaskSegment( false ); TaskSegment mergedSegment = new TaskSegment( false );

View File

@ -15,18 +15,10 @@
package org.apache.maven.lifecycle.internal; package org.apache.maven.lifecycle.internal;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.LifecycleNotFoundException;
import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
import org.apache.maven.plugin.*;
import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.util.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -34,43 +26,9 @@ import java.util.List;
* @author Kristian Rosenvold * @author Kristian Rosenvold
* This class is not part of any public api and can be changed or deleted without prior notice. * This class is not part of any public api and can be changed or deleted without prior notice.
*/ */
@Component(role = BuildListCalculator.class) @Component( role = BuildListCalculator.class )
public class BuildListCalculator public class BuildListCalculator
{ {
@Requirement
private LifecycleTaskSegmentCalculator lifeCycleTaskSegmentCalculator;
@SuppressWarnings({"UnusedDeclaration"})
public BuildListCalculator()
{
}
public BuildListCalculator( LifecycleTaskSegmentCalculator lifeCycleTaskSegmentCalculator )
{
this.lifeCycleTaskSegmentCalculator = lifeCycleTaskSegmentCalculator;
}
public List<TaskSegment> calculateTaskSegments( MavenSession session )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
PluginVersionResolutionException, LifecyclePhaseNotFoundException, LifecycleNotFoundException
{
MavenProject rootProject = session.getTopLevelProject();
List<String> tasks = session.getGoals();
if ( tasks == null || tasks.isEmpty() )
{
if ( !StringUtils.isEmpty( rootProject.getDefaultGoal() ) )
{
tasks = Arrays.asList( StringUtils.split( rootProject.getDefaultGoal() ) );
}
}
return lifeCycleTaskSegmentCalculator.calculateTaskSegments( session, tasks );
}
public ProjectBuildList calculateProjectBuilds( MavenSession session, List<TaskSegment> taskSegments ) public ProjectBuildList calculateProjectBuilds( MavenSession session, List<TaskSegment> taskSegments )
{ {
List<ProjectSegment> projectBuilds = new ArrayList<ProjectSegment>(); List<ProjectSegment> projectBuilds = new ArrayList<ProjectSegment>();

View File

@ -15,6 +15,8 @@
package org.apache.maven.lifecycle.internal; package org.apache.maven.lifecycle.internal;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.LifecycleNotFoundException;
import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
import org.apache.maven.plugin.*; import org.apache.maven.plugin.*;
import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException; import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
import org.apache.maven.plugin.version.PluginVersionResolutionException; import org.apache.maven.plugin.version.PluginVersionResolutionException;
@ -34,10 +36,10 @@ import java.util.List;
public interface LifecycleTaskSegmentCalculator public interface LifecycleTaskSegmentCalculator
{ {
List<TaskSegment> calculateTaskSegments( MavenSession session, List<String> tasks ) public List<TaskSegment> calculateTaskSegments( MavenSession session )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException, MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
PluginVersionResolutionException; PluginVersionResolutionException, LifecyclePhaseNotFoundException, LifecycleNotFoundException;
public boolean requiresProject( MavenSession session ); public boolean requiresProject( MavenSession session );

View File

@ -15,14 +15,23 @@
package org.apache.maven.lifecycle.internal; package org.apache.maven.lifecycle.internal;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.*; import org.apache.maven.lifecycle.LifecycleNotFoundException;
import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
import org.apache.maven.plugin.InvalidPluginDescriptorException;
import org.apache.maven.plugin.MojoNotFoundException;
import org.apache.maven.plugin.PluginDescriptorParsingException;
import org.apache.maven.plugin.PluginNotFoundException;
import org.apache.maven.plugin.PluginResolutionException;
import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException; import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
import org.apache.maven.plugin.version.PluginVersionResolutionException; import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.util.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
/** /**
@ -36,7 +45,7 @@ import java.util.List;
* NOTE: This class is not part of any public api and can be changed or deleted without prior notice. * NOTE: This class is not part of any public api and can be changed or deleted without prior notice.
*/ */
@Component(role = LifecycleTaskSegmentCalculator.class) @Component( role = LifecycleTaskSegmentCalculator.class )
public class LifecycleTaskSegmentCalculatorImpl public class LifecycleTaskSegmentCalculatorImpl
implements LifecycleTaskSegmentCalculator implements LifecycleTaskSegmentCalculator
{ {
@ -50,6 +59,27 @@ public class LifecycleTaskSegmentCalculatorImpl
{ {
} }
public List<TaskSegment> calculateTaskSegments( MavenSession session )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
PluginVersionResolutionException, LifecyclePhaseNotFoundException, LifecycleNotFoundException
{
MavenProject rootProject = session.getTopLevelProject();
List<String> tasks = session.getGoals();
if ( tasks == null || tasks.isEmpty() )
{
if ( !StringUtils.isEmpty( rootProject.getDefaultGoal() ) )
{
tasks = Arrays.asList( StringUtils.split( rootProject.getDefaultGoal() ) );
}
}
return calculateTaskSegments( session, tasks );
}
public List<TaskSegment> calculateTaskSegments( MavenSession session, List<String> tasks ) public List<TaskSegment> calculateTaskSegments( MavenSession session, List<String> tasks )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException, MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,

View File

@ -59,7 +59,7 @@ import java.util.concurrent.Future;
* <p/> * <p/>
* NOTE: This class is not part of any public api and can be changed or deleted without prior notice. * NOTE: This class is not part of any public api and can be changed or deleted without prior notice.
*/ */
@Component(role = LifecycleWeaveBuilder.class) @Component( role = LifecycleWeaveBuilder.class )
public class LifecycleWeaveBuilder public class LifecycleWeaveBuilder
{ {
@ -75,16 +75,16 @@ public class LifecycleWeaveBuilder
@Requirement @Requirement
private ExecutionEventCatapult eventCatapult; private ExecutionEventCatapult eventCatapult;
private Map<MavenProject, MavenExecutionPlan> executionPlans = new HashMap<MavenProject, MavenExecutionPlan>( ); private Map<MavenProject, MavenExecutionPlan> executionPlans = new HashMap<MavenProject, MavenExecutionPlan>();
@SuppressWarnings({"UnusedDeclaration"}) @SuppressWarnings( { "UnusedDeclaration" } )
public LifecycleWeaveBuilder() public LifecycleWeaveBuilder()
{ {
} }
public LifecycleWeaveBuilder(MojoExecutor mojoExecutor, BuilderCommon builderCommon, Logger logger, public LifecycleWeaveBuilder( MojoExecutor mojoExecutor, BuilderCommon builderCommon, Logger logger,
ExecutionEventCatapult eventCatapult) ExecutionEventCatapult eventCatapult )
{ {
this.mojoExecutor = mojoExecutor; this.mojoExecutor = mojoExecutor;
this.builderCommon = builderCommon; this.builderCommon = builderCommon;
@ -105,14 +105,15 @@ public class LifecycleWeaveBuilder
for ( TaskSegment taskSegment : taskSegments ) for ( TaskSegment taskSegment : taskSegments )
{ {
ProjectBuildList segmentChunks = projectBuilds.getByTaskSegment( taskSegment ); ProjectBuildList segmentChunks = projectBuilds.getByTaskSegment( taskSegment );
ThreadOutputMuxer muxer = null; // new ThreadOutputMuxer( segmentChunks, System.out );
Set<String> projectArtifacts = new HashSet<String>(); Set<String> projectArtifacts = new HashSet<String>();
Set<Artifact> projectArtifactsA = new HashSet<Artifact>(); Set<Artifact> projectArtifactsA = new HashSet<Artifact>();
for (ProjectSegment segmentChunk : segmentChunks) { for ( ProjectSegment segmentChunk : segmentChunks )
{
Artifact artifact = segmentChunk.getProject().getArtifact(); Artifact artifact = segmentChunk.getProject().getArtifact();
if (artifact != null) { if ( artifact != null )
projectArtifacts.add( ArtifactUtils.key(artifact)); {
projectArtifactsA.add( artifact); projectArtifacts.add( ArtifactUtils.key( artifact ) );
projectArtifactsA.add( artifact );
} }
} }
for ( ProjectSegment projectBuild : segmentChunks ) for ( ProjectSegment projectBuild : segmentChunks )
@ -122,12 +123,14 @@ public class LifecycleWeaveBuilder
MavenExecutionPlan executionPlan = MavenExecutionPlan executionPlan =
builderCommon.resolveBuildPlan( projectBuild.getSession(), projectBuild.getProject(), builderCommon.resolveBuildPlan( projectBuild.getSession(), projectBuild.getProject(),
projectBuild.getTaskSegment(), projectArtifactsA ); projectBuild.getTaskSegment(), projectArtifactsA );
for (Artifact dependency : projectBuild.getProject().getDependencyArtifacts()) { for ( Artifact dependency : projectBuild.getProject().getDependencyArtifacts() )
String s = ArtifactUtils.key(dependency); {
if ( projectArtifacts.contains(s)){ String s = ArtifactUtils.key( dependency );
dependency.setFile( null); if ( projectArtifacts.contains( s ) )
dependency.setResolved( false); {
dependency.setRepository( null); dependency.setFile( null );
dependency.setResolved( false );
dependency.setRepository( null );
} }
} }
@ -137,9 +140,8 @@ public class LifecycleWeaveBuilder
final Callable<ProjectSegment> projectBuilder = final Callable<ProjectSegment> projectBuilder =
createCallableForBuildingOneFullModule( buildContext, session, reactorBuildStatus, createCallableForBuildingOneFullModule( buildContext, session, reactorBuildStatus,
executionPlan, projectBuild, muxer, executionPlan, projectBuild, dependencyContext,
dependencyContext, concurrentBuildLogger, concurrentBuildLogger );
projectBuilds );
futures.add( service.submit( projectBuilder ) ); futures.add( service.submit( projectBuilder ) );
} }
@ -169,10 +171,8 @@ public class LifecycleWeaveBuilder
final ReactorBuildStatus reactorBuildStatus, final ReactorBuildStatus reactorBuildStatus,
final MavenExecutionPlan executionPlan, final MavenExecutionPlan executionPlan,
final ProjectSegment projectBuild, final ProjectSegment projectBuild,
final ThreadOutputMuxer muxer,
final DependencyContext dependencyContext, final DependencyContext dependencyContext,
final ConcurrentBuildLogger concurrentBuildLogger, final ConcurrentBuildLogger concurrentBuildLogger )
final ProjectBuildList projectBuilds )
{ {
return new Callable<ProjectSegment>() return new Callable<ProjectSegment>()
{ {
@ -195,7 +195,7 @@ public class LifecycleWeaveBuilder
try try
{ {
while (current != null && !reactorBuildStatus.isHaltedOrBlacklisted( projectBuild.getProject() )) while ( current != null && !reactorBuildStatus.isHaltedOrBlacklisted( projectBuild.getProject() ) )
{ {
PhaseRecorder phaseRecorder = new PhaseRecorder( projectBuild.getProject() ); PhaseRecorder phaseRecorder = new PhaseRecorder( projectBuild.getProject() );
@ -203,7 +203,8 @@ public class LifecycleWeaveBuilder
concurrentBuildLogger.createBuildLogItem( projectBuild.getProject(), current ); concurrentBuildLogger.createBuildLogItem( projectBuild.getProject(), current );
final Schedule schedule = current.getSchedule(); final Schedule schedule = current.getSchedule();
buildExecutionPlanItem(current, phaseRecorder, schedule, reactorContext, projectBuild, dependencyContext); buildExecutionPlanItem( current, phaseRecorder, schedule, reactorContext, projectBuild,
dependencyContext );
current.setComplete(); current.setComplete();
builtLogItem.setComplete(); builtLogItem.setComplete();
@ -215,9 +216,10 @@ public class LifecycleWeaveBuilder
final Schedule scheduleOfNext = nextPlanItem.getSchedule(); final Schedule scheduleOfNext = nextPlanItem.getSchedule();
if ( scheduleOfNext == null || !scheduleOfNext.isParallel() ) if ( scheduleOfNext == null || !scheduleOfNext.isParallel() )
{ {
waitForAppropriateUpstreamExecutionsToFinish(builtLogItem, nextPlanItem, projectBuild); waitForAppropriateUpstreamExecutionsToFinish( builtLogItem, nextPlanItem,
projectBuild );
} }
reResolveReactorDependencies(nextPlanItem, projectBuild); reResolveReactorDependencies( nextPlanItem, projectBuild );
} }
current = nextPlanItem; current = nextPlanItem;
} }
@ -247,18 +249,23 @@ public class LifecycleWeaveBuilder
}; };
} }
private void reResolveReactorDependencies(ExecutionPlanItem nextPlanItem, ProjectSegment projectBuild) { private void reResolveReactorDependencies( ExecutionPlanItem nextPlanItem, ProjectSegment projectBuild )
{
if ( requiresReResolutionOfUpstreamReactorArtifacts( nextPlanItem ) ) if ( requiresReResolutionOfUpstreamReactorArtifacts( nextPlanItem ) )
{ {
reresolveUpstreamProjectArtifacts(projectBuild); reresolveUpstreamProjectArtifacts( projectBuild );
} }
else if (requiresReResolutionOfUpstreamTestScopedReactorArtifacts( nextPlanItem)) else if ( requiresReResolutionOfUpstreamTestScopedReactorArtifacts( nextPlanItem ) )
{ {
reresolveUpstreamTestScopedArtifacts( projectBuild); reresolveUpstreamTestScopedArtifacts( projectBuild );
} }
} }
private void waitForAppropriateUpstreamExecutionsToFinish(BuildLogItem builtLogItem, ExecutionPlanItem nextPlanItem, ProjectSegment projectBuild) throws InterruptedException { private void waitForAppropriateUpstreamExecutionsToFinish( BuildLogItem builtLogItem,
ExecutionPlanItem nextPlanItem,
ProjectSegment projectBuild )
throws InterruptedException
{
for ( MavenProject upstreamProject : projectBuild.getImmediateUpstreamProjects() ) for ( MavenProject upstreamProject : projectBuild.getImmediateUpstreamProjects() )
{ {
final MavenExecutionPlan upstreamPlan = executionPlans.get( upstreamProject ); final MavenExecutionPlan upstreamPlan = executionPlans.get( upstreamProject );
@ -286,58 +293,69 @@ public class LifecycleWeaveBuilder
} }
} }
private void reresolveUpstreamProjectArtifacts(ProjectSegment projectBuild) { private void reresolveUpstreamProjectArtifacts( ProjectSegment projectBuild )
for ( MavenProject upstreamProject : projectBuild.getTransitiveUpstreamProjects() ){ {
for ( MavenProject upstreamProject : projectBuild.getTransitiveUpstreamProjects() )
{
Artifact upStreamArtifact = upstreamProject.getArtifact(); Artifact upStreamArtifact = upstreamProject.getArtifact();
Artifact dependencyArtifact = findDependency(projectBuild.getProject(), upStreamArtifact); Artifact dependencyArtifact = findDependency( projectBuild.getProject(), upStreamArtifact );
if (dependencyArtifact != null){ if ( dependencyArtifact != null )
dependencyArtifact.setFile( upStreamArtifact.getFile()); {
dependencyArtifact.setFile( upStreamArtifact.getFile() );
dependencyArtifact.setResolved( true ); dependencyArtifact.setResolved( true );
dependencyArtifact.setRepository( upStreamArtifact.getRepository()); dependencyArtifact.setRepository( upStreamArtifact.getRepository() );
} }
} }
} }
private void reresolveUpstreamTestScopedArtifacts(ProjectSegment projectBuild) { private void reresolveUpstreamTestScopedArtifacts( ProjectSegment projectBuild )
for ( MavenProject upstreamProject : projectBuild.getTransitiveUpstreamProjects() ){ {
Artifact upStreamArtifact = findTestScopedArtifact(upstreamProject); for ( MavenProject upstreamProject : projectBuild.getTransitiveUpstreamProjects() )
Artifact dependencyArtifact = findDependency(projectBuild.getProject(), upStreamArtifact); {
if (dependencyArtifact != null){ Artifact upStreamArtifact = findTestScopedArtifact( upstreamProject );
dependencyArtifact.setFile( upStreamArtifact.getFile()); Artifact dependencyArtifact = findDependency( projectBuild.getProject(), upStreamArtifact );
dependencyArtifact.setResolved( upStreamArtifact.isResolved()); if ( dependencyArtifact != null )
dependencyArtifact.setRepository( upStreamArtifact.getRepository()); {
dependencyArtifact.setFile( upStreamArtifact.getFile() );
dependencyArtifact.setResolved( upStreamArtifact.isResolved() );
dependencyArtifact.setRepository( upStreamArtifact.getRepository() );
} }
} }
} }
private Artifact findTestScopedArtifact(MavenProject upstreamProject) { private Artifact findTestScopedArtifact( MavenProject upstreamProject )
if ( upstreamProject == null){ {
if ( upstreamProject == null )
{
return null; return null;
} }
List<Artifact> artifactList = upstreamProject.getAttachedArtifacts(); List<Artifact> artifactList = upstreamProject.getAttachedArtifacts();
for (Artifact artifact : artifactList) { for ( Artifact artifact : artifactList )
if (Artifact.SCOPE_TEST.equals( artifact.getScope())){ {
if ( Artifact.SCOPE_TEST.equals( artifact.getScope() ) )
{
return artifact; return artifact;
} }
} }
return null; return null;
} }
private static Artifact findDependency(MavenProject project, Artifact upStreamArtifact) { private static Artifact findDependency( MavenProject project, Artifact upStreamArtifact )
if (upStreamArtifact == null){ {
if ( upStreamArtifact == null )
{
return null; return null;
} }
String key = ArtifactUtils.key( upStreamArtifact.getGroupId(), String key = ArtifactUtils.key( upStreamArtifact.getGroupId(), upStreamArtifact.getArtifactId(),
upStreamArtifact.getArtifactId(),
upStreamArtifact.getVersion() ); upStreamArtifact.getVersion() );
final Set<Artifact> deps = project.getDependencyArtifacts(); final Set<Artifact> deps = project.getDependencyArtifacts();
for ( Artifact dep : deps ) for ( Artifact dep : deps )
{ {
String depKey = ArtifactUtils.key(dep.getGroupId(), dep.getArtifactId(), dep.getVersion()); String depKey = ArtifactUtils.key( dep.getGroupId(), dep.getArtifactId(), dep.getVersion() );
if ( key.equals( depKey ) ) if ( key.equals( depKey ) )
{ {
return dep; return dep;
@ -350,28 +368,31 @@ public class LifecycleWeaveBuilder
private boolean requiresReResolutionOfUpstreamReactorArtifacts( ExecutionPlanItem nextExecutionPlanItem ) private boolean requiresReResolutionOfUpstreamReactorArtifacts( ExecutionPlanItem nextExecutionPlanItem )
{ {
final String phase = nextExecutionPlanItem.getLifecyclePhase(); final String phase = nextExecutionPlanItem.getLifecyclePhase();
return "package".equals(phase) || "install".equals( phase ) || "compile".equals( phase ); return "package".equals( phase ) || "install".equals( phase ) || "compile".equals( phase );
} }
private boolean requiresReResolutionOfUpstreamTestScopedReactorArtifacts( ExecutionPlanItem nextExecutionPlanItem ) private boolean requiresReResolutionOfUpstreamTestScopedReactorArtifacts( ExecutionPlanItem nextExecutionPlanItem )
{ {
final String phase = nextExecutionPlanItem.getLifecyclePhase(); final String phase = nextExecutionPlanItem.getLifecyclePhase();
return "package".equals(phase) || "install".equals( phase ) || "compile".equals( phase ) || "test-compile".equals( phase ); return "package".equals( phase ) || "install".equals( phase ) || "compile".equals( phase ) ||
"test-compile".equals( phase );
} }
private void buildExecutionPlanItem(ExecutionPlanItem current, PhaseRecorder phaseRecorder, Schedule schedule, ReactorContext reactorContext, ProjectSegment projectBuild, DependencyContext dependencyContext) throws LifecycleExecutionException { private void buildExecutionPlanItem( ExecutionPlanItem current, PhaseRecorder phaseRecorder, Schedule schedule,
ReactorContext reactorContext, ProjectSegment projectBuild,
DependencyContext dependencyContext )
throws LifecycleExecutionException
{
if ( schedule != null && schedule.isMojoSynchronized() ) if ( schedule != null && schedule.isMojoSynchronized() )
{ {
synchronized ( current.getPlugin() ) synchronized ( current.getPlugin() )
{ {
buildExecutionPlanItem( reactorContext, current, projectBuild, dependencyContext, buildExecutionPlanItem( reactorContext, current, projectBuild, dependencyContext, phaseRecorder );
phaseRecorder );
} }
} }
else else
{ {
buildExecutionPlanItem( reactorContext, current, projectBuild, dependencyContext, buildExecutionPlanItem( reactorContext, current, projectBuild, dependencyContext, phaseRecorder );
phaseRecorder );
} }
} }

View File

@ -305,9 +305,6 @@ public class LifecycleExecutorTest
System.out.println( dom ); System.out.println( dom );
} }
// Todo: This method is kind of an oddity. It is only called from the LifecycleExecutorTest, hence it should
// really not exist, or at least be moved into the test class.
MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks ) MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException, MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,

View File

@ -29,9 +29,10 @@ public class BuildListCalculatorTest
public void testCalculateProjectBuilds() public void testCalculateProjectBuilds()
throws Exception throws Exception
{ {
BuildListCalculator buildListCalculator = createBuildListCalculator(); LifecycleTaskSegmentCalculator lifecycleTaskSegmentCalculator = getTaskSegmentCalculator();
BuildListCalculator buildListCalculator = new BuildListCalculator();
final MavenSession session = ProjectDependencyGraphStub.getMavenSession(); final MavenSession session = ProjectDependencyGraphStub.getMavenSession();
List<TaskSegment> taskSegments = buildListCalculator.calculateTaskSegments( session ); List<TaskSegment> taskSegments = lifecycleTaskSegmentCalculator.calculateTaskSegments( session );
final ProjectBuildList buildList = buildListCalculator.calculateProjectBuilds( session, taskSegments ); final ProjectBuildList buildList = buildListCalculator.calculateProjectBuilds( session, taskSegments );
final ProjectBuildList segments = buildList.getByTaskSegment( taskSegments.get( 0 ) ); final ProjectBuildList segments = buildList.getByTaskSegment( taskSegments.get( 0 ) );
assertEquals( "Stub data contains 3 segments", 3, taskSegments.size() ); assertEquals( "Stub data contains 3 segments", 3, taskSegments.size() );
@ -40,10 +41,9 @@ public class BuildListCalculatorTest
assertNotNull( build ); assertNotNull( build );
} }
public static BuildListCalculator createBuildListCalculator() private static LifecycleTaskSegmentCalculator getTaskSegmentCalculator()
{ {
LifecycleTaskSegmentCalculator lifecycleTaskSegmentCalculator = new LifecycleTaskSegmentCalculatorStub(); return new LifecycleTaskSegmentCalculatorStub();
return new BuildListCalculator( lifecycleTaskSegmentCalculator );
} }
} }

View File

@ -0,0 +1,38 @@
package org.apache.maven.lifecycle.internal;
import junit.framework.TestCase;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.internal.stub.LifecycleTaskSegmentCalculatorStub;
import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
import java.util.List;
/**
* @author <a href="mailto:kristian@zenior.no">Kristian Rosenvold</a>
*/
public class LifecycleTaskSegmentCalculatorImplTest
extends TestCase
{
public void testCalculateProjectBuilds()
throws Exception
{
LifecycleTaskSegmentCalculator lifecycleTaskSegmentCalculator = getTaskSegmentCalculator();
BuildListCalculator buildListCalculator = new BuildListCalculator();
final MavenSession session = ProjectDependencyGraphStub.getMavenSession();
List<TaskSegment> taskSegments = lifecycleTaskSegmentCalculator.calculateTaskSegments( session );
final ProjectBuildList buildList = buildListCalculator.calculateProjectBuilds( session, taskSegments );
final ProjectBuildList segments = buildList.getByTaskSegment( taskSegments.get( 0 ) );
assertEquals( "Stub data contains 3 segments", 3, taskSegments.size() );
assertEquals( "Stub data contains 6 items", 6, segments.size() );
final ProjectSegment build = segments.get( 0 );
assertNotNull( build );
}
private static LifecycleTaskSegmentCalculator getTaskSegmentCalculator()
{
return new LifecycleTaskSegmentCalculatorStub();
}
}

View File

@ -20,13 +20,7 @@ import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.LifecycleNotFoundException; import org.apache.maven.lifecycle.LifecycleNotFoundException;
import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException; import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
import org.apache.maven.lifecycle.internal.stub.CompletionServiceStub; import org.apache.maven.lifecycle.internal.stub.*;
import org.apache.maven.lifecycle.internal.stub.ExecutionEventCatapultStub;
import org.apache.maven.lifecycle.internal.stub.LifecycleExecutionPlanCalculatorStub;
import org.apache.maven.lifecycle.internal.stub.LoggerStub;
import org.apache.maven.lifecycle.internal.stub.MojoExecutorStub;
import org.apache.maven.lifecycle.internal.stub.ProjectDependenciesResolverStub;
import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
import org.apache.maven.plugin.InvalidPluginDescriptorException; import org.apache.maven.plugin.InvalidPluginDescriptorException;
import org.apache.maven.plugin.MojoNotFoundException; import org.apache.maven.plugin.MojoNotFoundException;
import org.apache.maven.plugin.PluginDescriptorParsingException; import org.apache.maven.plugin.PluginDescriptorParsingException;
@ -85,9 +79,9 @@ public class LifecycleWeaveBuilderTest
final ClassLoader loader = Thread.currentThread().getContextClassLoader(); final ClassLoader loader = Thread.currentThread().getContextClassLoader();
try try
{ {
BuildListCalculator buildListCalculator = BuildListCalculatorTest.createBuildListCalculator(); BuildListCalculator buildListCalculator = new BuildListCalculator();
final MavenSession session = ProjectDependencyGraphStub.getMavenSession(); final MavenSession session = ProjectDependencyGraphStub.getMavenSession();
List<TaskSegment> taskSegments = buildListCalculator.calculateTaskSegments( session ); List<TaskSegment> taskSegments = getTaskSegmentCalculator().calculateTaskSegments( session );
ProjectBuildList projectBuildList = buildListCalculator.calculateProjectBuilds( session, taskSegments ); ProjectBuildList projectBuildList = buildListCalculator.calculateProjectBuilds( session, taskSegments );
final MojoExecutorStub mojoExecutorStub = new MojoExecutorStub(); final MojoExecutorStub mojoExecutorStub = new MojoExecutorStub();
@ -109,6 +103,11 @@ public class LifecycleWeaveBuilderTest
} }
private static LifecycleTaskSegmentCalculator getTaskSegmentCalculator()
{
return new LifecycleTaskSegmentCalculatorStub();
}
private ReactorContext createBuildContext( MavenSession session ) private ReactorContext createBuildContext( MavenSession session )
{ {
MavenExecutionResult mavenExecutionResult = new DefaultMavenExecutionResult(); MavenExecutionResult mavenExecutionResult = new DefaultMavenExecutionResult();
@ -120,8 +119,6 @@ public class LifecycleWeaveBuilderTest
{ {
final BuilderCommon builderCommon = getBuilderCommon(); final BuilderCommon builderCommon = getBuilderCommon();
final LoggerStub loggerStub = new LoggerStub(); final LoggerStub loggerStub = new LoggerStub();
final LifecycleDependencyResolver lifecycleDependencyResolver =
new LifecycleDependencyResolver( new ProjectDependenciesResolverStub(), loggerStub );
return new LifecycleWeaveBuilder( mojoExecutor, builderCommon, loggerStub, new ExecutionEventCatapultStub() ); return new LifecycleWeaveBuilder( mojoExecutor, builderCommon, loggerStub, new ExecutionEventCatapultStub() );
} }

View File

@ -18,7 +18,7 @@ package org.apache.maven.lifecycle.internal.stub;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.internal.GoalTask; import org.apache.maven.lifecycle.internal.GoalTask;
import org.apache.maven.lifecycle.internal.LifecycleTask; import org.apache.maven.lifecycle.internal.LifecycleTask;
import org.apache.maven.lifecycle.internal.LifecycleTaskSegmentCalculator; import org.apache.maven.lifecycle.internal.LifecycleTaskSegmentCalculatorImpl;
import org.apache.maven.lifecycle.internal.TaskSegment; import org.apache.maven.lifecycle.internal.TaskSegment;
import org.apache.maven.plugin.InvalidPluginDescriptorException; import org.apache.maven.plugin.InvalidPluginDescriptorException;
import org.apache.maven.plugin.MojoNotFoundException; import org.apache.maven.plugin.MojoNotFoundException;
@ -36,7 +36,7 @@ import java.util.List;
*/ */
public class LifecycleTaskSegmentCalculatorStub public class LifecycleTaskSegmentCalculatorStub
implements LifecycleTaskSegmentCalculator extends LifecycleTaskSegmentCalculatorImpl
{ {
public static final String clean = "clean"; public static final String clean = "clean";
@ -44,6 +44,7 @@ public class LifecycleTaskSegmentCalculatorStub
public static final String install = "install"; public static final String install = "install";
public List<TaskSegment> calculateTaskSegments( MavenSession session, List<String> tasks ) public List<TaskSegment> calculateTaskSegments( MavenSession session, List<String> tasks )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException, MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,