From 9aae6eaa679aa7d585c7ee63fa41eb05fafe9e57 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Thu, 21 May 2009 14:00:34 +0000 Subject: [PATCH] o using mojo executions as the placeholders in the lifecycle instead of string representations git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@777120 13f79535-47bb-0310-9956-ffa450edef68 --- .../lifecycle/DefaultLifecycleExecutor.java | 54 ++++++------- .../apache/maven/plugin/MojoExecution.java | 75 ++++++++++++++++--- .../lifecycle/LifecycleExecutorTest.java | 2 +- .../org/apache/maven/project/pom-4.0.0.xml | 2 +- 4 files changed, 96 insertions(+), 37 deletions(-) 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 e33e608521..32559565b3 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 @@ -227,7 +227,7 @@ public class DefaultLifecycleExecutor { MavenProject project = session.getCurrentProject(); - List phasesWithMojosToExecute = new ArrayList(); + List phasesWithMojosToExecute = new ArrayList(); List lifecyclePlan = new ArrayList(); @@ -238,7 +238,9 @@ public class DefaultLifecycleExecutor { MojoDescriptor mojoDescriptor = getMojoDescriptor( task, session ); - MojoExecution mojoExecution = getMojoExecution( project, mojoDescriptor ); + MojoExecution mojoExecution = new MojoExecution( mojoDescriptor ); + + populateMojoExecutionConfiguration( project, mojoExecution ); lifecyclePlan.add( mojoExecution ); } @@ -265,7 +267,7 @@ public class DefaultLifecycleExecutor // // Create an ordered Map of the phases in the lifecycle to a list of mojos to execute. - Map> phaseToMojoMapping = new LinkedHashMap>(); + Map> phaseToMojoMapping = new LinkedHashMap>(); // 4. @@ -273,11 +275,12 @@ public class DefaultLifecycleExecutor for ( String phase : lifecycle.getPhases() ) { - List mojos = new ArrayList(); + List mojos = new ArrayList(); + //TODO: remove hard coding if ( phase.equals( "clean" ) ) { - mojos.add( "org.apache.maven.plugins:maven-clean-plugin:clean" ); + mojos.add( new MojoExecution( "org.apache.maven.plugins", "maven-clean-plugin", "2.3", "clean", null ) ); } // This is just just laying out the initial structure of the mojos to run in each phase of the @@ -310,10 +313,11 @@ public class DefaultLifecycleExecutor // So for the lifecycle mapping we need a map with the phases as keys so we can easily check // if this phase belongs to the given lifecycle. this shows the system is messed up. this // shouldn't happen. - phaseToMojoMapping.put( execution.getPhase(), new ArrayList() ); + phaseToMojoMapping.put( execution.getPhase(), new ArrayList() ); } - phaseToMojoMapping.get( execution.getPhase() ).add( s ); + MojoExecution mojoExecution = new MojoExecution( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion(), goal, execution.getId() ); + phaseToMojoMapping.get( execution.getPhase() ).add( mojoExecution ); } } // if not then i need to grab the mojo descriptor and look at the phase that is specified @@ -326,7 +330,8 @@ public class DefaultLifecycleExecutor if ( mojoDescriptor.getPhase() != null && phaseToMojoMapping.get( mojoDescriptor.getPhase() ) != null ) { - phaseToMojoMapping.get( mojoDescriptor.getPhase() ).add( s ); + MojoExecution mojoExecution = new MojoExecution( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion(), goal, execution.getId() ); + phaseToMojoMapping.get( mojoDescriptor.getPhase() ).add( mojoExecution ); } } } @@ -338,7 +343,6 @@ public class DefaultLifecycleExecutor // We are only interested in the phases that correspond to the lifecycle we are trying to run. If we are running the "clean" // lifecycle we are not interested in goals -- like "generate-sources -- that belong to the default lifecycle. // - for ( String phase : phaseToMojoMapping.keySet() ) { phasesWithMojosToExecute.addAll( phaseToMojoMapping.get( phase ) ); @@ -354,17 +358,19 @@ public class DefaultLifecycleExecutor // 7. Now we create the correct configuration for the mojo to execute. //TODO: this needs to go to the model builder. - - for ( String mojo : phasesWithMojosToExecute ) + //TODO: just used a hollowed out MojoExecution + for ( MojoExecution mojoExecution : phasesWithMojosToExecute ) { // These are bits that look like this: // // org.apache.maven.plugins:maven-remote-resources-plugin:1.0:process - // + // + MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( + mojoExecution.getGroupId(), mojoExecution.getArtifactId(), mojoExecution.getVersion(), mojoExecution.getGoal(), session.getLocalRepository(), project.getRemoteArtifactRepositories() ); - MojoDescriptor mojoDescriptor = getMojoDescriptor( mojo, session ); - - MojoExecution mojoExecution = getMojoExecution( project, mojoDescriptor ); + mojoExecution.setMojoDescriptor( mojoDescriptor ); + + populateMojoExecutionConfiguration( project, mojoExecution ); lifecyclePlan.add( mojoExecution ); } @@ -380,13 +386,13 @@ public class DefaultLifecycleExecutor return sb.toString(); } - private MojoExecution getMojoExecution( MavenProject project, MojoDescriptor mojoDescriptor ) - { - MojoExecution mojoExecution = new MojoExecution( mojoDescriptor ); - - String g = mojoDescriptor.getPluginDescriptor().getGroupId(); + //this will get the wrong configuration because it's only matching the goal not the execution id + + private void populateMojoExecutionConfiguration( MavenProject project, MojoExecution mojoExecution ) + { + String g = mojoExecution.getGroupId(); - String a = mojoDescriptor.getPluginDescriptor().getArtifactId(); + String a = mojoExecution.getArtifactId(); Plugin p = project.getPlugin( g + ":" + a ); @@ -394,18 +400,16 @@ public class DefaultLifecycleExecutor { for ( String goal : e.getGoals() ) { - if ( mojoDescriptor.getGoal().equals( goal ) ) + if ( mojoExecution.getGoal().equals( goal ) ) { Xpp3Dom executionConfiguration = (Xpp3Dom) e.getConfiguration(); - Xpp3Dom mojoConfiguration = extractMojoConfiguration( executionConfiguration, mojoDescriptor ); + Xpp3Dom mojoConfiguration = extractMojoConfiguration( executionConfiguration, mojoExecution.getMojoDescriptor() ); mojoExecution.setConfiguration( mojoConfiguration ); } } } - - return mojoExecution; } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java b/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java index 1e74ee0053..cc0aab0165 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java @@ -22,26 +22,37 @@ package org.apache.maven.plugin; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.codehaus.plexus.util.xml.Xpp3Dom; -/** - * Describes a single mojo invocation. - * - * @author Brett Porter - * @version $Id$ - */ public class MojoExecution { - private final String executionId; - - private final MojoDescriptor mojoDescriptor; + private String groupId; + + private String artifactId; + + private String version; + + private String goal; + + private String executionId; + + private MojoDescriptor mojoDescriptor; private Xpp3Dom configuration; - + /** * The phase may or may not have been bound to a phase but once the plan has been calculated we know what phase * this mojo execution is going to run in. */ private String lifecyclePhase; + public MojoExecution( String groupId, String artifactId, String version, String goal, String executionId ) + { + this.groupId = groupId; + this.artifactId = artifactId; + this.version = version; + this.goal = goal; + this.executionId = executionId; + } + public MojoExecution( MojoDescriptor mojoDescriptor ) { this.mojoDescriptor = mojoDescriptor; @@ -115,4 +126,48 @@ public class MojoExecution return buffer.toString(); } + public String getGroupId() + { + if ( mojoDescriptor != null ) + { + return mojoDescriptor.getPluginDescriptor().getGroupId(); + } + + return groupId; + } + + public String getArtifactId() + { + if ( mojoDescriptor != null ) + { + return mojoDescriptor.getPluginDescriptor().getArtifactId(); + } + + return artifactId; + } + + public String getVersion() + { + if ( mojoDescriptor != null ) + { + return mojoDescriptor.getPluginDescriptor().getVersion(); + } + + return version; + } + + public String getGoal() + { + if ( mojoDescriptor != null ) + { + return mojoDescriptor.getGoal(); + } + + return goal; + } + + public void setMojoDescriptor( MojoDescriptor mojoDescriptor ) + { + this.mojoDescriptor = mojoDescriptor; + } } 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 deed47cb6a..70aad7a0e0 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 @@ -87,7 +87,7 @@ public class LifecycleExecutorTest 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() ); + assertEquals( "2.3", mojoExecution.getMojoDescriptor().getPluginDescriptor().getVersion() ); } // We need to take in multiple lifecycles diff --git a/maven-model-builder/src/main/resources/org/apache/maven/project/pom-4.0.0.xml b/maven-model-builder/src/main/resources/org/apache/maven/project/pom-4.0.0.xml index be8af2e11f..14693391ae 100644 --- a/maven-model-builder/src/main/resources/org/apache/maven/project/pom-4.0.0.xml +++ b/maven-model-builder/src/main/resources/org/apache/maven/project/pom-4.0.0.xml @@ -117,7 +117,7 @@ under the License. maven-plugin-plugin - 2.4.2 + 2.5 maven-rar-plugin