Wiring plugin-as-extension back into the new extension scanning stuff.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@598720 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2007-11-27 17:59:22 +00:00
parent 2b135180ba
commit 249af52bb5
7 changed files with 95 additions and 16 deletions

View File

@ -25,6 +25,7 @@ import org.apache.maven.model.Build;
import org.apache.maven.model.Extension; import org.apache.maven.model.Extension;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.Parent; import org.apache.maven.model.Parent;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.loader.PluginLoader; import org.apache.maven.plugin.loader.PluginLoader;
import org.apache.maven.profiles.ProfileManager; import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.profiles.activation.DefaultProfileActivationContext; import org.apache.maven.profiles.activation.DefaultProfileActivationContext;
@ -273,6 +274,9 @@ public class DefaultBuildExtensionScanner
private void checkModelBuildForExtensions( Model model, MavenExecutionRequest request, List remoteRepositories ) private void checkModelBuildForExtensions( Model model, MavenExecutionRequest request, List remoteRepositories )
throws ExtensionScanningException throws ExtensionScanningException
{ {
// FIXME: Fix the log level here.
getLogger().info( "Checking " + model.getId() + " for extensions." );
Build build = model.getBuild(); Build build = model.getBuild();
if ( build != null ) if ( build != null )
@ -303,6 +307,31 @@ public class DefaultBuildExtensionScanner
} }
} }
} }
List plugins = build.getPlugins();
if ( ( plugins != null ) && !plugins.isEmpty() )
{
for ( Iterator extensionIterator = plugins.iterator(); extensionIterator.hasNext(); )
{
Plugin plugin = (Plugin) extensionIterator.next();
if ( plugin.isExtensions() )
{
getLogger().debug( "Adding plugin: " + plugin.getKey() + " as an extension(from model: " + model.getId() + ")" );
try
{
extensionManager.addPluginAsExtension( plugin, model, remoteRepositories, request );
}
catch ( ExtensionManagerException e )
{
throw new ExtensionScanningException( "Cannot resolve pre-scanned plugin artifact (for use as an extension): "
+ plugin.getKey() + ": " + e.getMessage(), model, plugin, e );
}
}
}
}
} }
} }

View File

