From 9dfca575c78a04897857a454c2d5bebc95820c46 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Wed, 20 May 2009 04:25:59 +0000 Subject: [PATCH] o clean lifecycle is handled by defaults populator git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@776540 13f79535-47bb-0310-9956-ffa450edef68 --- .../resolver/DefaultArtifactResolver.java | 2 - .../lifecycle/DefaultLifecycleExecutor.java | 50 +++---------------- .../lifecycle/LifecycleExecutorTest.java | 22 +++++++- 3 files changed, 26 insertions(+), 48 deletions(-) diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java index b68f188ccf..ed385608c6 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java @@ -42,10 +42,8 @@ import org.apache.maven.artifact.transform.ArtifactTransformationManager; import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.TransferFailedException; import org.apache.maven.wagon.events.TransferListener; -import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.FileUtils; diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java index 009c175c9a..c41192c124 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java @@ -267,24 +267,6 @@ public class DefaultLifecycleExecutor // on to the given phases in the lifecycle are going to be a little different then, say, a project of type JAR. // - Map lifecyclePhasesForPackaging; - - if ( task.equals( "clean" ) ) - { - lifecyclePhasesForPackaging = new HashMap(); - - for ( String phase : lifecycle.getDefaultPhases() ) - { - lifecyclePhasesForPackaging.put( "clean", "org.apache.maven.plugins:maven-clean-plugin:clean" ); - } - } - else - { - LifecycleMapping lifecycleMappingForPackaging = lifecycleMappings.get( project.getPackaging() ); - - lifecyclePhasesForPackaging = lifecycleMappingForPackaging.getLifecycles().get( lifecycle.getId() ).getPhases(); - } - // 3. // // Once we have the lifecycle mapping for the given packaging, we need to know whats phases we need to worry about executing. @@ -300,7 +282,12 @@ public class DefaultLifecycleExecutor for ( String phase : lifecycle.getPhases() ) { List mojos = new ArrayList(); - + + if ( phase.equals( "clean" ) ) + { + mojos.add( "org.apache.maven.plugins:maven-clean-plugin:clean" ); + } + // This is just just laying out the initial structure of the mojos to run in each phase of the // lifecycle. Everything is now done in the project builder correctly so this could likely // go away shortly. We no longer need to pull out bits from the default lifecycle. The MavenProject @@ -384,31 +371,6 @@ public class DefaultLifecycleExecutor MojoExecution mojoExecution = getMojoExecution( project, mojoDescriptor ); - /* - MojoExecution mojoExecution = new MojoExecution( mojoDescriptor ); - - String g = mojoExecution.getMojoDescriptor().getPluginDescriptor().getGroupId(); - - String a = mojoExecution.getMojoDescriptor().getPluginDescriptor().getArtifactId(); - - Plugin p = project.getPlugin( g + ":" + a ); - - for ( PluginExecution e : p.getExecutions() ) - { - for ( String goal : e.getGoals() ) - { - if ( mojoDescriptor.getGoal().equals( goal ) ) - { - Xpp3Dom executionConfiguration = (Xpp3Dom) e.getConfiguration(); - - Xpp3Dom mojoConfiguration = extractMojoConfiguration( executionConfiguration, mojoDescriptor ); - - mojoExecution.setConfiguration( mojoConfiguration ); - } - } - } - */ - lifecyclePlan.add( mojoExecution ); } } diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java index ea74c1f560..35926c7bc8 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java @@ -71,7 +71,25 @@ public class LifecycleExecutorTest assertEquals( "2.3", mojoExecution.getMojoDescriptor().getPluginDescriptor().getVersion() ); } - public void testCalculationOfBuildPlanWithIndividualTaskWherePluginIsNotSpecifiedInThePom() + public void testCalculationOfBuildPlanWithIndividualTaskOfTheCleanLifecycle() + throws Exception + { + // We are doing something like "mvn clean:clean" where no version is specified but this + // project we are working on has the version specified in the POM so the version should come from there. + File pom = getProject( "project-with-additional-lifecycle-elements" ); + MavenSession session = createMavenSession( pom ); + assertEquals( "project-with-additional-lifecycle-elements", session.getCurrentProject().getArtifactId() ); + assertEquals( "1.0", session.getCurrentProject().getVersion() ); + List lifecyclePlan = lifecycleExecutor.calculateBuildPlan( "clean", session ); + assertEquals( 1, lifecyclePlan.size() ); + MojoExecution mojoExecution = lifecyclePlan.get( 0 ); + assertNotNull( mojoExecution ); + assertEquals( "org.apache.maven.plugins", mojoExecution.getMojoDescriptor().getPluginDescriptor().getGroupId() ); + assertEquals( "maven-clean-plugin", mojoExecution.getMojoDescriptor().getPluginDescriptor().getArtifactId() ); + assertEquals( "2.2", mojoExecution.getMojoDescriptor().getPluginDescriptor().getVersion() ); + } + + public void testCalculationOfBuildPlanWithIndividualTaskOfTheCleanCleanGoal() throws Exception { // We are doing something like "mvn clean:clean" where no version is specified but this @@ -88,7 +106,7 @@ public class LifecycleExecutorTest assertEquals( "maven-clean-plugin", mojoExecution.getMojoDescriptor().getPluginDescriptor().getArtifactId() ); assertEquals( "2.2", mojoExecution.getMojoDescriptor().getPluginDescriptor().getVersion() ); } - + public void testLifecycleQueryingUsingADefaultLifecyclePhase() throws Exception {