o giving shane a handle on how to grab default plugin information as i've removed all the diddling in the plugin manager itself

git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@769637 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-04-29 03:45:42 +00:00
parent e59d107cf1
commit 6d229c8e46
7 changed files with 82 additions and 32 deletions

View File

@ -25,6 +25,7 @@ import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.ReactorManager;
import org.apache.maven.lifecycle.mapping.LifecycleMapping;
@ -40,10 +41,13 @@ import org.apache.maven.plugin.descriptor.MojoDescriptor;
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;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
//TODO: The configuration for the lifecycle needs to be externalized so that I can use the annotations
// properly for the wiring and reference and external source for the lifecycle configuration.
@ -334,7 +338,7 @@ public class DefaultLifecycleExecutor
for( String goal : execution.getGoals() )
{
String s = plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion() + ":" + goal;
MojoDescriptor md = getMojoDescriptor( s, session, project );
MojoDescriptor md = getMojoDescriptor( s, session.getCurrentProject(), session.getLocalRepository() );
// 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() ) )
@ -357,7 +361,7 @@ public class DefaultLifecycleExecutor
//
// org.apache.maven.plugins:maven-remote-resources-plugin:1.0:process
//
lifecyclePlan.add( getMojoDescriptor( mojo, session, project ) );
lifecyclePlan.add( getMojoDescriptor( mojo, project, session.getLocalRepository() ) );
}
}
@ -365,7 +369,8 @@ public class DefaultLifecycleExecutor
}
// org.apache.maven.plugins:maven-remote-resources-plugin:1.0:process
MojoDescriptor getMojoDescriptor( String task, MavenSession session, MavenProject project )
MojoDescriptor getMojoDescriptor( String task, MavenProject project, ArtifactRepository localRepository )
//MojoDescriptor getMojoDescriptor( String groupId, String artifactId, String version, String goal, MavenProject project, ArtifactRepository localRepository )
throws LifecycleExecutionException
{
String goal;
@ -389,7 +394,7 @@ public class DefaultLifecycleExecutor
// Maven plugin deployment we will find the right PluginDescriptor from the remote
// repository.
plugin = pluginManager.findPluginForPrefix( prefix, project, session );
plugin = pluginManager.findPluginForPrefix( prefix, project );
// Search plugin in the current POM
if ( plugin == null )
@ -400,7 +405,7 @@ public class DefaultLifecycleExecutor
try
{
desc = pluginManager.loadPlugin( buildPlugin, project, session );
desc = pluginManager.loadPlugin( buildPlugin, project, localRepository );
}
catch ( PluginLoaderException e )
{
@ -449,7 +454,7 @@ public class DefaultLifecycleExecutor
try
{
mojoDescriptor = pluginManager.getMojoDescriptor( plugin, goal, session );
mojoDescriptor = pluginManager.getMojoDescriptor( plugin, goal, project, localRepository );
}
catch ( PluginLoaderException e )
{
@ -496,4 +501,33 @@ public class DefaultLifecycleExecutor
return null;
}
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() );
}
public Xpp3Dom getMojoConfiguration( MojoDescriptor mojoDescriptor )
{
PlexusConfiguration configuration = mojoDescriptor.getConfiguration();
return convert( configuration );
}
public Xpp3Dom convert( PlexusConfiguration c )
{
Xpp3Dom dom = new Xpp3Dom( "configuration" );
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 );
}
return dom;
}
}

View File

@ -47,7 +47,6 @@ import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.RuntimeInformation;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
@ -136,7 +135,7 @@ public class DefaultPluginManager
}
// This should be template method code for allowing subclasses to assist in contributing search/hint information
public Plugin findPluginForPrefix( String prefix, MavenProject project, MavenSession session )
public Plugin findPluginForPrefix( String prefix, MavenProject project )
{
//Use the plugin managers capabilities to get information to augement the request
@ -144,7 +143,7 @@ public class DefaultPluginManager
//return getByPrefix( prefix, session.getPluginGroups(), project.getRemoteArtifactRepositories(), session.getLocalRepository() );
}
public PluginDescriptor loadPlugin( Plugin plugin, MavenProject project, MavenSession session )
public PluginDescriptor loadPlugin( Plugin plugin, MavenProject project, ArtifactRepository localRepository )
throws PluginLoaderException
{
PluginDescriptor pluginDescriptor = getPluginDescriptor( plugin );
@ -158,7 +157,7 @@ public class DefaultPluginManager
try
{
return addPlugin( plugin, project, session );
return addPlugin( plugin, project, localRepository );
}
catch ( ArtifactResolutionException e )
{
@ -191,12 +190,10 @@ public class DefaultPluginManager
return plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion();
}
protected PluginDescriptor addPlugin( Plugin plugin, MavenProject project, MavenSession session )
protected PluginDescriptor addPlugin( Plugin plugin, MavenProject project, ArtifactRepository localRepository )
throws ArtifactNotFoundException, ArtifactResolutionException, InvalidPluginException, PluginVersionResolutionException, PluginContainerException, PluginVersionNotFoundException
{
resolvePluginVersion( plugin, project, session );
ArtifactRepository localRepository = session.getLocalRepository();
resolvePluginVersion( plugin, project );
MavenProject pluginProject = buildPluginProject( plugin, localRepository, new ArrayList( project.getRemoteArtifactRepositories() ) );
@ -214,7 +211,7 @@ public class DefaultPluginManager
ClassRealm pluginRealm = container.createChildRealm( pluginKey( plugin ) );
Set<Artifact> pluginArtifacts = getPluginArtifacts( pluginArtifact, plugin, project, session.getLocalRepository() );
Set<Artifact> pluginArtifacts = getPluginArtifacts( pluginArtifact, plugin, project, localRepository );
for ( Artifact a : pluginArtifacts )
{
@ -571,7 +568,7 @@ public class DefaultPluginManager
// override in the POM.
validatePomConfiguration( mojoDescriptor, pomConfiguration );
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, mojoExecution );
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session );
checkDeprecatedParameters( mojoDescriptor, pomConfiguration );
@ -929,7 +926,7 @@ public class DefaultPluginManager
}
}
public void resolvePluginVersion( Plugin plugin, MavenProject project, MavenSession session )
public void resolvePluginVersion( Plugin plugin, MavenProject project )
throws PluginVersionNotFoundException
{
String version = plugin.getVersion();
@ -1022,7 +1019,7 @@ public class DefaultPluginManager
}
}
public MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, MavenSession session )
public MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, MavenProject project, ArtifactRepository localRepository )
throws PluginLoaderException
{
if ( plugin.getVersion() == null )
@ -1030,7 +1027,7 @@ public class DefaultPluginManager
throw new IllegalArgumentException("plugin.version: null");
}
PluginDescriptor pluginDescriptor = loadPlugin( plugin, session.getCurrentProject(), session );
PluginDescriptor pluginDescriptor = loadPlugin( plugin, project, localRepository );
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal );

