o removing MavenProject from the public signature of the plugin manager to enforce the concern of the plugin manager which is simply to execute plugins. all configuration and processing of configuration happens before the plugin manager. the only thing left is the expression evaluator which has the mixed concern of configuration and componnent injection.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@774361 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-05-13 13:41:06 +00:00
parent 861244fe51
commit d13f1295b7
5 changed files with 33 additions and 21 deletions

View File

@ -445,7 +445,7 @@ public class DefaultLifecycleExecutor
// Maven plugin deployment we will find the right PluginDescriptor from the remote // Maven plugin deployment we will find the right PluginDescriptor from the remote
// repository. // repository.
plugin = pluginManager.findPluginForPrefix( prefix, project ); plugin = pluginManager.findPluginForPrefix( prefix, localRepository, project.getRemoteArtifactRepositories() );
// Search plugin in the current POM // Search plugin in the current POM
if ( plugin == null ) if ( plugin == null )
@ -456,7 +456,7 @@ public class DefaultLifecycleExecutor
try try
{ {
desc = pluginManager.loadPlugin( buildPlugin, project, localRepository ); desc = pluginManager.loadPlugin( buildPlugin, localRepository, project.getRemoteArtifactRepositories() );
} }
catch ( PluginLoaderException e ) catch ( PluginLoaderException e )
{ {
@ -505,7 +505,7 @@ public class DefaultLifecycleExecutor
try try
{ {
mojoDescriptor = pluginManager.getMojoDescriptor( plugin, goal, project, localRepository ); mojoDescriptor = pluginManager.getMojoDescriptor( plugin, goal, localRepository, project.getRemoteArtifactRepositories() );
} }
catch ( PluginLoaderException e ) catch ( PluginLoaderException e )
{ {
@ -530,7 +530,7 @@ public class DefaultLifecycleExecutor
try try
{ {
mojoDescriptor = pluginManager.getMojoDescriptor( plugin, goal, project, localRepository ); mojoDescriptor = pluginManager.getMojoDescriptor( plugin, goal, localRepository, project.getRemoteArtifactRepositories() );
} }
catch ( PluginLoaderException e ) catch ( PluginLoaderException e )
{ {

View File

@ -114,7 +114,7 @@ public class DefaultPluginManager
} }
// This should be template method code for allowing subclasses to assist in contributing search/hint information // This should be template method code for allowing subclasses to assist in contributing search/hint information
public Plugin findPluginForPrefix( String prefix, MavenProject project ) public Plugin findPluginForPrefix( String prefix, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
{ {
//Use the plugin managers capabilities to get information to augement the request //Use the plugin managers capabilities to get information to augement the request
@ -122,7 +122,7 @@ public class DefaultPluginManager
//return getByPrefix( prefix, session.getPluginGroups(), project.getRemoteArtifactRepositories(), session.getLocalRepository() ); //return getByPrefix( prefix, session.getPluginGroups(), project.getRemoteArtifactRepositories(), session.getLocalRepository() );
} }
public PluginDescriptor loadPlugin( Plugin plugin, MavenProject project, ArtifactRepository localRepository ) public PluginDescriptor loadPlugin( Plugin plugin, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws PluginLoaderException throws PluginLoaderException
{ {
PluginDescriptor pluginDescriptor = getPluginDescriptor( plugin ); PluginDescriptor pluginDescriptor = getPluginDescriptor( plugin );
@ -136,7 +136,7 @@ public class DefaultPluginManager
try try
{ {
return addPlugin( plugin, project, localRepository ); return addPlugin( plugin, localRepository, remoteRepositories );
} }
catch ( ArtifactResolutionException e ) catch ( ArtifactResolutionException e )
// PluginResolutionException - a problem that occurs resolving the plugin artifact or its deps // PluginResolutionException - a problem that occurs resolving the plugin artifact or its deps
@ -167,7 +167,7 @@ public class DefaultPluginManager
return plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion(); return plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion();
} }
protected PluginDescriptor addPlugin( Plugin plugin, MavenProject project, ArtifactRepository localRepository ) protected PluginDescriptor addPlugin( Plugin plugin, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws ArtifactNotFoundException, ArtifactResolutionException, PluginVersionResolutionException, PluginContainerException, PluginVersionNotFoundException throws ArtifactNotFoundException, ArtifactResolutionException, PluginVersionResolutionException, PluginContainerException, PluginVersionNotFoundException
{ {
Artifact pluginArtifact = repositorySystem.createPluginArtifact( plugin ); Artifact pluginArtifact = repositorySystem.createPluginArtifact( plugin );
@ -175,7 +175,7 @@ public class DefaultPluginManager
ArtifactResolutionRequest request = new ArtifactResolutionRequest() ArtifactResolutionRequest request = new ArtifactResolutionRequest()
.setArtifact( pluginArtifact ) .setArtifact( pluginArtifact )
.setLocalRepository( localRepository ) .setLocalRepository( localRepository )
.setRemoteRepostories( project.getRemoteArtifactRepositories() ); .setRemoteRepostories( remoteRepositories );
ArtifactResolutionResult result = repositorySystem.resolve( request ); ArtifactResolutionResult result = repositorySystem.resolve( request );
@ -183,7 +183,7 @@ public class DefaultPluginManager
ClassRealm pluginRealm = container.createChildRealm( pluginKey( plugin ) ); ClassRealm pluginRealm = container.createChildRealm( pluginKey( plugin ) );
Set<Artifact> pluginArtifacts = getPluginArtifacts( pluginArtifact, plugin, project, localRepository ); Set<Artifact> pluginArtifacts = getPluginArtifacts( pluginArtifact, plugin, localRepository, remoteRepositories );
for ( Artifact a : pluginArtifacts ) for ( Artifact a : pluginArtifacts )
{ {
@ -230,7 +230,7 @@ public class DefaultPluginManager
// its dependencies while filtering out what's in the core // its dependencies while filtering out what's in the core
// layering on the project level plugin dependencies // layering on the project level plugin dependencies
private Set<Artifact> getPluginArtifacts( Artifact pluginArtifact, Plugin pluginAsSpecifiedinPom, MavenProject project, ArtifactRepository localRepository ) private Set<Artifact> getPluginArtifacts( Artifact pluginArtifact, Plugin pluginAsSpecifiedinPom, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws ArtifactNotFoundException, ArtifactResolutionException throws ArtifactNotFoundException, ArtifactResolutionException
{ {
AndArtifactFilter filter = new AndArtifactFilter(); AndArtifactFilter filter = new AndArtifactFilter();
@ -260,7 +260,7 @@ public class DefaultPluginManager
// So this in fact are overrides ... // So this in fact are overrides ...
.setArtifactDependencies( dependenciesToResolveForPlugin ) .setArtifactDependencies( dependenciesToResolveForPlugin )
.setLocalRepository( localRepository ) .setLocalRepository( localRepository )
.setRemoteRepostories( project.getRemoteArtifactRepositories() ) .setRemoteRepostories( remoteRepositories )
.setFilter( filter ) .setFilter( filter )
.setResolveTransitively( true ); .setResolveTransitively( true );
@ -536,10 +536,10 @@ public class DefaultPluginManager
} }
} }
public MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, MavenProject project, ArtifactRepository localRepository ) public MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws PluginLoaderException throws PluginLoaderException
{ {
PluginDescriptor pluginDescriptor = loadPlugin( plugin, project, localRepository ); PluginDescriptor pluginDescriptor = loadPlugin( plugin, localRepository, remoteRepositories );
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal ); MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal );

View File

@ -15,12 +15,13 @@ package org.apache.maven.plugin;
* the License. * the License.
*/ */
import java.util.List;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin; import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.discovery.ComponentDiscoverer; import org.codehaus.plexus.component.discovery.ComponentDiscoverer;
import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener; import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener;
@ -35,12 +36,12 @@ public interface PluginManager
// - configure the plugin [extension point] // - configure the plugin [extension point]
// - execute the plugin // - execute the plugin
Plugin findPluginForPrefix( String prefix, MavenProject project ); Plugin findPluginForPrefix( String prefix, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories );
PluginDescriptor loadPlugin( Plugin plugin, MavenProject project, ArtifactRepository localRepository ) PluginDescriptor loadPlugin( Plugin plugin, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws PluginLoaderException; throws PluginLoaderException;
MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, MavenProject project, ArtifactRepository localRepository ) MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws PluginLoaderException; throws PluginLoaderException;
void executeMojo( MavenSession session, MojoExecution execution ) void executeMojo( MavenSession session, MojoExecution execution )

View File

@ -6,6 +6,7 @@ import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.util.xml.Xpp3Dom;
public class PluginManagerTest public class PluginManagerTest
extends AbstractCoreMavenComponentTestCase extends AbstractCoreMavenComponentTestCase
@ -77,10 +78,16 @@ public class PluginManagerTest
public void testRemoteResourcesPlugin() public void testRemoteResourcesPlugin()
throws Exception throws Exception
{ {
//TODO: turn an equivalent back on when the RR plugin is released.
/* /*
This will not work until the RR plugin is released to get rid of the binding to the reporting exception which is a mistake. This will not work until the RR plugin is released to get rid of the binding to the reporting exception which is a mistake.
This happpens after removing the reporting API from the core:
java.lang.NoClassDefFoundError: org/apache/maven/reporting/MavenReportException
MavenSession session = createMavenSession( getProject( "project-with-inheritance" ) ); MavenSession session = createMavenSession( getProject( "project-with-inheritance" ) );
String goal = "process"; String goal = "process";
@ -107,9 +114,14 @@ public class PluginManagerTest
plugin.setArtifactId( "maven-surefire-plugin" ); plugin.setArtifactId( "maven-surefire-plugin" );
plugin.setVersion( "2.4.2" ); plugin.setVersion( "2.4.2" );
// The project has already been fully interpolated so getting the raw mojoDescriptor is not going to have the processes configuration.
MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( plugin, goal, session.getCurrentProject(), session.getLocalRepository() ); MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( plugin, goal, session.getCurrentProject(), session.getLocalRepository() );
assertPluginDescriptor( mojoDescriptor, "org.apache.maven.plugins", "maven-surefire-plugin", "2.4.2" ); assertPluginDescriptor( mojoDescriptor, "org.apache.maven.plugins", "maven-surefire-plugin", "2.4.2" );
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor );
System.out.println( session.getCurrentProject().getBuild().getPluginsAsMap() );
Xpp3Dom configuration = (Xpp3Dom) session.getCurrentProject().getBuild().getPluginsAsMap().get( plugin.getKey() ).getExecutions().get( 0 ).getConfiguration();
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor, configuration );
pluginManager.executeMojo( session, mojoExecution ); pluginManager.executeMojo( session, mojoExecution );
} }

View File

@ -1457,8 +1457,7 @@ public class PomConstructionTest
ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration(); ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration();
String localRepoUrl = String localRepoUrl = System.getProperty( "maven.repo.local", System.getProperty( "user.home" ) + "/.m2/repository" );
System.getProperty( "maven.repo.local", System.getProperty( "user.home" ) + "/.m2/repository" );
localRepoUrl = "file://" + localRepoUrl; localRepoUrl = "file://" + localRepoUrl;
config.setLocalRepository( new DefaultArtifactRepository( "local", localRepoUrl, new DefaultRepositoryLayout() ) ); config.setLocalRepository( new DefaultArtifactRepository( "local", localRepoUrl, new DefaultRepositoryLayout() ) );