This commit is contained in:
Jason van Zyl 2009-03-05 07:35:00 +00:00
parent 0cc04bdd8a
commit 04998877df
13 changed files with 85 additions and 165 deletions

View File

@ -13,43 +13,48 @@ import java.util.Collection;
import java.util.ArrayList;
import java.io.StringReader;
public class DefaultPluginContext implements PluginContext {
public class DefaultPluginContext
implements PluginContext
{
@Requirement
protected MavenPluginCollector pluginCollector;
@Requirement
protected PluginManager pluginManager;
public Collection<MojoExecution> getMojoExecutionsForGoal(String goal) throws Exception
public Collection<MojoExecution> getMojoExecutionsForGoal( String goal )
throws Exception
{
List<MojoExecution> mojoExecutions = new ArrayList<MojoExecution>();
for(PluginDescriptor descriptor : pluginCollector.getPluginDescriptors())
for ( PluginDescriptor descriptor : pluginCollector.getPluginDescriptors() )
{
MojoDescriptor mojoDescriptor = descriptor.getMojo(goal);
if(mojoDescriptor != null)
MojoDescriptor mojoDescriptor = descriptor.getMojo( goal );
if ( mojoDescriptor != null )
{
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor );
mojoExecution.setConfiguration(
Xpp3DomBuilder.build( new StringReader( mojoDescriptor.getMojoConfiguration().toString() ) ) );
mojoExecutions.add(mojoExecution);
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor );
mojoExecution.setConfiguration( Xpp3DomBuilder.build( new StringReader( mojoDescriptor.getMojoConfiguration().toString() ) ) );
mojoExecutions.add( mojoExecution );
}
}
return mojoExecutions;
}
public Object getMojoParameterFor(MojoExecution mojoExecution, String xPath) throws Exception {
Xpp3Dom mojoDescriptorConfiguration =
Xpp3DomBuilder.build( new StringReader(mojoExecution.getMojoDescriptor().getMojoConfiguration().toString()));
public Object getMojoParameterFor( MojoExecution mojoExecution, String xPath )
throws Exception
{
Xpp3Dom mojoDescriptorConfiguration = Xpp3DomBuilder.build( new StringReader( mojoExecution.getMojoDescriptor().getMojoConfiguration().toString() ) );
Xpp3Dom mergedConfig = Xpp3Dom.mergeXpp3Dom( mojoExecution.getConfiguration(), mojoDescriptorConfiguration );
return JXPathContext.newContext( mergedConfig ).getValue( xPath );
}
public void executeMojo( MojoExecution mojoExecution, MavenSession session ) throws Exception
public void executeMojo( MojoExecution mojoExecution, MavenSession session )
throws Exception
{
pluginManager.executeMojo(session.getCurrentProject(), mojoExecution, session);
pluginManager.executeMojo( session.getCurrentProject(), mojoExecution, session );
}
}

View File

