Artifact pluginArtifact,
MavenProject project,
ArtifactRepository localRepository )
throws PluginManagerException, InvalidPluginException
{
PlexusContainer child;
try
{
child = container.createChildContainer( plugin.getKey(),
Collections.singletonList( pluginArtifact.getFile() ),
Collections.EMPTY_MAP,
Collections.singletonList( pluginCollector ) );
try
{
child.getContainerRealm().importFrom( "plexus.core", "org.codehaus.plexus.util.xml.Xpp3Dom" );
child.getContainerRealm().importFrom( "plexus.core", "org.codehaus.plexus.util.xml.pull" );
// MNG-2878
child.getContainerRealm().importFrom( "plexus.core", "/default-report.xml" );
}
catch ( NoSuchRealmException e )
{
// won't happen
}
}
catch ( PlexusContainerException e )
{
throw new PluginManagerException(
"Failed to create plugin container for plugin '" + plugin + "': " + e.getMessage(), e );
}
// this plugin's descriptor should have been discovered in the child creation, so we should be able to
// circle around and set the artifacts and class realm
PluginDescriptor addedPlugin = pluginCollector.getPluginDescriptor( plugin );
if ( addedPlugin == null )
{
throw new IllegalStateException( "The PluginDescriptor for the plugin " + plugin + " was not found." );
}
addedPlugin.setClassRealm( child.getContainerRealm() );
// we're only setting the plugin's artifact itself as the artifact list, to allow it to be retrieved
// later when the plugin is first invoked. Retrieving this artifact will in turn allow us to
// transitively resolve its dependencies, and add them to the plugin container...
addedPlugin.setArtifacts( Collections.singletonList( pluginArtifact ) );