From b5670bdcaac1361dab9f781c72a4d257958721a5 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Wed, 4 May 2005 01:20:49 +0000 Subject: [PATCH] start to clean up the plugin vs. goal name handling so the hardcoding can be reduced, and eventually removed git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@168040 13f79535-47bb-0310-9956-ffa450edef68 --- .../lifecycle/DefaultLifecycleExecutor.java | 83 ++++++------------- .../maven/plugin/DefaultPluginManager.java | 22 +---- maven-model/maven.mdo | 22 +++++ maven-model/pom.xml | 5 +- .../plugin/descriptor/PluginDescriptor.java | 21 ++++- .../descriptor/PluginDescriptorBuilder.java | 2 + .../generator/PluginDescriptorGenerator.java | 6 ++ 7 files changed, 83 insertions(+), 78 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 4735e3b157..86c4ad4232 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 @@ -23,7 +23,6 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.execution.MavenExecutionResponse; import org.apache.maven.execution.MavenSession; -import org.apache.maven.model.Goal; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginManagement; import org.apache.maven.monitor.event.EventDispatcher; @@ -40,18 +39,18 @@ import org.apache.maven.settings.Settings; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.Logger; +import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Collections; /** - * @todo there is some duplication between this and the plugin manager * @author Jason van Zyl * @version $Id: DefaultLifecycleExecutor.java,v 1.16 2005/03/04 09:04:25 * jdcasey Exp $ + * @todo there is some duplication between this and the plugin manager */ public class DefaultLifecycleExecutor extends AbstractLogEnabled @@ -135,7 +134,7 @@ public class DefaultLifecycleExecutor { if ( artifactHandler.packageGoal() != null ) { - verifyMojoPhase( artifactHandler.packageGoal(), session, phaseMap ); + configureMojo( artifactHandler.packageGoal(), session, phaseMap ); } if ( artifactHandler.additionalPlugin() != null ) @@ -149,7 +148,7 @@ public class DefaultLifecycleExecutor } } - processPluginConfiguration( session.getProject(), session, phaseMap ); + processPluginConfiguration( project, session, phaseMap ); for ( Iterator i = tasks.iterator(); i.hasNext(); ) { @@ -177,6 +176,9 @@ public class DefaultLifecycleExecutor private void injectHandlerPluginConfiguration( MavenProject project, String groupId, String artifactId ) { + // TODO: use the model injector, or just lookup the versions from the project? + // They need to be injected, but we should track the required plugins first, then just sweep through. + // TODO: this is a bit of a hack to get the version from plugin management - please fix Plugin plugin = findPlugin( project.getPlugins(), groupId, artifactId ); @@ -210,9 +212,10 @@ public class DefaultLifecycleExecutor if ( plugin.getVersion() == null ) { // TODO: this has probably supplanted the default in the plugin manager - plugin.setVersion( "1.0-SNAPSHOT" ); + plugin.setVersion( PluginDescriptor.getDefaultPluginVersion() ); } } + } private static Plugin findPlugin( List plugins, String groupId, String artifactId ) @@ -272,38 +275,19 @@ public class DefaultLifecycleExecutor // mojos the user has specified and ignore the rest. // ---------------------------------------------------------------------- - if ( plugin.getGoals().size() > 0 ) + for ( Iterator j = pluginDescriptor.getMojos().iterator(); j.hasNext(); ) { - String pluginId = pluginDescriptor.getArtifactId(); + MojoDescriptor mojoDescriptor = (MojoDescriptor) j.next(); - // TODO: Right now this maven-foo-plugin so this is a hack right now. - - pluginId = PluginDescriptor.getPluginIdFromArtifactId( pluginId ); - - for ( Iterator i = plugin.getGoals().iterator(); i.hasNext(); ) + // TODO: remove later + if ( mojoDescriptor.getGoal() == null ) { - Goal goal = (Goal) i.next(); - - String mojoId = pluginId + ":" + goal.getId(); - - MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( mojoId ); - - if ( mojoDescriptor == null ) - { - throw new LifecycleExecutionException( "A goal '" + mojoId + - "' was declared in pom.xml, but does not exist" ); - } - - configureMojo( mojoDescriptor, phaseMap, session.getSettings() ); + throw new LifecycleExecutionException( "The plugin " + artifactId + " was built with an older version of Maven" ); } - } - else - { - for ( Iterator j = pluginDescriptor.getMojos().iterator(); j.hasNext(); ) - { - MojoDescriptor mojoDescriptor = (MojoDescriptor) j.next(); - configureMojo( mojoDescriptor, phaseMap, session.getSettings() ); + if ( plugin.getGoals().isEmpty() || plugin.getGoalsAsMap().containsKey( mojoDescriptor.getGoal() ) ) + { + configureMojoPhaseBinding( mojoDescriptor, phaseMap, session.getSettings() ); } } } @@ -315,7 +299,7 @@ public class DefaultLifecycleExecutor * * @param mojoDescriptor */ - private void configureMojo( MojoDescriptor mojoDescriptor, Map phaseMap, Settings settings ) + private void configureMojoPhaseBinding( MojoDescriptor mojoDescriptor, Map phaseMap, Settings settings ) throws LifecycleExecutionException { if ( settings.getActiveProfile().isOffline() && mojoDescriptor.requiresOnline() ) @@ -331,7 +315,8 @@ public class DefaultLifecycleExecutor if ( phase == null ) { - throw new LifecycleExecutionException( "Required phase '" + mojoDescriptor.getPhase() + "' not found" ); + throw new LifecycleExecutionException( + "Required phase '" + mojoDescriptor.getPhase() + "' not found" ); } phase.getGoals().add( mojoDescriptor.getId() ); } @@ -359,18 +344,18 @@ public class DefaultLifecycleExecutor { String goal = (String) k.next(); - verifyMojoPhase( goal, session, phaseMap ); + configureMojo( goal, session, phaseMap ); } } } } else { - verifyMojoPhase( task, session, phaseMap ); + configureMojo( task, session, phaseMap ); } } - private void verifyMojoPhase( String task, MavenSession session, Map phaseMap ) + private void configureMojo( String task, MavenSession session, Map phaseMap ) throws LifecycleExecutionException, ArtifactResolutionException { MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( task ); @@ -379,20 +364,13 @@ public class DefaultLifecycleExecutor { String groupId = PluginDescriptor.getDefaultPluginGroupId(); - String pluginId = task; - - if ( pluginId.indexOf( ":" ) > 0 ) - { - pluginId = pluginId.substring( 0, pluginId.indexOf( ":" ) ); - } - - String artifactId = PluginDescriptor.getDefaultPluginArtifactId( pluginId ); + String artifactId = PluginDescriptor.getPluginArtifactIdFromGoal( task ); injectHandlerPluginConfiguration( session.getProject(), groupId, artifactId ); try { - pluginManager.verifyPluginForGoal( task, session ); + pluginManager.verifyPlugin( groupId, artifactId, session ); } catch ( PluginManagerException e ) { @@ -407,7 +385,7 @@ public class DefaultLifecycleExecutor } } - configureMojo( mojoDescriptor, phaseMap, session.getSettings() ); + configureMojoPhaseBinding( mojoDescriptor, phaseMap, session.getSettings() ); } private void executePhase( String phase, MavenSession session, Map phaseMap ) @@ -466,15 +444,6 @@ public class DefaultLifecycleExecutor throws MojoExecutionException, PluginNotFoundException, PluginManagerException, ArtifactResolutionException, LifecycleExecutionException { - // ---------------------------------------------------------------------- - // We have something of the form :, so this might be - // something like: - // - // clean:clean - // idea:idea - // archetype:create - // ---------------------------------------------------------------------- - Logger logger = getLogger(); logger.debug( "Resolving artifacts from:" ); logger.debug( "\t{localRepository: " + session.getLocalRepository() + "}" ); 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 2ec31e89d7..ba65361233 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 @@ -97,15 +97,6 @@ public class DefaultPluginManager pluginDescriptorBuilder = new PluginDescriptorBuilder(); } - // ---------------------------------------------------------------------- - // Goal descriptors - // ---------------------------------------------------------------------- - - public Map getMojoDescriptors() - { - return mojoDescriptors; - } - /** * Mojo descriptors are looked up using their id which is of the form * : . So this might be archetype:create for example which @@ -190,7 +181,7 @@ public class DefaultPluginManager public void verifyPluginForGoal( String goalName, MavenSession session ) throws ArtifactResolutionException, PluginManagerException { - String pluginId = PluginDescriptor.getPluginIdFromGoal( goalName ); + String pluginId = PluginDescriptor.getPluginArtifactIdFromGoal( goalName ); verifyPlugin( PluginDescriptor.getDefaultPluginGroupId(), pluginId, session ); } @@ -378,17 +369,10 @@ public class DefaultPluginManager // TODO: remove boolean newMojoTechnique = checkMojoTechnique( plugin.getClass() ); - String goalId = null; - - // TODO: much less of this magic is needed - make the mojoDescriptor just store the first and second part - int index = goalName.indexOf( ':' ); - if ( index >= 0 ) - { - goalId = goalName.substring( index + 1 ); - } + String goalId = PluginDescriptor.getGoalIdFromFullGoal( goalName ); // TODO: can probable refactor these a little when only the new plugin technique is in place - Xpp3Dom dom = session.getProject().getGoalConfiguration( PluginDescriptor.getPluginIdFromGoal( goalName ), + Xpp3Dom dom = session.getProject().getGoalConfiguration( PluginDescriptor.getPluginArtifactIdFromGoal( goalName ), goalId ); PlexusConfiguration pomConfiguration; diff --git a/maven-model/maven.mdo b/maven-model/maven.mdo index b93a7e7eff..3317adbe68 100644 --- a/maven-model/maven.mdo +++ b/maven-model/maven.mdo @@ -1993,6 +1993,28 @@ + + + 4.0.0 + + + Goal diff --git a/maven-model/pom.xml b/maven-model/pom.xml index 7bd01ca5af..bf82532311 100644 --- a/maven-model/pom.xml +++ b/maven-model/pom.xml @@ -18,7 +18,10 @@ - org.apache.maven.plugins + maven-modello-plugin 1.0-alpha-2-SNAPSHOT diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java index f4ba2fad12..97ba67c14e 100644 --- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java +++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java @@ -101,7 +101,7 @@ public class PluginDescriptor /** * @todo remove - harcoding. */ - public static String getPluginIdFromGoal( String goalName ) + public static String getPluginArtifactIdFromGoal( String goalName ) { String pluginId = goalName; @@ -142,4 +142,23 @@ public class PluginDescriptor return artifactId.substring( firstHyphen + 1, lastHyphen ); } + + /** + * @todo remove - harcoding. What about clashes? + */ + public static String getDefaultPluginVersion() + { + return "1.0-SNAPSHOT"; + } + + public static String getGoalIdFromFullGoal( String goalName ) + { + // TODO: much less of this magic is needed - make the mojoDescriptor just store the first and second part + int index = goalName.indexOf( ':' ); + if ( index >= 0 ) + { + return goalName.substring( index + 1 ); + } + return null; + } } diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java index ef6f0b60c8..4f51c7d528 100755 --- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java +++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java @@ -93,6 +93,8 @@ public class PluginDescriptorBuilder mojo.setId( c.getChild( "id" ).getValue() ); + mojo.setGoal( c.getChild( "goal" ).getValue() ); + mojo.setImplementation( c.getChild( "implementation" ).getValue() ); PlexusConfiguration langConfig = c.getChild( "language" ); diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java index 9756f9fe0b..350d41c033 100644 --- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java +++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java @@ -98,6 +98,12 @@ public class PluginDescriptorGenerator w.endElement(); + w.startElement( "goal" ); + + w.writeText( mojoDescriptor.getGoal() ); + + w.endElement(); + // ---------------------------------------------------------------------- // // ----------------------------------------------------------------------