[MNG-6867] extract methods, apply SLA

This commit is contained in:
Lewinski, Arne 2020-02-16 14:54:11 +01:00 committed by Sylwester Lachiewicz
parent 9567da2bc8
commit c423a090e3
1 changed files with 42 additions and 26 deletions

View File

@ -328,37 +328,15 @@ public class DefaultMavenPluginManager
if ( plugin.isExtensions() )
{
ExtensionRealmCache.CacheRecord extensionRecord;
try
{
RepositorySystemSession repositorySession = session.getRepositorySession();
extensionRecord = setupExtensionsRealm( project, plugin, repositorySession );
}
catch ( PluginManagerException e )
{
// extensions realm is expected to be fully setup at this point
// any exception means a problem in maven code, not a user error
throw new IllegalStateException( e );
}
ClassRealm pluginRealm = extensionRecord.getRealm();
List<Artifact> pluginArtifacts = extensionRecord.getArtifacts();
for ( ComponentDescriptor<?> componentDescriptor : pluginDescriptor.getComponents() )
{
componentDescriptor.setRealm( pluginRealm );
}
pluginDescriptor.setClassRealm( pluginRealm );
pluginDescriptor.setArtifacts( pluginArtifacts );
setupPluginDescriptor( pluginDescriptor, session );
}
else
{
Map<String, ClassLoader> foreignImports = calcImports( project, parent, imports );
PluginRealmCache.Key cacheKey = pluginRealmCache.createKey( plugin, parent, foreignImports, filter,
project.getRemotePluginRepositories(),
session.getRepositorySession() );
PluginRealmCache.Key cacheKey =
pluginRealmCache.createKey( plugin, parent, foreignImports, filter,
project.getRemotePluginRepositories(), session.getRepositorySession() );
PluginRealmCache.CacheRecord cacheRecord = pluginRealmCache.get( cacheKey );
@ -383,6 +361,44 @@ public class DefaultMavenPluginManager
}
}
private void setupPluginDescriptor( PluginDescriptor pluginDescriptor, MavenSession session )
{
setupPluginDescriptor( pluginDescriptor,
setupExtensionsRealmInternal( session.getCurrentProject(), pluginDescriptor.getPlugin(),
session.getRepositorySession() ) );
}
private void setupPluginDescriptor( PluginDescriptor pluginDescriptor,
ExtensionRealmCache.CacheRecord extensionRecord )
{
setupComponentDescriptors( extensionRecord, pluginDescriptor.getComponents() );
pluginDescriptor.setClassRealm( extensionRecord.getRealm() );
pluginDescriptor.setArtifacts( extensionRecord.getArtifacts() );
}
private void setupComponentDescriptors( ExtensionRealmCache.CacheRecord extensionRecord,
List<ComponentDescriptor<?>> components )
{
components.stream().forEach( descriptor -> descriptor.setRealm( extensionRecord.getRealm() ) );
}
/**
* For internal usage. It is assumed that the prerequisites are met so a setup of the extensions realm can be
* processed without any error. Any exception thrown indicates a programming error, not a user error!
*/
private ExtensionRealmCache.CacheRecord setupExtensionsRealmInternal( MavenProject project, Plugin plugin,
RepositorySystemSession repositorySystemSession )
{
try
{
return setupExtensionsRealm( project, plugin, repositorySystemSession );
}
catch ( PluginManagerException e )
{
throw new IllegalStateException( e );
}
}
private void createPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent,
Map<String, ClassLoader> foreignImports, DependencyFilter filter )
throws PluginResolutionException, PluginContainerException