You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by si...@apache.org on 2009/02/13 16:40:01 UTC
svn commit: r744145 - in /maven/components/trunk: maven-core/
maven-core/src/main/java/org/apache/maven/plugin/
maven-embedder/src/main/java/org/apache/maven/embedder/
Author: sisbell
Date: Fri Feb 13 15:39:54 2009
New Revision: 744145
URL: http://svn.apache.org/viewvc?rev=744145&view=rev
Log:
[MNG-3631] Mojo Configuration. Allow embedder to get executions by goal, query config with xpath and execute mojo.
Added:
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginContext.java
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginContext.java
Modified:
maven/components/trunk/maven-core/pom.xml
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/DefaultPluginRepository.java
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginCollector.java
maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java
Modified: maven/components/trunk/maven-core/pom.xml
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/pom.xml?rev=744145&r1=744144&r2=744145&view=diff
==============================================================================
--- maven/components/trunk/maven-core/pom.xml (original)
+++ maven/components/trunk/maven-core/pom.xml Fri Feb 13 15:39:54 2009
@@ -117,6 +117,10 @@
<groupId>org.sonatype.plexus</groupId>
<artifactId>plexus-sec-dispatcher</artifactId>
</dependency>
+ <dependency>
+ <groupId>commons-jxpath</groupId>
+ <artifactId>commons-jxpath</artifactId>
+ </dependency>
</dependencies>
<build>
<plugins>
Added: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginContext.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginContext.java?rev=744145&view=auto
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginContext.java (added)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginContext.java Fri Feb 13 15:39:54 2009
@@ -0,0 +1,55 @@
+package org.apache.maven.plugin;
+
+import org.codehaus.plexus.component.annotations.Requirement;
+import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.apache.maven.plugin.descriptor.PluginDescriptor;
+import org.apache.maven.plugin.descriptor.MojoDescriptor;
+import org.apache.maven.execution.MavenSession;
+import org.apache.commons.jxpath.JXPathContext;
+
+import java.util.List;
+import java.util.Collection;
+import java.util.ArrayList;
+import java.io.StringReader;
+
+public class DefaultPluginContext implements PluginContext {
+
+ @Requirement
+ protected MavenPluginCollector pluginCollector;
+
+ @Requirement
+ protected PluginManager pluginManager;
+
+ public Collection<MojoExecution> getMojoExecutionsForGoal(String goal) throws Exception
+ {
+ List<MojoExecution> mojoExecutions = new ArrayList<MojoExecution>();
+
+ for(PluginDescriptor descriptor : pluginCollector.getPluginDescriptors())
+ {
+ MojoDescriptor mojoDescriptor = descriptor.getMojo(goal);
+ if(mojoDescriptor != null)
+ {
+ MojoExecution mojoExecution = new MojoExecution( mojoDescriptor );
+ mojoExecution.setConfiguration(
+ Xpp3DomBuilder.build( new StringReader( mojoDescriptor.getMojoConfiguration().toString() ) ) );
+ mojoExecutions.add(mojoExecution);
+ }
+ }
+
+ return mojoExecutions;
+ }
+
+ public Object getMojoParameterFor(MojoExecution mojoExecution, String xPath) throws Exception {
+ Xpp3Dom mojoDescriptorConfiguration =
+ Xpp3DomBuilder.build( new StringReader(mojoExecution.getMojoDescriptor().getMojoConfiguration().toString()));
+
+ Xpp3Dom mergedConfig = Xpp3Dom.mergeXpp3Dom( mojoExecution.getConfiguration(), mojoDescriptorConfiguration );
+ return JXPathContext.newContext( mergedConfig ).getValue( xPath );
+ }
+
+ public void executeMojo( MojoExecution mojoExecution, MavenSession session ) throws Exception
+ {
+ pluginManager.executeMojo(session.getCurrentProject(), mojoExecution, session);
+ }
+}
Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java?rev=744145&r1=744144&r2=744145&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 Feb 13 15:39:54 2009
@@ -847,13 +847,13 @@
getLogger(),
session.getExecutionProperties() );
- List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
+ List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
- interpolatorProperties.addAll(InterpolatorProperty.toInterpolatorProperties(session.getProjectBuilderConfiguration().getExecutionProperties(),
- PomInterpolatorTag.EXECUTION_PROPERTIES.name()));
+ interpolatorProperties.addAll(InterpolatorProperty.toInterpolatorProperties(session.getProjectBuilderConfiguration().getExecutionProperties(),
+ PomInterpolatorTag.EXECUTION_PROPERTIES.name()));
- interpolatorProperties.addAll(InterpolatorProperty.toInterpolatorProperties(session.getProjectBuilderConfiguration().getUserProperties(),
- PomInterpolatorTag.USER_PROPERTIES.name()));
+ interpolatorProperties.addAll(InterpolatorProperty.toInterpolatorProperties(session.getProjectBuilderConfiguration().getUserProperties(),
+ PomInterpolatorTag.USER_PROPERTIES.name()));
Plugin plugin = null;
try {
@@ -878,7 +878,7 @@
checkRequiredParameters( mojoDescriptor, mojoConfiguration, expressionEvaluator );
populatePluginFields( mojo, mojoDescriptor, mojoConfiguration, expressionEvaluator );
-
+
return mojo;
} finally {
@@ -1005,29 +1005,6 @@
}
}
-
- public static PlexusConfiguration copyConfiguration( PlexusConfiguration src )
- {
- // TODO: shouldn't be necessary
- XmlPlexusConfiguration dom = new XmlPlexusConfiguration( src.getName() );
- dom.setValue( src.getValue( null ) );
-
- String[] attributeNames = src.getAttributeNames();
- for ( int i = 0; i < attributeNames.length; i++ )
- {
- String attributeName = attributeNames[i];
- dom.setAttribute( attributeName, src.getAttribute( attributeName, null ) );
- }
-
- PlexusConfiguration[] children = src.getChildren();
- for ( int i = 0; i < children.length; i++ )
- {
- dom.addChild( copyConfiguration( children[i] ) );
- }
-
- return dom;
- }
-
// ----------------------------------------------------------------------
// Mojo Parameter Handling
// ----------------------------------------------------------------------
@@ -1063,7 +1040,7 @@
getLogger().debug( "Configuring mojo '" + mojoDescriptor.getId() + "' with "
+ ( configuratorId == null ? "basic" : configuratorId )
+ " configurator -->" );
-
+
// This needs to be able to use methods
configurator.configureComponent( plugin, configuration, expressionEvaluator, realm, listener );
Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginRepository.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginRepository.java?rev=744145&r1=744144&r2=744145&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginRepository.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginRepository.java Fri Feb 13 15:39:54 2009
@@ -2,14 +2,30 @@
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
+import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
+import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
+import org.codehaus.plexus.component.configurator.ComponentConfigurator;
+import org.codehaus.plexus.component.configurator.ConfigurationListener;
+import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
+import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter;
+import org.apache.maven.shared.model.InterpolatorProperty;
+import org.apache.maven.project.builder.PomInterpolatorTag;
+import org.apache.maven.project.builder.Mixer;
+import org.apache.maven.execution.MavenSession;
import java.util.List;
+import java.util.ArrayList;
import java.io.StringReader;
@Component( role = PluginRepository.class)
Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginCollector.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginCollector.java?rev=744145&r1=744144&r2=744145&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginCollector.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginCollector.java Fri Feb 13 15:39:54 2009
@@ -29,18 +29,14 @@
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
public class MavenPluginCollector
implements ComponentDiscoveryListener, LogEnabled
{
private Set pluginsInProcess = new HashSet();
- private Map pluginDescriptors = new HashMap();
+ private Map<String, PluginDescriptor> pluginDescriptors = new HashMap();
private Map pluginIdsByPrefix = new HashMap();
@@ -75,8 +71,12 @@
public PluginDescriptor getPluginDescriptor( Plugin plugin )
{
- String key = constructPluginKey( plugin );
- return (PluginDescriptor) pluginDescriptors.get( key );
+ return pluginDescriptors.get( constructPluginKey( plugin ) );
+ }
+
+ public Collection<PluginDescriptor> getPluginDescriptors()
+ {
+ return pluginDescriptors.values();
}
private String constructPluginKey( Plugin plugin )
@@ -97,7 +97,7 @@
return pluginDescriptors.containsKey( key );
}
- public Set getPluginDescriptorsForPrefix( String prefix )
+ public Set<PluginDescriptor> getPluginDescriptorsForPrefix( String prefix )
{
Set result = new HashSet();
for ( Iterator it = pluginDescriptors.values().iterator(); it.hasNext(); )
Added: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginContext.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginContext.java?rev=744145&view=auto
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginContext.java (added)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/PluginContext.java Fri Feb 13 15:39:54 2009
@@ -0,0 +1,15 @@
+package org.apache.maven.plugin;
+
+import org.apache.maven.execution.MavenSession;
+
+import java.util.Collection;
+
+public interface PluginContext {
+
+ Collection<MojoExecution> getMojoExecutionsForGoal(String goal) throws Exception;
+
+ Object getMojoParameterFor(MojoExecution mojoExecution, String xPath) throws Exception;
+
+ void executeMojo(MojoExecution mojoExecution, MavenSession session) throws Exception;
+
+}
Modified: maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java?rev=744145&r1=744144&r2=744145&view=diff
==============================================================================
--- maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java (original)
+++ maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java Fri Feb 13 15:39:54 2009
@@ -24,10 +24,7 @@
import java.io.Reader;
import java.io.Writer;
import java.net.URL;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
+import java.util.*;
import org.apache.maven.Maven;
import org.apache.maven.artifact.Artifact;
@@ -90,8 +87,6 @@
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.component.repository.exception.ComponentRepositoryException;
import org.codehaus.plexus.configuration.PlexusConfigurationException;
-import org.codehaus.plexus.configuration.PlexusConfiguration;
-import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
import org.codehaus.plexus.logging.LoggerManager;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
@@ -170,6 +165,8 @@
private Configuration configuration;
+ private PluginContext pluginContext;
+
// ----------------------------------------------------------------------------
// Constructors
// ----------------------------------------------------------------------------
@@ -185,6 +182,21 @@
return request;
}
+ public Collection<MojoExecution> getMojoExecutionsForGoal(String goal) throws Exception
+ {
+ return pluginContext.getMojoExecutionsForGoal( goal );
+ }
+
+ public Object getMojoParameterFor(MojoExecution mojoExecution, String xPath) throws Exception
+ {
+ return pluginContext.getMojoParameterFor( mojoExecution, xPath);
+ }
+
+ public void executeMojo(MojoExecution mojoExecution, MavenSession mavenSession ) throws Exception
+ {
+ pluginContext.executeMojo( mojoExecution, mavenSession );
+ }
+
// ----------------------------------------------------------------------
// Accessors
// ----------------------------------------------------------------------
@@ -250,32 +262,6 @@
modelWriter.write( writer, model );
}
- public PlexusConfiguration getPluginConfiguration(String pluginId, String mojoId, Model model) throws Exception
- {
- try {
- return mixer.mixPluginAndReturnConfig(pluginRepository.findPluginById(pluginId, mojoId), null, model, null);
- } catch (PlexusConfigurationException e) {
- throw new IOException(e.getMessage());
- }
- }
-
- public Object getPluginConfigurationAsDom(String pluginId, String mojoId, Model model) throws Exception
- {
- try {
- return mixer.mixPluginAndReturnConfigAsDom(pluginRepository.findPluginById(pluginId, mojoId), model);
- } catch (PlexusConfigurationException e) {
- throw new IOException(e.getMessage());
- }
- }
-
- public Object getPluginConfigurationAsDom(String pluginId, String mojoId, Model model, String xpathExpression) throws Exception
- {
- try {
- return mixer.mixPluginAndReturnConfigAsDom(pluginRepository.findPluginById(pluginId, mojoId), model, xpathExpression);
- } catch (PlexusConfigurationException e) {
- throw new IOException(e.getMessage());
- }
- }
// ----------------------------------------------------------------------
// Settings