[MNG-4795] [regression] Dependencies in forked reactor projects are not resolved when aggregator bound to lifecycle forks

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@996206 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2010-09-11 20:19:40 +00:00
parent e2378b2b47
commit 0ce5541bb5
17 changed files with 224 additions and 242 deletions

View File

@ -42,7 +42,7 @@ public class EmptyLifecycleExecutor
public MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks ) public MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks )
{ {
return new MavenExecutionPlan(null, null, null, new DefaultLifecycles() ); return new MavenExecutionPlan( null, new DefaultLifecycles() );
} }
public void execute( MavenSession session ) public void execute( MavenSession session )

View File

@ -20,9 +20,7 @@ package org.apache.maven.lifecycle;
*/ */
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.internal.DependencyContext;
import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator; import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator;
import org.apache.maven.lifecycle.internal.DefaultLifecycleExecutionPlanCalculator;
import org.apache.maven.lifecycle.internal.LifecycleStarter; import org.apache.maven.lifecycle.internal.LifecycleStarter;
import org.apache.maven.lifecycle.internal.LifecycleTaskSegmentCalculator; import org.apache.maven.lifecycle.internal.LifecycleTaskSegmentCalculator;
import org.apache.maven.lifecycle.internal.MojoDescriptorCreator; import org.apache.maven.lifecycle.internal.MojoDescriptorCreator;
@ -44,11 +42,9 @@ 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 java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.TreeSet;
/** /**
* A facade that provides lifecycle services to components outside maven core. * A facade that provides lifecycle services to components outside maven core.
@ -166,20 +162,7 @@ public class DefaultLifecycleExecutor
public List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, MavenSession session ) public List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, MavenSession session )
throws LifecycleExecutionException throws LifecycleExecutionException
{ {
Set<String> requiredDependencyResolutionScopes = new TreeSet<String>(); return mojoExecutor.executeForkedExecutions( mojoExecution, session, new ProjectIndex( session.getProjects() ) );
Set<String> requiredDependencyCollectionScopes = new TreeSet<String>();
// Ok, so this method could probably have a better location.
DefaultLifecycleExecutionPlanCalculator.collectDependencyRequirements( requiredDependencyResolutionScopes,
requiredDependencyCollectionScopes,
mojoExecution );
final DependencyContext context =
new DependencyContext( requiredDependencyCollectionScopes, requiredDependencyResolutionScopes,
mojoExecution.getMojoDescriptor().isAggregator() );
mojoExecutor.executeForkedExecutions( mojoExecution, session, new ProjectIndex( session.getProjects() ),
context );
return Collections.emptyList();
} }
} }

View File

@ -54,16 +54,6 @@ public class MavenExecutionPlan
*/ */
/**
* For project dependency resolution, the scopes of resolution required if any.
*/
private final Set<String> requiredDependencyResolutionScopes;
/**
* For project dependency collection, the scopes of collection required if any.
*/
private final Set<String> requiredDependencyCollectionScopes;
private final List<ExecutionPlanItem> planItem; private final List<ExecutionPlanItem> planItem;
private final Map<String, ExecutionPlanItem> lastMojoExecutionForAllPhases; private final Map<String, ExecutionPlanItem> lastMojoExecutionForAllPhases;
@ -71,13 +61,10 @@ public class MavenExecutionPlan
final List<String> phasesInExecutionPlan; final List<String> phasesInExecutionPlan;
public MavenExecutionPlan( Set<String> requiredDependencyResolutionScopes, public MavenExecutionPlan( List<ExecutionPlanItem> planItem, DefaultLifecycles defaultLifecycles )
Set<String> requiredDependencyCollectionScopes, List<ExecutionPlanItem> planItem,
DefaultLifecycles defaultLifecycles )
{ {
this.requiredDependencyResolutionScopes = requiredDependencyResolutionScopes;
this.requiredDependencyCollectionScopes = requiredDependencyCollectionScopes;
this.planItem = planItem; this.planItem = planItem;
lastMojoExecutionForAllPhases = new LinkedHashMap<String, ExecutionPlanItem>(); lastMojoExecutionForAllPhases = new LinkedHashMap<String, ExecutionPlanItem>();
LinkedHashSet<String> totalPhaseSet = new LinkedHashSet<String>(); LinkedHashSet<String> totalPhaseSet = new LinkedHashSet<String>();
@ -115,7 +102,6 @@ public class MavenExecutionPlan
} }
} }
public Iterator<ExecutionPlanItem> iterator() public Iterator<ExecutionPlanItem> iterator()
{ {
return getExecutionPlanItems().iterator(); return getExecutionPlanItems().iterator();
@ -177,16 +163,6 @@ public class MavenExecutionPlan
return phasesInExecutionPlan.contains( phase ); return phasesInExecutionPlan.contains( phase );
} }
public Set<String> getRequiredResolutionScopes()
{
return requiredDependencyResolutionScopes;
}
public Set<String> getRequiredCollectionScopes()
{
return requiredDependencyCollectionScopes;
}
public List<MojoExecution> getMojoExecutions() public List<MojoExecution> getMojoExecutions()
{ {
List<MojoExecution> result = new ArrayList<MojoExecution>(); List<MojoExecution> result = new ArrayList<MojoExecution>();

View File

@ -62,9 +62,6 @@ public class BuilderCommon
@Requirement @Requirement
private LifecycleExecutionPlanCalculator lifeCycleExecutionPlanCalculator; private LifecycleExecutionPlanCalculator lifeCycleExecutionPlanCalculator;
@Requirement
private LifecycleDependencyResolver lifecycleDependencyResolver;
@Requirement @Requirement
private ExecutionEventCatapult eventCatapult; private ExecutionEventCatapult eventCatapult;
@ -72,19 +69,16 @@ public class BuilderCommon
private Logger logger; private Logger logger;
@SuppressWarnings( { "UnusedDeclaration" } ) @SuppressWarnings( { "UnusedDeclaration" } )
public BuilderCommon() public BuilderCommon()
{ {
} }
public BuilderCommon( LifecycleDebugLogger lifecycleDebugLogger, public BuilderCommon( LifecycleDebugLogger lifecycleDebugLogger,
LifecycleExecutionPlanCalculator lifeCycleExecutionPlanCalculator, LifecycleExecutionPlanCalculator lifeCycleExecutionPlanCalculator, Logger logger )
LifecycleDependencyResolver lifecycleDependencyResolver, Logger logger )
{ {
this.lifecycleDebugLogger = lifecycleDebugLogger; this.lifecycleDebugLogger = lifecycleDebugLogger;
this.lifeCycleExecutionPlanCalculator = lifeCycleExecutionPlanCalculator; this.lifeCycleExecutionPlanCalculator = lifeCycleExecutionPlanCalculator;
this.lifecycleDependencyResolver = lifecycleDependencyResolver;
this.logger = logger; this.logger = logger;
} }
@ -97,6 +91,7 @@ public class BuilderCommon
{ {
MavenExecutionPlan executionPlan = MavenExecutionPlan executionPlan =
lifeCycleExecutionPlanCalculator.calculateExecutionPlan( session, project, taskSegment.getTasks() ); lifeCycleExecutionPlanCalculator.calculateExecutionPlan( session, project, taskSegment.getTasks() );
lifecycleDebugLogger.debugProjectPlan( project, executionPlan ); lifecycleDebugLogger.debugProjectPlan( project, executionPlan );
if ( session.getRequest().isThreadConfigurationPresent() ) if ( session.getRequest().isThreadConfigurationPresent() )
@ -122,17 +117,9 @@ public class BuilderCommon
} }
} }
// TODO: once we have calculated the build plan then we should accurately be able to download
// the project dependencies. Having it happen in the plugin manager is a tangled mess. We can optimize
// this later by looking at the build plan. Would be better to just batch download everything required
// by the reactor.
lifecycleDependencyResolver.resolveDependencies( taskSegment.isAggregating(), project, session, executionPlan,
projectArtifacts );
return executionPlan; return executionPlan;
} }
public void handleBuildError( final ReactorContext buildContext, final MavenSession rootSession, public void handleBuildError( final ReactorContext buildContext, final MavenSession rootSession,
final MavenProject mavenProject, Exception e, final long buildStartTime ) final MavenProject mavenProject, Exception e, final long buildStartTime )
{ {

View File

@ -109,28 +109,18 @@ public class DefaultLifecycleExecutionPlanCalculator
PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException, PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException,
NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException
{ {
Set<String> requiredDependencyResolutionScopes = new TreeSet<String>();
Set<String> requiredDependencyCollectionScopes = new TreeSet<String>();
lifecyclePluginResolver.resolveMissingPluginVersions( project, session ); lifecyclePluginResolver.resolveMissingPluginVersions( project, session );
final List<MojoExecution> executions = calculateMojoExecutions( session, project, tasks ); final List<MojoExecution> executions = calculateMojoExecutions( session, project, tasks );
setupMojoExections( session, project, requiredDependencyResolutionScopes, requiredDependencyCollectionScopes, setupMojoExections( session, project, executions );
executions );
final List<ExecutionPlanItem> planItem = defaultSchedules.createExecutionPlanItem( project, executions ); final List<ExecutionPlanItem> planItem = defaultSchedules.createExecutionPlanItem( project, executions );
return new MavenExecutionPlan( requiredDependencyResolutionScopes, requiredDependencyCollectionScopes, planItem, return new MavenExecutionPlan( planItem, defaultLifeCycles );
defaultLifeCycles );
} }
private void setupMojoExections( MavenSession session, MavenProject project, private void setupMojoExections( MavenSession session, MavenProject project, List<MojoExecution> mojoExecutions )
Set<String> requiredDependencyResolutionScopes,
Set<String> requiredDependencyCollectionScopes,
List<MojoExecution> mojoExecutions )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
MojoNotFoundException, InvalidPluginDescriptorException, NoPluginFoundForPrefixException, MojoNotFoundException, InvalidPluginDescriptorException, NoPluginFoundForPrefixException,
LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
@ -155,9 +145,6 @@ public class DefaultLifecycleExecutionPlanCalculator
finalizeMojoConfiguration( mojoExecution ); finalizeMojoConfiguration( mojoExecution );
calculateForkedExecutions( mojoExecution, session, project, new HashSet<MojoDescriptor>() ); calculateForkedExecutions( mojoExecution, session, project, new HashSet<MojoDescriptor>() );
collectDependencyRequirements( requiredDependencyResolutionScopes, requiredDependencyCollectionScopes,
mojoExecution );
} }
} }
@ -202,37 +189,6 @@ public class DefaultLifecycleExecutionPlanCalculator
return mojoExecutions; return mojoExecutions;
} }
public static void collectDependencyRequirements( Collection<String> requiredDependencyResolutionScopes,
Collection<String> requiredDependencyCollectionScopes,
MojoExecution mojoExecution )
{
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
String requiredDependencyResolutionScope = mojoDescriptor.getDependencyResolutionRequired();
if ( StringUtils.isNotEmpty( requiredDependencyResolutionScope ) )
{
requiredDependencyResolutionScopes.add( requiredDependencyResolutionScope );
}
String requiredDependencyCollectionScope = mojoDescriptor.getDependencyCollectionRequired();
if ( StringUtils.isNotEmpty( requiredDependencyCollectionScope ) )
{
requiredDependencyCollectionScopes.add( requiredDependencyCollectionScope );
}
for ( List<MojoExecution> forkedExecutions : mojoExecution.getForkedExecutions().values() )
{
for ( MojoExecution forkedExecution : forkedExecutions )
{
collectDependencyRequirements( requiredDependencyResolutionScopes, requiredDependencyCollectionScopes,
forkedExecution );
}
}
}
private Map<String, List<MojoExecution>> calculateLifecycleMappings( MavenSession session, MavenProject project, private Map<String, List<MojoExecution>> calculateLifecycleMappings( MavenSession session, MavenProject project,
String lifecyclePhase ) String lifecyclePhase )
throws LifecyclePhaseNotFoundException, PluginNotFoundException, PluginResolutionException, throws LifecyclePhaseNotFoundException, PluginNotFoundException, PluginResolutionException,