@ -29,6 +29,7 @@ import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutio
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;
@ -44,9 +45,11 @@ import java.util.Map;
*/
@Component(role = PluginMappingManager.class)
public class DefaultPluginMappingManager
extends AbstractLogEnabled
implements PluginMappingManager
{
@Requirement
private Logger logger;
@Requirement
protected RepositoryMetadataManager repositoryMetadataManager;
@ -58,7 +61,7 @@ public class DefaultPluginMappingManager
// if not found, try from the remote repository
if ( !pluginDefinitionsByPrefix.containsKey( pluginPrefix ) )
{
getLogger().info( "Searching repository for plugin with prefix: \'" + pluginPrefix + "\'." );
logger.info( "Searching repository for plugin with prefix: \'" + pluginPrefix + "\'." );
loadPluginMappings( groupIds, pluginRepositories, localRepository );
}
@ -67,7 +70,7 @@ public class DefaultPluginMappingManager
if ( result == null )
{
getLogger().debug( "Failed to resolve plugin from prefix: " + pluginPrefix, new Throwable() );
logger.debug( "Failed to resolve plugin from prefix: " + pluginPrefix, new Throwable() );
}
return result;
@ -90,16 +93,16 @@ public class DefaultPluginMappingManager
for ( Iterator it = pluginGroupIds.iterator(); it.hasNext(); )
{
String groupId = (String) it.next();
getLogger().debug( "Loading plugin prefixes from group: " + groupId );
logger.debug( "Loading plugin prefixes from group: " + groupId );
try
{
loadPluginMappings( groupId, pluginRepositories, localRepository );
}
catch ( RepositoryMetadataResolutionException e )
{
getLogger().warn( "Cannot resolve plugin-mapping metadata for groupId: " + groupId + " - IGNORING." );
logger.warn( "Cannot resolve plugin-mapping metadata for groupId: " + groupId + " - IGNORING." );
getLogger().debug( "Error resolving plugin-mapping metadata for groupId: " + groupId + ".", e );
logger.debug( "Error resolving plugin-mapping metadata for groupId: " + groupId + ".", e );
}
}
}
@ -109,7 +112,7 @@ public class DefaultPluginMappingManager
{
RepositoryMetadata metadata = new GroupRepositoryMetadata( groupId );
getLogger().debug( "Checking repositories:\n" + pluginRepositories + "\n\nfor plugin prefix metadata: " + groupId );
logger.debug( "Checking repositories:\n" + pluginRepositories + "\n\nfor plugin prefix metadata: " + groupId );
repositoryMetadataManager.resolve( metadata, pluginRepositories, localRepository );
Metadata repoMetadata = metadata.getMetadata();
@ -118,7 +121,7 @@ public class DefaultPluginMappingManager
for ( Iterator pluginIterator = repoMetadata.getPlugins().iterator(); pluginIterator.hasNext(); )
{
Plugin mapping = (Plugin) pluginIterator.next();
getLogger().debug( "Found plugin: " + mapping.getName() + " with prefix: " + mapping.getPrefix() );
logger.debug( "Found plugin: " + mapping.getName() + " with prefix: " + mapping.getPrefix() );
String prefix = mapping.getPrefix();

View File

@ -126,10 +126,7 @@ public class DefaultPluginVersionManager
return version;
}
private String getVersionFromPluginConfig( String groupId,
String artifactId,
MavenProject project,
boolean resolveAsReportPlugin )
private String getVersionFromPluginConfig( String groupId, String artifactId, MavenProject project, boolean resolveAsReportPlugin )
{
String version = null;

View File

@ -19,29 +19,35 @@ package org.apache.maven.plugin;
* under the License.
*/
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.component.discovery.ComponentDiscoveryEvent;
import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener;
import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import java.util.*;
public class MavenPluginCollector
implements ComponentDiscoveryListener, LogEnabled
implements ComponentDiscoveryListener
{
@Requirement
private Logger logger;
private Set pluginsInProcess = new HashSet();
private Map<String, PluginDescriptor> pluginDescriptors = new HashMap();
private Map pluginIdsByPrefix = new HashMap();
private Logger logger;
// ----------------------------------------------------------------------
// Mojo discovery
// ----------------------------------------------------------------------

View File

@ -35,39 +35,28 @@ public class PluginConfigurationException
private String originalMessage;
public PluginConfigurationException(
PluginDescriptor pluginDescriptor,
String originalMessage )
public PluginConfigurationException( PluginDescriptor pluginDescriptor, String originalMessage )
{
super( originalMessage );
this.pluginDescriptor = pluginDescriptor;
this.originalMessage = originalMessage;
}
public PluginConfigurationException(
PluginDescriptor pluginDescriptor,
String originalMessage,
ExpressionEvaluationException cause )
public PluginConfigurationException( PluginDescriptor pluginDescriptor, String originalMessage, ExpressionEvaluationException cause )
{
super( cause );
this.pluginDescriptor = pluginDescriptor;
this.originalMessage = originalMessage;
}
public PluginConfigurationException(
PluginDescriptor pluginDescriptor,
String originalMessage,
ComponentConfigurationException cause )
public PluginConfigurationException( PluginDescriptor pluginDescriptor, String originalMessage, ComponentConfigurationException cause )
{
super( cause );
this.pluginDescriptor = pluginDescriptor;
this.originalMessage = originalMessage;
}
public PluginConfigurationException(
PluginDescriptor pluginDescriptor,
String originalMessage,
ComponentLookupException cause )
public PluginConfigurationException( PluginDescriptor pluginDescriptor, String originalMessage, ComponentLookupException cause )
{
super( cause );
this.pluginDescriptor = pluginDescriptor;

View File

@ -24,39 +24,28 @@ public class PluginContainerException
private ClassRealm pluginRealm;
public PluginContainerException( MojoDescriptor mojoDescriptor,
ClassRealm pluginRealm,
String message,
ComponentLookupException e )
public PluginContainerException( MojoDescriptor mojoDescriptor, ClassRealm pluginRealm, String message, ComponentLookupException e )
{
super( mojoDescriptor, message, e );
this.pluginRealm = pluginRealm;
}
public PluginContainerException( Plugin plugin,
ClassRealm pluginRealm,
String message,
PlexusConfigurationException e )
public PluginContainerException( Plugin plugin, ClassRealm pluginRealm, String message, PlexusConfigurationException e )
{
super( plugin, message, e );
this.pluginRealm = pluginRealm;
}
public PluginContainerException( Plugin plugin,
ClassRealm pluginRealm,
String message,
ComponentRepositoryException e )
public PluginContainerException( Plugin plugin, ClassRealm pluginRealm, String message, ComponentRepositoryException e )
{
super( plugin, message, e );
this.pluginRealm = pluginRealm;
}
public PluginContainerException( Plugin plugin,
String message,
RealmManagementException e )
public PluginContainerException( Plugin plugin, String message, RealmManagementException e )
{
super( plugin, message, e );
}

View File

@ -11,5 +11,4 @@ public interface PluginContext {
Object getMojoParameterFor(MojoExecution mojoExecution, String xPath) throws Exception;
void executeMojo(MojoExecution mojoExecution, MavenSession session) throws Exception;
}

View File

@ -9,25 +9,19 @@ public class PluginExecutionException
private final MojoExecution mojoExecution;
public PluginExecutionException( MojoExecution mojoExecution,
MavenProject project,
String message )
public PluginExecutionException( MojoExecution mojoExecution, MavenProject project, String message )
{
super( mojoExecution.getMojoDescriptor(), project, message );
this.mojoExecution = mojoExecution;
}
public PluginExecutionException( MojoExecution mojoExecution,
MavenProject project,
MojoExecutionException cause )
public PluginExecutionException( MojoExecution mojoExecution, MavenProject project, MojoExecutionException cause )
{
super( mojoExecution.getMojoDescriptor(), project, "Mojo execution failed.", cause );
this.mojoExecution = mojoExecution;
}
public PluginExecutionException( MojoExecution mojoExecution,
MavenProject project,
DuplicateArtifactAttachmentException cause )
public PluginExecutionException( MojoExecution mojoExecution, MavenProject project, DuplicateArtifactAttachmentException cause )
{
super( mojoExecution.getMojoDescriptor(), project, "Mojo execution failed.", cause );
this.mojoExecution = mojoExecution;
@ -37,5 +31,4 @@ public class PluginExecutionException
{
return mojoExecution;
}
}

View File

@ -35,36 +35,18 @@ import org.apache.maven.reporting.MavenReport;
*/
public interface PluginManager
{
String ROLE = PluginManager.class.getName();
void executeMojo( MavenProject project, MojoExecution execution, MavenSession session )
throws ArtifactResolutionException, MojoFailureException, ArtifactNotFoundException, InvalidDependencyVersionException, PluginManagerException, PluginConfigurationException;
void executeMojo( MavenProject project,
MojoExecution execution,
MavenSession session )
throws ArtifactResolutionException, MojoFailureException, ArtifactNotFoundException,
InvalidDependencyVersionException, PluginManagerException, PluginConfigurationException;
MavenReport getReport( MavenProject project, MojoExecution mojoExecution, MavenSession session )
throws ArtifactNotFoundException, PluginConfigurationException, PluginManagerException, ArtifactResolutionException;
MavenReport getReport( MavenProject project,
MojoExecution mojoExecution,
MavenSession session )
throws ArtifactNotFoundException, PluginConfigurationException, PluginManagerException,
ArtifactResolutionException;
Plugin getPluginDefinitionForPrefix( String prefix, MavenSession session, MavenProject project );
Plugin getPluginDefinitionForPrefix( String prefix,
MavenSession session,
MavenProject project );
PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, MavenSession session )
throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException, InvalidPluginException, PluginManagerException, PluginNotFoundException, PluginVersionNotFoundException;
PluginDescriptor verifyPlugin( Plugin plugin,
MavenProject project,
MavenSession session )
throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException,
InvalidPluginException, PluginManagerException, PluginNotFoundException,
PluginVersionNotFoundException;
PluginDescriptor verifyReportPlugin( ReportPlugin reportPlugin,
MavenProject project,
MavenSession session )
throws PluginVersionResolutionException, ArtifactResolutionException, ArtifactNotFoundException,
InvalidPluginException, PluginManagerException, PluginNotFoundException,
PluginVersionNotFoundException;
PluginDescriptor verifyReportPlugin( ReportPlugin reportPlugin, MavenProject project, MavenSession session )
throws PluginVersionResolutionException, ArtifactResolutionException, ArtifactNotFoundException, InvalidPluginException, PluginManagerException, PluginNotFoundException, PluginVersionNotFoundException;
}

View File

@ -50,10 +50,7 @@ public class PluginManagerException
private MavenProject project;
protected PluginManagerException( Plugin plugin,
String message,
MavenProject project,
Throwable cause )
protected PluginManagerException( Plugin plugin, String message, MavenProject project, Throwable cause )
{
super( message, cause );
@ -63,9 +60,7 @@ public class PluginManagerException
pluginVersion = plugin.getVersion();
}
protected PluginManagerException( Plugin plugin,
String message,
Throwable cause )
protected PluginManagerException( Plugin plugin, String message, Throwable cause )
{
super( message, cause );
@ -74,9 +69,7 @@ public class PluginManagerException
pluginVersion = plugin.getVersion();
}
protected PluginManagerException( MojoDescriptor mojoDescriptor,
String message,
Throwable cause )
protected PluginManagerException( MojoDescriptor mojoDescriptor, String message, Throwable cause )
{
super( message, cause );
pluginGroupId = mojoDescriptor.getPluginDescriptor().getGroupId();
@ -85,9 +78,7 @@ public class PluginManagerException
goal = mojoDescriptor.getGoal();
}
protected PluginManagerException( MojoDescriptor mojoDescriptor,
MavenProject project,
String message )
protected PluginManagerException( MojoDescriptor mojoDescriptor, MavenProject project, String message )
{
super( message );
this.project = project;
@ -97,10 +88,7 @@ public class PluginManagerException
goal = mojoDescriptor.getGoal();
}
protected PluginManagerException( MojoDescriptor mojoDescriptor,
MavenProject project,
String message,
Throwable cause )
protected PluginManagerException( MojoDescriptor mojoDescriptor, MavenProject project, String message, Throwable cause )
{
super( message, cause );
this.project = project;
@ -110,8 +98,7 @@ public class PluginManagerException
goal = mojoDescriptor.getGoal();
}
public PluginManagerException( Plugin plugin,
InvalidVersionSpecificationException cause )
public PluginManagerException( Plugin plugin, InvalidVersionSpecificationException cause )
{
super( cause );
@ -120,9 +107,7 @@ public class PluginManagerException
pluginVersion = plugin.getVersion();
}
public PluginManagerException( Plugin plugin,
String message,
PlexusConfigurationException cause )
public PluginManagerException( Plugin plugin, String message, PlexusConfigurationException cause )
{
super( message, cause );
@ -131,9 +116,7 @@ public class PluginManagerException
pluginVersion = plugin.getVersion();
}
public PluginManagerException( Plugin plugin,
String message,
ComponentRepositoryException cause )
public PluginManagerException( Plugin plugin, String message, ComponentRepositoryException cause )
{
super( message, cause );
@ -142,10 +125,7 @@ public class PluginManagerException
pluginVersion = plugin.getVersion();
}
public PluginManagerException( MojoDescriptor mojoDescriptor,
MavenProject project,
String message,
NoSuchRealmException cause )
public PluginManagerException( MojoDescriptor mojoDescriptor, MavenProject project, String message, NoSuchRealmException cause )
{
super( message, cause );
@ -156,10 +136,7 @@ public class PluginManagerException
goal = mojoDescriptor.getGoal();
}
public PluginManagerException( MojoDescriptor mojoDescriptor,
String message,
MavenProject project,
PlexusContainerException cause )
public PluginManagerException( MojoDescriptor mojoDescriptor, String message, MavenProject project, PlexusContainerException cause )
{
super( message, cause );
@ -173,9 +150,7 @@ public class PluginManagerException
goal = mojoDescriptor.getGoal();
}
public PluginManagerException( Plugin plugin,
String message,
PlexusContainerException cause )
public PluginManagerException( Plugin plugin, String message, PlexusContainerException cause )
{
super( message, cause );
@ -184,9 +159,7 @@ public class PluginManagerException
pluginVersion = plugin.getVersion();
}
public PluginManagerException( Plugin plugin,
String message,
RealmManagementException cause )
public PluginManagerException( Plugin plugin, String message, RealmManagementException cause )
{
super( message, cause );
@ -195,9 +168,7 @@ public class PluginManagerException
pluginVersion = plugin.getVersion();
}
public PluginManagerException( Plugin plugin,
String message,
MavenProject project )
public PluginManagerException( Plugin plugin, String message, MavenProject project )
{
super( message );

View File

@ -14,15 +14,10 @@ import java.util.List;
public interface PluginManagerSupport
{
Artifact resolvePluginArtifact( Plugin plugin,
MavenProject project,
MavenSession session )
throws PluginManagerException, InvalidPluginException, PluginVersionResolutionException,
ArtifactResolutionException, ArtifactNotFoundException;
Artifact resolvePluginArtifact( Plugin plugin, MavenProject project, MavenSession session )
throws PluginManagerException, InvalidPluginException, PluginVersionResolutionException, ArtifactResolutionException, ArtifactNotFoundException;
MavenProject buildPluginProject( Plugin plugin,
ArtifactRepository localRepository,
List remoteRepositories )
MavenProject buildPluginProject( Plugin plugin, ArtifactRepository localRepository, List remoteRepositories )
throws InvalidPluginException;
/**
@ -30,18 +25,11 @@ public interface PluginManagerSupport
* @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 )
void checkRequiredMavenVersion( Plugin plugin, MavenProject pluginProject, ArtifactRepository localRepository, List remoteRepositories )
throws PluginVersionResolutionException, InvalidPluginException;
void checkPluginDependencySpec( Plugin plugin,
MavenProject pluginProject )
void checkPluginDependencySpec( Plugin plugin, MavenProject pluginProject )
throws InvalidPluginException;
PluginDescriptor loadIsolatedPluginDescriptor( Plugin plugin,
MavenProject project,
MavenSession session );
PluginDescriptor loadIsolatedPluginDescriptor( Plugin plugin, MavenProject project, MavenSession session );
}

View File

@ -31,6 +31,5 @@ import java.util.List;
*/
public interface PluginMappingManager
{
Plugin getByPrefix( String pluginPrefix, List groupIds, List pluginRepositories,
ArtifactRepository localRepository );
Plugin getByPrefix( String pluginPrefix, List groupIds, List pluginRepositories, ArtifactRepository localRepository );
}

View File

@ -19,7 +19,6 @@ package org.apache.maven.plugin;
* under the License.
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;