diff --git a/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java b/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java
index 1a494ab847..253dc6b1bf 100644
--- a/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java
+++ b/maven-core/src/main/java/org/apache/maven/extension/DefaultBuildExtensionScanner.java
@@ -25,6 +25,7 @@ import org.apache.maven.model.Build;
import org.apache.maven.model.Extension;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
+import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.loader.PluginLoader;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.profiles.activation.DefaultProfileActivationContext;
@@ -273,6 +274,9 @@ public class DefaultBuildExtensionScanner
private void checkModelBuildForExtensions( Model model, MavenExecutionRequest request, List remoteRepositories )
throws ExtensionScanningException
{
+ // FIXME: Fix the log level here.
+ getLogger().info( "Checking " + model.getId() + " for extensions." );
+
Build build = model.getBuild();
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 );
+ }
+ }
+ }
+ }
}
}
diff --git a/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java b/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java
index b38ca90999..cd5c1b6764 100644
--- a/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java
+++ b/maven-core/src/main/java/org/apache/maven/extension/DefaultExtensionManager.java
@@ -63,6 +63,7 @@ import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
+import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
@@ -160,6 +161,8 @@ public class DefaultExtensionManager
MavenExecutionRequest request )
throws ExtensionManagerException
{
+ getLogger().debug( "Adding plugin: " + plugin.getKey() + " as an extension." );
+
Parent originatingParent = originatingModel.getParent();
String groupId = originatingModel.getGroupId();
@@ -178,9 +181,17 @@ public class DefaultExtensionManager
version = originatingParent.getVersion();
}
+ String pluginVersion = plugin.getVersion();
+
+ // TODO: Forbid this?
+ if ( pluginVersion == null )
+ {
+ pluginVersion = Artifact.RELEASE_VERSION;
+ }
+
Artifact pluginArtifact = artifactFactory.createBuildArtifact( plugin.getGroupId(),
plugin.getArtifactId(),
- plugin.getVersion(), "maven-plugin" );
+ pluginVersion, "maven-plugin" );
getLogger().debug( "Starting extension-addition process for: " + pluginArtifact );
@@ -195,6 +206,10 @@ public class DefaultExtensionManager
&& coreFilter.include( pluginArtifact ) )
{
MavenProject dummyProject = new MavenProject( originatingModel );
+
+ dummyProject.setPluginArtifactRepositories( remoteRepositories );
+ dummyProject.setRemoteArtifactRepositories( Collections.EMPTY_LIST );
+
EventDispatcher dispatcher = new DefaultEventDispatcher( request.getEventMonitors() );
MavenSession session = new MavenSession( container, request, dispatcher, null );
diff --git a/maven-core/src/main/java/org/apache/maven/extension/ExtensionManager.java b/maven-core/src/main/java/org/apache/maven/extension/ExtensionManager.java
index ce357e7086..e47653d9f6 100644
--- a/maven-core/src/main/java/org/apache/maven/extension/ExtensionManager.java
+++ b/maven-core/src/main/java/org/apache/maven/extension/ExtensionManager.java
@@ -22,6 +22,7 @@ package org.apache.maven.extension;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.model.Extension;
import org.apache.maven.model.Model;
+import org.apache.maven.model.Plugin;
import org.apache.maven.project.MavenProject;
import java.util.List;
@@ -34,12 +35,22 @@ import java.util.List;
*/
public interface ExtensionManager
{
- void addExtension( Extension extension, MavenProject project, MavenExecutionRequest request )
+ void addExtension( Extension extension,
+ MavenProject project,
+ MavenExecutionRequest request )
throws ExtensionManagerException;
void registerWagons();
- void addExtension( Extension extension, Model originatingModel, List remoteRepositories,
+ void addExtension( Extension extension,
+ Model originatingModel,
+ List remoteRepositories,
MavenExecutionRequest request )
throws ExtensionManagerException;
+
+ void addPluginAsExtension( Plugin plugin,
+ Model originatingModel,
+ List remoteRepositories,
+ MavenExecutionRequest request )
+ throws ExtensionManagerException;
}
diff --git a/maven-core/src/main/java/org/apache/maven/extension/ExtensionScanningException.java b/maven-core/src/main/java/org/apache/maven/extension/ExtensionScanningException.java
index f516b3352b..f66f323231 100644
--- a/maven-core/src/main/java/org/apache/maven/extension/ExtensionScanningException.java
+++ b/maven-core/src/main/java/org/apache/maven/extension/ExtensionScanningException.java
@@ -2,6 +2,7 @@ package org.apache.maven.extension;
import org.apache.maven.model.Extension;
import org.apache.maven.model.Model;
+import org.apache.maven.model.Plugin;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.interpolation.ModelInterpolationException;
@@ -78,6 +79,16 @@ public class ExtensionScanningException
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()
{
return pomFile;
diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
index 4173cf27f9..317e79257e 100644
--- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
+++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
@@ -162,15 +162,20 @@ public class DefaultPluginManager
ArtifactNotFoundException, InvalidPluginException,
PluginManagerException, PluginNotFoundException, PluginVersionNotFoundException
{
+ String pluginVersion = plugin.getVersion();
+
// TODO: this should be possibly outside
// 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() );
- String version = pluginVersionManager.resolvePluginVersion( plugin.getGroupId(),
+ pluginVersion = pluginVersionManager.resolvePluginVersion( plugin.getGroupId(),
plugin.getArtifactId(),
project, session );
- plugin.setVersion( version );
+ plugin.setVersion( pluginVersion );
+
+ getLogger().debug( "Resolved to version: " + pluginVersion );
}
return verifyVersionedPlugin( plugin, project, session );
@@ -379,8 +384,14 @@ public class DefaultPluginManager
if ( pluginDescriptor == null )
{
+ if ( ( pluginRealm != null ) && getLogger().isDebugEnabled() )
+ {
+ getLogger().debug( "Plugin Realm: " );
+ pluginRealm.display();
+ }
+
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 );
diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java b/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java
index a44915423f..eb3bb32a89 100644
--- a/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java
+++ b/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java
@@ -41,10 +41,8 @@ import org.apache.maven.project.ProjectBuildingException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.StringUtils;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
public class DefaultPluginVersionManager
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.
String version = getVersionFromPluginConfig( groupId, artifactId, project, resolveAsReportPlugin );
+
getLogger().debug( "Version from POM: " + version );
// 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
// also set that resolved version as the in settings.xml.
- if ( StringUtils.isEmpty( version ) )
+ 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 );
@@ -116,7 +115,7 @@ public class DefaultPluginVersionManager
// final pass...retrieve the version for RELEASE and also set that resolved version as the
// in settings.xml.
- if ( StringUtils.isEmpty( version ) )
+ 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 );
@@ -143,7 +142,7 @@ public class DefaultPluginVersionManager
{
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();
@@ -158,7 +157,7 @@ public class DefaultPluginVersionManager
{
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();
@@ -208,14 +207,14 @@ public class DefaultPluginVersionManager
{
boolean pluginValid = false;
- while ( !pluginValid && artifactVersion != null )
+ while ( !pluginValid && ( artifactVersion != null ) )
{
pluginValid = true;
MavenProject pluginProject;
try
{
artifact = artifactFactory.createProjectArtifact( groupId, artifactId, artifactVersion );
-
+
pluginProject = mavenProjectBuilder.buildFromRepository( artifact, project.getPluginArtifactRepositories(), localRepository );
}
catch ( ProjectBuildingException e )
@@ -225,7 +224,7 @@ public class DefaultPluginVersionManager
}
// 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 =
new DefaultArtifactVersion( pluginProject.getPrerequisites().getMaven() );
diff --git a/maven-core/src/main/resources/META-INF/plexus/components.xml b/maven-core/src/main/resources/META-INF/plexus/components.xml
index 8fe14804d1..9da3f89d2d 100644
--- a/maven-core/src/main/resources/META-INF/plexus/components.xml
+++ b/maven-core/src/main/resources/META-INF/plexus/components.xml
@@ -248,6 +248,9 @@ under the License.
org.apache.maven.extension.ExtensionManager
org.apache.maven.extension.DefaultExtensionManager
+
+ org.apache.maven.plugin.PluginManager
+
org.apache.maven.ArtifactFilterManager