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 de560976ca..e32b652931 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 @@ -39,11 +39,11 @@ import org.apache.maven.plugin.PluginExecutionException; import org.apache.maven.plugin.PluginLoaderException; import org.apache.maven.plugin.PluginManager; import org.apache.maven.plugin.descriptor.MojoDescriptor; +import org.apache.maven.plugin.descriptor.Parameter; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.configuration.PlexusConfiguration; -import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; @@ -173,14 +173,10 @@ public class DefaultLifecycleExecutor private void executeGoal( String task, MavenSession session, MavenProject project ) throws LifecycleExecutionException, MojoFailureException { - List lifecyclePlan = calculateLifecyclePlan( task, session ); + List lifecyclePlan = calculateLifecyclePlan( task, session ); - for ( MojoDescriptor mojoDescriptor : lifecyclePlan ) - { - MojoExecution mojoExecution = new MojoExecution( mojoDescriptor ); - - System.out.println( mojoExecution.getMojoDescriptor().getGoal() ); - + for ( MojoExecution mojoExecution : lifecyclePlan ) + { try { pluginManager.executeMojo( session, mojoExecution ); @@ -203,7 +199,7 @@ public class DefaultLifecycleExecutor // 3. Find the mojos associated with the lifecycle given the project packaging (jar lifecycle mapping for the default lifecycle) // 4. Bind those mojos found in the lifecycle mapping for the packaging to the lifecycle // 5. Bind mojos specified in the project itself to the lifecycle - public List calculateLifecyclePlan( String lifecyclePhase, MavenSession session ) + public List calculateLifecyclePlan( String lifecyclePhase, MavenSession session ) throws LifecycleExecutionException { // Extract the project from the session @@ -304,16 +300,21 @@ public class DefaultLifecycleExecutor // need to know if this plugin belongs to a phase in the lifecycle that's running if ( md.getPhase() != null && lifecycle.getPhases().contains( md.getPhase() ) ) - { - phaseToMojoMapping.get( md.getPhase() ).add( s ); + { + if ( phaseToMojoMapping.get( md.getPhase() ) != null ) + { + phaseToMojoMapping.get( md.getPhase() ).add( s ); + } } + + //TODO Here we need to break when we have reached the desired phase. } } } } - List lifecyclePlan = new ArrayList(); - + List lifecyclePlan = new ArrayList(); + // We need to turn this into a set of MojoExecutions for( List mojos : phaseToMojoMapping.values() ) { @@ -323,7 +324,28 @@ public class DefaultLifecycleExecutor // // org.apache.maven.plugins:maven-remote-resources-plugin:1.0:process // - lifecyclePlan.add( getMojoDescriptor( mojo, project, session.getLocalRepository() ) ); + MojoDescriptor mojoDescriptor = getMojoDescriptor( mojo, project, session.getLocalRepository() ); + + 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 ) ) + { + mojoExecution.setConfiguration( (Xpp3Dom) e.getConfiguration() ); + } + } + } + + lifecyclePlan.add( mojoExecution ); } } @@ -541,27 +563,29 @@ public class DefaultLifecycleExecutor public Xpp3Dom getDefaultPluginConfiguration( String groupId, String artifactId, String version, String goal, MavenProject project, ArtifactRepository localRepository ) throws LifecycleExecutionException { - return convert( getMojoDescriptor( groupId+":"+artifactId+":"+version+":"+goal, project, localRepository ).getMojoConfiguration() ); + return convert( getMojoDescriptor( groupId+":"+artifactId+":"+version+":"+goal, project, localRepository ) ); } public Xpp3Dom getMojoConfiguration( MojoDescriptor mojoDescriptor ) { - PlexusConfiguration configuration = mojoDescriptor.getConfiguration(); - - return convert( configuration ); + return convert( mojoDescriptor ); } - public Xpp3Dom convert( PlexusConfiguration c ) + public Xpp3Dom convert( MojoDescriptor mojoDescriptor ) { - Xpp3Dom dom = new Xpp3Dom( "configuration" ); + Map parameters = mojoDescriptor.getParameterMap(); + Xpp3Dom dom = new Xpp3Dom( "configuration" ); + + PlexusConfiguration c = mojoDescriptor.getMojoConfiguration(); + PlexusConfiguration[] ces = c.getChildren(); for( PlexusConfiguration ce : ces ) { Xpp3Dom e = new Xpp3Dom( ce.getName() ); e.setValue( ce.getValue( ce.getAttribute( "default-value", null ) ) ); - dom.addChild( e ); + dom.addChild( e ); } return dom; diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java index c237da7c11..175b5e429d 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java @@ -22,13 +22,12 @@ package org.apache.maven.lifecycle; import java.util.List; import java.util.Set; -import org.apache.maven.BuildFailureException; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Plugin; +import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.xml.Xpp3Dom; @@ -47,7 +46,7 @@ public interface LifecycleExecutor * @return * @throws LifecycleExecutionException */ - List calculateLifecyclePlan( String lifecyclePhase, MavenSession session ) + List calculateLifecyclePlan( String lifecyclePhase, MavenSession session ) throws LifecycleExecutionException; // For a given project packaging find all the plugins that are bound to any registered diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index 378d0120c6..040c6f9946 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -519,16 +519,19 @@ public class DefaultPluginManager { pomConfiguration = new XmlPlexusConfiguration( dom ); } - + // Validate against non-editable (@readonly) parameters, to make sure users aren't trying to // override in the POM. - validatePomConfiguration( mojoDescriptor, pomConfiguration ); - ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session ); + ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, mojoExecution ); + // This stuff is moved to the lifecycle executor + //validatePomConfiguration( mojoDescriptor, pomConfiguration ); + checkDeprecatedParameters( mojoDescriptor, pomConfiguration ); checkRequiredParameters( mojoDescriptor, pomConfiguration, expressionEvaluator ); + // populatePluginFields( mojo, mojoDescriptor, pomConfiguration, expressionEvaluator ); @@ -940,24 +943,6 @@ public class DefaultPluginManager plugin.setVersion( version ); } - /* - public MavenProject buildPluginProject( Plugin plugin, ArtifactRepository localRepository, List remoteRepositories ) - throws InvalidPluginException - { - Artifact artifact = repositorySystem.createProjectArtifact( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() ); - try - { - MavenProject p = mavenProjectBuilder.buildFromRepository( artifact, remoteRepositories, localRepository ); - - return p; - } - catch ( ProjectBuildingException e ) - { - throw new InvalidPluginException( "Unable to build project for plugin '" + plugin.getKey() + "': " + e.getMessage(), e ); - } - } - */ - public void checkRequiredMavenVersion( Plugin plugin, MavenProject pluginProject, ArtifactRepository localRepository, List remoteRepositories ) throws PluginVersionResolutionException, InvalidPluginException { diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java index 52d0a3788b..f6a03adb12 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java @@ -46,13 +46,12 @@ public class PluginParameterExpressionEvaluator private Properties properties; - @Deprecated - public PluginParameterExpressionEvaluator( MavenSession session, MojoExecution mojoExecution ) + public PluginParameterExpressionEvaluator( MavenSession session ) { - this( session ); + this( session, null ); } - public PluginParameterExpressionEvaluator( MavenSession session ) + public PluginParameterExpressionEvaluator( MavenSession session, MojoExecution mojoExecution ) { this.session = session; this.mojoExecution = mojoExecution;