diff --git a/maven-compat/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java b/maven-compat/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java index d1e7643e23..e9bdd7184c 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java +++ b/maven-compat/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java @@ -52,7 +52,7 @@ public class EmptyLifecycleExecutor throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, MojoNotFoundException { - return new MavenExecutionPlan(null, null, null ); + return new MavenExecutionPlan(null, null, null, new DefaultLifecycles() ); } public void execute( MavenSession session ) diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycles.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycles.java index 803e0694c2..c8ba824eca 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycles.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycles.java @@ -14,15 +14,6 @@ */ package org.apache.maven.lifecycle; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - import org.apache.maven.lifecycle.internal.BuilderCommon; import org.apache.maven.lifecycle.internal.ExecutionPlanItem; import org.apache.maven.plugin.InvalidPluginDescriptorException; @@ -37,6 +28,15 @@ import org.apache.maven.project.MavenProject; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.StringUtils; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + /** * @author Jason van Zyl * @author Kristian Rosenvold @@ -49,10 +49,8 @@ public class DefaultLifecycles // @Configuration(source="org/apache/maven/lifecycle/lifecycles.xml") - // @Requirement(role=Lifecycle.class) private Map lifecycles; - // @Requirement private Logger logger; private List schedules; @@ -62,15 +60,12 @@ public class DefaultLifecycles { } - public DefaultLifecycles( List lifecycles, List schedules ) + public DefaultLifecycles( Map lifecycles, List schedules, Logger logger ) { this.lifecycles = new LinkedHashMap(); this.schedules = schedules; - - for ( Lifecycle lifecycle : lifecycles ) - { - this.lifecycles.put( lifecycle.getId(), lifecycle ); - } + this.logger = logger; + this.lifecycles = lifecycles; } public List createExecutionPlanItem( MavenProject mavenProject, List executions ) @@ -104,9 +99,9 @@ public class DefaultLifecycles * Gets scheduling associated with a given phase. *

* This is part of the experimental weave mode and therefore not part of the public api. - * - * @param lifecyclePhaseName - * @return + * + * @param lifecyclePhaseName The name of the lifecycle phase + * @return Schecduling information related to phase */ private Scheduling getScheduling( String lifecyclePhaseName ) @@ -129,6 +124,8 @@ public class DefaultLifecycles /** * We use this to map all phases to the lifecycle that contains it. This is used so that a user can specify the * phase they want to execute and we can easily determine what lifecycle we need to run. + * + * @return A map of lifecycles, indexed on id */ public Map getPhaseToLifecycleMap() { @@ -143,7 +140,7 @@ public class DefaultLifecycles { logger.debug( "Lifecycle " + lifecycle ); } - + for ( String phase : lifecycle.getPhases() ) { // The first definition wins. @@ -154,8 +151,9 @@ public class DefaultLifecycles else { Lifecycle original = phaseToLifecycleMap.get( phase ); - logger.warn( "Duplicated lifecycle phase " + phase + ". Defined in " + original.getId() - + " but also in " + lifecycle.getId() ); + logger.warn( + "Duplicated lifecycle phase " + phase + ". Defined in " + original.getId() + " but also in " + + lifecycle.getId() ); } } } diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/MavenExecutionPlan.java b/maven-core/src/main/java/org/apache/maven/lifecycle/MavenExecutionPlan.java index ff692dbd5d..882f349d64 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/MavenExecutionPlan.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/MavenExecutionPlan.java @@ -19,6 +19,9 @@ package org.apache.maven.lifecycle; * under the License. */ +import org.apache.maven.lifecycle.internal.ExecutionPlanItem; +import org.apache.maven.plugin.MojoExecution; + import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -26,16 +29,13 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.apache.maven.lifecycle.internal.ExecutionPlanItem; -import org.apache.maven.plugin.MojoExecution; -import org.apache.maven.plugin.descriptor.MojoDescriptor; - //TODO: lifecycles being executed //TODO: what runs in each phase //TODO: plugins that need downloading //TODO: project dependencies that need downloading //TODO: unfortunately the plugins need to be downloaded in order to get the plugin.xml file. need to externalize this from the plugin archive. //TODO: this will be the class that people get in IDEs to modify + public class MavenExecutionPlan implements Iterable { @@ -48,44 +48,89 @@ public class MavenExecutionPlan separate this into a separate mutable structure. */ - /** For project dependency resolution, the scopes of resolution required if any. */ + + /** + * For project dependency resolution, the scopes of resolution required if any. + */ private final Set requiredDependencyResolutionScopes; - /** For project dependency collection, the scopes of collection required if any. */ + /** + * For project dependency collection, the scopes of collection required if any. + */ private final Set requiredDependencyCollectionScopes; private final List planItem; - private final Map lastInPhase; - private final List phasesInOrder; + private final Map lastMojoExecutionForAllPhases; + + + final List phases; public MavenExecutionPlan( Set requiredDependencyResolutionScopes, - Set requiredDependencyCollectionScopes, List planItem ) + Set requiredDependencyCollectionScopes, List planItem, + DefaultLifecycles defaultLifecycles ) { this.requiredDependencyResolutionScopes = requiredDependencyResolutionScopes; this.requiredDependencyCollectionScopes = requiredDependencyCollectionScopes; this.planItem = planItem; - lastInPhase = new HashMap(); - phasesInOrder = new ArrayList(); + lastMojoExecutionForAllPhases = new HashMap(); + + String firstPhasePreset = getFirstPhasePresentInPlan(); + + List phases = null; + if ( defaultLifecycles != null ) + { + final Lifecycle lifecycle = defaultLifecycles.get( firstPhasePreset ); + if ( lifecycle != null ) + { + phases = lifecycle.getPhases(); + } + } + this.phases = phases; + + Map lastInExistingPhases = new HashMap(); for ( ExecutionPlanItem executionPlanItem : getExecutionPlanItems() ) { - final String phaseName = getPhase( executionPlanItem ); - if ( !lastInPhase.containsKey( phaseName ) ) + final String phaseName = executionPlanItem.getLifecyclePhase(); + if ( phaseName != null ) { - phasesInOrder.add( phaseName ); + lastInExistingPhases.put( phaseName, executionPlanItem ); } - lastInPhase.put( phaseName, executionPlanItem ); } + + ExecutionPlanItem lastSeenExecutionPlanItem = null; + ExecutionPlanItem forThis; + + if ( phases != null ) + { + for ( String phase : phases ) + { + forThis = lastInExistingPhases.get( phase ); + if ( forThis != null ) + { + lastSeenExecutionPlanItem = forThis; + } + lastMojoExecutionForAllPhases.put( phase, lastSeenExecutionPlanItem ); + + } + } + } - private String getPhase( ExecutionPlanItem executionPlanItem ) + private String getFirstPhasePresentInPlan() { - final MojoExecution mojoExecution = executionPlanItem.getMojoExecution(); - final MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); - return mojoDescriptor.getPhase(); - + for ( ExecutionPlanItem executionPlanItem : getExecutionPlanItems() ) + { + final String phase = executionPlanItem.getLifecyclePhase(); + if ( phase != null ) + { + return phase; + } + } + return null; } + public Iterator iterator() { return getExecutionPlanItems().iterator(); @@ -93,14 +138,23 @@ public class MavenExecutionPlan /** * Returns the last ExecutionPlanItem in the supplied phase. If no items are in the specified phase, - * the closest upstream item will be returned. - * @param executionPlanItem The execution plan item + * the closest executionPlanItem from an earlier phase item will be returned. + * + * @param requestedPhase the requested phase + * The execution plan item * @return The ExecutionPlanItem or null if none can be found */ - public ExecutionPlanItem findLastInPhase( ExecutionPlanItem executionPlanItem ) + public ExecutionPlanItem findLastInPhase( String requestedPhase ) { - ExecutionPlanItem executionPlanItem1 = lastInPhase.get( getPhase( executionPlanItem ) ); - return executionPlanItem1; + ExecutionPlanItem result = lastMojoExecutionForAllPhases.get( requestedPhase ); + int i = phases.indexOf( requestedPhase ); + while ( result == null && i > 0 ) + { + final String previousPhase = phases.get( --i ); + result = lastMojoExecutionForAllPhases.get( previousPhase ); + + } + return result; } private List getExecutionPlanItems() @@ -136,6 +190,8 @@ public class MavenExecutionPlan return result; } + // Used by m2e but will be removed, really. + @SuppressWarnings({"UnusedDeclaration"}) @Deprecated public List getExecutions() { diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/ExecutionPlanItem.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/ExecutionPlanItem.java index deda72246f..55f0bf976b 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/ExecutionPlanItem.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/ExecutionPlanItem.java @@ -50,6 +50,16 @@ public class ExecutionPlanItem return mojoExecution; } + public String getLifecyclePhase() + { + final MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); + if ( mojoDescriptor.getPhase() != null ) + { + return mojoDescriptor.getPhase(); + } + return mojoExecution.getLifecyclePhase(); + } + public void setComplete() { boolean transitionSuccessful = ensureComplete(); diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolver.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolver.java index 9d64e74706..0b88c6214c 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolver.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolver.java @@ -233,22 +233,4 @@ public class LifecycleDependencyResolver return projectKeys; } - - public void reResolveReactorArtifacts( ProjectBuildList projectBuilds, boolean aggregating, MavenProject project, - MavenSession session, MavenExecutionPlan executionPlan ) - throws LifecycleExecutionException - { - final Set reactorProjectKeys = projectBuilds.getReactorProjectKeys(); - final Set artifactSet = project.getArtifacts(); - for ( Artifact artifact : artifactSet ) - { - String key = ArtifactUtils.key( artifact ); - if ( reactorProjectKeys.contains( key ) ) - { - artifact.setResolved( false ); - } - - } - resolveDependencies( aggregating, project, session, executionPlan ); - } } diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleExecutionPlanCalculatorImpl.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleExecutionPlanCalculatorImpl.java index 7cbf0e037f..2415877e87 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleExecutionPlanCalculatorImpl.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleExecutionPlanCalculatorImpl.java @@ -92,7 +92,7 @@ public class LifecycleExecutionPlanCalculatorImpl final List planItem = defaultLifeCycles.createExecutionPlanItem( project, executions ); return new MavenExecutionPlan( requiredDependencyResolutionScopes, requiredDependencyCollectionScopes, - planItem ); + planItem, defaultLifeCycles ); } diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleWeaveBuilder.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleWeaveBuilder.java index 4fee93e49c..70821fbf75 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleWeaveBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleWeaveBuilder.java @@ -18,13 +18,21 @@ import org.apache.maven.execution.BuildSuccess; import org.apache.maven.execution.ExecutionEvent; import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenSession; -import org.apache.maven.lifecycle.*; +import org.apache.maven.lifecycle.LifecycleExecutionException; +import org.apache.maven.lifecycle.MavenExecutionPlan; +import org.apache.maven.lifecycle.Schedule; 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 java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; import java.util.concurrent.Callable; import java.util.concurrent.CompletionService; import java.util.concurrent.ExecutionException; @@ -61,9 +69,6 @@ public class LifecycleWeaveBuilder @Requirement private Logger logger; - @Requirement - private LifecycleDependencyResolver lifecycleDependencyResolver; - @Requirement private ExecutionEventCatapult eventCatapult; @@ -77,17 +82,17 @@ public class LifecycleWeaveBuilder } public LifecycleWeaveBuilder( MojoExecutor mojoExecutor, BuilderCommon builderCommon, Logger logger, - LifecycleDependencyResolver lifecycleDependencyResolver, ExecutionEventCatapult eventCatapult ) + ExecutionEventCatapult eventCatapult ) { this.mojoExecutor = mojoExecutor; this.builderCommon = builderCommon; this.logger = logger; - this.lifecycleDependencyResolver = lifecycleDependencyResolver; this.eventCatapult = eventCatapult; } public void build( ProjectBuildList projectBuilds, ReactorContext buildContext, List taskSegments, - MavenSession session, CompletionService service, ReactorBuildStatus reactorBuildStatus ) + MavenSession session, CompletionService service, + ReactorBuildStatus reactorBuildStatus ) throws ExecutionException, InterruptedException { ConcurrentBuildLogger concurrentBuildLogger = new ConcurrentBuildLogger(); @@ -97,7 +102,7 @@ public class LifecycleWeaveBuilder for ( TaskSegment taskSegment : taskSegments ) { - ProjectBuildList segmentChunks = projectBuilds.getByTaskSegment( taskSegment ); + ProjectBuildList segmentChunks = projectBuilds.getByTaskSegment( taskSegment ); ThreadOutputMuxer muxer = null; // new ThreadOutputMuxer( segmentChunks, System.out ); for ( ProjectSegment projectBuild : segmentChunks ) { @@ -113,8 +118,7 @@ public class LifecycleWeaveBuilder final Callable projectBuilder = createCallableForBuildingOneFullModule( buildContext, session, reactorBuildStatus, executionPlan, projectBuild, muxer, - dependencyContext, concurrentBuildLogger, - projectBuilds ); + dependencyContext, concurrentBuildLogger ); futures.add( service.submit( projectBuilder ) ); } @@ -140,14 +144,13 @@ public class LifecycleWeaveBuilder } private Callable createCallableForBuildingOneFullModule( final ReactorContext reactorContext, - final MavenSession rootSession, - final ReactorBuildStatus reactorBuildStatus, - final MavenExecutionPlan executionPlan, - final ProjectSegment projectBuild, - final ThreadOutputMuxer muxer, - final DependencyContext dependencyContext, - final ConcurrentBuildLogger concurrentBuildLogger, - final ProjectBuildList projectBuilds ) + final MavenSession rootSession, + final ReactorBuildStatus reactorBuildStatus, + final MavenExecutionPlan executionPlan, + final ProjectSegment projectBuild, + final ThreadOutputMuxer muxer, + final DependencyContext dependencyContext, + final ConcurrentBuildLogger concurrentBuildLogger ) { return new Callable() { @@ -168,27 +171,13 @@ public class LifecycleWeaveBuilder eventCatapult.fire( ExecutionEvent.Type.ProjectStarted, projectBuild.getSession(), null ); - boolean packagePhaseSeen = false; - boolean runBAbyRun = false; try { while ( current != null && !reactorBuildStatus.isHalted() && !reactorBuildStatus.isBlackListed( projectBuild.getProject() ) ) { - final String phase = current.getMojoExecution().getMojoDescriptor().getPhase(); PhaseRecorder phaseRecorder = new PhaseRecorder( projectBuild.getProject() ); - if ( !packagePhaseSeen && phase != null && phase.equals( "package" ) ) - { - // Re-resolve. A bit of a kludge ATM - packagePhaseSeen = true; - lifecycleDependencyResolver.reResolveReactorArtifacts( projectBuilds, false, - projectBuild.getProject(), - projectBuild.getSession(), - executionPlan ); - - } - BuiltLogItem builtLogItem = concurrentBuildLogger.createBuildLogItem( projectBuild.getProject(), current ); final Schedule schedule = current.getSchedule(); @@ -210,16 +199,17 @@ public class LifecycleWeaveBuilder current.setComplete(); builtLogItem.setComplete(); - ExecutionPlanItem next = planItems.hasNext() ? planItems.next() : null; - if ( next != null ) + ExecutionPlanItem nextPlanItem = planItems.hasNext() ? planItems.next() : null; + if ( nextPlanItem != null ) { - final Schedule scheduleOfNext = next.getSchedule(); - if ( !runBAbyRun && ( scheduleOfNext == null || !scheduleOfNext.isParallel() ) ) + final Schedule scheduleOfNext = nextPlanItem.getSchedule(); + if ( scheduleOfNext == null || !scheduleOfNext.isParallel() ) { for ( MavenProject upstreamProject : projectBuild.getImmediateUpstreamProjects() ) { final MavenExecutionPlan upstreamPlan = executionPlans.get( upstreamProject ); - final ExecutionPlanItem inSchedule = upstreamPlan.findLastInPhase( next ); + final String nextPhase = nextPlanItem.getLifecyclePhase(); + final ExecutionPlanItem inSchedule = upstreamPlan.findLastInPhase( nextPhase ); if ( inSchedule != null ) { long startWait = System.currentTimeMillis(); @@ -229,12 +219,7 @@ public class LifecycleWeaveBuilder } } } - current = next; - - if ( packagePhaseSeen && !runBAbyRun ) - { - runBAbyRun = true; - } + current = nextPlanItem; } final long wallClockTime = System.currentTimeMillis() - buildStartTime; diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/MavenExecutionPlanTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/MavenExecutionPlanTest.java index 0e764a1b59..0723d8b60b 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/MavenExecutionPlanTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/MavenExecutionPlanTest.java @@ -13,7 +13,6 @@ * the License. */ - package org.apache.maven.lifecycle; import junit.framework.TestCase; @@ -33,9 +32,9 @@ public class MavenExecutionPlanTest public void testFindFirstWithMatchingSchedule() throws Exception { - MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan(); final List cycles = DefaultLifecyclesStub.getSchedulingList(); final Schedule schedule = cycles.get( 0 ).getSchedules().get( 0 ); + assertNotNull( schedule); } @@ -49,4 +48,33 @@ public class MavenExecutionPlanTest assertFalse( planItemIterator.next().ensureComplete() ); } + public void testFindLastInPhase() + throws Exception + { + MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan(); + + ExecutionPlanItem expected = plan.findLastInPhase( "package" ); + ExecutionPlanItem beerPhase = plan.findLastInPhase( "BEER" ); // Beer comes straight after package in stub + assertEquals( expected, beerPhase ); + assertNotNull( expected ); + } + + public void testFindLastWhenFirst() + throws Exception + { + MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan(); + + ExecutionPlanItem beerPhase = plan.findLastInPhase( LifecycleExecutionPlanCalculatorStub.VALIDATE.getPhase()); // Beer comes straight after package in stub + assertNull ( beerPhase); + } + + public void testFindLastInPhaseMisc() + throws Exception + { + MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan(); + + assertNull( plan.findLastInPhase( "pacXkage" )); + // Beer comes straight after package in stub, much like real life. + assertNotNull( plan.findLastInPhase( LifecycleExecutionPlanCalculatorStub.INITIALIZE.getPhase())); + } } diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleWeaveBuilderTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleWeaveBuilderTest.java index cddc1be891..11c0dca873 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleWeaveBuilderTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleWeaveBuilderTest.java @@ -122,8 +122,7 @@ public class LifecycleWeaveBuilderTest final LoggerStub loggerStub = new LoggerStub(); final LifecycleDependencyResolver lifecycleDependencyResolver = new LifecycleDependencyResolver( new ProjectDependenciesResolverStub(), loggerStub ); - return new LifecycleWeaveBuilder( mojoExecutor, builderCommon, loggerStub, lifecycleDependencyResolver, - new ExecutionEventCatapultStub() ); + return new LifecycleWeaveBuilder( mojoExecutor, builderCommon, loggerStub, new ExecutionEventCatapultStub() ); } private BuilderCommon getBuilderCommon() diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/DefaultLifecyclesStub.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/DefaultLifecyclesStub.java index 18573067b0..ccf4e3725b 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/DefaultLifecyclesStub.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/DefaultLifecyclesStub.java @@ -15,13 +15,19 @@ package org.apache.maven.lifecycle.internal.stub; -import java.util.Arrays; -import java.util.List; - import org.apache.maven.lifecycle.DefaultLifecycles; import org.apache.maven.lifecycle.Lifecycle; import org.apache.maven.lifecycle.Schedule; import org.apache.maven.lifecycle.Scheduling; +import org.omg.CORBA.INITIALIZE; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import static org.apache.maven.lifecycle.internal.stub.LifecycleExecutionPlanCalculatorStub.*; /** * @author Kristian Rosenvold @@ -31,12 +37,31 @@ public class DefaultLifecyclesStub { public static DefaultLifecycles createDefaultLifeCycles() { - final Lifecycle lifecycle1 = new Lifecycle( "abc", Arrays.asList( "compile" ), null ); - final Lifecycle lifecycle2 = new Lifecycle( "abc", Arrays.asList( "test" ), null ); - final List lifeCycles = Arrays.asList( lifecycle1, lifecycle2 ); + + List stubDefaultCycle = + Arrays.asList( VALIDATE.getPhase(), INITIALIZE.getPhase(), PROCESS_RESOURCES.getPhase(), COMPILE.getPhase(), + TEST.getPhase(), PROCESS_TEST_RESOURCES.getPhase(), PACKAGE.getPhase(), "BEER", + INSTALL.getPhase() ); + + // The two phases below are really for future expansion, some would say they lack a drink + // The point being that they do not really have to match the "real" stuff, + List stubCleanCycle = + Arrays.asList( PRE_CLEAN.getPhase(), CLEAN.getPhase(), POST_CLEAN.getPhase() ); + + List stubSiteCycle = + Arrays.asList( PRE_SITE.getPhase(), SITE.getPhase(), POST_SITE.getPhase(), SITE_DEPLOY.getPhase()); + + Iterator> lcs = Arrays.asList( stubDefaultCycle, stubCleanCycle, stubSiteCycle ).iterator(); + + Map lifeCycles = new HashMap(); + for ( String s : DefaultLifecycles.STANDARD_LIFECYCLES ) + { + final Lifecycle lifecycle = new Lifecycle( s, lcs.next(), null ); + lifeCycles.put( s, lifecycle ); + + } final List schedulingList = getSchedulingList(); - final DefaultLifecycles defaultLifecycles = new DefaultLifecycles( lifeCycles, schedulingList ); - return defaultLifecycles; + return new DefaultLifecycles( lifeCycles, schedulingList, new LoggerStub() ); } public static List getSchedulingList() diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/LifecycleExecutionPlanCalculatorStub.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/LifecycleExecutionPlanCalculatorStub.java index bdd4aa30a7..6e9e997bfd 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/LifecycleExecutionPlanCalculatorStub.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/LifecycleExecutionPlanCalculatorStub.java @@ -49,10 +49,16 @@ import java.util.Set; public class LifecycleExecutionPlanCalculatorStub implements LifecycleExecutionPlanCalculator { + // clean + public final static MojoDescriptor PRE_CLEAN = createMojoDescriptor( "pre-clean" ); public final static MojoDescriptor CLEAN = createMojoDescriptor( "clean" ); + public final static MojoDescriptor POST_CLEAN = createMojoDescriptor( "post-clean" ); + // default (or at least some of them) public final static MojoDescriptor VALIDATE = createMojoDescriptor( "validate" ); + public final static MojoDescriptor INITIALIZE = createMojoDescriptor( "initialize" ); + public final static MojoDescriptor TEST_COMPILE = createMojoDescriptor( "test-compile" ); public final static MojoDescriptor PROCESS_TEST_RESOURCES = createMojoDescriptor( "process-test-resources" ); @@ -67,6 +73,15 @@ public class LifecycleExecutionPlanCalculatorStub public final static MojoDescriptor INSTALL = createMojoDescriptor( "install" ); + + // site + public final static MojoDescriptor PRE_SITE = createMojoDescriptor( "pre-site" ); + public final static MojoDescriptor SITE = createMojoDescriptor( "site" ); + public final static MojoDescriptor POST_SITE = createMojoDescriptor( "post-site" ); + public final static MojoDescriptor SITE_DEPLOY = createMojoDescriptor( "site-deploy" ); + + + public int getNumberOfExceutions( ProjectBuildList projectBuildList ) throws InvalidPluginDescriptorException, PluginVersionResolutionException, PluginDescriptorParsingException, NoPluginFoundForPrefixException, MojoNotFoundException, PluginNotFoundException, PluginResolutionException, @@ -99,9 +114,7 @@ public class LifecycleExecutionPlanCalculatorStub List me = new ArrayList(); me.add( createMojoExecution( new Plugin(), "resources", "default-resources", PROCESS_RESOURCES ) ); me.add( createMojoExecution( new Plugin(), "compile", "default-compile", COMPILE ) ); - return new MavenExecutionPlan( getScopes(), getScopes(), - DefaultLifecyclesStub.createDefaultLifeCycles().createExecutionPlanItem( project, - me ) ); + return createExecutionPlan( project, me ); } public static MavenExecutionPlan getProjectAExceutionPlan() @@ -110,7 +123,7 @@ public class LifecycleExecutionPlanCalculatorStub NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException { List me = new ArrayList(); - me.add( createMojoExecution( new Plugin(), "enforce", "enforce-versions", VALIDATE ) ); + me.add( createMojoExecution( new Plugin(), "initialize", "default-initialize", INITIALIZE ) ); me.add( createMojoExecution( new Plugin(), "resources", "default-resources", PROCESS_RESOURCES ) ); me.add( createMojoExecution( new Plugin(), "compile", "default-compile", COMPILE ) ); me.add( createMojoExecution( new Plugin(), "testResources", "default-testResources", PROCESS_TEST_RESOURCES ) ); @@ -118,12 +131,10 @@ public class LifecycleExecutionPlanCalculatorStub me.add( createMojoExecution( new Plugin(), "test", "default-test", TEST ) ); me.add( createMojoExecution( new Plugin(), "war", "default-war", PACKAGE ) ); me.add( createMojoExecution( new Plugin(), "install", "default-install", INSTALL ) ); - final List executionPlanItem = - DefaultLifecyclesStub.createDefaultLifeCycles().createExecutionPlanItem( - ProjectDependencyGraphStub.A.getExecutionProject(), me ); - return new MavenExecutionPlan( getScopes(), getScopes(), executionPlanItem ); + return createExecutionPlan( ProjectDependencyGraphStub.A.getExecutionProject(), me ); } + public static MavenExecutionPlan getProjectBExecutionPlan() throws PluginNotFoundException, PluginResolutionException, LifecyclePhaseNotFoundException, PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException, @@ -136,10 +147,19 @@ public class LifecycleExecutionPlanCalculatorStub me.add( createMojoExecution( new Plugin(), "testResources", "default-testResources", PROCESS_TEST_RESOURCES ) ); me.add( createMojoExecution( new Plugin(), "testCompile", "default-testCompile", TEST_COMPILE ) ); me.add( createMojoExecution( new Plugin(), "test", "default-test", TEST ) ); - final List planItem = - DefaultLifecyclesStub.createDefaultLifeCycles().createExecutionPlanItem( - ProjectDependencyGraphStub.B.getExecutionProject(), me ); - return new MavenExecutionPlan( getScopes(), getScopes(), planItem ); + return createExecutionPlan( ProjectDependencyGraphStub.B.getExecutionProject(), me ); + } + + + private static MavenExecutionPlan createExecutionPlan( MavenProject project, List mojoExecutions ) + throws InvalidPluginDescriptorException, PluginVersionResolutionException, PluginDescriptorParsingException, + NoPluginFoundForPrefixException, MojoNotFoundException, PluginNotFoundException, PluginResolutionException, + LifecyclePhaseNotFoundException, LifecycleNotFoundException + { + final List planItemList = + DefaultLifecyclesStub.createDefaultLifeCycles().createExecutionPlanItem( project, mojoExecutions ); + return new MavenExecutionPlan( getScopes(), getScopes(), planItemList, + DefaultLifecyclesStub.createDefaultLifeCycles() ); } private static MojoExecution createMojoExecution( Plugin plugin, String goal, String executionId, diff --git a/maven-core/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java b/maven-core/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java index 70ab6c9274..3d89ffa076 100644 --- a/maven-core/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java +++ b/maven-core/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java @@ -55,7 +55,7 @@ public class EmptyLifecycleExecutor throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, MojoNotFoundException { - return new MavenExecutionPlan(null, null, null ); + return new MavenExecutionPlan(null, null, null, null ); } public void execute( MavenSession session )