MNG-5742 fixed null ComponentDescriptor#realm for extensions plugins

Signed-off-by: Igor Fedorenko <ifedorenko@apache.org>
This commit is contained in:
Igor Fedorenko 2014-12-26 13:27:46 -05:00
parent 6f1571a1a6
commit 6ab41ee8d3
3 changed files with 59 additions and 2 deletions

View File

@ -390,8 +390,6 @@ private void createPluginRealm( PluginDescriptor pluginDescriptor, MavenSession
RepositorySystemSession repositorySession = session.getRepositorySession();
if ( plugin.isExtensions() )
{
// TODO discover components in #setupExtensionsRealm
ExtensionRealmCache.CacheRecord extensionRecord;
try
{
@ -406,6 +404,11 @@ private void createPluginRealm( PluginDescriptor pluginDescriptor, MavenSession
pluginRealm = extensionRecord.realm;
pluginArtifacts = extensionRecord.artifacts;
for ( ComponentDescriptor<?> componentDescriptor : pluginDescriptor.getComponents() )
{
componentDescriptor.setRealm( pluginRealm );
}
}
else
{
@ -877,6 +880,8 @@ public ExtensionRealmCache.CacheRecord setupExtensionsRealm( MavenProject projec
{
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() )
{

View File

@ -30,6 +30,7 @@
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 void testPluginRealmCache()
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());
}
}

View File

@ -0,0 +1,31 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.test</groupId>
<artifactId>project-with-build-extensions-plugin</artifactId>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin</artifactId>
<version>0.1</version>
<extensions>true</extensions>
<executions>
<execution>
<id>load</id>
<phase>validate</phase>
<configuration>
<resourcePaths>maven-core-it.properties</resourcePaths>
<pluginClassLoaderOutput>target/pcl.properties</pluginClassLoaderOutput>
</configuration>
<goals>
<goal>load</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>