mirror of https://github.com/apache/maven.git
[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:
parent
e2378b2b47
commit
0ce5541bb5
|
@ -42,7 +42,7 @@ public class EmptyLifecycleExecutor
|
|||
|
||||
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 )
|
||||
|
|
|
@ -20,9 +20,7 @@ package org.apache.maven.lifecycle;
|
|||
*/
|
||||
|
||||
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.DefaultLifecycleExecutionPlanCalculator;
|
||||
import org.apache.maven.lifecycle.internal.LifecycleStarter;
|
||||
import org.apache.maven.lifecycle.internal.LifecycleTaskSegmentCalculator;
|
||||
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.Requirement;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
* 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 )
|
||||
throws LifecycleExecutionException
|
||||
{
|
||||
Set<String> requiredDependencyResolutionScopes = new TreeSet<String>();
|
||||
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();
|
||||
return mojoExecutor.executeForkedExecutions( mojoExecution, session, new ProjectIndex( session.getProjects() ) );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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 Map<String, ExecutionPlanItem> lastMojoExecutionForAllPhases;
|
||||
|
@ -71,13 +61,10 @@ public class MavenExecutionPlan
|
|||
|
||||
final List<String> phasesInExecutionPlan;
|
||||
|
||||
public MavenExecutionPlan( Set<String> requiredDependencyResolutionScopes,
|
||||
Set<String> requiredDependencyCollectionScopes, List<ExecutionPlanItem> planItem,
|
||||
DefaultLifecycles defaultLifecycles )
|
||||
public MavenExecutionPlan( List<ExecutionPlanItem> planItem, DefaultLifecycles defaultLifecycles )
|
||||
{
|
||||
this.requiredDependencyResolutionScopes = requiredDependencyResolutionScopes;
|
||||
this.requiredDependencyCollectionScopes = requiredDependencyCollectionScopes;
|
||||
this.planItem = planItem;
|
||||
|
||||
lastMojoExecutionForAllPhases = new LinkedHashMap<String, ExecutionPlanItem>();
|
||||
|
||||
LinkedHashSet<String> totalPhaseSet = new LinkedHashSet<String>();
|
||||
|
@ -115,7 +102,6 @@ public class MavenExecutionPlan
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public Iterator<ExecutionPlanItem> iterator()
|
||||
{
|
||||
return getExecutionPlanItems().iterator();
|
||||
|
@ -177,16 +163,6 @@ public class MavenExecutionPlan
|
|||
return phasesInExecutionPlan.contains( phase );
|
||||
}
|
||||
|
||||
public Set<String> getRequiredResolutionScopes()
|
||||
{
|
||||
return requiredDependencyResolutionScopes;
|
||||
}
|
||||
|
||||
public Set<String> getRequiredCollectionScopes()
|
||||
{
|
||||
return requiredDependencyCollectionScopes;
|
||||
}
|
||||
|
||||
public List<MojoExecution> getMojoExecutions()
|
||||
{
|
||||
List<MojoExecution> result = new ArrayList<MojoExecution>();
|
||||
|
|
|
@ -62,9 +62,6 @@ public class BuilderCommon
|
|||
@Requirement
|
||||
private LifecycleExecutionPlanCalculator lifeCycleExecutionPlanCalculator;
|
||||
|
||||
@Requirement
|
||||
private LifecycleDependencyResolver lifecycleDependencyResolver;
|
||||
|
||||
@Requirement
|
||||
private ExecutionEventCatapult eventCatapult;
|
||||
|
||||
|
@ -72,19 +69,16 @@ public class BuilderCommon
|
|||
private Logger logger;
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings( { "UnusedDeclaration" } )
|
||||
public BuilderCommon()
|
||||
{
|
||||
}
|
||||
|
||||
public BuilderCommon( LifecycleDebugLogger lifecycleDebugLogger,
|
||||
LifecycleExecutionPlanCalculator lifeCycleExecutionPlanCalculator,
|
||||
LifecycleDependencyResolver lifecycleDependencyResolver, Logger logger )
|
||||
LifecycleExecutionPlanCalculator lifeCycleExecutionPlanCalculator, Logger logger )
|
||||
{
|
||||
this.lifecycleDebugLogger = lifecycleDebugLogger;
|
||||
this.lifeCycleExecutionPlanCalculator = lifeCycleExecutionPlanCalculator;
|
||||
this.lifecycleDependencyResolver = lifecycleDependencyResolver;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
|
@ -97,6 +91,7 @@ public class BuilderCommon
|
|||
{
|
||||
MavenExecutionPlan executionPlan =
|
||||
lifeCycleExecutionPlanCalculator.calculateExecutionPlan( session, project, taskSegment.getTasks() );
|
||||
|
||||
lifecycleDebugLogger.debugProjectPlan( project, executionPlan );
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
public void handleBuildError( final ReactorContext buildContext, final MavenSession rootSession,
|
||||
final MavenProject mavenProject, Exception e, final long buildStartTime )
|
||||
{
|
||||
|
|
|
@ -109,28 +109,18 @@ public class DefaultLifecycleExecutionPlanCalculator
|
|||
PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException,
|
||||
NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException
|
||||
{
|
||||
Set<String> requiredDependencyResolutionScopes = new TreeSet<String>();
|
||||
Set<String> requiredDependencyCollectionScopes = new TreeSet<String>();
|
||||
|
||||
lifecyclePluginResolver.resolveMissingPluginVersions( project, session );
|
||||
|
||||
final List<MojoExecution> executions = calculateMojoExecutions( session, project, tasks );
|
||||
|
||||
setupMojoExections( session, project, requiredDependencyResolutionScopes, requiredDependencyCollectionScopes,
|
||||
executions );
|
||||
setupMojoExections( session, project, executions );
|
||||
|
||||
final List<ExecutionPlanItem> planItem = defaultSchedules.createExecutionPlanItem( project, executions );
|
||||
|
||||
return new MavenExecutionPlan( requiredDependencyResolutionScopes, requiredDependencyCollectionScopes, planItem,
|
||||
defaultLifeCycles );
|
||||
|
||||
|
||||
return new MavenExecutionPlan( planItem, defaultLifeCycles );
|
||||
}
|
||||
|
||||
private void setupMojoExections( MavenSession session, MavenProject project,
|
||||
Set<String> requiredDependencyResolutionScopes,
|
||||
Set<String> requiredDependencyCollectionScopes,
|
||||
List<MojoExecution> mojoExecutions )
|
||||
private void setupMojoExections( MavenSession session, MavenProject project, List<MojoExecution> mojoExecutions )
|
||||
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
|
||||
MojoNotFoundException, InvalidPluginDescriptorException, NoPluginFoundForPrefixException,
|
||||
LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
|
||||
|
@ -155,9 +145,6 @@ public class DefaultLifecycleExecutionPlanCalculator
|
|||
finalizeMojoConfiguration( mojoExecution );
|
||||
|
||||
calculateForkedExecutions( mojoExecution, session, project, new HashSet<MojoDescriptor>() );
|
||||
|
||||
collectDependencyRequirements( requiredDependencyResolutionScopes, requiredDependencyCollectionScopes,
|
||||
mojoExecution );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,37 +189,6 @@ public class DefaultLifecycleExecutionPlanCalculator
|
|||
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,
|
||||
String lifecyclePhase )
|
||||
throws LifecyclePhaseNotFoundException, PluginNotFoundException, PluginResolutionException,
|
||||
|
|
|
@ -19,14 +19,15 @@ package org.apache.maven.lifecycle.internal;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.lifecycle.MavenExecutionPlan;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
import java.util.Arrays;
|
||||
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
|
||||
* @author Benjamin Bentmann
|
||||
|
@ -38,84 +39,81 @@ import java.util.Collection;
|
|||
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,
|
||||
boolean aggregating )
|
||||
private volatile Collection<?> lastDependencyArtifacts = UNRESOLVED;
|
||||
|
||||
private volatile int lastDependencyArtifactCount = -1;
|
||||
|
||||
public DependencyContext( MavenProject project, Collection<String> scopesToCollect,
|
||||
Collection<String> scopesToResolve )
|
||||
{
|
||||
this.scopesToCollect = scopesToCollect;
|
||||
this.scopesToResolve = scopesToResolve;
|
||||
this.aggregating = aggregating;
|
||||
this.project = project;
|
||||
scopesToCollectForCurrentProject = scopesToCollect;
|
||||
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;
|
||||
lastDependencyArtifactCount = ( lastDependencyArtifacts != null ) ? lastDependencyArtifacts.size() : 0;
|
||||
return scopesToCollectForCurrentProject;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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 != project.getDependencyArtifacts()
|
||||
|| ( lastDependencyArtifacts != null && lastDependencyArtifactCount != lastDependencyArtifacts.size() ) )
|
||||
{
|
||||
if ( lastDependencyArtifacts != lastProject.getDependencyArtifacts()
|
||||
|| ( lastDependencyArtifacts != null && lastDependencyArtifactCount != lastDependencyArtifacts.size() ) )
|
||||
{
|
||||
return true;
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,14 +23,18 @@ import org.apache.maven.execution.MavenSession;
|
|||
import org.apache.maven.execution.ProjectDependencyGraph;
|
||||
import org.apache.maven.lifecycle.MavenExecutionPlan;
|
||||
import org.apache.maven.plugin.MojoExecution;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.component.annotations.Requirement;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
* Logs debug output from the various lifecycle phases.
|
||||
|
@ -76,6 +80,7 @@ public class LifecycleDebugLogger
|
|||
{
|
||||
return;
|
||||
}
|
||||
|
||||
logger.debug( "=== REACTOR BUILD PLAN ================================================" );
|
||||
|
||||
for ( Iterator<ProjectSegment> it = projectBuilds.iterator(); it.hasNext(); )
|
||||
|
@ -98,10 +103,15 @@ public class LifecycleDebugLogger
|
|||
|
||||
public void debugProjectPlan( MavenProject currentProject, MavenExecutionPlan executionPlan )
|
||||
{
|
||||
if ( !logger.isDebugEnabled() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
logger.debug( "=== PROJECT BUILD PLAN ================================================" );
|
||||
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 )
|
||||
{
|
||||
|
@ -124,6 +134,8 @@ public class LifecycleDebugLogger
|
|||
{
|
||||
logger.debug( "--- init fork of " + fork.getKey() + " for " + mojoExecId + " ---" );
|
||||
|
||||
debugDependencyRequirements( fork.getValue() );
|
||||
|
||||
for ( MojoExecution forkedExecution : fork.getValue() )
|
||||
{
|
||||
debugMojoExecution( forkedExecution );
|
||||
|
@ -140,6 +152,32 @@ public class LifecycleDebugLogger
|
|||
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 )
|
||||
{
|
||||
if ( !logger.isInfoEnabled() )
|
||||
|
|
|
@ -21,7 +21,6 @@ import org.apache.maven.artifact.ArtifactUtils;
|
|||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.lifecycle.LifecycleExecutionException;
|
||||
import org.apache.maven.lifecycle.MavenExecutionPlan;
|
||||
import org.apache.maven.project.DefaultDependencyResolutionRequest;
|
||||
import org.apache.maven.project.DependencyResolutionException;
|
||||
import org.apache.maven.project.DependencyResolutionResult;
|
||||
|
@ -73,15 +72,6 @@ public class LifecycleDependencyResolver
|
|||
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 )
|
||||
{
|
||||
if ( aggregator )
|
||||
|
@ -94,36 +84,9 @@ public class LifecycleDependencyResolver
|
|||
}
|
||||
}
|
||||
|
||||
public void checkForUpdate( MavenSession session, DependencyContext dependenctContext )
|
||||
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,
|
||||
boolean aggregating, Set<Artifact> projectArtifacts )
|
||||
public void resolveProjectDependencies( MavenProject project, Collection<String> scopesToCollect,
|
||||
Collection<String> scopesToResolve, MavenSession session,
|
||||
boolean aggregating, Set<Artifact> projectArtifacts )
|
||||
throws LifecycleExecutionException
|
||||
{
|
||||
if ( project.getDependencyArtifacts() == null )
|
||||
|
|
|
@ -62,8 +62,6 @@ public class LifecycleModuleBuilder
|
|||
public void buildProject( MavenSession session, MavenSession rootSession, ReactorContext reactorContext,
|
||||
MavenProject currentProject, TaskSegment taskSegment )
|
||||
{
|
||||
boolean isAggregating = taskSegment.isAggregating();
|
||||
|
||||
session.setCurrentProject( currentProject );
|
||||
|
||||
long buildStartTime = System.currentTimeMillis();
|
||||
|
@ -83,9 +81,7 @@ public class LifecycleModuleBuilder
|
|||
MavenExecutionPlan executionPlan =
|
||||
builderCommon.resolveBuildPlan( session, currentProject, taskSegment, new HashSet<Artifact>() );
|
||||
|
||||
DependencyContext dependencyContext = new DependencyContext( executionPlan, isAggregating );
|
||||
mojoExecutor.execute( session, executionPlan.getMojoExecutions(), reactorContext.getProjectIndex(),
|
||||
dependencyContext );
|
||||
mojoExecutor.execute( session, executionPlan.getMojoExecutions(), reactorContext.getProjectIndex() );
|
||||
|
||||
long buildEndTime = System.currentTimeMillis();
|
||||
|
||||
|
|
|
@ -151,8 +151,9 @@ public class LifecycleWeaveBuilder
|
|||
try
|
||||
{
|
||||
final MavenExecutionPlan executionPlan = plans.get( projectBuild ).get();
|
||||
|
||||
DependencyContext dependencyContext =
|
||||
new DependencyContext( executionPlan, projectBuild.getTaskSegment().isAggregating() );
|
||||
mojoExecutor.newDependencyContext( session, executionPlan.getMojoExecutions() );
|
||||
|
||||
final Callable<ProjectSegment> projectBuilder =
|
||||
createCallableForBuildingOneFullModule( buildContext, session, reactorBuildStatus,
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.maven.lifecycle.internal;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||
import org.apache.maven.artifact.resolver.filter.CumulativeScopeArtifactFilter;
|
||||
import org.apache.maven.execution.ExecutionEvent;
|
||||
|
@ -38,9 +39,13 @@ import org.codehaus.plexus.component.annotations.Requirement;
|
|||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
* Executes an individual mojo
|
||||
|
@ -69,12 +74,67 @@ public class MojoExecutor
|
|||
{
|
||||
}
|
||||
|
||||
public void execute( MavenSession session, List<MojoExecution> mojoExecutions, ProjectIndex projectIndex,
|
||||
DependencyContext dependencyContext )
|
||||
public DependencyContext newDependencyContext( MavenSession session, List<MojoExecution> mojoExecutions )
|
||||
{
|
||||
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
|
||||
|
||||
{
|
||||
DependencyContext dependencyContext = newDependencyContext( session, mojoExecutions );
|
||||
|
||||
PhaseRecorder phaseRecorder = new PhaseRecorder( session.getCurrentProject() );
|
||||
|
||||
for ( MojoExecution mojoExecution : mojoExecutions )
|
||||
{
|
||||
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 =
|
||||
executeForkedExecutions( mojoExecution, session, projectIndex, dependencyContext );
|
||||
ensureDependenciesAreResolved( mojoDescriptor, session, dependencyContext );
|
||||
|
||||
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
|
||||
|
@ -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 )
|
||||
{
|
||||
String scopeToResolve = mojoDescriptor.getDependencyResolutionRequired();
|
||||
|
@ -204,7 +302,7 @@ public class MojoExecutor
|
|||
}
|
||||
|
||||
public List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, MavenSession session,
|
||||
ProjectIndex projectIndex, DependencyContext dependencyContext )
|
||||
ProjectIndex projectIndex )
|
||||
throws LifecycleExecutionException
|
||||
{
|
||||
List<MavenProject> forkedProjects = Collections.emptyList();
|
||||
|
@ -219,8 +317,6 @@ public class MojoExecutor
|
|||
|
||||
forkedProjects = new ArrayList<MavenProject>( forkedExecutions.size() );
|
||||
|
||||
dependencyContext = dependencyContext.clone();
|
||||
|
||||
try
|
||||
{
|
||||
for ( Map.Entry<String, List<MojoExecution>> fork : forkedExecutions.entrySet() )
|
||||
|
@ -252,7 +348,7 @@ public class MojoExecutor
|
|||
|
||||
eventCatapult.fire( ExecutionEvent.Type.ForkedProjectStarted, session, mojoExecution );
|
||||
|
||||
execute( session, mojoExecutions, projectIndex, dependencyContext );
|
||||
execute( session, mojoExecutions, projectIndex );
|
||||
|
||||
eventCatapult.fire( ExecutionEvent.Type.ForkedProjectSucceeded, session, mojoExecution );
|
||||
}
|
||||
|
|
|
@ -195,10 +195,6 @@ public class LifecycleExecutorTest
|
|||
|
||||
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 );
|
||||
|
||||
//[01] clean:clean
|
||||
|
|
|
@ -21,7 +21,6 @@ import org.apache.maven.execution.MavenSession;
|
|||
import org.apache.maven.lifecycle.MavenExecutionPlan;
|
||||
import org.apache.maven.lifecycle.internal.stub.LifecycleExecutionPlanCalculatorStub;
|
||||
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 java.util.HashSet;
|
||||
|
@ -68,9 +67,7 @@ public class BuilderCommonTest
|
|||
public static BuilderCommon getBuilderCommon()
|
||||
{
|
||||
final LifecycleDebugLogger logger = new LifecycleDebugLogger( new LoggerStub() );
|
||||
final LifecycleDependencyResolver lifecycleDependencyResolver =
|
||||
new LifecycleDependencyResolver( new ProjectDependenciesResolverStub(), new LoggerStub() );
|
||||
return new BuilderCommon( logger, new LifecycleExecutionPlanCalculatorStub(), lifecycleDependencyResolver,
|
||||
return new BuilderCommon( logger, new LifecycleExecutionPlanCalculatorStub(),
|
||||
new LoggerStub() );
|
||||
}
|
||||
|
||||
|
|
|
@ -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.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.MojoNotFoundException;
|
||||
|
@ -131,9 +130,7 @@ public class LifecycleWeaveBuilderTest
|
|||
private BuilderCommon getBuilderCommon()
|
||||
{
|
||||
final LifecycleDebugLogger logger = new LifecycleDebugLogger( new LoggerStub() );
|
||||
final LifecycleDependencyResolver lifecycleDependencyResolver =
|
||||
new LifecycleDependencyResolver( new ProjectDependenciesResolverStub(), new LoggerStub() );
|
||||
return new BuilderCommon( logger, new LifecycleExecutionPlanCalculatorStub(), lifecycleDependencyResolver,
|
||||
return new BuilderCommon( logger, new LifecycleExecutionPlanCalculatorStub(),
|
||||
new LoggerStub() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -171,8 +171,7 @@ public class LifecycleExecutionPlanCalculatorStub
|
|||
{
|
||||
final List<ExecutionPlanItem> planItemList =
|
||||
DefaultSchedulesStub.createDefaultSchedules().createExecutionPlanItem( project, mojoExecutions );
|
||||
return new MavenExecutionPlan( getScopes(), getScopes(), planItemList,
|
||||
DefaultLifecyclesStub.createDefaultLifecycles() );
|
||||
return new MavenExecutionPlan( planItemList, DefaultLifecyclesStub.createDefaultLifecycles() );
|
||||
}
|
||||
|
||||
private static MojoExecution createMojoExecution( String goal, String executionId, MojoDescriptor mojoDescriptor )
|
||||
|
|
|
@ -47,8 +47,7 @@ public class MojoExecutorStub
|
|||
}
|
||||
|
||||
@Override
|
||||
public void execute( MavenSession session, List<MojoExecution> mojoExecutions, ProjectIndex projectIndex,
|
||||
DependencyContext dependencyContext )
|
||||
public void execute( MavenSession session, List<MojoExecution> mojoExecutions, ProjectIndex projectIndex )
|
||||
throws LifecycleExecutionException
|
||||
{
|
||||
for ( MojoExecution mojoExecution : mojoExecutions )
|
||||
|
|
|
@ -43,7 +43,7 @@ public class EmptyLifecycleExecutor
|
|||
|
||||
public MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks )
|
||||
{
|
||||
return new MavenExecutionPlan(null, null, null, null );
|
||||
return new MavenExecutionPlan( null, null );
|
||||
}
|
||||
|
||||
public void execute( MavenSession session )
|
||||
|
|
Loading…
Reference in New Issue