o start the grand plugin refactoring, just putting it all together in addition to putting all the repository/artifact calls

behind the repository system you can see project and plugins being processed an incredible number of times and the recursion
  in the collector is broken causing POMs for plugins to be processed hundreds of times. The bootstrap under profiling reveals
  the xpp3 parser being used almost 30k times which is pure insanity.



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@750774 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-03-06 05:38:48 +00:00
parent 98891350b8
commit 1ffdc9286a
21 changed files with 626 additions and 1485 deletions

View File

@ -46,7 +46,6 @@ import org.apache.maven.plugin.InvalidPluginException;
import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.PluginConfigurationException; import org.apache.maven.plugin.PluginConfigurationException;
import org.apache.maven.plugin.PluginLoader;
import org.apache.maven.plugin.PluginLoaderException; import org.apache.maven.plugin.PluginLoaderException;
import org.apache.maven.plugin.PluginManager; import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.PluginManagerException; import org.apache.maven.plugin.PluginManagerException;
@ -83,9 +82,6 @@ public class DefaultLifecycleExecutor
@Requirement @Requirement
private PluginManager pluginManager; private PluginManager pluginManager;
@Requirement
private PluginLoader pluginLoader;
@Requirement @Requirement
private BuildPlanner buildPlanner; private BuildPlanner buildPlanner;
@ -446,10 +442,7 @@ public class DefaultLifecycleExecutor
PluginDescriptor pluginDescriptor; PluginDescriptor pluginDescriptor;
try try
{ {
pluginDescriptor = pluginLoader.loadPlugin( pluginDescriptor = pluginManager.loadPlugin( mojoBinding, project, session );
mojoBinding,
project,
session );
} }
catch ( PluginLoaderException e ) catch ( PluginLoaderException e )
{ {
@ -846,10 +839,7 @@ public class DefaultLifecycleExecutor
session, session,
true ); true );
PluginDescriptor descriptor = pluginLoader.loadPlugin( PluginDescriptor descriptor = pluginManager.loadPlugin( binding, project, session );
binding,
project,
session );
MojoDescriptor mojoDescriptor = descriptor.getMojo( binding.getGoal() ); MojoDescriptor mojoDescriptor = descriptor.getMojo( binding.getGoal() );

View File