View File

@ -15,6 +15,7 @@ package org.apache.maven.plugin;
* the License.
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
@ -34,12 +35,12 @@ public interface PluginManager
// - configure the plugin [extension point]
// - execute the plugin
Plugin findPluginForPrefix( String prefix, MavenProject project, MavenSession session );
Plugin findPluginForPrefix( String prefix, MavenProject project );
PluginDescriptor loadPlugin( Plugin plugin, MavenProject project, MavenSession session )
PluginDescriptor loadPlugin( Plugin plugin, MavenProject project, ArtifactRepository localRepository )
throws PluginLoaderException;
MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, MavenSession session )
MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, MavenProject project, ArtifactRepository localRepository )
throws PluginLoaderException;
void executeMojo( MavenSession session, MojoExecution execution )

View File

@ -46,7 +46,13 @@ public class PluginParameterExpressionEvaluator
private Properties properties;
@Deprecated
public PluginParameterExpressionEvaluator( MavenSession session, MojoExecution mojoExecution )
{
this( session );
}
public PluginParameterExpressionEvaluator( MavenSession session )
{
this.session = session;
this.mojoExecution = mojoExecution;

View File

@ -13,6 +13,7 @@ import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.util.xml.Xpp3Dom;
public class LifecycleExecutorTest
extends AbstractCoreMavenComponentTestCase
@ -95,4 +96,15 @@ public class LifecycleExecutorTest
assertEquals( 8, plugins.size() );
}
public void testPluginConfigurationCreation()
throws Exception
{
File pom = getProject( "project-with-additional-lifecycle-elements" );
MavenSession session = createMavenSession( pom );
MojoDescriptor mojoDescriptor = lifecycleExecutor.getMojoDescriptor( "org.apache.maven.plugins:maven-remote-resources-plugin:1.0:process", session.getCurrentProject(), session.getLocalRepository() );
Xpp3Dom dom = lifecycleExecutor.convert( mojoDescriptor.getMojoConfiguration() );
System.out.println( dom );
}
}

View File

@ -35,7 +35,7 @@ public class PluginManagerTest
plugin.setGroupId( "org.codehaus.plexus" );
plugin.setArtifactId( "plexus-component-metadata" );
plugin.setVersion( plexusVersion );
PluginDescriptor pluginDescriptor = pluginManager.loadPlugin( plugin, session.getCurrentProject(), session );
PluginDescriptor pluginDescriptor = pluginManager.loadPlugin( plugin, session.getCurrentProject(), session.getLocalRepository() );
assertNotNull( pluginDescriptor );
assertNotNull( pluginDescriptor.getClassRealm() );
}
@ -50,7 +50,7 @@ public class PluginManagerTest
plugin.setArtifactId( "plexus-component-metadata" );
plugin.setVersion( plexusVersion );
MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( plugin, goal, session );
MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( plugin, goal, session.getCurrentProject(), session.getLocalRepository() );
assertNotNull( mojoDescriptor );
assertEquals( "generate-metadata", mojoDescriptor.getGoal() );
assertNotNull( mojoDescriptor.getRealm() );
@ -86,7 +86,7 @@ public class PluginManagerTest
plugin.setArtifactId( "maven-remote-resources-plugin" );
plugin.setVersion( "1.0-beta-2" );
MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( plugin, goal, session );
MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( plugin, goal, session.getCurrentProject(), session.getLocalRepository() );
assertPluginDescriptor( mojoDescriptor, "org.apache.maven.plugins", "maven-remote-resources-plugin", "1.1" );
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor );
pluginManager.executeMojo( session, mojoExecution );
@ -103,7 +103,7 @@ public class PluginManagerTest
plugin.setArtifactId( "maven-surefire-plugin" );
plugin.setVersion( "2.4.2" );
MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( plugin, goal, session );
MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( plugin, goal, session.getCurrentProject(), session.getLocalRepository() );
assertPluginDescriptor( mojoDescriptor, "org.apache.maven.plugins", "maven-surefire-plugin", "2.4.2" );
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor );
pluginManager.executeMojo( session, mojoExecution );

View File

@ -274,13 +274,13 @@ public class MavenEmbedder
* mkleint: protected so that IDE integrations can selectively allow downloading artifacts
* from remote repositories (if they prohibit by default on project loading)
* @throws PluginLoaderException
*/
protected void verifyPlugin( Plugin plugin, MavenProject project )
throws ComponentLookupException, PluginLoaderException
{
MavenSession session = new MavenSession( request );
pluginManager.loadPlugin( plugin, project, session );
}
*/
// ----------------------------------------------------------------------
// Project