Author: jdcasey Date: Fri Apr 29 20:50:47 2005 New Revision: 165378 URL: http://svn.apache.org/viewcvs?rev=165378&view=rev Log: Removed the need for MavenMojoDescriptor (collapsed to just MojoDescriptor)...also partially setup the possibility for container-injected configurations, provided we enhance as described in getting-to-container-configured-mojos.apt.
Added: maven/components/trunk/maven-core/src/site/apt/getting-to-container-configured-mojos.apt (with props) Removed: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/MavenMojoDescriptor.java Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginDiscoverer.java maven/components/trunk/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java?rev=165378&r1=165377&r2=165378&view=diff ============================================================================== --- maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java (original) +++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java Fri Apr 29 20:50:47 2005 @@ -20,12 +20,11 @@ import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.monitor.event.EventDispatcher; import org.apache.maven.monitor.logging.Log; -import org.apache.maven.plugin.PluginManager; import org.apache.maven.project.MavenProject; import org.apache.maven.settings.Settings; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; -import org.codehaus.plexus.util.dag.DAG; +import org.codehaus.plexus.context.Context; import java.util.List; @@ -56,7 +55,7 @@ this.project = project; this.container = container; - + this.settings = settings; this.localRepository = localRepository; @@ -66,6 +65,24 @@ this.log = log; this.goals = goals; + + // TODO: Go back to this when we get the container ready to configure mojos... + // NOTE: [jc] This is a possible way to add project, etc. to the container context to allow container-injected + // mojo configuration. +// initializeContainerContext(); + } + + private void initializeContainerContext() + { + Context context = container.getContext(); + + context.put( "project", project ); + context.put( "settings", settings ); + context.put( "basedir", project.getBasedir().getAbsolutePath() ); + context.put( "localRepository", localRepository ); + + // TODO: remove this alias...change to ${project.build.finalName} + context.put( "maven.final.name", project.getBuild().getFinalName() ); } public PlexusContainer getContainer() Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java?rev=165378&r1=165377&r2=165378&view=diff ============================================================================== --- maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java (original) +++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java Fri Apr 29 20:50:47 2005 @@ -72,9 +72,6 @@ extends AbstractLogEnabled implements PluginManager, ComponentDiscoveryListener, Initializable, Contextualizable { - // TODO: share with type handler - static String MAVEN_PLUGIN = "maven-plugin"; - protected Map mojoDescriptors; protected Map pluginDescriptors; @@ -148,9 +145,7 @@ for ( Iterator it = mavenPluginDescriptor.getMavenMojoDescriptors().iterator(); it.hasNext(); ) { - MavenMojoDescriptor mavenMojoDescriptor = (MavenMojoDescriptor) it.next(); - - MojoDescriptor mojoDescriptor = mavenMojoDescriptor.getMojoDescriptor(); + MojoDescriptor mojoDescriptor = (MojoDescriptor) it.next(); mojoDescriptors.put( mojoDescriptor.getId(), mojoDescriptor ); } @@ -241,7 +236,7 @@ try { Artifact pluginArtifact = artifactFactory.createArtifact( groupId, artifactId, version, null, - MAVEN_PLUGIN, null ); + MojoDescriptor.MAVEN_PLUGIN, null ); addPlugin( pluginArtifact, session ); } @@ -398,7 +393,11 @@ ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, pathTranslator ); PlexusConfiguration mergedConfiguration = mergeConfiguration( pomConfiguration, - mojoDescriptor.getConfiguration() ); + mojoDescriptor.getMojoConfiguration() ); + + // TODO: Go back to this when we get the container ready to configure mojos... +// PlexusConfiguration mergedConfiguration = mergeConfiguration( pomConfiguration, +// mojoDescriptor.getConfiguration() ); try { @@ -681,7 +680,10 @@ if ( foundInConfiguration && expression != null && parameter.getDeprecated() != null ) { - PlexusConfiguration goalConfiguration = goal.getConfiguration(); + PlexusConfiguration goalConfiguration = goal.getMojoConfiguration(); + + // TODO: Go back to this when we get the container ready to configure mojos... +// PlexusConfiguration goalConfiguration = goal.getConfiguration(); if ( !expression.equals( goalConfiguration.getChild( lookupKey, false ).getValue( null ) ) && !expression.equals( goalConfiguration.getChild( key, false ).getValue( null ) ) ) Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginDiscoverer.java URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginDiscoverer.java?rev=165378&r1=165377&r2=165378&view=diff ============================================================================== --- maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginDiscoverer.java (original) +++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginDiscoverer.java Fri Apr 29 20:50:47 2005 @@ -22,7 +22,6 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder; import org.codehaus.plexus.component.discovery.AbstractComponentDiscoverer; -import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentSetDescriptor; import org.codehaus.plexus.configuration.PlexusConfigurationException; @@ -103,9 +102,7 @@ for ( Iterator iterator = pluginDescriptor.getMojos().iterator(); iterator.hasNext(); ) { - ComponentDescriptor cd = new MavenMojoDescriptor( (MojoDescriptor) iterator.next() ); - - componentDescriptors.add( cd ); + componentDescriptors.add( (MojoDescriptor) iterator.next() ); } componentSet.setComponents( componentDescriptors ); Added: maven/components/trunk/maven-core/src/site/apt/getting-to-container-configured-mojos.apt URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/site/apt/getting-to-container-configured-mojos.apt?rev=165378&view=auto ============================================================================== --- maven/components/trunk/maven-core/src/site/apt/getting-to-container-configured-mojos.apt (added) +++ maven/components/trunk/maven-core/src/site/apt/getting-to-container-configured-mojos.apt Fri Apr 29 20:50:47 2005 @@ -0,0 +1,85 @@ + --- + Getting to Plexus-configured Mojos + --- + John Casey + --- + 29-April-2005 + +* Abstract + + We're moving toward integrating mojos as first-class plexus components, while + at the same time avoiding introducing required plexus dependencies into the + mojo development model. + + In order to really achieve this, we need mojo configurations (which are + provided both in terms of static expressions that are just looked up, and + in terms of user-provided configuration from system properties or the POM). + If these mojos are to be first-class components, the configuration from these + various sources must be consolidated and injected using the container. + + Currently, mojo configuration is done externally to the container, in the + DefaultPluginManager in the maven-core API. In order to get from here to + there, we need to do several things to add capability to the default + configuration of plexus. This document will detail those changes. + +* Container Enhancements + +** ExpressionEvaluator + + Currently, the expression evaluator used to resolve configuration values + is the DefaultExpressionEvaluator, which is a local variable within the + implementation of the BasicComponentConfigurator. This ExpressionEvaluator + simply returns the expression itself as the resolved value, which adds + very little value to the container. Things like ${project.build.resources} + are not resolved, and result in a type mismatch for the member injection. + + We need a replacement for DefaultExpressionEvaluator that is capable of + traversing an object graph and extracting Object values, not just Strings. + +** ComponentConfigurator + + Currently, the container uses BasicComponentConfigurator, to configure + components. This wouldn't be a problem, except for the local instance of + DefaultExpressionEvaluator used within. See the above discussion for more + on why this evaluator is bad. We need to provide either an alternative + implementation under a different roleHint, or else replace the + BasicComponentConfigurator. + +** Other + + We may need to define a new lifecycle/phase to contextualize a mojo right + before it's used, and reset it's state afterward. Up to now, the approach + of most plexus components has been to avoid instance state like the plague. + With the current parameter passing model of mojos, this will not be possible, + particularly when we move mojos to a singleton instantiation model, and then + run a reactorized project...the successive calls may leave behind configuration + artifacts from invocation to invocation. + +* Maven Modifications + +** DefaultPluginManager + + s/getMojoConfiguration()/getConfiguration()/g + + That should re-enable usage of mojo configuration. Ideally, we won't need any + of the code that references this method, since the container should provide + some way of recontextualizing the mojo, and all we would need to do is inject + POM configuration via the lookup method or something. + +** PluginDescriptorBuilder + + s/getMojoConfiguration()/getConfiguration()/g + + That should be all there is to it. + +** MojoDescriptor + + Remove set/getMojoConfiguration(..), as it will become obsolete. + +** MavenSession + + We may need to enable the context injection here, since this will be + instantiated per-project. If we always inject the same context parameters, + and are careful to inject nulls where things are missing, we should be + able to minimize reconfiguration artifacts injected from basic parameters. + Propchange: maven/components/trunk/maven-core/src/site/apt/getting-to-container-configured-mojos.apt ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author" Modified: maven/components/trunk/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java?rev=165378&r1=165377&r2=165378&view=diff ============================================================================== --- maven/components/trunk/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java (original) +++ maven/components/trunk/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java Fri Apr 29 20:50:47 2005 @@ -65,15 +65,10 @@ ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, null ); - Object value = expressionEvaluator.evaluate( "#project.build.directory/classes" ); + Object value = expressionEvaluator.evaluate( "${project.build.directory}/classes" ); String actual = new File( value.toString() ).getCanonicalPath(); assertEquals( expected, actual ); - - value = expressionEvaluator.evaluate( "${project.build.directory}/classes" ); - actual = new File( value.toString() ).getCanonicalPath(); - - assertEquals( expected, actual ); } private static MavenSession createSession( MavenProject project, PlexusContainer container, @@ -93,11 +88,10 @@ ArtifactRepository repo = new ArtifactRepository( "test", "http://www.test.com", repoLayout ); PlexusContainer container = getContainer(); - MavenSession session = createSession( null, container, repo ); + MavenSession session = createSession( new MavenProject(new Model()), container, repo ); ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, null ); - assertNotNull( expressionEvaluator.evaluate( "#component.org.apache.maven.project.MavenProjectBuilder" ) ); assertNotNull( expressionEvaluator.evaluate( "${component.org.apache.maven.project.MavenProjectBuilder}" ) ); } @@ -110,10 +104,10 @@ ArtifactRepository repo = new ArtifactRepository( "local", "target/repo", repoLayout ); PlexusContainer container = getContainer(); - MavenSession session = createSession( null, container, repo ); + MavenSession session = createSession( new MavenProject(new Model()), container, repo ); ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, null ); - Object value = expressionEvaluator.evaluate( "#localRepository" ); + Object value = expressionEvaluator.evaluate( "${localRepository}" ); assertEquals( "local", ( (ArtifactRepository) value ).getId() ); } Modified: maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java?rev=165378&r1=165377&r2=165378&view=diff ============================================================================== --- maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java (original) +++ maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java Fri Apr 29 20:50:47 2005 @@ -16,10 +16,11 @@ * limitations under the License. */ -import org.codehaus.plexus.component.repository.ComponentRequirement; +import org.apache.maven.plugin.Mojo; +import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.configuration.PlexusConfiguration; +import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; -import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -31,17 +32,19 @@ * @todo is there a need for the delegation of MavenMojoDescriptor to this? Why not just extend ComponentDescriptor here? */ public class MojoDescriptor + extends ComponentDescriptor implements Cloneable { + // TODO: share with type handler + public static String MAVEN_PLUGIN = "maven-plugin"; + public static final String SINGLE_PASS_EXEC_STRATEGY = "once-per-session"; public static final String MULTI_PASS_EXEC_STRATEGY = "always"; - private static final String DEFAULT_LANGUAGE = "java"; - - private String implementation; + private static final String DEFAULT_INSTANTIATION_STRATEGY = "per-lookup"; - private String description; + private static final String DEFAULT_LANGUAGE = "java"; private String id; @@ -49,8 +52,6 @@ private Map parameterMap; - private String instantiationStrategy = "per-lookup"; - private String executionStrategy = SINGLE_PASS_EXEC_STRATEGY; private String goal; @@ -59,8 +60,6 @@ private String executePhase; - private List requirements; - private String deprecated; // ---------------------------------------------------------------------- @@ -73,52 +72,26 @@ private boolean requiresOnline = false; - private String language = DEFAULT_LANGUAGE; + private PlexusConfiguration mojoConfiguration; - private PlexusConfiguration configuration; + public MojoDescriptor() + { + setInstantiationStrategy( DEFAULT_INSTANTIATION_STRATEGY ); + setComponentFactory( DEFAULT_LANGUAGE ); + } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- - public String getImplementation() - { - return implementation; - } - - public void setImplementation( String implementation ) - { - this.implementation = implementation; - } - - public String getDescription() - { - return description; - } - - public void setDescription( String description ) - { - this.description = description; - } - - public String getInstantiationStrategy() - { - return instantiationStrategy; - } - - public void setInstantiationStrategy( String instantiationStrategy ) - { - this.instantiationStrategy = instantiationStrategy; - } - public String getLanguage() { - return language; + return getComponentFactory(); } public void setLanguage( String language ) { - this.language = language; + setComponentFactory( language ); } public String getId() @@ -218,20 +191,6 @@ return requiresOnline; } - public void setRequirements( List requirements ) - { - this.requirements = requirements; - } - - public List getRequirements() - { - if ( requirements == null ) - { - requirements = new ArrayList(); - } - return requirements; - } - public String getPhase() { return phase; @@ -277,18 +236,33 @@ this.executionStrategy = executionStrategy; } - public void addRequirement( ComponentRequirement cr ) + public PlexusConfiguration getMojoConfiguration() + { + if ( mojoConfiguration == null ) + { + mojoConfiguration = new XmlPlexusConfiguration( "configuration" ); + } + return mojoConfiguration; + } + + public void setMojoConfiguration( PlexusConfiguration mojoConfiguration ) { - getRequirements().add( cr ); + this.mojoConfiguration = mojoConfiguration; } - public void setConfiguration( PlexusConfiguration configuration ) + public String getRole() { - this.configuration = configuration; + return Mojo.ROLE; } - public PlexusConfiguration getConfiguration() + public String getRoleHint() { - return configuration; + return getId(); } + + public String getComponentType() + { + return MAVEN_PLUGIN; + } + } Modified: maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java?rev=165378&r1=165377&r2=165378&view=diff ============================================================================== --- maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java (original) +++ maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java Fri Apr 29 20:50:47 2005 @@ -184,7 +184,10 @@ // Configuration // ---------------------------------------------------------------------- - mojo.setConfiguration( c.getChild( "configuration" ) ); + mojo.setMojoConfiguration( c.getChild( "configuration" ) ); + + // TODO: Go back to this when we get the container ready to configure mojos... +// mojo.setConfiguration( c.getChild( "configuration" ) ); // ---------------------------------------------------------------------- // Requirements --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]