View File

@ -19,14 +19,15 @@ package org.apache.maven.lifecycle.internal;
* under the License. * under the License.
*/ */
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.MavenExecutionPlan;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.TreeSet;
/** /**
* Context of dependency artifacts for the entire build. * Context of dependency artifacts for a particular project.
* *
* @since 3.0 * @since 3.0
* @author Benjamin Bentmann * @author Benjamin Bentmann
@ -38,84 +39,81 @@ import java.util.Collection;
public class DependencyContext public class DependencyContext
{ {
private final Collection<String> scopesToCollect; private static final Collection<?> UNRESOLVED = Arrays.asList();
private final Collection<String> scopesToResolve; private final MavenProject project;
private final boolean aggregating; private final Collection<String> scopesToCollectForCurrentProject;
private volatile MavenProject lastProject; private final Collection<String> scopesToResolveForCurrentProject;
private volatile Collection<?> lastDependencyArtifacts; private final Collection<String> scopesToCollectForAggregatedProjects;
private volatile int lastDependencyArtifactCount; private final Collection<String> scopesToResolveForAggregatedProjects;
public DependencyContext( Collection<String> scopesToCollect, Collection<String> scopesToResolve, private volatile Collection<?> lastDependencyArtifacts = UNRESOLVED;
boolean aggregating )
private volatile int lastDependencyArtifactCount = -1;
public DependencyContext( MavenProject project, Collection<String> scopesToCollect,
Collection<String> scopesToResolve )
{ {
this.scopesToCollect = scopesToCollect; this.project = project;
this.scopesToResolve = scopesToResolve; scopesToCollectForCurrentProject = scopesToCollect;
this.aggregating = aggregating; scopesToResolveForCurrentProject = scopesToResolve;
scopesToCollectForAggregatedProjects = Collections.synchronizedSet( new TreeSet<String>() );
scopesToResolveForAggregatedProjects = Collections.synchronizedSet( new TreeSet<String>() );
} }
public DependencyContext( MavenExecutionPlan executionPlan, boolean aggregating ) public MavenProject getProject()
{ {
this( executionPlan.getRequiredCollectionScopes(), executionPlan.getRequiredResolutionScopes(), aggregating ); return project;
} }
public void setLastDependencyArtifacts( Collection<?> lastDependencyArtifacts ) public Collection<String> getScopesToCollectForCurrentProject()
{ {
this.lastDependencyArtifacts = lastDependencyArtifacts; return scopesToCollectForCurrentProject;
lastDependencyArtifactCount = ( lastDependencyArtifacts != null ) ? lastDependencyArtifacts.size() : 0;
} }
public MavenProject getLastProject() public Collection<String> getScopesToResolveForCurrentProject()
{ {
return lastProject; return scopesToResolveForCurrentProject;
} }
public void setLastProject( MavenProject lastProject ) public Collection<String> getScopesToCollectForAggregatedProjects()
{ {
this.lastProject = lastProject; return scopesToCollectForAggregatedProjects;
} }
public Collection<String> getScopesToCollect() public Collection<String> getScopesToResolveForAggregatedProjects()
{ {
return scopesToCollect; return scopesToResolveForAggregatedProjects;
} }
public Collection<String> getScopesToResolve() public boolean isResolutionRequiredForCurrentProject()
{ {
return scopesToResolve; if ( lastDependencyArtifacts != project.getDependencyArtifacts()
}
public boolean isAggregating()
{
return aggregating;
}
public DependencyContext clone()
{
return new DependencyContext( scopesToCollect, scopesToResolve, aggregating );
}
public boolean isSameProject( MavenSession session )
{
return ( lastProject == session.getCurrentProject() );
}
public boolean isSameButUpdatedProject( MavenSession session )
{
if ( isSameProject( session ) )
{
if ( lastDependencyArtifacts != lastProject.getDependencyArtifacts()
|| ( lastDependencyArtifacts != null && lastDependencyArtifactCount != lastDependencyArtifacts.size() ) ) || ( lastDependencyArtifacts != null && lastDependencyArtifactCount != lastDependencyArtifacts.size() ) )
{ {
return true; return true;
} }
}
return false; return false;
} }
public boolean isResolutionRequiredForAggregatedProjects( Collection<String> scopesToCollect,
Collection<String> scopesToResolve )
{
boolean required =
scopesToCollectForAggregatedProjects.addAll( scopesToCollect )
|| scopesToResolveForAggregatedProjects.addAll( scopesToResolve );
return required;
}
public void synchronizeWithProjectState()
{
lastDependencyArtifacts = project.getDependencyArtifacts();
lastDependencyArtifactCount = ( lastDependencyArtifacts != null ) ? lastDependencyArtifacts.size() : 0;
}
} }

View File

@ -23,14 +23,18 @@ import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.ProjectDependencyGraph; import org.apache.maven.execution.ProjectDependencyGraph;
import org.apache.maven.lifecycle.MavenExecutionPlan; import org.apache.maven.lifecycle.MavenExecutionPlan;
import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
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.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.StringUtils;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
/** /**
* Logs debug output from the various lifecycle phases. * Logs debug output from the various lifecycle phases.
@ -76,6 +80,7 @@ public class LifecycleDebugLogger
{ {
return; return;
} }
logger.debug( "=== REACTOR BUILD PLAN ================================================" ); logger.debug( "=== REACTOR BUILD PLAN ================================================" );
for ( Iterator<ProjectSegment> it = projectBuilds.iterator(); it.hasNext(); ) for ( Iterator<ProjectSegment> it = projectBuilds.iterator(); it.hasNext(); )
@ -98,10 +103,15 @@ public class LifecycleDebugLogger
public void debugProjectPlan( MavenProject currentProject, MavenExecutionPlan executionPlan ) public void debugProjectPlan( MavenProject currentProject, MavenExecutionPlan executionPlan )
{ {
if ( !logger.isDebugEnabled() )
{
return;
}
logger.debug( "=== PROJECT BUILD PLAN ================================================" ); logger.debug( "=== PROJECT BUILD PLAN ================================================" );
logger.debug( "Project: " + BuilderCommon.getKey( currentProject ) ); logger.debug( "Project: " + BuilderCommon.getKey( currentProject ) );
logger.debug( "Dependencies (collect): " + executionPlan.getRequiredCollectionScopes() );
logger.debug( "Dependencies (resolve): " + executionPlan.getRequiredResolutionScopes() ); debugDependencyRequirements( executionPlan.getMojoExecutions() );
for ( ExecutionPlanItem mojoExecution : executionPlan ) for ( ExecutionPlanItem mojoExecution : executionPlan )
{ {
@ -124,6 +134,8 @@ public class LifecycleDebugLogger
{ {
logger.debug( "--- init fork of " + fork.getKey() + " for " + mojoExecId + " ---" ); logger.debug( "--- init fork of " + fork.getKey() + " for " + mojoExecId + " ---" );
debugDependencyRequirements( fork.getValue() );
for ( MojoExecution forkedExecution : fork.getValue() ) for ( MojoExecution forkedExecution : fork.getValue() )
{ {
debugMojoExecution( forkedExecution ); debugMojoExecution( forkedExecution );
@ -140,6 +152,32 @@ public class LifecycleDebugLogger
logger.debug( "Configuration: " + mojoExecution.getConfiguration() ); logger.debug( "Configuration: " + mojoExecution.getConfiguration() );
} }
private void debugDependencyRequirements( List<MojoExecution> mojoExecutions )
{
Set<String> scopesToCollect = new TreeSet<String>();
Set<String> scopesToResolve = new TreeSet<String>();
for ( MojoExecution mojoExecution : mojoExecutions )
{
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
String scopeToCollect = mojoDescriptor.getDependencyCollectionRequired();
if ( StringUtils.isNotEmpty( scopeToCollect ) )
{
scopesToCollect.add( scopeToCollect );
}
String scopeToResolve = mojoDescriptor.getDependencyResolutionRequired();
if ( StringUtils.isNotEmpty( scopeToResolve ) )
{
scopesToResolve.add( scopeToResolve );
}
}
logger.debug( "Dependencies (collect): " + scopesToCollect );
logger.debug( "Dependencies (resolve): " + scopesToResolve );
}
public void logWeavePlan( MavenSession session ) public void logWeavePlan( MavenSession session )
{ {
if ( !logger.isInfoEnabled() ) if ( !logger.isInfoEnabled() )

View File

@ -21,7 +21,6 @@ import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.LifecycleExecutionException; import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.lifecycle.MavenExecutionPlan;
import org.apache.maven.project.DefaultDependencyResolutionRequest; import org.apache.maven.project.DefaultDependencyResolutionRequest;
import org.apache.maven.project.DependencyResolutionException; import org.apache.maven.project.DependencyResolutionException;
import org.apache.maven.project.DependencyResolutionResult; import org.apache.maven.project.DependencyResolutionResult;
@ -73,15 +72,6 @@ public class LifecycleDependencyResolver
this.logger = logger; this.logger = logger;
} }
public void resolveDependencies( boolean aggregating, MavenProject currentProject,
MavenSession sessionForThisModule, MavenExecutionPlan executionPlan,
Set<Artifact> projectArtifacts )
throws LifecycleExecutionException
{
List<MavenProject> projectsToResolve = getProjects( currentProject, sessionForThisModule, aggregating );
resolveDependencies( aggregating, sessionForThisModule, executionPlan, projectsToResolve, projectArtifacts );
}
public static List<MavenProject> getProjects( MavenProject project, MavenSession session, boolean aggregator ) public static List<MavenProject> getProjects( MavenProject project, MavenSession session, boolean aggregator )
{ {
if ( aggregator ) if ( aggregator )
@ -94,34 +84,7 @@ public class LifecycleDependencyResolver
} }
} }
public void checkForUpdate( MavenSession session, DependencyContext dependenctContext ) public void resolveProjectDependencies( MavenProject project, Collection<String> scopesToCollect,
throws LifecycleExecutionException
{
if ( dependenctContext.isSameButUpdatedProject( session ) )
{
resolveProjectDependencies( dependenctContext.getLastProject(), dependenctContext.getScopesToCollect(),
dependenctContext.getScopesToResolve(), session,
dependenctContext.isAggregating(), new HashSet<Artifact>() );
}
dependenctContext.setLastProject( session.getCurrentProject() );
dependenctContext.setLastDependencyArtifacts( session.getCurrentProject().getDependencyArtifacts() );
}
private void resolveDependencies( boolean aggregating, MavenSession session, MavenExecutionPlan executionPlan,
List<MavenProject> projectsToResolve, Set<Artifact> projectArtifacts )
throws LifecycleExecutionException
{
for ( MavenProject project : projectsToResolve )
{
resolveProjectDependencies( project, executionPlan.getRequiredCollectionScopes(),
executionPlan.getRequiredResolutionScopes(), session, aggregating,
projectArtifacts );
}
}
private void resolveProjectDependencies( MavenProject project, Collection<String> scopesToCollect,
Collection<String> scopesToResolve, MavenSession session, Collection<String> scopesToResolve, MavenSession session,
boolean aggregating, Set<Artifact> projectArtifacts ) boolean aggregating, Set<Artifact> projectArtifacts )
throws LifecycleExecutionException throws LifecycleExecutionException

View File

@ -62,8 +62,6 @@ public class LifecycleModuleBuilder
public void buildProject( MavenSession session, MavenSession rootSession, ReactorContext reactorContext, public void buildProject( MavenSession session, MavenSession rootSession, ReactorContext reactorContext,
MavenProject currentProject, TaskSegment taskSegment ) MavenProject currentProject, TaskSegment taskSegment )
{ {
boolean isAggregating = taskSegment.isAggregating();
session.setCurrentProject( currentProject ); session.setCurrentProject( currentProject );
long buildStartTime = System.currentTimeMillis(); long buildStartTime = System.currentTimeMillis();
@ -83,9 +81,7 @@ public class LifecycleModuleBuilder
MavenExecutionPlan executionPlan = MavenExecutionPlan executionPlan =
builderCommon.resolveBuildPlan( session, currentProject, taskSegment, new HashSet<Artifact>() ); builderCommon.resolveBuildPlan( session, currentProject, taskSegment, new HashSet<Artifact>() );
DependencyContext dependencyContext = new DependencyContext( executionPlan, isAggregating ); mojoExecutor.execute( session, executionPlan.getMojoExecutions(), reactorContext.getProjectIndex() );
mojoExecutor.execute( session, executionPlan.getMojoExecutions(), reactorContext.getProjectIndex(),
dependencyContext );
long buildEndTime = System.currentTimeMillis(); long buildEndTime = System.currentTimeMillis();

View File

@ -151,8 +151,9 @@ public class LifecycleWeaveBuilder
try try
{ {
final MavenExecutionPlan executionPlan = plans.get( projectBuild ).get(); final MavenExecutionPlan executionPlan = plans.get( projectBuild ).get();
DependencyContext dependencyContext = DependencyContext dependencyContext =
new DependencyContext( executionPlan, projectBuild.getTaskSegment().isAggregating() ); mojoExecutor.newDependencyContext( session, executionPlan.getMojoExecutions() );
final Callable<ProjectSegment> projectBuilder = final Callable<ProjectSegment> projectBuilder =
createCallableForBuildingOneFullModule( buildContext, session, reactorBuildStatus, createCallableForBuildingOneFullModule( buildContext, session, reactorBuildStatus,

View File

@ -19,6 +19,7 @@ package org.apache.maven.lifecycle.internal;
* under the License. * under the License.
*/ */
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.CumulativeScopeArtifactFilter; import org.apache.maven.artifact.resolver.filter.CumulativeScopeArtifactFilter;
import org.apache.maven.execution.ExecutionEvent; import org.apache.maven.execution.ExecutionEvent;
@ -38,9 +39,13 @@ import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
/** /**
* Executes an individual mojo * Executes an individual mojo
@ -69,12 +74,67 @@ public class MojoExecutor
{ {
} }
public void execute( MavenSession session, List<MojoExecution> mojoExecutions, ProjectIndex projectIndex, public DependencyContext newDependencyContext( MavenSession session, List<MojoExecution> mojoExecutions )
DependencyContext dependencyContext ) {
Set<String> scopesToCollect = new TreeSet<String>();
Set<String> scopesToResolve = new TreeSet<String>();
collectDependencyRequirements( scopesToResolve, scopesToCollect, mojoExecutions );
return new DependencyContext( session.getCurrentProject(), scopesToCollect, scopesToResolve );
}
private void collectDependencyRequirements( Set<String> scopesToResolve, Set<String> scopesToCollect,
Collection<MojoExecution> mojoExecutions )
{
for ( MojoExecution mojoExecution : mojoExecutions )
{
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
scopesToResolve.addAll( toScopes( mojoDescriptor.getDependencyResolutionRequired() ) );
scopesToCollect.addAll( toScopes( mojoDescriptor.getDependencyCollectionRequired() ) );
}
}
private Collection<String> toScopes( String classpath )
{
if ( StringUtils.isNotEmpty( classpath ) )
{
if ( Artifact.SCOPE_COMPILE.equals( classpath ) )
{
return Arrays.asList( Artifact.SCOPE_COMPILE, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_PROVIDED );
}
else if ( Artifact.SCOPE_RUNTIME.equals( classpath ) )
{
return Arrays.asList( Artifact.SCOPE_COMPILE, Artifact.SCOPE_RUNTIME );
}
else if ( Artifact.SCOPE_COMPILE_PLUS_RUNTIME.equals( classpath ) )
{
return Arrays.asList( Artifact.SCOPE_COMPILE, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_PROVIDED,
Artifact.SCOPE_RUNTIME );
}
else if ( Artifact.SCOPE_RUNTIME_PLUS_SYSTEM.equals( classpath ) )
{
return Arrays.asList( Artifact.SCOPE_COMPILE, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_RUNTIME );
}
else if ( Artifact.SCOPE_TEST.equals( classpath ) )
{
return Arrays.asList( Artifact.SCOPE_COMPILE, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_PROVIDED,
Artifact.SCOPE_RUNTIME, Artifact.SCOPE_TEST );
}
}
return Collections.emptyList();
}
public void execute( MavenSession session, List<MojoExecution> mojoExecutions, ProjectIndex projectIndex )
throws LifecycleExecutionException throws LifecycleExecutionException
{ {
DependencyContext dependencyContext = newDependencyContext( session, mojoExecutions );
PhaseRecorder phaseRecorder = new PhaseRecorder( session.getCurrentProject() ); PhaseRecorder phaseRecorder = new PhaseRecorder( session.getCurrentProject() );
for ( MojoExecution mojoExecution : mojoExecutions ) for ( MojoExecution mojoExecution : mojoExecutions )
{ {
execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder );
@ -122,22 +182,12 @@ public class MojoExecutor
} }
} }
lifeCycleDependencyResolver.checkForUpdate( session, dependencyContext ); List<MavenProject> forkedProjects = executeForkedExecutions( mojoExecution, session, projectIndex );
List<MavenProject> forkedProjects = ensureDependenciesAreResolved( mojoDescriptor, session, dependencyContext );
executeForkedExecutions( mojoExecution, session, projectIndex, dependencyContext );
eventCatapult.fire( ExecutionEvent.Type.MojoStarted, session, mojoExecution ); eventCatapult.fire( ExecutionEvent.Type.MojoStarted, session, mojoExecution );
ArtifactFilter artifactFilter = getArtifactFilter( mojoDescriptor );
List<MavenProject> resolvedProjects =
LifecycleDependencyResolver.getProjects( session.getCurrentProject(), session,
mojoDescriptor.isAggregator() );
for ( MavenProject project : resolvedProjects )
{
project.setArtifactFilter( artifactFilter );
}
try try
{ {
try try
@ -178,6 +228,54 @@ public class MojoExecutor
} }
} }
private void ensureDependenciesAreResolved( MojoDescriptor mojoDescriptor, MavenSession session,
DependencyContext dependencyContext )
throws LifecycleExecutionException
{
MavenProject project = dependencyContext.getProject();
boolean aggregating = mojoDescriptor.isAggregator();
if ( dependencyContext.isResolutionRequiredForCurrentProject() )
{
Collection<String> scopesToCollect = dependencyContext.getScopesToCollectForCurrentProject();
Collection<String> scopesToResolve = dependencyContext.getScopesToResolveForCurrentProject();
lifeCycleDependencyResolver.resolveProjectDependencies( project, scopesToCollect, scopesToResolve, session,
aggregating, Collections.<Artifact> emptySet() );
dependencyContext.synchronizeWithProjectState();
}
if ( aggregating )
{
Collection<String> scopesToCollect = toScopes( mojoDescriptor.getDependencyCollectionRequired() );
Collection<String> scopesToResolve = toScopes( mojoDescriptor.getDependencyResolutionRequired() );
if ( dependencyContext.isResolutionRequiredForAggregatedProjects( scopesToCollect, scopesToResolve ) )
{
for ( MavenProject aggregatedProject : session.getProjects() )
{
if ( aggregatedProject != project )
{
lifeCycleDependencyResolver.resolveProjectDependencies( aggregatedProject, scopesToCollect,
scopesToResolve, session, aggregating,
Collections.<Artifact> emptySet() );
}
}
}
}
ArtifactFilter artifactFilter = getArtifactFilter( mojoDescriptor );
List<MavenProject> projectsToResolve =
LifecycleDependencyResolver.getProjects( session.getCurrentProject(), session,
mojoDescriptor.isAggregator() );
for ( MavenProject projectToResolve : projectsToResolve )
{
projectToResolve.setArtifactFilter( artifactFilter );
}
}
private ArtifactFilter getArtifactFilter( MojoDescriptor mojoDescriptor ) private ArtifactFilter getArtifactFilter( MojoDescriptor mojoDescriptor )
{ {
String scopeToResolve = mojoDescriptor.getDependencyResolutionRequired(); String scopeToResolve = mojoDescriptor.getDependencyResolutionRequired();
@ -204,7 +302,7 @@ public class MojoExecutor
} }
public List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, MavenSession session, public List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, MavenSession session,
ProjectIndex projectIndex, DependencyContext dependencyContext ) ProjectIndex projectIndex )
throws LifecycleExecutionException throws LifecycleExecutionException
{ {
List<MavenProject> forkedProjects = Collections.emptyList(); List<MavenProject> forkedProjects = Collections.emptyList();
@ -219,8 +317,6 @@ public class MojoExecutor
forkedProjects = new ArrayList<MavenProject>( forkedExecutions.size() ); forkedProjects = new ArrayList<MavenProject>( forkedExecutions.size() );
dependencyContext = dependencyContext.clone();
try try
{ {
for ( Map.Entry<String, List<MojoExecution>> fork : forkedExecutions.entrySet() ) for ( Map.Entry<String, List<MojoExecution>> fork : forkedExecutions.entrySet() )
@ -252,7 +348,7 @@ public class MojoExecutor
eventCatapult.fire( ExecutionEvent.Type.ForkedProjectStarted, session, mojoExecution ); eventCatapult.fire( ExecutionEvent.Type.ForkedProjectStarted, session, mojoExecution );
execute( session, mojoExecutions, projectIndex, dependencyContext ); execute( session, mojoExecutions, projectIndex );
eventCatapult.fire( ExecutionEvent.Type.ForkedProjectSucceeded, session, mojoExecution ); eventCatapult.fire( ExecutionEvent.Type.ForkedProjectSucceeded, session, mojoExecution );
} }

View File

@ -195,10 +195,6 @@ public class LifecycleExecutorTest
MavenExecutionPlan plan = calculateExecutionPlan( session, "clean", "install" ); MavenExecutionPlan plan = calculateExecutionPlan( session, "clean", "install" );
assertTrue( plan.getRequiredResolutionScopes().contains( Artifact.SCOPE_COMPILE ) );
assertTrue( plan.getRequiredResolutionScopes().contains( Artifact.SCOPE_RUNTIME ) );
assertTrue( plan.getRequiredResolutionScopes().contains( Artifact.SCOPE_TEST ) );
List<MojoExecution> executions = getExecutions( plan ); List<MojoExecution> executions = getExecutions( plan );
//[01] clean:clean //[01] clean:clean

View File

@ -21,7 +21,6 @@ import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.MavenExecutionPlan; import org.apache.maven.lifecycle.MavenExecutionPlan;
import org.apache.maven.lifecycle.internal.stub.LifecycleExecutionPlanCalculatorStub; import org.apache.maven.lifecycle.internal.stub.LifecycleExecutionPlanCalculatorStub;
import org.apache.maven.lifecycle.internal.stub.LoggerStub; import org.apache.maven.lifecycle.internal.stub.LoggerStub;
import org.apache.maven.lifecycle.internal.stub.ProjectDependenciesResolverStub;
import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub; import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
import java.util.HashSet; import java.util.HashSet;
@ -68,9 +67,7 @@ public class BuilderCommonTest
public static BuilderCommon getBuilderCommon() public static BuilderCommon getBuilderCommon()
{ {
final LifecycleDebugLogger logger = new LifecycleDebugLogger( new LoggerStub() ); final LifecycleDebugLogger logger = new LifecycleDebugLogger( new LoggerStub() );
final LifecycleDependencyResolver lifecycleDependencyResolver = return new BuilderCommon( logger, new LifecycleExecutionPlanCalculatorStub(),
new LifecycleDependencyResolver( new ProjectDependenciesResolverStub(), new LoggerStub() );
return new BuilderCommon( logger, new LifecycleExecutionPlanCalculatorStub(), lifecycleDependencyResolver,
new LoggerStub() ); new LoggerStub() );
} }

View File

@ -25,7 +25,6 @@ import org.apache.maven.lifecycle.internal.stub.LifecycleExecutionPlanCalculator
import org.apache.maven.lifecycle.internal.stub.LifecycleTaskSegmentCalculatorStub; import org.apache.maven.lifecycle.internal.stub.LifecycleTaskSegmentCalculatorStub;
import org.apache.maven.lifecycle.internal.stub.LoggerStub; import org.apache.maven.lifecycle.internal.stub.LoggerStub;
import org.apache.maven.lifecycle.internal.stub.MojoExecutorStub; 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.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;
@ -131,9 +130,7 @@ public class LifecycleWeaveBuilderTest
private BuilderCommon getBuilderCommon() private BuilderCommon getBuilderCommon()
{ {
final LifecycleDebugLogger logger = new LifecycleDebugLogger( new LoggerStub() ); final LifecycleDebugLogger logger = new LifecycleDebugLogger( new LoggerStub() );
final LifecycleDependencyResolver lifecycleDependencyResolver = return new BuilderCommon( logger, new LifecycleExecutionPlanCalculatorStub(),
new LifecycleDependencyResolver( new ProjectDependenciesResolverStub(), new LoggerStub() );
return new BuilderCommon( logger, new LifecycleExecutionPlanCalculatorStub(), lifecycleDependencyResolver,
new LoggerStub() ); new LoggerStub() );
} }
} }

View File

@ -171,8 +171,7 @@ public class LifecycleExecutionPlanCalculatorStub
{ {
final List<ExecutionPlanItem> planItemList = final List<ExecutionPlanItem> planItemList =
DefaultSchedulesStub.createDefaultSchedules().createExecutionPlanItem( project, mojoExecutions ); DefaultSchedulesStub.createDefaultSchedules().createExecutionPlanItem( project, mojoExecutions );
return new MavenExecutionPlan( getScopes(), getScopes(), planItemList, return new MavenExecutionPlan( planItemList, DefaultLifecyclesStub.createDefaultLifecycles() );
DefaultLifecyclesStub.createDefaultLifecycles() );
} }
private static MojoExecution createMojoExecution( String goal, String executionId, MojoDescriptor mojoDescriptor ) private static MojoExecution createMojoExecution( String goal, String executionId, MojoDescriptor mojoDescriptor )

View File

@ -47,8 +47,7 @@ public class MojoExecutorStub
} }
@Override @Override
public void execute( MavenSession session, List<MojoExecution> mojoExecutions, ProjectIndex projectIndex, public void execute( MavenSession session, List<MojoExecution> mojoExecutions, ProjectIndex projectIndex )
DependencyContext dependencyContext )
throws LifecycleExecutionException throws LifecycleExecutionException
{ {
for ( MojoExecution mojoExecution : mojoExecutions ) for ( MojoExecution mojoExecution : mojoExecutions )

View File

@ -43,7 +43,7 @@ public class EmptyLifecycleExecutor
public MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks ) public MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks )
{ {
return new MavenExecutionPlan(null, null, null, null ); return new MavenExecutionPlan( null, null );
} }
public void execute( MavenSession session ) public void execute( MavenSession session )