@ -63,6 +63,7 @@ import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
@ -160,6 +161,8 @@ public class DefaultExtensionManager
MavenExecutionRequest request ) MavenExecutionRequest request )
throws ExtensionManagerException throws ExtensionManagerException
{ {
getLogger().debug( "Adding plugin: " + plugin.getKey() + " as an extension." );
Parent originatingParent = originatingModel.getParent(); Parent originatingParent = originatingModel.getParent();
String groupId = originatingModel.getGroupId(); String groupId = originatingModel.getGroupId();
@ -178,9 +181,17 @@ public class DefaultExtensionManager
version = originatingParent.getVersion(); version = originatingParent.getVersion();
} }
String pluginVersion = plugin.getVersion();
// TODO: Forbid this?
if ( pluginVersion == null )
{
pluginVersion = Artifact.RELEASE_VERSION;
}
Artifact pluginArtifact = artifactFactory.createBuildArtifact( plugin.getGroupId(), Artifact pluginArtifact = artifactFactory.createBuildArtifact( plugin.getGroupId(),
plugin.getArtifactId(), plugin.getArtifactId(),
plugin.getVersion(), "maven-plugin" ); pluginVersion, "maven-plugin" );
getLogger().debug( "Starting extension-addition process for: " + pluginArtifact ); getLogger().debug( "Starting extension-addition process for: " + pluginArtifact );
@ -195,6 +206,10 @@ public class DefaultExtensionManager
&& coreFilter.include( pluginArtifact ) ) && coreFilter.include( pluginArtifact ) )
{ {
MavenProject dummyProject = new MavenProject( originatingModel ); MavenProject dummyProject = new MavenProject( originatingModel );
dummyProject.setPluginArtifactRepositories( remoteRepositories );
dummyProject.setRemoteArtifactRepositories( Collections.EMPTY_LIST );
EventDispatcher dispatcher = new DefaultEventDispatcher( request.getEventMonitors() ); EventDispatcher dispatcher = new DefaultEventDispatcher( request.getEventMonitors() );
MavenSession session = new MavenSession( container, request, dispatcher, null ); MavenSession session = new MavenSession( container, request, dispatcher, null );

View File

@ -22,6 +22,7 @@ package org.apache.maven.extension;
import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.model.Extension; import org.apache.maven.model.Extension;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import java.util.List; import java.util.List;
@ -34,12 +35,22 @@ import java.util.List;
*/ */
public interface ExtensionManager public interface ExtensionManager
{ {
void addExtension( Extension extension, MavenProject project, MavenExecutionRequest request ) void addExtension( Extension extension,
MavenProject project,
MavenExecutionRequest request )
throws ExtensionManagerException; throws ExtensionManagerException;
void registerWagons(); void registerWagons();
void addExtension( Extension extension, Model originatingModel, List remoteRepositories, void addExtension( Extension extension,
Model originatingModel,
List remoteRepositories,
MavenExecutionRequest request ) MavenExecutionRequest request )
throws ExtensionManagerException; throws ExtensionManagerException;
void addPluginAsExtension( Plugin plugin,
Model originatingModel,
List remoteRepositories,
MavenExecutionRequest request )
throws ExtensionManagerException;
} }

View File

@ -2,6 +2,7 @@ package org.apache.maven.extension;
import org.apache.maven.model.Extension; import org.apache.maven.model.Extension;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.project.ProjectBuildingException; import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.interpolation.ModelInterpolationException; import org.apache.maven.project.interpolation.ModelInterpolationException;
@ -78,6 +79,16 @@ public class ExtensionScanningException
this.pomFile = pomFile; this.pomFile = pomFile;
} }
public ExtensionScanningException( String message,
Model model,
Plugin plugin,
ExtensionManagerException cause )
{
super( message, cause );
modelId = model.getId();
extensionId = plugin.getGroupId() + ":" + plugin.getArtifactId();
}
public File getPomFile() public File getPomFile()
{ {
return pomFile; return pomFile;

View File

@ -162,15 +162,20 @@ public class DefaultPluginManager
ArtifactNotFoundException, InvalidPluginException, ArtifactNotFoundException, InvalidPluginException,
PluginManagerException, PluginNotFoundException, PluginVersionNotFoundException PluginManagerException, PluginNotFoundException, PluginVersionNotFoundException
{ {
String pluginVersion = plugin.getVersion();
// TODO: this should be possibly outside // TODO: this should be possibly outside
// All version-resolution logic has been moved to DefaultPluginVersionManager. // All version-resolution logic has been moved to DefaultPluginVersionManager.
if ( plugin.getVersion() == null ) getLogger().debug( "Resolving plugin: " + plugin.getKey() + " with version: " + pluginVersion );
if ( ( pluginVersion == null ) || Artifact.LATEST_VERSION.equals( pluginVersion ) || Artifact.RELEASE_VERSION.equals( pluginVersion ) )
{ {
getLogger().debug( "Resolving version for plugin: " + plugin.getKey() ); getLogger().debug( "Resolving version for plugin: " + plugin.getKey() );
String version = pluginVersionManager.resolvePluginVersion( plugin.getGroupId(), pluginVersion = pluginVersionManager.resolvePluginVersion( plugin.getGroupId(),
plugin.getArtifactId(), plugin.getArtifactId(),
project, session ); project, session );
plugin.setVersion( version ); plugin.setVersion( pluginVersion );
getLogger().debug( "Resolved to version: " + pluginVersion );
} }
return verifyVersionedPlugin( plugin, project, session ); return verifyVersionedPlugin( plugin, project, session );
@ -379,8 +384,14 @@ public class DefaultPluginManager
if ( pluginDescriptor == null ) if ( pluginDescriptor == null )
{ {
if ( ( pluginRealm != null ) && getLogger().isDebugEnabled() )
{
getLogger().debug( "Plugin Realm: " );
pluginRealm.display();
}
throw new IllegalStateException( "The PluginDescriptor for the plugin " throw new IllegalStateException( "The PluginDescriptor for the plugin "
+ projectPlugin.getKey() + " was not found" ); + projectPlugin.getKey() + " was not found. Should have been in realm: " + pluginRealm );
} }
pluginDescriptor.setPluginArtifact( pluginArtifact ); pluginDescriptor.setPluginArtifact( pluginArtifact );

View File

@ -41,10 +41,8 @@ import org.apache.maven.project.ProjectBuildingException;
import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
public class DefaultPluginVersionManager public class DefaultPluginVersionManager
extends AbstractLogEnabled extends AbstractLogEnabled
@ -85,6 +83,7 @@ public class DefaultPluginVersionManager
{ {
// first pass...if the plugin is specified in the pom, try to retrieve the version from there. // first pass...if the plugin is specified in the pom, try to retrieve the version from there.
String version = getVersionFromPluginConfig( groupId, artifactId, project, resolveAsReportPlugin ); String version = getVersionFromPluginConfig( groupId, artifactId, project, resolveAsReportPlugin );
getLogger().debug( "Version from POM: " + version ); getLogger().debug( "Version from POM: " + version );
// NOTE: We CANNOT check the current project version here, so delay it until later. // NOTE: We CANNOT check the current project version here, so delay it until later.
@ -107,7 +106,7 @@ public class DefaultPluginVersionManager
// third pass...we're always checking for latest install/deploy, so retrieve the version for LATEST metadata and // 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. // also set that resolved version as the <useVersion/> in settings.xml.
if ( StringUtils.isEmpty( version ) ) if ( StringUtils.isEmpty( version ) || Artifact.LATEST_VERSION.equals( version ) )
{ {
// 1. resolve the version to be used // 1. resolve the version to be used
version = resolveMetaVersion( groupId, artifactId, project, localRepository, Artifact.LATEST_VERSION ); version = resolveMetaVersion( groupId, artifactId, project, localRepository, Artifact.LATEST_VERSION );
@ -116,7 +115,7 @@ public class DefaultPluginVersionManager
// final pass...retrieve the version for RELEASE and also set that resolved version as the <useVersion/> // final pass...retrieve the version for RELEASE and also set that resolved version as the <useVersion/>
// in settings.xml. // in settings.xml.
if ( StringUtils.isEmpty( version ) ) if ( StringUtils.isEmpty( version ) || Artifact.RELEASE_VERSION.equals( version ) )
{ {
// 1. resolve the version to be used // 1. resolve the version to be used
version = resolveMetaVersion( groupId, artifactId, project, localRepository, Artifact.RELEASE_VERSION ); version = resolveMetaVersion( groupId, artifactId, project, localRepository, Artifact.RELEASE_VERSION );
@ -143,7 +142,7 @@ public class DefaultPluginVersionManager
{ {
if ( project.getReportPlugins() != null ) if ( project.getReportPlugins() != null )
{ {
for ( Iterator it = project.getReportPlugins().iterator(); it.hasNext() && version == null; ) for ( Iterator it = project.getReportPlugins().iterator(); it.hasNext() && ( version == null ); )
{ {
ReportPlugin plugin = (ReportPlugin) it.next(); ReportPlugin plugin = (ReportPlugin) it.next();
@ -158,7 +157,7 @@ public class DefaultPluginVersionManager
{ {
if ( project.getBuildPlugins() != null ) if ( project.getBuildPlugins() != null )
{ {
for ( Iterator it = project.getBuildPlugins().iterator(); it.hasNext() && version == null; ) for ( Iterator it = project.getBuildPlugins().iterator(); it.hasNext() && ( version == null ); )
{ {
Plugin plugin = (Plugin) it.next(); Plugin plugin = (Plugin) it.next();
@ -208,14 +207,14 @@ public class DefaultPluginVersionManager
{ {
boolean pluginValid = false; boolean pluginValid = false;
while ( !pluginValid && artifactVersion != null ) while ( !pluginValid && ( artifactVersion != null ) )
{ {
pluginValid = true; pluginValid = true;
MavenProject pluginProject; MavenProject pluginProject;
try try
{ {
artifact = artifactFactory.createProjectArtifact( groupId, artifactId, artifactVersion ); artifact = artifactFactory.createProjectArtifact( groupId, artifactId, artifactVersion );
pluginProject = mavenProjectBuilder.buildFromRepository( artifact, project.getPluginArtifactRepositories(), localRepository ); pluginProject = mavenProjectBuilder.buildFromRepository( artifact, project.getPluginArtifactRepositories(), localRepository );
} }
catch ( ProjectBuildingException e ) catch ( ProjectBuildingException e )
@ -225,7 +224,7 @@ public class DefaultPluginVersionManager
} }
// if we don't have the required Maven version, then ignore an update // if we don't have the required Maven version, then ignore an update
if ( pluginProject.getPrerequisites() != null && pluginProject.getPrerequisites().getMaven() != null ) if ( ( pluginProject.getPrerequisites() != null ) && ( pluginProject.getPrerequisites().getMaven() != null ) )
{ {
DefaultArtifactVersion requiredVersion = DefaultArtifactVersion requiredVersion =
new DefaultArtifactVersion( pluginProject.getPrerequisites().getMaven() ); new DefaultArtifactVersion( pluginProject.getPrerequisites().getMaven() );

View File

@ -248,6 +248,9 @@ under the License.
<role>org.apache.maven.extension.ExtensionManager</role> <role>org.apache.maven.extension.ExtensionManager</role>
<implementation>org.apache.maven.extension.DefaultExtensionManager</implementation> <implementation>org.apache.maven.extension.DefaultExtensionManager</implementation>
<requirements> <requirements>
<requirement>
<role>org.apache.maven.plugin.PluginManager</role>
</requirement>
<requirement> <requirement>
<role>org.apache.maven.ArtifactFilterManager</role> <role>org.apache.maven.ArtifactFilterManager</role>
</requirement> </requirement>