if ( build != null )
{
for ( Extension extension : build.getExtensions() )
{
Plugin plugin = new Plugin();
plugin.setGroupId( extension.getGroupId() );
plugin.setArtifactId( extension.getArtifactId() );
plugin.setVersion( extension.getVersion() );
extensionPlugins.add( plugin );
}
for ( Plugin plugin : build.getPlugins() )
{
if ( plugin.isExtensions() )
{
extensionPlugins.add( plugin );
}
}
}
if ( extensionPlugins.isEmpty() )
{
if ( logger.isDebugEnabled() )
{
logger.debug( "Extension realms for project " + model.getId() + ": (none)" );
}
return new ProjectRealmCache.CacheRecord( null, null );
}
List<ClassRealm> extensionRealms = new ArrayList<ClassRealm>();
Map<ClassRealm, List<String>> exportedPackages = new HashMap<ClassRealm, List<String>>();
Map<ClassRealm, List<String>> exportedArtifacts = new HashMap<ClassRealm, List<String>>();
List<Artifact> publicArtifacts = new ArrayList<Artifact>();
for ( Plugin plugin : extensionPlugins )
{
if ( plugin.getVersion() == null )
{
PluginVersionRequest versionRequest =
new DefaultPluginVersionRequest( plugin, request.getRepositorySession(),
project.getRemotePluginRepositories() );
plugin.setVersion( pluginVersionResolver.resolve( versionRequest ).getVersion() );
}
List<Artifact> artifacts;
PluginArtifactsCache.Key cacheKey =
pluginArtifactsCache.createKey( plugin, null, project.getRemotePluginRepositories(),
request.getRepositorySession() );
PluginArtifactsCache.CacheRecord recordArtifacts = pluginArtifactsCache.get( cacheKey );
if ( recordArtifacts != null )
{
artifacts = recordArtifacts.artifacts;
}
else
{
try
{
artifacts = resolveExtensionArtifacts( plugin, project.getRemotePluginRepositories(), request );
recordArtifacts = pluginArtifactsCache.put( cacheKey, artifacts );
}
catch ( PluginResolutionException e )
{
pluginArtifactsCache.put( cacheKey, e );
pluginArtifactsCache.register( project, recordArtifacts );
throw e;
}
}
pluginArtifactsCache.register( project, recordArtifacts );
ClassRealm extensionRealm;
ExtensionDescriptor extensionDescriptor = null;
ExtensionRealmCache.CacheRecord recordRealm = extensionRealmCache.get( artifacts );
if ( recordRealm != null )
{
extensionRealm = recordRealm.realm;
extensionDescriptor = recordRealm.desciptor;
}
else
{
extensionRealm = classRealmManager.createExtensionRealm( plugin, artifacts );
try
{
container.discoverComponents( extensionRealm );
}
catch ( Exception e )
{
throw new IllegalStateException( "Failed to discover components in extension realm "
+ extensionRealm.getId(), e );
}
Artifact extensionArtifact = artifacts.get( 0 );
try
{
extensionDescriptor = extensionDescriptorBuilder.build( extensionArtifact.getFile() );
}
catch ( IOException e )
{
String message = "Invalid extension descriptor for " + plugin.getId() + ": " + e.getMessage();
if ( logger.isDebugEnabled() )
{
logger.error( message, e );
}
else
{
logger.error( message );
}
}
recordRealm = extensionRealmCache.put( artifacts, extensionRealm, extensionDescriptor );
}
extensionRealmCache.register( project, recordRealm );
extensionRealms.add( extensionRealm );
if ( extensionDescriptor != null )
{
exportedPackages.put( extensionRealm, extensionDescriptor.getExportedPackages() );
exportedArtifacts.put( extensionRealm, extensionDescriptor.getExportedArtifacts() );
}
if ( !plugin.isExtensions() && artifacts.size() == 2 && artifacts.get( 0 ).getFile() != null
&& "plexus-utils".equals( artifacts.get( 1 ).getArtifactId() ) )
{
/*
* This is purely for backward-compat with 2.x where <extensions> consisting of a single artifact where
* loaded into the core and hence available to plugins, in contrast to bigger extensions that were