@ -21,8 +21,8 @@ import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution; import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.ReportPlugin; import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.ReportSet; import org.apache.maven.model.ReportSet;
import org.apache.maven.plugin.PluginLoader;
import org.apache.maven.plugin.PluginLoaderException; import org.apache.maven.plugin.PluginLoaderException;
import org.apache.maven.plugin.PluginManager;
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.plugin.lifecycle.Execution; import org.apache.maven.plugin.lifecycle.Execution;
@ -31,7 +31,6 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.MavenReport; import org.apache.maven.reporting.MavenReport;
import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.LogEnabled; import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.Logger;
@ -52,7 +51,7 @@ public class DefaultLifecycleBindingManager
implements LifecycleBindingManager, LogEnabled implements LifecycleBindingManager, LogEnabled
{ {
@Requirement @Requirement
private PluginLoader pluginLoader; private PluginManager pluginLoader;
@Requirement @Requirement
private MojoBindingFactory mojoBindingFactory; private MojoBindingFactory mojoBindingFactory;

View File

@ -7,7 +7,6 @@ import org.apache.maven.lifecycle.LifecycleLoaderException;
import org.apache.maven.lifecycle.LifecycleSpecificationException; import org.apache.maven.lifecycle.LifecycleSpecificationException;
import org.apache.maven.lifecycle.model.MojoBinding; import org.apache.maven.lifecycle.model.MojoBinding;
import org.apache.maven.model.Plugin; import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.PluginLoader;
import org.apache.maven.plugin.PluginLoaderException; import org.apache.maven.plugin.PluginLoaderException;
import org.apache.maven.plugin.PluginManager; import org.apache.maven.plugin.PluginManager;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;

View File

@ -4,7 +4,6 @@ import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.LifecycleLoaderException; import org.apache.maven.lifecycle.LifecycleLoaderException;
import org.apache.maven.lifecycle.LifecycleSpecificationException; import org.apache.maven.lifecycle.LifecycleSpecificationException;
import org.apache.maven.lifecycle.model.MojoBinding; import org.apache.maven.lifecycle.model.MojoBinding;
import org.apache.maven.plugin.PluginLoader;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
/** /**

View File

@ -1,5 +1,13 @@
package org.apache.maven.lifecycle.plan; package org.apache.maven.lifecycle.plan;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.Stack;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.LifecycleLoaderException; import org.apache.maven.lifecycle.LifecycleLoaderException;
import org.apache.maven.lifecycle.LifecycleSpecificationException; import org.apache.maven.lifecycle.LifecycleSpecificationException;
@ -9,8 +17,8 @@ import org.apache.maven.lifecycle.binding.LifecycleBindingManager;
import org.apache.maven.lifecycle.binding.MojoBindingFactory; import org.apache.maven.lifecycle.binding.MojoBindingFactory;
import org.apache.maven.lifecycle.model.LifecycleBindings; import org.apache.maven.lifecycle.model.LifecycleBindings;
import org.apache.maven.lifecycle.model.MojoBinding; import org.apache.maven.lifecycle.model.MojoBinding;
import org.apache.maven.plugin.PluginLoader;
import org.apache.maven.plugin.PluginLoaderException; import org.apache.maven.plugin.PluginLoaderException;
import org.apache.maven.plugin.PluginManager;
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.apache.maven.project.MavenProject;
@ -19,14 +27,6 @@ import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.LogEnabled; import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.Logger;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.Stack;
/** /**
* Responsible for creating a plan of execution for a given project and list of tasks. This build plan consists of * Responsible for creating a plan of execution for a given project and list of tasks. This build plan consists of
* MojoBinding instances that carry all the information necessary to execute a mojo, including configuration from the * MojoBinding instances that carry all the information necessary to execute a mojo, including configuration from the
@ -41,7 +41,7 @@ public class DefaultBuildPlanner
implements BuildPlanner, LogEnabled implements BuildPlanner, LogEnabled
{ {
@Requirement @Requirement
private PluginLoader pluginLoader; private PluginManager pluginLoader;
@Requirement @Requirement
private LifecycleBindingManager lifecycleBindingManager; private LifecycleBindingManager lifecycleBindingManager;

View File

@ -7,8 +7,8 @@ import org.apache.maven.lifecycle.model.MojoBinding;
import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.PluginLoader;
import org.apache.maven.plugin.PluginLoaderException; import org.apache.maven.plugin.PluginLoaderException;
import org.apache.maven.plugin.PluginManager;
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.apache.maven.project.MavenProject;
@ -19,7 +19,7 @@ public class ResolveLateBoundPluginMojo extends AbstractMojo
/** /**
* @component * @component
*/ */
private PluginLoader pluginLoader; private PluginManager pluginLoader;
private String groupId; private String groupId;

View File

@ -1,181 +0,0 @@
package org.apache.maven.plugin;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.model.MojoBinding;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
/**
* Responsible for loading plugins, reports, and any components contained therein. Will resolve
* plugin versions and plugin prefixes as necessary for plugin resolution.
*
* @author jdcasey
*
*/
@Component(role = PluginLoader.class)
public class DefaultPluginLoader
implements PluginLoader
{
@Requirement
private PluginManager pluginManager;
@Requirement
private Logger logger;
/**
* Load the {@link PluginDescriptor} instance for the plugin implied by the specified MojoBinding,
* using the project for {@link ArtifactRepository} and other supplemental plugin information as
* necessary.
*/
public PluginDescriptor loadPlugin( MojoBinding mojoBinding, MavenProject project, MavenSession session )
throws PluginLoaderException
{
PluginDescriptor pluginDescriptor = null;
Plugin plugin = new Plugin();
plugin.setGroupId( mojoBinding.getGroupId() );
plugin.setArtifactId( mojoBinding.getArtifactId() );
plugin.setVersion( mojoBinding.getVersion() );
pluginDescriptor = loadPlugin( plugin, project, session );
// fill in any blanks once we know more about this plugin.
if ( pluginDescriptor != null )
{
mojoBinding.setGroupId( pluginDescriptor.getGroupId() );
mojoBinding.setArtifactId( pluginDescriptor.getArtifactId() );
mojoBinding.setVersion( pluginDescriptor.getVersion() );
}
return pluginDescriptor;
}
/**
* Load the {@link PluginDescriptor} instance for the specified plugin, using the project for
* the {@link ArtifactRepository} and other supplemental plugin information as necessary.
*/
public PluginDescriptor loadPlugin( Plugin plugin, MavenProject project, MavenSession session )
throws PluginLoaderException
{
if ( plugin.getGroupId() == null )
{
plugin.setGroupId( PluginDescriptor.getDefaultPluginGroupId() );
}
try
{
PluginDescriptor result = pluginManager.verifyPlugin( plugin, project, session );
// this has been simplified from the old code that injected the plugin management stuff, since
// pluginManagement injection is now handled by the project method.
project.addPlugin( plugin );
return result;
}
catch ( ArtifactResolutionException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( ArtifactNotFoundException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( PluginNotFoundException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( PluginVersionResolutionException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( InvalidPluginException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( PluginManagerException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( PluginVersionNotFoundException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
}
public void enableLogging( Logger logger )
{
this.logger = logger;
}
/**
* Load the {@link PluginDescriptor} instance for the report plugin implied by the specified MojoBinding,
* using the project for {@link ArtifactRepository} and other supplemental report/plugin information as
* necessary.
*/
public PluginDescriptor loadReportPlugin( MojoBinding mojoBinding, MavenProject project, MavenSession session )
throws PluginLoaderException
{
ReportPlugin plugin = new ReportPlugin();
plugin.setGroupId( mojoBinding.getGroupId() );
plugin.setArtifactId( mojoBinding.getArtifactId() );
plugin.setVersion( mojoBinding.getVersion() );
PluginDescriptor pluginDescriptor = loadReportPlugin( plugin, project, session );
mojoBinding.setVersion( pluginDescriptor.getVersion() );
return pluginDescriptor;
}
/**
* Load the {@link PluginDescriptor} instance for the specified report plugin, using the project for
* the {@link ArtifactRepository} and other supplemental report/plugin information as necessary.
*/
public PluginDescriptor loadReportPlugin( ReportPlugin plugin, MavenProject project, MavenSession session )
throws PluginLoaderException
{
// TODO: Shouldn't we be injecting pluginManagement info here??
try
{
return pluginManager.verifyReportPlugin( plugin, project, session );
}
catch ( ArtifactResolutionException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( ArtifactNotFoundException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( PluginNotFoundException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( PluginVersionResolutionException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( InvalidPluginException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( PluginManagerException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( PluginVersionNotFoundException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
}
}

View File

@ -32,10 +32,16 @@ import java.util.Set;
import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathContext;
import org.apache.maven.ArtifactFilterManager; import org.apache.maven.ArtifactFilterManager;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ResolutionGroup; import org.apache.maven.artifact.metadata.ResolutionGroup;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.Metadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
@ -48,6 +54,7 @@ import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException
import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.RuntimeInformation; import org.apache.maven.execution.RuntimeInformation;
import org.apache.maven.lifecycle.model.MojoBinding;
import org.apache.maven.lifecycle.statemgmt.StateManagementUtils; import org.apache.maven.lifecycle.statemgmt.StateManagementUtils;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin; import org.apache.maven.model.Plugin;
@ -70,6 +77,7 @@ import org.apache.maven.project.builder.ProjectUri;
import org.apache.maven.project.path.PathTranslator; import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.realm.MavenRealmManager; import org.apache.maven.realm.MavenRealmManager;
import org.apache.maven.realm.RealmManagementException; import org.apache.maven.realm.RealmManagementException;
import org.apache.maven.realm.RealmScanningUtils;
import org.apache.maven.reporting.MavenReport; import org.apache.maven.reporting.MavenReport;
import org.apache.maven.repository.MavenRepositorySystem; import org.apache.maven.repository.MavenRepositorySystem;
import org.apache.maven.repository.VersionNotFoundException; import org.apache.maven.repository.VersionNotFoundException;
@ -92,6 +100,8 @@ import org.codehaus.plexus.component.repository.exception.ComponentRepositoryExc
import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.configuration.PlexusConfigurationException; import org.codehaus.plexus.configuration.PlexusConfigurationException;
import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom; import org.codehaus.plexus.util.xml.Xpp3Dom;
@ -127,9 +137,6 @@ public class DefaultPluginManager
@Requirement @Requirement
protected MavenPluginCollector pluginCollector; protected MavenPluginCollector pluginCollector;
@Requirement
protected PluginVersionManager pluginVersionManager;
@Requirement @Requirement
protected MavenRepositorySystem repositorySystem; protected MavenRepositorySystem repositorySystem;
@ -142,15 +149,16 @@ public class DefaultPluginManager
@Requirement @Requirement
protected MavenProjectBuilder mavenProjectBuilder; protected MavenProjectBuilder mavenProjectBuilder;
@Requirement
protected PluginMappingManager pluginMappingManager;
@Requirement
private PluginManagerSupport pluginManagerSupport;
@Requirement @Requirement
private Logger logger; private Logger logger;
@Requirement
protected RepositoryMetadataManager repositoryMetadataManager;
private Map pluginDefinitionsByPrefix = new HashMap();
private Context containerContext;
public DefaultPluginManager() public DefaultPluginManager()
{ {
pluginDescriptorBuilder = new PluginDescriptorBuilder(); pluginDescriptorBuilder = new PluginDescriptorBuilder();
@ -164,7 +172,7 @@ public class DefaultPluginManager
{ {
// TODO: since this is only used in the lifecycle executor, maybe it should be moved there? There is no other // TODO: since this is only used in the lifecycle executor, maybe it should be moved there? There is no other
// use for the mapping manager in here // use for the mapping manager in here
return pluginMappingManager.getByPrefix( prefix, session.getPluginGroups(), project.getRemoteArtifactRepositories(), session.getLocalRepository() ); return getByPrefix( prefix, session.getPluginGroups(), project.getRemoteArtifactRepositories(), session.getLocalRepository() );
} }
public PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, MavenSession session ) public PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, MavenSession session )
@ -179,7 +187,7 @@ public class DefaultPluginManager
if ( ( pluginVersion == null ) || Artifact.LATEST_VERSION.equals( pluginVersion ) || Artifact.RELEASE_VERSION.equals( pluginVersion ) ) if ( ( pluginVersion == null ) || Artifact.LATEST_VERSION.equals( pluginVersion ) || Artifact.RELEASE_VERSION.equals( pluginVersion ) )
{ {
logger.debug( "Resolving version for plugin: " + plugin.getKey() ); logger.debug( "Resolving version for plugin: " + plugin.getKey() );
pluginVersion = pluginVersionManager.resolvePluginVersion( plugin.getGroupId(), plugin.getArtifactId(), project, session ); pluginVersion = resolvePluginVersion( plugin.getGroupId(), plugin.getArtifactId(), project, session );
plugin.setVersion( pluginVersion ); plugin.setVersion( pluginVersion );
logger.debug( "Resolved to version: " + pluginVersion ); logger.debug( "Resolved to version: " + pluginVersion );
@ -204,7 +212,7 @@ public class DefaultPluginManager
// if the groupId is internal, don't try to resolve it... // if the groupId is internal, don't try to resolve it...
if ( !RESERVED_GROUP_IDS.contains( plugin.getGroupId() ) ) if ( !RESERVED_GROUP_IDS.contains( plugin.getGroupId() ) )
{ {
Artifact pluginArtifact = pluginManagerSupport.resolvePluginArtifact( plugin, project, session ); Artifact pluginArtifact = resolvePluginArtifact( plugin, project, session );
addPlugin( plugin, pluginArtifact, project, session ); addPlugin( plugin, pluginArtifact, project, session );
} }
@ -671,7 +679,7 @@ public class DefaultPluginManager
if ( version == null ) if ( version == null )
{ {
version = pluginVersionManager.resolveReportPluginVersion( reportPlugin.getGroupId(), reportPlugin.getArtifactId(), project, session ); version = resolveReportPluginVersion( reportPlugin.getGroupId(), reportPlugin.getArtifactId(), project, session );
reportPlugin.setVersion( version ); reportPlugin.setVersion( version );
} }
@ -1584,7 +1592,7 @@ public class DefaultPluginManager
plugin = new Plugin(); plugin = new Plugin();
plugin.setArtifactId( PluginDescriptor.getDefaultPluginArtifactId( prefix ) ); plugin.setArtifactId( PluginDescriptor.getDefaultPluginArtifactId( prefix ) );
PluginDescriptor pluginDescriptor = pluginManagerSupport.loadIsolatedPluginDescriptor( plugin, project, session ); PluginDescriptor pluginDescriptor = loadIsolatedPluginDescriptor( plugin, project, session );
plugin = toPlugin( pluginDescriptor ); plugin = toPlugin( pluginDescriptor );
} }
@ -1625,7 +1633,7 @@ public class DefaultPluginManager
{ {
Plugin plugin = (Plugin) it.next(); Plugin plugin = (Plugin) it.next();
PluginDescriptor pluginDescriptor = pluginManagerSupport.loadIsolatedPluginDescriptor( plugin, project, session ); PluginDescriptor pluginDescriptor = loadIsolatedPluginDescriptor( plugin, project, session );
if ( ( pluginDescriptor != null ) && prefix.equals( pluginDescriptor.getGoalPrefix() ) ) if ( ( pluginDescriptor != null ) && prefix.equals( pluginDescriptor.getGoalPrefix() ) )
{ {
@ -1644,7 +1652,7 @@ public class DefaultPluginManager
private Plugin loadFromPrefixMapper( String prefix, MavenProject project, MavenSession session ) private Plugin loadFromPrefixMapper( String prefix, MavenProject project, MavenSession session )
throws PluginLoaderException throws PluginLoaderException
{ {
Plugin plugin = pluginMappingManager.getByPrefix( prefix, session.getPluginGroups(), project.getRemoteArtifactRepositories(), session.getLocalRepository() ); Plugin plugin = getByPrefix( prefix, session.getPluginGroups(), project.getRemoteArtifactRepositories(), session.getLocalRepository() );
if ( plugin != null ) if ( plugin != null )
{ {
@ -1694,4 +1702,544 @@ public class DefaultPluginManager
{ {
executeMojo( session.getCurrentProject(), mojoExecution, session ); executeMojo( session.getCurrentProject(), mojoExecution, session );
} }
// Version Manager
public String resolvePluginVersion( String groupId, String artifactId, MavenProject project, MavenSession session )
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException
{
return resolvePluginVersion( groupId, artifactId, project, session.getLocalRepository(), false );
}
public String resolveReportPluginVersion( String groupId, String artifactId, MavenProject project, MavenSession session )
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException
{
return resolvePluginVersion( groupId, artifactId, project, session.getLocalRepository(), true );
}
private String resolvePluginVersion( String groupId, String artifactId, MavenProject project, ArtifactRepository localRepository, boolean resolveAsReportPlugin )
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException
{
// first pass...if the plugin is specified in the pom, try to retrieve the version from there.
String version = getVersionFromPluginConfig( groupId, artifactId, project, resolveAsReportPlugin );
// final pass...retrieve the version for RELEASE and also set that resolved version as the <useVersion/>
// in settings.xml.
if ( StringUtils.isEmpty( version ) || Artifact.RELEASE_VERSION.equals( version ) )
{
// 1. resolve the version to be used
version = resolveMetaVersion( groupId, artifactId, project, localRepository, Artifact.RELEASE_VERSION );
logger.debug( "Version from RELEASE metadata: " + version );
}
// if we still haven't found a version, then fail early before we get into the update goop.
if ( StringUtils.isEmpty( version ) )
{
throw new PluginVersionNotFoundException( groupId, artifactId );
}
return version;
}
private String getVersionFromPluginConfig( String groupId, String artifactId, MavenProject project, boolean resolveAsReportPlugin )
{
String version = null;
if ( resolveAsReportPlugin )
{
if ( project.getReportPlugins() != null )
{
for ( Iterator it = project.getReportPlugins().iterator(); it.hasNext() && ( version == null ); )
{
ReportPlugin plugin = (ReportPlugin) it.next();
if ( groupId.equals( plugin.getGroupId() ) && artifactId.equals( plugin.getArtifactId() ) )
{
version = plugin.getVersion();
}
}
}
}
else
{
if ( project.getBuildPlugins() != null )
{
for ( Iterator it = project.getBuildPlugins().iterator(); it.hasNext() && ( version == null ); )
{
Plugin plugin = (Plugin) it.next();
if ( groupId.equals( plugin.getGroupId() ) && artifactId.equals( plugin.getArtifactId() ) )
{
version = plugin.getVersion();
}
}
}
}
return version;
}
private String resolveMetaVersion( String groupId, String artifactId, MavenProject project, ArtifactRepository localRepository, String metaVersionId )
throws PluginVersionResolutionException, InvalidPluginException
{
logger.info( "Attempting to resolve a version for plugin: " + groupId + ":" + artifactId + " using meta-version: " + metaVersionId );
Artifact artifact = repositorySystem.createProjectArtifact( groupId, artifactId, metaVersionId );
String key = artifact.getDependencyConflictId();
String version = null;
// This takes the spec version and resolves a real version
try
{
ResolutionGroup resolutionGroup = repositorySystem.retrieve( artifact, localRepository, project.getRemoteArtifactRepositories() );
// switching this out with the actual resolved artifact instance, since the MMSource re-creates the pom
// artifact.
artifact = resolutionGroup.getPomArtifact();
}
catch ( ArtifactMetadataRetrievalException e )
{
throw new PluginVersionResolutionException( groupId, artifactId, e.getMessage(), e );
}
String artifactVersion = artifact.getVersion();
// make sure this artifact was transformed to a real version, and actually resolved to a file in the repo...
if ( !metaVersionId.equals( artifactVersion ) && ( artifact.getFile() != null ) )
{
boolean pluginValid = false;
while ( !pluginValid && ( artifactVersion != null ) )
{
pluginValid = true;
MavenProject pluginProject;
try
{
artifact = repositorySystem.createProjectArtifact( groupId, artifactId, artifactVersion );
pluginProject = mavenProjectBuilder.buildFromRepository( artifact, project.getRemoteArtifactRepositories(), localRepository );
}
catch ( ProjectBuildingException e )
{
throw new InvalidPluginException( "Unable to build project information for plugin '" + ArtifactUtils.versionlessKey( groupId, artifactId ) + "': " + e.getMessage(), e );
}
}
version = artifactVersion;
}
if ( version == null )
{
version = artifactVersion;
}
logger.info( "Using version: " + version + " of plugin: " + groupId + ":" + artifactId );
return version;
}
// Plugin Manager Support
public Artifact resolvePluginArtifact( Plugin plugin, MavenProject project, MavenSession session )
throws PluginManagerException, InvalidPluginException, PluginVersionResolutionException, ArtifactResolutionException, ArtifactNotFoundException
{
logger.debug( "Resolving plugin artifact " + plugin.getKey() + " from " + project.getRemoteArtifactRepositories() );
ArtifactRepository localRepository = session.getLocalRepository();
MavenProject pluginProject = buildPluginProject( plugin, localRepository, project.getRemoteArtifactRepositories() );
Artifact pluginArtifact = repositorySystem.createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() );
checkRequiredMavenVersion( plugin, pluginProject, localRepository, project.getRemoteArtifactRepositories() );
checkPluginDependencySpec( plugin, pluginProject );
pluginArtifact = project.replaceWithActiveArtifact( pluginArtifact );
ArtifactResolutionRequest request = new ArtifactResolutionRequest( pluginArtifact, localRepository, project.getRemoteArtifactRepositories() );
ArtifactResolutionResult result = repositorySystem.resolve( request );
resolutionErrorHandler.throwErrors( request, result );
return pluginArtifact;
}
public MavenProject buildPluginProject( Plugin plugin, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws InvalidPluginException
{
Artifact artifact = repositorySystem.createProjectArtifact( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() );
try
{
MavenProject p = mavenProjectBuilder.buildFromRepository( artifact, remoteRepositories, localRepository );
return p;
}
catch ( ProjectBuildingException e )
{
throw new InvalidPluginException( "Unable to build project for plugin '" + plugin.getKey() + "': " + e.getMessage(), e );
}
}
/**
* @param pluginProject
* @todo would be better to store this in the plugin descriptor, but then it won't be available
* to the version manager which executes before the plugin is instantiated
*/
public void checkRequiredMavenVersion( Plugin plugin, MavenProject pluginProject, ArtifactRepository localRepository, List remoteRepositories )
throws PluginVersionResolutionException, InvalidPluginException
{
// if we don't have the required Maven version, then ignore an update
if ( ( pluginProject.getPrerequisites() != null ) && ( pluginProject.getPrerequisites().getMaven() != null ) )
{
DefaultArtifactVersion requiredVersion = new DefaultArtifactVersion( pluginProject.getPrerequisites().getMaven() );
if ( runtimeInformation.getApplicationInformation().getVersion().compareTo( requiredVersion ) < 0 )
{
throw new PluginVersionResolutionException( plugin.getGroupId(), plugin.getArtifactId(), "Plugin requires Maven version " + requiredVersion );
}
}
}
public void checkPluginDependencySpec( Plugin plugin, MavenProject pluginProject )
throws InvalidPluginException
{
ArtifactFilter filter = new ScopeArtifactFilter( "runtime" );
try
{
repositorySystem.createArtifacts( pluginProject.getDependencies(), null, filter, pluginProject );
}
catch ( VersionNotFoundException e )
{
throw new InvalidPluginException( "Plugin: " + plugin.getKey() + " has a dependency with an invalid version." );
}
}
public PluginDescriptor loadIsolatedPluginDescriptor( Plugin plugin, MavenProject project, MavenSession session )
{
if ( plugin.getVersion() == null )
{
try
{
plugin.setVersion( resolvePluginVersion( plugin.getGroupId(), plugin.getArtifactId(), project, session ) );
}
catch ( PluginVersionResolutionException e )
{
logger.debug( "Failed to load plugin descriptor for: " + plugin.getKey(), e );
}
catch ( InvalidPluginException e )
{
logger.debug( "Failed to load plugin descriptor for: " + plugin.getKey(), e );
}
catch ( PluginVersionNotFoundException e )
{
logger.debug( "Failed to load plugin descriptor for: " + plugin.getKey(), e );
}
}
if ( plugin.getVersion() == null )
{
return null;
}
Artifact artifact = null;
try
{
artifact = resolvePluginArtifact( plugin, project, session );
}
catch ( ArtifactResolutionException e )
{
logger.debug( "Failed to load plugin descriptor for: " + plugin.getKey(), e );
}
catch ( ArtifactNotFoundException e )
{
logger.debug( "Failed to load plugin descriptor for: " + plugin.getKey(), e );
}
catch ( PluginManagerException e )
{
logger.debug( "Failed to load plugin descriptor for: " + plugin.getKey(), e );
}
catch ( InvalidPluginException e )
{
logger.debug( "Failed to load plugin descriptor for: " + plugin.getKey(), e );
}
catch ( PluginVersionResolutionException e )
{
logger.debug( "Failed to load plugin descriptor for: " + plugin.getKey(), e );
}
if ( artifact == null )
{
return null;
}
MavenPluginDiscoverer discoverer = new MavenPluginDiscoverer();
discoverer.setManager( RealmScanningUtils.getDummyComponentDiscovererManager() );
try
{
List componentSetDescriptors = RealmScanningUtils.scanForComponentSetDescriptors( artifact, discoverer, containerContext, "Plugin: " + plugin.getKey() );
if ( !componentSetDescriptors.isEmpty() )
{
return (PluginDescriptor) componentSetDescriptors.get( 0 );
}
}
catch ( RealmManagementException e )
{
logger.debug( "Failed to scan plugin artifact: " + artifact.getId() + " for descriptors.", e );
}
return null;
}
public void contextualize( Context context )
throws ContextException
{
containerContext = context;
}
// Plugin Mapping Manager
public org.apache.maven.model.Plugin getByPrefix( String pluginPrefix, List groupIds, List pluginRepositories,
ArtifactRepository localRepository )
{
// if not found, try from the remote repository
if ( !pluginDefinitionsByPrefix.containsKey( pluginPrefix ) )
{
logger.info( "Searching repository for plugin with prefix: \'" + pluginPrefix + "\'." );
loadPluginMappings( groupIds, pluginRepositories, localRepository );
}
org.apache.maven.model.Plugin result = (org.apache.maven.model.Plugin) pluginDefinitionsByPrefix.get( pluginPrefix );
if ( result == null )
{
logger.debug( "Failed to resolve plugin from prefix: " + pluginPrefix, new Throwable() );
}
return result;
}
private void loadPluginMappings( List groupIds, List pluginRepositories, ArtifactRepository localRepository )
{
List pluginGroupIds = new ArrayList( groupIds );
// TODO: use constant
if ( !pluginGroupIds.contains( "org.apache.maven.plugins" ) )
{
pluginGroupIds.add( "org.apache.maven.plugins" );
}
if ( !pluginGroupIds.contains( "org.codehaus.mojo" ) )
{
pluginGroupIds.add( "org.codehaus.mojo" );
}
for ( Iterator it = pluginGroupIds.iterator(); it.hasNext(); )
{
String groupId = (String) it.next();
logger.debug( "Loading plugin prefixes from group: " + groupId );
try
{
loadPluginMappings( groupId, pluginRepositories, localRepository );
}
catch ( RepositoryMetadataResolutionException e )
{
logger.warn( "Cannot resolve plugin-mapping metadata for groupId: " + groupId + " - IGNORING." );
logger.debug( "Error resolving plugin-mapping metadata for groupId: " + groupId + ".", e );
}
}
}
private void loadPluginMappings( String groupId, List pluginRepositories, ArtifactRepository localRepository )
throws RepositoryMetadataResolutionException
{
RepositoryMetadata metadata = new GroupRepositoryMetadata( groupId );
logger.debug( "Checking repositories:\n" + pluginRepositories + "\n\nfor plugin prefix metadata: " + groupId );
repositoryMetadataManager.resolve( metadata, pluginRepositories, localRepository );
Metadata repoMetadata = metadata.getMetadata();
if ( repoMetadata != null )
{
for ( Iterator pluginIterator = repoMetadata.getPlugins().iterator(); pluginIterator.hasNext(); )
{
org.apache.maven.artifact.repository.metadata.Plugin mapping = (org.apache.maven.artifact.repository.metadata.Plugin) pluginIterator.next();
logger.debug( "Found plugin: " + mapping.getName() + " with prefix: " + mapping.getPrefix() );
String prefix = mapping.getPrefix();
//if the prefix has already been found, don't add it again.
//this is to preserve the correct ordering of prefix searching (MNG-2926)
if ( !pluginDefinitionsByPrefix.containsKey( prefix ) )
{
String artifactId = mapping.getArtifactId();
org.apache.maven.model.Plugin plugin = new org.apache.maven.model.Plugin();
plugin.setGroupId( metadata.getGroupId() );
plugin.setArtifactId( artifactId );
pluginDefinitionsByPrefix.put( prefix, plugin );
}
}
}
}
// Plugin Loader
/**
* Load the {@link PluginDescriptor} instance for the plugin implied by the specified MojoBinding,
* using the project for {@link ArtifactRepository} and other supplemental plugin information as
* necessary.
*/
public PluginDescriptor loadPlugin( MojoBinding mojoBinding, MavenProject project, MavenSession session )
throws PluginLoaderException
{
PluginDescriptor pluginDescriptor = null;
Plugin plugin = new Plugin();
plugin.setGroupId( mojoBinding.getGroupId() );
plugin.setArtifactId( mojoBinding.getArtifactId() );
plugin.setVersion( mojoBinding.getVersion() );
pluginDescriptor = loadPlugin( plugin, project, session );
// fill in any blanks once we know more about this plugin.
if ( pluginDescriptor != null )
{
mojoBinding.setGroupId( pluginDescriptor.getGroupId() );
mojoBinding.setArtifactId( pluginDescriptor.getArtifactId() );
mojoBinding.setVersion( pluginDescriptor.getVersion() );
}
return pluginDescriptor;
}
/**
* Load the {@link PluginDescriptor} instance for the specified plugin, using the project for
* the {@link ArtifactRepository} and other supplemental plugin information as necessary.
*/
public PluginDescriptor loadPlugin( Plugin plugin, MavenProject project, MavenSession session )
throws PluginLoaderException
{
if ( plugin.getGroupId() == null )
{
plugin.setGroupId( PluginDescriptor.getDefaultPluginGroupId() );
}
try
{
PluginDescriptor result = verifyPlugin( plugin, project, session );
// this has been simplified from the old code that injected the plugin management stuff, since
// pluginManagement injection is now handled by the project method.
project.addPlugin( plugin );
return result;
}
catch ( ArtifactResolutionException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( ArtifactNotFoundException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( PluginNotFoundException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( PluginVersionResolutionException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( InvalidPluginException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( PluginManagerException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( PluginVersionNotFoundException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
}
public void enableLogging( Logger logger )
{
this.logger = logger;
}
/**
* Load the {@link PluginDescriptor} instance for the report plugin implied by the specified MojoBinding,
* using the project for {@link ArtifactRepository} and other supplemental report/plugin information as
* necessary.
*/
public PluginDescriptor loadReportPlugin( MojoBinding mojoBinding, MavenProject project, MavenSession session )
throws PluginLoaderException
{
ReportPlugin plugin = new ReportPlugin();
plugin.setGroupId( mojoBinding.getGroupId() );
plugin.setArtifactId( mojoBinding.getArtifactId() );
plugin.setVersion( mojoBinding.getVersion() );
PluginDescriptor pluginDescriptor = loadReportPlugin( plugin, project, session );
mojoBinding.setVersion( pluginDescriptor.getVersion() );
return pluginDescriptor;
}
/**
* Load the {@link PluginDescriptor} instance for the specified report plugin, using the project for
* the {@link ArtifactRepository} and other supplemental report/plugin information as necessary.
*/
public PluginDescriptor loadReportPlugin( ReportPlugin plugin, MavenProject project, MavenSession session )
throws PluginLoaderException
{
// TODO: Shouldn't we be injecting pluginManagement info here??
try
{
return verifyReportPlugin( plugin, project, session );
}
catch ( ArtifactResolutionException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( ArtifactNotFoundException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( PluginNotFoundException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( PluginVersionResolutionException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( InvalidPluginException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( PluginManagerException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
catch ( PluginVersionNotFoundException e )
{
throw new PluginLoaderException( plugin, "Failed to load plugin. Reason: " + e.getMessage(), e );
}
}
} }

View File

@ -1,237 +0,0 @@
package org.apache.maven.plugin;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.util.List;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ResolutionErrorHandler;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
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.model.Plugin;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.realm.RealmManagementException;
import org.apache.maven.realm.RealmScanningUtils;
import org.apache.maven.repository.MavenRepositorySystem;
import org.apache.maven.repository.VersionNotFoundException;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
@Component(role = PluginManagerSupport.class)
public class DefaultPluginManagerSupport
implements PluginManagerSupport, Contextualizable
{
@Requirement
private MavenRepositorySystem repositorySystem;
@Requirement
private ResolutionErrorHandler resolutionErrorHandler;
@Requirement
private MavenProjectBuilder mavenProjectBuilder;
@Requirement
private RuntimeInformation runtimeInformation;
@Requirement
private PluginVersionManager pluginVersionManager;
@Requirement
private Logger logger;
private Context containerContext;
public Artifact resolvePluginArtifact( Plugin plugin, MavenProject project, MavenSession session )
throws PluginManagerException, InvalidPluginException, PluginVersionResolutionException, ArtifactResolutionException, ArtifactNotFoundException
{
logger.debug( "Resolving plugin artifact " + plugin.getKey() + " from "
+ project.getRemoteArtifactRepositories() );
ArtifactRepository localRepository = session.getLocalRepository();
MavenProject pluginProject = buildPluginProject( plugin, localRepository, project.getRemoteArtifactRepositories() );
Artifact pluginArtifact = repositorySystem.createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() );
checkRequiredMavenVersion( plugin, pluginProject, localRepository, project.getRemoteArtifactRepositories() );
checkPluginDependencySpec( plugin, pluginProject );
pluginArtifact = project.replaceWithActiveArtifact( pluginArtifact );
ArtifactResolutionRequest request = new ArtifactResolutionRequest( pluginArtifact, localRepository, project.getRemoteArtifactRepositories() );
ArtifactResolutionResult result = repositorySystem.resolve( request );
resolutionErrorHandler.throwErrors( request, result );
return pluginArtifact;
}
public MavenProject buildPluginProject( Plugin plugin, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws InvalidPluginException
{
Artifact artifact = repositorySystem.createProjectArtifact( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() );
try
{
MavenProject p = mavenProjectBuilder.buildFromRepository( artifact, remoteRepositories, localRepository );
return p;
}
catch ( ProjectBuildingException e )
{
throw new InvalidPluginException( "Unable to build project for plugin '" + plugin.getKey() + "': " + e.getMessage(), e );
}
}
/**
* @param pluginProject
* @todo would be better to store this in the plugin descriptor, but then it won't be available to the version
* manager which executes before the plugin is instantiated
*/
public void checkRequiredMavenVersion( Plugin plugin, MavenProject pluginProject, ArtifactRepository localRepository, List remoteRepositories )
throws PluginVersionResolutionException, InvalidPluginException
{
// if we don't have the required Maven version, then ignore an update
if ( ( pluginProject.getPrerequisites() != null ) && ( pluginProject.getPrerequisites().getMaven() != null ) )
{
DefaultArtifactVersion requiredVersion = new DefaultArtifactVersion( pluginProject.getPrerequisites().getMaven() );
if ( runtimeInformation.getApplicationInformation().getVersion().compareTo( requiredVersion ) < 0 )
{
throw new PluginVersionResolutionException( plugin.getGroupId(), plugin.getArtifactId(), "Plugin requires Maven version " + requiredVersion );
}
}
}
public void checkPluginDependencySpec( Plugin plugin, MavenProject pluginProject )
throws InvalidPluginException
{
ArtifactFilter filter = new ScopeArtifactFilter( "runtime" );
try
{
repositorySystem.createArtifacts( pluginProject.getDependencies(), null, filter, pluginProject );
}
catch ( VersionNotFoundException e )
{
throw new InvalidPluginException( "Plugin: " + plugin.getKey() + " has a dependency with an invalid version." );
}
}
public PluginDescriptor loadIsolatedPluginDescriptor( Plugin plugin, MavenProject project, MavenSession session )
{
if ( plugin.getVersion() == null )
{
try
{
plugin.setVersion( pluginVersionManager.resolvePluginVersion( plugin.getGroupId(), plugin.getArtifactId(), project, session ) );
}
catch ( PluginVersionResolutionException e )
{
logger.debug( "Failed to load plugin descriptor for: " + plugin.getKey(), e );
}
catch ( InvalidPluginException e )
{
logger.debug( "Failed to load plugin descriptor for: " + plugin.getKey(), e );
}
catch ( PluginVersionNotFoundException e )
{
logger.debug( "Failed to load plugin descriptor for: " + plugin.getKey(), e );
}
}
if ( plugin.getVersion() == null )
{
return null;
}
Artifact artifact = null;
try
{
artifact = resolvePluginArtifact( plugin, project, session );
}
catch ( ArtifactResolutionException e )
{
logger.debug( "Failed to load plugin descriptor for: " + plugin.getKey(), e );
}
catch ( ArtifactNotFoundException e )
{
logger.debug( "Failed to load plugin descriptor for: " + plugin.getKey(), e );
}
catch ( PluginManagerException e )
{
logger.debug( "Failed to load plugin descriptor for: " + plugin.getKey(), e );
}
catch ( InvalidPluginException e )
{
logger.debug( "Failed to load plugin descriptor for: " + plugin.getKey(), e );
}
catch ( PluginVersionResolutionException e )
{
logger.debug( "Failed to load plugin descriptor for: " + plugin.getKey(), e );
}
if ( artifact == null )
{
return null;
}
MavenPluginDiscoverer discoverer = new MavenPluginDiscoverer();
discoverer.setManager( RealmScanningUtils.getDummyComponentDiscovererManager() );
try
{
List componentSetDescriptors = RealmScanningUtils.scanForComponentSetDescriptors( artifact, discoverer, containerContext, "Plugin: " + plugin.getKey() );
if ( !componentSetDescriptors.isEmpty() )
{
return (PluginDescriptor) componentSetDescriptors.get( 0 );
}
}
catch ( RealmManagementException e )
{
logger.debug( "Failed to scan plugin artifact: " + artifact.getId()
+ " for descriptors.", e );
}
return null;
}
public void contextualize( Context context )
throws ContextException
{
containerContext = context;
}
}

View File

@ -1,145 +0,0 @@
package org.apache.maven.plugin;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.Metadata;
import org.apache.maven.artifact.repository.metadata.Plugin;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* Manage plugin prefix to artifact ID mapping associations.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
@Component(role = PluginMappingManager.class)
public class DefaultPluginMappingManager
implements PluginMappingManager
{
@Requirement
private Logger logger;
@Requirement
protected RepositoryMetadataManager repositoryMetadataManager;
private Map pluginDefinitionsByPrefix = new HashMap();
public org.apache.maven.model.Plugin getByPrefix( String pluginPrefix, List groupIds, List pluginRepositories,
ArtifactRepository localRepository )
{
// if not found, try from the remote repository
if ( !pluginDefinitionsByPrefix.containsKey( pluginPrefix ) )
{
logger.info( "Searching repository for plugin with prefix: \'" + pluginPrefix + "\'." );
loadPluginMappings( groupIds, pluginRepositories, localRepository );
}
org.apache.maven.model.Plugin result = (org.apache.maven.model.Plugin) pluginDefinitionsByPrefix.get( pluginPrefix );
if ( result == null )
{
logger.debug( "Failed to resolve plugin from prefix: " + pluginPrefix, new Throwable() );
}
return result;
}
private void loadPluginMappings( List groupIds, List pluginRepositories, ArtifactRepository localRepository )
{
List pluginGroupIds = new ArrayList( groupIds );
// TODO: use constant
if ( !pluginGroupIds.contains( "org.apache.maven.plugins" ) )
{
pluginGroupIds.add( "org.apache.maven.plugins" );
}
if ( !pluginGroupIds.contains( "org.codehaus.mojo" ) )
{
pluginGroupIds.add( "org.codehaus.mojo" );
}
for ( Iterator it = pluginGroupIds.iterator(); it.hasNext(); )
{
String groupId = (String) it.next();
logger.debug( "Loading plugin prefixes from group: " + groupId );
try
{
loadPluginMappings( groupId, pluginRepositories, localRepository );
}
catch ( RepositoryMetadataResolutionException e )
{
logger.warn( "Cannot resolve plugin-mapping metadata for groupId: " + groupId + " - IGNORING." );
logger.debug( "Error resolving plugin-mapping metadata for groupId: " + groupId + ".", e );
}
}
}
private void loadPluginMappings( String groupId, List pluginRepositories, ArtifactRepository localRepository )
throws RepositoryMetadataResolutionException
{
RepositoryMetadata metadata = new GroupRepositoryMetadata( groupId );
logger.debug( "Checking repositories:\n" + pluginRepositories + "\n\nfor plugin prefix metadata: " + groupId );
repositoryMetadataManager.resolve( metadata, pluginRepositories, localRepository );
Metadata repoMetadata = metadata.getMetadata();
if ( repoMetadata != null )
{
for ( Iterator pluginIterator = repoMetadata.getPlugins().iterator(); pluginIterator.hasNext(); )
{
Plugin mapping = (Plugin) pluginIterator.next();
logger.debug( "Found plugin: " + mapping.getName() + " with prefix: " + mapping.getPrefix() );
String prefix = mapping.getPrefix();
//if the prefix has already been found, don't add it again.
//this is to preserve the correct ordering of prefix searching (MNG-2926)
if ( !pluginDefinitionsByPrefix.containsKey( prefix ) )
{
String artifactId = mapping.getArtifactId();
org.apache.maven.model.Plugin plugin = new org.apache.maven.model.Plugin();
plugin.setGroupId( metadata.getGroupId() );
plugin.setArtifactId( artifactId );
pluginDefinitionsByPrefix.put( prefix, plugin );
}
}
}
}
}

View File

@ -1,297 +0,0 @@
package org.apache.maven.plugin;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.util.Iterator;
import java.util.List;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ResolutionGroup;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.Restriction;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.RuntimeInformation;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.repository.MavenRepositorySystem;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.StringUtils;
@Component(role = PluginVersionManager.class)
public class DefaultPluginVersionManager
implements PluginVersionManager
{
@Requirement
private Logger logger;
@Requirement
private MavenRepositorySystem repositoryTools;
@Requirement
private MavenProjectBuilder mavenProjectBuilder;
@Requirement
private RuntimeInformation runtimeInformation;
public String resolvePluginVersion( String groupId, String artifactId, MavenProject project, MavenSession session )
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException
{
return resolvePluginVersion( groupId, artifactId, project, session.getLocalRepository(), false );
}
public String resolveReportPluginVersion( String groupId, String artifactId, MavenProject project, MavenSession session )
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException
{
return resolvePluginVersion( groupId, artifactId, project, session.getLocalRepository(), true );
}
private String resolvePluginVersion( String groupId, String artifactId, MavenProject project, ArtifactRepository localRepository, boolean resolveAsReportPlugin )
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException
{
// first pass...if the plugin is specified in the pom, try to retrieve the version from there.
String version = getVersionFromPluginConfig( groupId, artifactId, project, resolveAsReportPlugin );
logger.debug( "Version from POM: " + version );
// NOTE: We CANNOT check the current project version here, so delay it until later.
// It will prevent plugins from building themselves, if they are part of the lifecycle mapping.
// if there was no explicit version, try for one in the reactor
if ( version == null )
{
if ( project.getProjectReferences() != null )
{
String refId = ArtifactUtils.versionlessKey( groupId, artifactId );
MavenProject ref = (MavenProject) project.getProjectReferences().get( refId );
if ( ref != null )
{
version = ref.getVersion();
}
}
}
logger.debug( "Version from another POM in the reactor: " + version );
// third pass...we're always checking for latest install/deploy, so retrieve the version for LATEST metadata and
// also set that resolved version as the <useVersion/> in settings.xml.
if ( StringUtils.isEmpty( version ) || Artifact.LATEST_VERSION.equals( version ) )
{
// 1. resolve the version to be used
version = resolveMetaVersion( groupId, artifactId, project, localRepository, Artifact.LATEST_VERSION );
logger.debug( "Version from LATEST metadata: " + version );
}
// final pass...retrieve the version for RELEASE and also set that resolved version as the <useVersion/>
// in settings.xml.
if ( StringUtils.isEmpty( version ) || Artifact.RELEASE_VERSION.equals( version ) )
{
// 1. resolve the version to be used
version = resolveMetaVersion( groupId, artifactId, project, localRepository, Artifact.RELEASE_VERSION );
logger.debug( "Version from RELEASE metadata: " + version );
}
// if we still haven't found a version, then fail early before we get into the update goop.
if ( StringUtils.isEmpty( version ) )
{
throw new PluginVersionNotFoundException( groupId, artifactId );
}
return version;
}
private String getVersionFromPluginConfig( String groupId, String artifactId, MavenProject project, boolean resolveAsReportPlugin )
{
String version = null;
if ( resolveAsReportPlugin )
{
if ( project.getReportPlugins() != null )
{
for ( Iterator it = project.getReportPlugins().iterator(); it.hasNext() && ( version == null ); )
{
ReportPlugin plugin = (ReportPlugin) it.next();
if ( groupId.equals( plugin.getGroupId() ) && artifactId.equals( plugin.getArtifactId() ) )
{
version = plugin.getVersion();
}
}
}
}
else
{
if ( project.getBuildPlugins() != null )
{
for ( Iterator it = project.getBuildPlugins().iterator(); it.hasNext() && ( version == null ); )
{
Plugin plugin = (Plugin) it.next();
if ( groupId.equals( plugin.getGroupId() ) && artifactId.equals( plugin.getArtifactId() ) )
{
version = plugin.getVersion();
}
}
}
}
return version;
}
private String resolveMetaVersion( String groupId, String artifactId, MavenProject project, ArtifactRepository localRepository, String metaVersionId )
throws PluginVersionResolutionException, InvalidPluginException
{
logger.info( "Attempting to resolve a version for plugin: " + groupId + ":" + artifactId + " using meta-version: " + metaVersionId );
Artifact artifact = repositoryTools.createProjectArtifact( groupId, artifactId, metaVersionId );
String key = artifact.getDependencyConflictId();
String version = null;
// This takes the spec version and resolves a real version
try
{
ResolutionGroup resolutionGroup = repositoryTools.retrieve( artifact, localRepository, project.getRemoteArtifactRepositories() );
// switching this out with the actual resolved artifact instance, since the MMSource re-creates the pom
// artifact.
artifact = resolutionGroup.getPomArtifact();
}
catch ( ArtifactMetadataRetrievalException e )
{
throw new PluginVersionResolutionException( groupId, artifactId, e.getMessage(), e );
}
String artifactVersion = artifact.getVersion();
// make sure this artifact was transformed to a real version, and actually resolved to a file in the repo...
if ( !metaVersionId.equals( artifactVersion ) && ( artifact.getFile() != null ) )
{
boolean pluginValid = false;
while ( !pluginValid && ( artifactVersion != null ) )
{
pluginValid = true;
MavenProject pluginProject;
try
{
artifact = repositoryTools.createProjectArtifact( groupId, artifactId, artifactVersion );
pluginProject = mavenProjectBuilder.buildFromRepository( artifact, project.getRemoteArtifactRepositories(), localRepository );
}
catch ( ProjectBuildingException e )
{
throw new InvalidPluginException( "Unable to build project information for plugin '" +
ArtifactUtils.versionlessKey( groupId, artifactId ) + "': " + e.getMessage(), e );
}
// if we don't have the required Maven version, then ignore an update
if ( ( pluginProject.getPrerequisites() != null ) && ( pluginProject.getPrerequisites().getMaven() != null ) )
{
String mavenVersion = pluginProject.getPrerequisites().getMaven();
VersionRange mavenRange = null;
try
{
mavenRange = VersionRange.createFromVersionSpec( mavenVersion );
List restrictions = mavenRange.getRestrictions();
if ( ( restrictions.size() == 1 ) && Restriction.EVERYTHING.equals( restrictions.get( 0 ) ) )
{
String range = "[" + mavenVersion + ",]";
logger.debug( "Plugin: "
+ pluginProject.getId()
+ " specifies a simple prerequisite Maven version of: "
+ mavenVersion
+ ". This version has been translated into the range: "
+ range + " for plugin-version resolution purposes." );
mavenRange = VersionRange.createFromVersionSpec( range );
}
}
catch ( InvalidVersionSpecificationException e )
{
logger.debug( "Invalid prerequisite Maven version: " + mavenVersion + " for plugin: " + pluginProject.getId() + e.getMessage() );
}
if ( ( mavenRange != null ) && !mavenRange.containsVersion( runtimeInformation.getApplicationInformation().getVersion() ) )
{
logger.info( "Ignoring available plugin version: " + artifactVersion + " for: " + groupId + ":" + artifactId + " as it requires Maven version matching: " + mavenVersion );
VersionRange vr;
try
{
vr = VersionRange.createFromVersionSpec( "(," + artifactVersion + ")" );
}
catch ( InvalidVersionSpecificationException e )
{
throw new PluginVersionResolutionException( groupId, artifactId, "Error getting available plugin versions: " + e.getMessage(), e );
}
logger.debug( "Trying " + vr );
try
{
List versions = repositoryTools.retrieveAvailableVersions( artifact, localRepository, project.getRemoteArtifactRepositories() );
ArtifactVersion v = vr.matchVersion( versions );
artifactVersion = v != null ? v.toString() : null;
}
catch ( ArtifactMetadataRetrievalException e )
{
throw new PluginVersionResolutionException( groupId, artifactId, "Error getting available plugin versions: " + e.getMessage(), e );
}
if ( artifactVersion != null )
{
logger.debug( "Found " + artifactVersion );
}
else
{
pluginValid = false;
}
}
}
}
version = artifactVersion;
}
if( version == null )
{
version = artifactVersion;
}
logger.info( "Using version: " + version + " of plugin: " + groupId + ":" + artifactId );
return version;
}
}

View File

@ -1,51 +0,0 @@
package org.apache.maven.plugin;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.model.MojoBinding;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
/**
* Responsible for loading plugins, reports, and any components contained therein. Will resolve
* plugin versions and plugin prefixes as necessary for plugin resolution.
*
* @author jdcasey
*
*/
public interface PluginLoader
{
/**
* Load the {@link PluginDescriptor} instance for the specified plugin, using the project for
* the {@link ArtifactRepository} and other supplemental plugin information as necessary.
*/
PluginDescriptor loadPlugin( Plugin plugin, MavenProject project, MavenSession session )
throws PluginLoaderException;
/**
* Load the {@link PluginDescriptor} instance for the plugin implied by the specified MojoBinding,
* using the project for {@link ArtifactRepository} and other supplemental plugin information as
* necessary.
*/
PluginDescriptor loadPlugin( MojoBinding mojoBinding, MavenProject project, MavenSession session )
throws PluginLoaderException;
/**
* Load the {@link PluginDescriptor} instance for the specified report plugin, using the project for
* the {@link ArtifactRepository} and other supplemental report/plugin information as necessary.
*/
PluginDescriptor loadReportPlugin( ReportPlugin reportPlugin, MavenProject project, MavenSession session )
throws PluginLoaderException;
/**
* Load the {@link PluginDescriptor} instance for the report plugin implied by the specified MojoBinding,
* using the project for {@link ArtifactRepository} and other supplemental report/plugin information as
* necessary.
*/
PluginDescriptor loadReportPlugin( MojoBinding mojoBinding, MavenProject project, MavenSession session )
throws PluginLoaderException;
}

View File

@ -20,6 +20,7 @@ import java.util.Collection;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.model.MojoBinding;
import org.apache.maven.model.Plugin; import org.apache.maven.model.Plugin;
import org.apache.maven.model.ReportPlugin; import org.apache.maven.model.ReportPlugin;
import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor;
@ -60,4 +61,37 @@ public interface PluginManager
void executeMojo( MojoExecution mojoExecution, MavenSession session ) void executeMojo( MojoExecution mojoExecution, MavenSession session )
throws Exception; throws Exception;
// Plugin Loader
/**
* Load the {@link PluginDescriptor} instance for the specified plugin, using the project for
* the {@link ArtifactRepository} and other supplemental plugin information as necessary.
*/
PluginDescriptor loadPlugin( Plugin plugin, MavenProject project, MavenSession session )
throws PluginLoaderException;
/**
* Load the {@link PluginDescriptor} instance for the plugin implied by the specified MojoBinding,
* using the project for {@link ArtifactRepository} and other supplemental plugin information as
* necessary.
*/
PluginDescriptor loadPlugin( MojoBinding mojoBinding, MavenProject project, MavenSession session )
throws PluginLoaderException;
/**
* Load the {@link PluginDescriptor} instance for the specified report plugin, using the project for
* the {@link ArtifactRepository} and other supplemental report/plugin information as necessary.
*/
PluginDescriptor loadReportPlugin( ReportPlugin reportPlugin, MavenProject project, MavenSession session )
throws PluginLoaderException;
/**
* Load the {@link PluginDescriptor} instance for the report plugin implied by the specified MojoBinding,
* using the project for {@link ArtifactRepository} and other supplemental report/plugin information as
* necessary.
*/
PluginDescriptor loadReportPlugin( MojoBinding mojoBinding, MavenProject project, MavenSession session )
throws PluginLoaderException;
} }

View File

@ -1,35 +0,0 @@
package org.apache.maven.plugin;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import java.util.List;
public interface PluginManagerSupport
{
Artifact resolvePluginArtifact( Plugin plugin, MavenProject project, MavenSession session )
throws PluginManagerException, InvalidPluginException, PluginVersionResolutionException, ArtifactResolutionException, ArtifactNotFoundException;
MavenProject buildPluginProject( Plugin plugin, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws InvalidPluginException;
/**
* @param pluginProject
* @todo would be better to store this in the plugin descriptor, but then it won't be available to the version
* manager which executes before the plugin is instantiated
*/
void checkRequiredMavenVersion( Plugin plugin, MavenProject pluginProject, ArtifactRepository localRepository, List remoteRepositories )
throws PluginVersionResolutionException, InvalidPluginException;
void checkPluginDependencySpec( Plugin plugin, MavenProject pluginProject )
throws InvalidPluginException;
PluginDescriptor loadIsolatedPluginDescriptor( Plugin plugin, MavenProject project, MavenSession session );
}

View File

@ -1,35 +0,0 @@
package org.apache.maven.plugin;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Plugin;
import java.util.List;
/**
* Manage plugin prefix to artifact ID mapping associations.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
*/
public interface PluginMappingManager
{
Plugin getByPrefix( String pluginPrefix, List groupIds, List pluginRepositories, ArtifactRepository localRepository );
}

View File

@ -1,34 +0,0 @@
package org.apache.maven.plugin;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
public interface PluginVersionManager
{
String ROLE = PluginVersionManager.class.getName();
String resolvePluginVersion( String groupId, String artifactId, MavenProject project, MavenSession session )
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException;
String resolveReportPluginVersion( String groupId, String artifactId, MavenProject project, MavenSession session )
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException;
}

View File

@ -42,7 +42,7 @@ use a configuration source to pull in the lifecycle information.
<implementation>org.apache.maven.lifecycle.binding.DefaultLifecycleBindingManager</implementation> <implementation>org.apache.maven.lifecycle.binding.DefaultLifecycleBindingManager</implementation>
<requirements> <requirements>
<requirement> <requirement>
<role>org.apache.maven.plugin.PluginLoader</role> <role>org.apache.maven.plugin.PluginManager</role>
</requirement> </requirement>
<requirement> <requirement>
<role>org.apache.maven.lifecycle.LifecycleBindingLoader</role> <role>org.apache.maven.lifecycle.LifecycleBindingLoader</role>

View File

@ -1,200 +0,0 @@
package org.apache.maven.lifecycle.plan;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.MojoBindingUtils;
import org.apache.maven.lifecycle.model.MojoBinding;
import org.apache.maven.lifecycle.plan.testutils.TestPluginLoader;
import org.apache.maven.model.Build;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.plugin.PluginLoader;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.realm.DefaultMavenRealmManager;
import org.apache.maven.realm.MavenRealmManager;
import org.apache.maven.shared.tools.easymock.MockManager;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.easymock.MockControl;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Stack;
public class DefaultBuildPlannerTest
extends PlexusTestCase
{
private DefaultBuildPlanner buildPlanner;
private TestPluginLoader pluginLoader;
private MockManager mockManager = new MockManager();
protected void setUp()
throws Exception
{
super.setUp();
buildPlanner = (DefaultBuildPlanner) lookup( BuildPlanner.class );
pluginLoader = (TestPluginLoader) lookup( PluginLoader.class );
}
public void test_constructBuildPlan_ForkedPhaseFromMojoBoundInThatPhase()
throws Exception
{
Model model = new Model();
Build build = new Build();
model.setBuild( build );
Plugin plugin = new Plugin();
plugin.setGroupId( "org.apache.maven.plugins" );
plugin.setArtifactId( "maven-assembly-plugin" );
plugin.setVersion( "1" );
build.addPlugin( plugin );
PluginExecution exec = new PluginExecution();
exec.setId( "assembly" );
exec.setPhase( "package" );
exec.addGoal( "assembly" );
plugin.addExecution( exec );
PluginDescriptor pd = TestPluginLoader.createPluginDescriptor( plugin.getArtifactId(),
"assembly",
plugin.getGroupId(),
plugin.getVersion() );
MojoDescriptor md = TestPluginLoader.createMojoDescriptor( pd, "assembly" );
md.setExecutePhase( "package" );
pluginLoader.addPluginDescriptor( pd );
MavenProject project = new MavenProject( model );
MavenRealmManager realmManager = new DefaultMavenRealmManager( getContainer(), new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );
MavenExecutionRequest request = new DefaultMavenExecutionRequest().setRealmManager( realmManager );
MavenSession session = new MavenSession( getContainer(), request, null, null );
BuildPlan plan = buildPlanner.constructBuildPlan( Collections.singletonList( "package" ),
project,
session,
false );
List rendered = plan.renderExecutionPlan( new Stack() );
List checkIds = new ArrayList();
checkIds.add( "org.apache.maven.plugins:maven-resources-plugin:resources" );
checkIds.add( "org.apache.maven.plugins:maven-compiler-plugin:compile" );
checkIds.add( "org.apache.maven.plugins:maven-resources-plugin:testResources" );
checkIds.add( "org.apache.maven.plugins:maven-compiler-plugin:testCompile" );
checkIds.add( "org.apache.maven.plugins:maven-surefire-plugin:test" );
checkIds.add( "org.apache.maven.plugins:maven-jar-plugin:jar" );
checkIds.add( "org.apache.maven.plugins.internal:maven-state-management:2.1:start-fork" );
checkIds.add( "org.apache.maven.plugins:maven-resources-plugin:resources" );
checkIds.add( "org.apache.maven.plugins:maven-compiler-plugin:compile" );
checkIds.add( "org.apache.maven.plugins:maven-resources-plugin:testResources" );
checkIds.add( "org.apache.maven.plugins:maven-compiler-plugin:testCompile" );
checkIds.add( "org.apache.maven.plugins:maven-surefire-plugin:test" );
checkIds.add( "org.apache.maven.plugins:maven-jar-plugin:jar" );
checkIds.add( "org.apache.maven.plugins.internal:maven-state-management:2.1:end-fork" );
checkIds.add( "org.apache.maven.plugins:maven-assembly-plugin:1:assembly" );
checkIds.add( "org.apache.maven.plugins.internal:maven-state-management:2.1:clear-fork-context" );
assertBindingIds( rendered, checkIds );
}
public void test_constructBuildPlan_CustomLifecycleIsUsedFromRealmManager()
throws Exception
{
Model model = new Model();
model.setPackaging( "test" );
MavenProject project = new MavenProject( model );
MavenRealmManager realmManager = new DefaultMavenRealmManager( getContainer(), new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );
MockControl extArtifactCtl = MockControl.createControl( Artifact.class );
mockManager.add( extArtifactCtl );
Artifact extensionArtifact = (Artifact) extArtifactCtl.getMock();
extensionArtifact.getGroupId();
extArtifactCtl.setReturnValue( "group", MockControl.ZERO_OR_MORE );
extensionArtifact.getArtifactId();
extArtifactCtl.setReturnValue( "artifact", MockControl.ZERO_OR_MORE );
extensionArtifact.getVersion();
extArtifactCtl.setReturnValue( "1", MockControl.ZERO_OR_MORE );
extensionArtifact.getFile();
extArtifactCtl.setReturnValue( getResourceFile( "org/apache/maven/lifecycle/plan/test-custom-lifecycle-buildPlan-1.jar" ),
MockControl.ZERO_OR_MORE );
mockManager.replayAll();
realmManager.createExtensionRealm( extensionArtifact, Collections.EMPTY_LIST );
realmManager.importExtensionsIntoProjectRealm( "group", "project", "1", extensionArtifact );
MavenExecutionRequest request = new DefaultMavenExecutionRequest().setRealmManager( realmManager );
MavenSession session = new MavenSession( getContainer(), request, null, null );
BuildPlan plan = buildPlanner.constructBuildPlan( Collections.singletonList( "deploy" ),
project,
session,
false );
List rendered = plan.renderExecutionPlan( new Stack() );
List checkIds = new ArrayList();
checkIds.add( "org.apache.maven.plugins:maven-deploy-plugin:deploy" );
checkIds.add( "org.apache.maven.plugins:maven-install-plugin:install" );
assertBindingIds( rendered, checkIds );
mockManager.verifyAll();
}
private File getResourceFile( String path )
{
ClassLoader cloader = Thread.currentThread().getContextClassLoader();
URL resource = cloader.getResource( path );
if ( resource == null )
{
fail( "Cannot find test resource: " + path );
}
return new File( resource.getPath() );
}
private void assertBindingIds( List bindings,
List checkIds )
{
assertEquals( checkIds.size(), bindings.size() );
for ( int i = 0; i < bindings.size(); i++ )
{
MojoBinding binding = (MojoBinding) bindings.get( i );
String checkId = (String) checkIds.get( i );
assertEquals( checkId, MojoBindingUtils.toString( binding ) );
}
}
}

View File

@ -1,152 +0,0 @@
package org.apache.maven.lifecycle.plan.testutils;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.MojoBindingUtils;
import org.apache.maven.lifecycle.model.MojoBinding;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.plugin.PluginLoader;
import org.apache.maven.plugin.PluginLoaderException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import java.util.HashMap;
import java.util.Map;
public class TestPluginLoader
implements PluginLoader
{
private static final Map DEFAULT_PLUGIN_DESCRIPTORS;
private static final Map DEFAULT_PLUGIN_PREFIXES;
static
{
Map descriptors = new HashMap();
Map prefixes = new HashMap();
{
PluginDescriptor pd = createPluginDescriptor( "maven-resources-plugin", "resources",
"org.apache.maven.plugins", "1" );
createMojoDescriptor( pd, "resources" );
createMojoDescriptor( pd, "testResources" );
descriptors.put( pd.getId(), pd );
prefixes.put( pd.getGoalPrefix(), pd );
}
{
PluginDescriptor pd = createPluginDescriptor( "maven-compiler-plugin", "compiler",
"org.apache.maven.plugins", "1" );
createMojoDescriptor( pd, "compile" );
createMojoDescriptor( pd, "testCompile" );
descriptors.put( pd.getId(), pd );
prefixes.put( pd.getGoalPrefix(), pd );
}
{
PluginDescriptor pd = createPluginDescriptor( "maven-surefire-plugin", "surefire",
"org.apache.maven.plugins", "1" );
createMojoDescriptor( pd, "test" );
descriptors.put( pd.getId(), pd );
prefixes.put( pd.getGoalPrefix(), pd );
}
{
PluginDescriptor pd = createPluginDescriptor( "maven-jar-plugin", "jar", "org.apache.maven.plugins", "1" );
createMojoDescriptor( pd, "jar" );
descriptors.put( pd.getId(), pd );
prefixes.put( pd.getGoalPrefix(), pd );
}
DEFAULT_PLUGIN_DESCRIPTORS = descriptors;
DEFAULT_PLUGIN_PREFIXES = prefixes;
}
private Map pluginDescriptors = new HashMap( DEFAULT_PLUGIN_DESCRIPTORS );
private Map pluginPrefixes = new HashMap( DEFAULT_PLUGIN_PREFIXES );
private Map components = new HashMap();
public static MojoDescriptor createMojoDescriptor( PluginDescriptor pd, String goal )
{
MojoDescriptor md = new MojoDescriptor();
md.setPluginDescriptor( pd );
md.setGoal( goal );
pd.addComponentDescriptor( md );
return md;
}
public static PluginDescriptor createPluginDescriptor( String artifactId, String goalPrefix, String groupId,
String version )
{
PluginDescriptor pd = new PluginDescriptor();
pd.setGroupId( groupId );
pd.setArtifactId( artifactId );
pd.setGoalPrefix( goalPrefix );
pd.setVersion( version );
return pd;
}
public PluginDescriptor findPluginForPrefix( String prefix, MavenProject project, MavenSession session )
throws PluginLoaderException
{
// System.out.println( "Find plugin for prefix: " + prefix + " in project: " + project.getId() );
return (PluginDescriptor) pluginPrefixes.get( prefix );
}
public PluginDescriptor loadPlugin( Plugin plugin, MavenProject project, MavenSession session )
throws PluginLoaderException
{
// System.out.println( "Load plugin from model definition: " + plugin.getKey() + " in project: " + project.getId() );
return (PluginDescriptor) pluginDescriptors.get( plugin.getKey() );
}
public PluginDescriptor loadPlugin( MojoBinding mojoBinding, MavenProject project, MavenSession session )
throws PluginLoaderException
{
// System.out.println( "Load plugin for mojo binding: " + MojoBindingUtils.toString( mojoBinding )
// + " in project: " + project.getId() );
return (PluginDescriptor) pluginDescriptors.get( MojoBindingUtils.createPluginKey( mojoBinding ) );
}
public PluginDescriptor loadReportPlugin( ReportPlugin plugin, MavenProject project, MavenSession session )
throws PluginLoaderException
{
System.out.println( "Load report plugin from model definition: " + plugin.getKey() + " in project: "
+ project.getId() );
return (PluginDescriptor) pluginDescriptors.get( plugin.getKey() );
}
public PluginDescriptor loadReportPlugin( MojoBinding mojoBinding, MavenProject project, MavenSession session )
throws PluginLoaderException
{
System.out.println( "Load report plugin for mojo binding: " + MojoBindingUtils.toString( mojoBinding )
+ " in project: " + project.getId() );
return (PluginDescriptor) pluginDescriptors.get( MojoBindingUtils.createPluginKey( mojoBinding ) );
}
public void addPluginDescriptor( PluginDescriptor pd )
{
pluginDescriptors.put( pd.getId(), pd );
pluginPrefixes.put( pd.getGoalPrefix(), pd );
}
}

View File

@ -168,17 +168,20 @@ public class MavenEmbedder
return request; return request;
} }
public Collection<MojoExecution> getMojoExecutionsForGoal(String goal) throws Exception public Collection<MojoExecution> getMojoExecutionsForGoal(String goal)
throws Exception
{ {
return pluginManager.getMojoExecutionsForGoal( goal ); return pluginManager.getMojoExecutionsForGoal( goal );
} }
public Object getMojoParameterFor(MojoExecution mojoExecution, String xPath) throws Exception public Object getMojoParameterFor(MojoExecution mojoExecution, String xPath)
throws Exception
{ {
return pluginManager.getMojoParameterFor( mojoExecution, xPath); return pluginManager.getMojoParameterFor( mojoExecution, xPath);
} }
public void executeMojo(MojoExecution mojoExecution, MavenSession mavenSession ) throws Exception public void executeMojo(MojoExecution mojoExecution, MavenSession mavenSession )
throws Exception
{ {
pluginManager.executeMojo( mojoExecution, mavenSession ); pluginManager.executeMojo( mojoExecution, mavenSession );
} }
@ -213,7 +216,7 @@ public class MavenEmbedder
} }
public Model readModel( File file ) public Model readModel( File file )
throws XmlPullParserException, IOException throws XmlPullParserException, IOException
{ {
Reader reader = ReaderFactory.newXmlReader( file ); Reader reader = ReaderFactory.newXmlReader( file );
@ -228,14 +231,12 @@ public class MavenEmbedder
} }
public Model readModel( Reader reader ) public Model readModel( Reader reader )
throws XmlPullParserException, IOException throws XmlPullParserException, IOException
{ {
return modelReader.read( reader ); return modelReader.read( reader );
} }
public void writeModel( Writer writer, public void writeModel( Writer writer, Model model, boolean namespaceDeclaration )
Model model,
boolean namespaceDeclaration )
throws IOException throws IOException
{ {
modelWriter.write( writer, model ); modelWriter.write( writer, model );
@ -315,8 +316,7 @@ public class MavenEmbedder
* mkleint: protected so that IDE integrations can selectively allow downloading artifacts * mkleint: protected so that IDE integrations can selectively allow downloading artifacts
* from remote repositories (if they prohibit by default on project loading) * from remote repositories (if they prohibit by default on project loading)
*/ */
protected void verifyPlugin( Plugin plugin, protected void verifyPlugin( Plugin plugin, MavenProject project )
MavenProject project )
throws ComponentLookupException, ArtifactResolutionException, PluginVersionResolutionException, throws ComponentLookupException, ArtifactResolutionException, PluginVersionResolutionException,
ArtifactNotFoundException, InvalidPluginException, PluginManagerException, ArtifactNotFoundException, InvalidPluginException, PluginManagerException,
PluginNotFoundException, PluginVersionNotFoundException PluginNotFoundException, PluginVersionNotFoundException
@ -331,7 +331,7 @@ public class MavenEmbedder
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
public MavenProject readProject( File mavenProject ) public MavenProject readProject( File mavenProject )
throws ProjectBuildingException, MavenExecutionException throws ProjectBuildingException, MavenExecutionException
{ {
CoreErrorReporter errorReporter = request.getErrorReporter(); CoreErrorReporter errorReporter = request.getErrorReporter();
errorReporter.clearErrors(); errorReporter.clearErrors();
@ -367,22 +367,7 @@ public class MavenEmbedder
CoreReporterManager.setReporter( errorReporter ); CoreReporterManager.setReporter( errorReporter );
// This is necessary to make the MavenEmbedderProjectWithExtensionReadingTest work which uses
// a custom type for a dependency like this:
//
// <dependency>
// <groupId>junit</groupId>
// <artifactId>junit</artifactId>
// <version>3.8.1</version>
// <scope>test</scope>
// <type>mkleint</type>
// </dependency>
//
// If the artifact handlers are not loaded up-front then this dependency element is not
// registered as an artifact and is not added to the classpath elements.
readProject( request.getPom(), request ); readProject( request.getPom(), request );
} }
catch ( MavenEmbedderException e ) catch ( MavenEmbedderException e )
{ {
@ -540,8 +525,6 @@ public class MavenEmbedder
configuration.getContainerCustomizer().customize( container ); configuration.getContainerCustomizer().customize( container );
} }
handleExtensions( configuration.getExtensions() );
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Lookup each of the components we need to provide the desired // Lookup each of the components we need to provide the desired
// client interface. // client interface.
@ -573,49 +556,6 @@ public class MavenEmbedder
} }
} }
// ----------------------------------------------------------------------
// Lifecycle
// ----------------------------------------------------------------------
private void handleExtensions( List extensions )
throws MavenEmbedderException
{
ClassRealm childRealm;
try
{
childRealm = container.getContainerRealm().createChildRealm( "embedder-extensions" );
}
catch ( DuplicateRealmException e1 )
{
try
{
childRealm = classWorld.getRealm( "embedder-extensions" );
}
catch ( NoSuchRealmException e )
{
throw new MavenEmbedderException( "Cannot create realm 'extensions'", e );
}
}
for ( Iterator it = extensions.iterator(); it.hasNext(); )
{
childRealm.addURL( (URL) it.next() );
}
try
{
container.discoverComponents( childRealm );
}
catch ( PlexusConfigurationException e )
{
throw new MavenEmbedderException( "Configuration error while discovering extension components", e );
}
catch ( ComponentRepositoryException e )
{
throw new MavenEmbedderException( "Component repository error while discovering extension components", e );
}
}
public void stop() public void stop()
throws MavenEmbedderException throws MavenEmbedderException
{ {

View File

@ -39,7 +39,6 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.ArtifactResolutionResult;