diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java index c815920805..570427656f 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java @@ -390,8 +390,6 @@ public class DefaultMavenPluginManager RepositorySystemSession repositorySession = session.getRepositorySession(); if ( plugin.isExtensions() ) { - // TODO discover components in #setupExtensionsRealm - ExtensionRealmCache.CacheRecord extensionRecord; try { @@ -406,6 +404,11 @@ public class DefaultMavenPluginManager pluginRealm = extensionRecord.realm; pluginArtifacts = extensionRecord.artifacts; + + for ( ComponentDescriptor componentDescriptor : pluginDescriptor.getComponents() ) + { + componentDescriptor.setRealm( pluginRealm ); + } } else { @@ -877,6 +880,8 @@ public class DefaultMavenPluginManager { ClassRealm extensionRealm = classRealmManager.createExtensionRealm( plugin, toAetherArtifacts( artifacts ) ); + // TODO figure out how to use the same PluginDescriptor when running mojos + PluginDescriptor pluginDescriptor = null; if ( plugin.isExtensions() && !artifacts.isEmpty() ) { diff --git a/maven-core/src/test/java/org/apache/maven/plugin/PluginManagerTest.java b/maven-core/src/test/java/org/apache/maven/plugin/PluginManagerTest.java index bc87702298..025e77255b 100644 --- a/maven-core/src/test/java/org/apache/maven/plugin/PluginManagerTest.java +++ b/maven-core/src/test/java/org/apache/maven/plugin/PluginManagerTest.java @@ -30,6 +30,7 @@ import org.apache.maven.model.Plugin; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.repository.ComponentDescriptor; @@ -318,4 +319,24 @@ public class PluginManagerTest assertNotNull( descriptor.getImplementationClass() ); } } + + public void testBuildExtensionsPluginLoading() + throws Exception + { + RepositoryRequest repositoryRequest = new DefaultRepositoryRequest(); + repositoryRequest.setLocalRepository( getLocalRepository() ); + repositoryRequest.setRemoteRepositories( getPluginArtifactRepositories() ); + + // prime realm cache + MavenSession session = createMavenSession( getProject( "project-with-build-extensions-plugin" ) ); + MavenProject project = session.getCurrentProject(); + Plugin plugin = project.getPlugin( "org.apache.maven.its.plugins:maven-it-plugin" ); + + PluginDescriptor pluginDescriptor = + pluginManager.loadPlugin( plugin, session.getCurrentProject().getRemotePluginRepositories(), + session.getRepositorySession() ); + ClassRealm pluginRealm = pluginManager.getPluginRealm( session, pluginDescriptor ); + + assertEquals(pluginRealm, pluginDescriptor.getComponents().get(0).getRealm()); + } } diff --git a/maven-core/src/test/projects/plugin-manager/project-with-build-extensions-plugin/pom.xml b/maven-core/src/test/projects/plugin-manager/project-with-build-extensions-plugin/pom.xml new file mode 100644 index 0000000000..d4e34a5d98 --- /dev/null +++ b/maven-core/src/test/projects/plugin-manager/project-with-build-extensions-plugin/pom.xml @@ -0,0 +1,31 @@ + + 4.0.0 + + org.apache.maven.test + project-with-build-extensions-plugin + 1.0 + + + + + org.apache.maven.its.plugins + maven-it-plugin + 0.1 + true + + + load + validate + + maven-core-it.properties + target/pcl.properties + + + load + + + + + + +