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

View File

@ -15,18 +15,10 @@
package org.apache.maven.lifecycle.internal;
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.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.Arrays;
import java.util.Collections;
import java.util.List;
@ -34,43 +26,9 @@ import java.util.List;
* @author Kristian Rosenvold
* 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
{
@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 )
{
List<ProjectSegment> projectBuilds = new ArrayList<ProjectSegment>();

View File

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

View File

@ -15,14 +15,23 @@
package org.apache.maven.lifecycle.internal;
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.prefix.NoPluginFoundForPrefixException;
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.Requirement;
import org.codehaus.plexus.util.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
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.
*/
@Component(role = LifecycleTaskSegmentCalculator.class)
@Component( role = LifecycleTaskSegmentCalculator.class )
public class LifecycleTaskSegmentCalculatorImpl
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 )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,

View File

@ -59,7 +59,7 @@ import java.util.concurrent.Future;
* <p/>
* 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
{
@ -75,16 +75,16 @@ public class LifecycleWeaveBuilder
@Requirement
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(MojoExecutor mojoExecutor, BuilderCommon builderCommon, Logger logger,
ExecutionEventCatapult eventCatapult)
public LifecycleWeaveBuilder( MojoExecutor mojoExecutor, BuilderCommon builderCommon, Logger logger,
ExecutionEventCatapult eventCatapult )
{
this.mojoExecutor = mojoExecutor;
this.builderCommon = builderCommon;
@ -105,14 +105,15 @@ public class LifecycleWeaveBuilder
for ( TaskSegment taskSegment : taskSegments )
{
ProjectBuildList segmentChunks = projectBuilds.getByTaskSegment( taskSegment );
ThreadOutputMuxer muxer = null; // new ThreadOutputMuxer( segmentChunks, System.out );
Set<String> projectArtifacts = new HashSet<String>();
Set<Artifact> projectArtifactsA = new HashSet<Artifact>();
for (ProjectSegment segmentChunk : segmentChunks) {
for ( ProjectSegment segmentChunk : segmentChunks )
{
Artifact artifact = segmentChunk.getProject().getArtifact();
if (artifact != null) {
projectArtifacts.add( ArtifactUtils.key(artifact));
projectArtifactsA.add( artifact);
if ( artifact != null )
{
projectArtifacts.add( ArtifactUtils.key( artifact ) );
projectArtifactsA.add( artifact );
}
}
for ( ProjectSegment projectBuild : segmentChunks )
@ -122,24 +123,25 @@ public class LifecycleWeaveBuilder
MavenExecutionPlan executionPlan =
builderCommon.resolveBuildPlan( projectBuild.getSession(), projectBuild.getProject(),
projectBuild.getTaskSegment(), projectArtifactsA );
for (Artifact dependency : projectBuild.getProject().getDependencyArtifacts()) {
String s = ArtifactUtils.key(dependency);
if ( projectArtifacts.contains(s)){
dependency.setFile( null);
dependency.setResolved( false);
dependency.setRepository( null);
for ( Artifact dependency : projectBuild.getProject().getDependencyArtifacts() )
{
String s = ArtifactUtils.key( dependency );
if ( projectArtifacts.contains( s ) )
{
dependency.setFile( null );
dependency.setResolved( false );
dependency.setRepository( null );
}
}
executionPlans.put( projectBuild.getProject(), executionPlan );
DependencyContext dependencyContext =
new DependencyContext( executionPlan, projectBuild.getTaskSegment().isAggregating() );
final Callable<ProjectSegment> projectBuilder =
createCallableForBuildingOneFullModule( buildContext, session, reactorBuildStatus,
executionPlan, projectBuild, muxer,
dependencyContext, concurrentBuildLogger,
projectBuilds );
executionPlan, projectBuild, dependencyContext,
concurrentBuildLogger );
futures.add( service.submit( projectBuilder ) );
}
@ -169,10 +171,8 @@ public class LifecycleWeaveBuilder
final ReactorBuildStatus reactorBuildStatus,
final MavenExecutionPlan executionPlan,
final ProjectSegment projectBuild,
final ThreadOutputMuxer muxer,
final DependencyContext dependencyContext,
final ConcurrentBuildLogger concurrentBuildLogger,
final ProjectBuildList projectBuilds )
final ConcurrentBuildLogger concurrentBuildLogger )
{
return new Callable<ProjectSegment>()
{
@ -195,7 +195,7 @@ public class LifecycleWeaveBuilder
try
{
while (current != null && !reactorBuildStatus.isHaltedOrBlacklisted( projectBuild.getProject() ))
while ( current != null && !reactorBuildStatus.isHaltedOrBlacklisted( projectBuild.getProject() ) )
{
PhaseRecorder phaseRecorder = new PhaseRecorder( projectBuild.getProject() );
@ -203,7 +203,8 @@ public class LifecycleWeaveBuilder
concurrentBuildLogger.createBuildLogItem( projectBuild.getProject(), current );
final Schedule schedule = current.getSchedule();
buildExecutionPlanItem(current, phaseRecorder, schedule, reactorContext, projectBuild, dependencyContext);
buildExecutionPlanItem( current, phaseRecorder, schedule, reactorContext, projectBuild,
dependencyContext );
current.setComplete();
builtLogItem.setComplete();
@ -215,16 +216,17 @@ public class LifecycleWeaveBuilder
final Schedule scheduleOfNext = nextPlanItem.getSchedule();
if ( scheduleOfNext == null || !scheduleOfNext.isParallel() )
{
waitForAppropriateUpstreamExecutionsToFinish(builtLogItem, nextPlanItem, projectBuild);
waitForAppropriateUpstreamExecutionsToFinish( builtLogItem, nextPlanItem,
projectBuild );
}
reResolveReactorDependencies(nextPlanItem, projectBuild);
reResolveReactorDependencies( nextPlanItem, projectBuild );
}
current = nextPlanItem;
}
final long wallClockTime = System.currentTimeMillis() - buildStartTime;
final BuildSuccess summary =
new BuildSuccess( projectBuild.getProject(), wallClockTime ); // - waitingTime
new BuildSuccess( projectBuild.getProject(), wallClockTime ); // - waitingTime
reactorContext.getResult().addBuildSummary( summary );
eventCatapult.fire( ExecutionEvent.Type.ProjectSucceeded, projectBuild.getSession(), null );
}
@ -247,18 +249,23 @@ public class LifecycleWeaveBuilder
};
}
private void reResolveReactorDependencies(ExecutionPlanItem nextPlanItem, ProjectSegment projectBuild) {
private void reResolveReactorDependencies( ExecutionPlanItem nextPlanItem, ProjectSegment projectBuild )
{
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() )
{
final MavenExecutionPlan upstreamPlan = executionPlans.get( upstreamProject );
@ -286,58 +293,69 @@ public class LifecycleWeaveBuilder
}
}
private void reresolveUpstreamProjectArtifacts(ProjectSegment projectBuild) {
for ( MavenProject upstreamProject : projectBuild.getTransitiveUpstreamProjects() ){
private void reresolveUpstreamProjectArtifacts( ProjectSegment projectBuild )
{
for ( MavenProject upstreamProject : projectBuild.getTransitiveUpstreamProjects() )
{
Artifact upStreamArtifact = upstreamProject.getArtifact();
Artifact dependencyArtifact = findDependency(projectBuild.getProject(), upStreamArtifact);
if (dependencyArtifact != null){
dependencyArtifact.setFile( upStreamArtifact.getFile());
Artifact dependencyArtifact = findDependency( projectBuild.getProject(), upStreamArtifact );
if ( dependencyArtifact != null )
{
dependencyArtifact.setFile( upStreamArtifact.getFile() );
dependencyArtifact.setResolved( true );
dependencyArtifact.setRepository( upStreamArtifact.getRepository());
dependencyArtifact.setRepository( upStreamArtifact.getRepository() );
}
}
}
private void reresolveUpstreamTestScopedArtifacts(ProjectSegment projectBuild) {
for ( MavenProject upstreamProject : projectBuild.getTransitiveUpstreamProjects() ){
Artifact upStreamArtifact = findTestScopedArtifact(upstreamProject);
Artifact dependencyArtifact = findDependency(projectBuild.getProject(), upStreamArtifact);
if (dependencyArtifact != null){
dependencyArtifact.setFile( upStreamArtifact.getFile());
dependencyArtifact.setResolved( upStreamArtifact.isResolved());
dependencyArtifact.setRepository( upStreamArtifact.getRepository());
private void reresolveUpstreamTestScopedArtifacts( ProjectSegment projectBuild )
{
for ( MavenProject upstreamProject : projectBuild.getTransitiveUpstreamProjects() )
{
Artifact upStreamArtifact = findTestScopedArtifact( upstreamProject );
Artifact dependencyArtifact = findDependency( projectBuild.getProject(), upStreamArtifact );
if ( dependencyArtifact != null )
{
dependencyArtifact.setFile( upStreamArtifact.getFile() );
dependencyArtifact.setResolved( upStreamArtifact.isResolved() );
dependencyArtifact.setRepository( upStreamArtifact.getRepository() );
}
}
}
private Artifact findTestScopedArtifact(MavenProject upstreamProject) {
if ( upstreamProject == null){
private Artifact findTestScopedArtifact( MavenProject upstreamProject )
{
if ( upstreamProject == null )
{
return null;
}
List<Artifact> artifactList = upstreamProject.getAttachedArtifacts();
for (Artifact artifact : artifactList) {
if (Artifact.SCOPE_TEST.equals( artifact.getScope())){
for ( Artifact artifact : artifactList )
{
if ( Artifact.SCOPE_TEST.equals( artifact.getScope() ) )
{
return artifact;
}
}
return null;
}
private static Artifact findDependency(MavenProject project, Artifact upStreamArtifact) {
if (upStreamArtifact == null){
private static Artifact findDependency( MavenProject project, Artifact upStreamArtifact )
{
if ( upStreamArtifact == null )
{
return null;
}
String key = ArtifactUtils.key( upStreamArtifact.getGroupId(),
upStreamArtifact.getArtifactId(),
String key = ArtifactUtils.key( upStreamArtifact.getGroupId(), upStreamArtifact.getArtifactId(),
upStreamArtifact.getVersion() );
final Set<Artifact> deps = project.getDependencyArtifacts();
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 ) )
{
return dep;
@ -350,28 +368,31 @@ public class LifecycleWeaveBuilder
private boolean requiresReResolutionOfUpstreamReactorArtifacts( ExecutionPlanItem nextExecutionPlanItem )
{
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 )
{
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() )
{
synchronized ( current.getPlugin() )
{
buildExecutionPlanItem( reactorContext, current, projectBuild, dependencyContext,
phaseRecorder );
buildExecutionPlanItem( reactorContext, current, projectBuild, dependencyContext, phaseRecorder );
}
}
else
{
buildExecutionPlanItem( reactorContext, current, projectBuild, dependencyContext,
phaseRecorder );
buildExecutionPlanItem( reactorContext, current, projectBuild, dependencyContext, phaseRecorder );
}
}

View File

@ -305,9 +305,6 @@ public class LifecycleExecutorTest
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 )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,

View File

@ -29,9 +29,10 @@ public class BuildListCalculatorTest
public void testCalculateProjectBuilds()
throws Exception
{
BuildListCalculator buildListCalculator = createBuildListCalculator();
LifecycleTaskSegmentCalculator lifecycleTaskSegmentCalculator = getTaskSegmentCalculator();
BuildListCalculator buildListCalculator = new BuildListCalculator();
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 segments = buildList.getByTaskSegment( taskSegments.get( 0 ) );
assertEquals( "Stub data contains 3 segments", 3, taskSegments.size() );
@ -40,10 +41,9 @@ public class BuildListCalculatorTest
assertNotNull( build );
}
public static BuildListCalculator createBuildListCalculator()
private static LifecycleTaskSegmentCalculator getTaskSegmentCalculator()
{
LifecycleTaskSegmentCalculator lifecycleTaskSegmentCalculator = new LifecycleTaskSegmentCalculatorStub();
return new BuildListCalculator( lifecycleTaskSegmentCalculator );
return new LifecycleTaskSegmentCalculatorStub();
}
}

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.lifecycle.LifecycleNotFoundException;
import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
import org.apache.maven.lifecycle.internal.stub.CompletionServiceStub;
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.lifecycle.internal.stub.*;
import org.apache.maven.plugin.InvalidPluginDescriptorException;
import org.apache.maven.plugin.MojoNotFoundException;
import org.apache.maven.plugin.PluginDescriptorParsingException;
@ -85,9 +79,9 @@ public class LifecycleWeaveBuilderTest
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
try
{
BuildListCalculator buildListCalculator = BuildListCalculatorTest.createBuildListCalculator();
BuildListCalculator buildListCalculator = new BuildListCalculator();
final MavenSession session = ProjectDependencyGraphStub.getMavenSession();
List<TaskSegment> taskSegments = buildListCalculator.calculateTaskSegments( session );
List<TaskSegment> taskSegments = getTaskSegmentCalculator().calculateTaskSegments( session );
ProjectBuildList projectBuildList = buildListCalculator.calculateProjectBuilds( session, taskSegments );
final MojoExecutorStub mojoExecutorStub = new MojoExecutorStub();
@ -109,6 +103,11 @@ public class LifecycleWeaveBuilderTest
}
private static LifecycleTaskSegmentCalculator getTaskSegmentCalculator()
{
return new LifecycleTaskSegmentCalculatorStub();
}
private ReactorContext createBuildContext( MavenSession session )
{
MavenExecutionResult mavenExecutionResult = new DefaultMavenExecutionResult();
@ -120,8 +119,6 @@ public class LifecycleWeaveBuilderTest
{
final BuilderCommon builderCommon = getBuilderCommon();
final LoggerStub loggerStub = new LoggerStub();
final LifecycleDependencyResolver lifecycleDependencyResolver =
new LifecycleDependencyResolver( new ProjectDependenciesResolverStub(), loggerStub );
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.lifecycle.internal.GoalTask;
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.plugin.InvalidPluginDescriptorException;
import org.apache.maven.plugin.MojoNotFoundException;
@ -36,7 +36,7 @@ import java.util.List;
*/
public class LifecycleTaskSegmentCalculatorStub
implements LifecycleTaskSegmentCalculator
extends LifecycleTaskSegmentCalculatorImpl
{
public static final String clean = "clean";
@ -44,6 +44,7 @@ public class LifecycleTaskSegmentCalculatorStub
public static final String install = "install";
public List<TaskSegment> calculateTaskSegments( MavenSession session, List<String> tasks )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,