private void discoverPluginComponents( final ClassRealm pluginRealm, Plugin plugin, PluginDescriptor pluginDescriptor ) throws PluginContainerException { try { if ( pluginDescriptor != null ) { for ( ComponentDescriptor<?> componentDescriptor : pluginDescriptor.getComponents() ) { componentDescriptor.setRealm( pluginRealm ); container.addComponentDescriptor( componentDescriptor ); } } ( (DefaultPlexusContainer) container ).discoverComponents( pluginRealm, new SessionScopeModule( container ), new MojoExecutionScopeModule( container ) ); } catch ( ComponentLookupException | CycleDetectedInComponentGraphException e ) { throw new PluginContainerException( plugin, pluginRealm, "Error in component graph of plugin " + plugin.getId() + ": " + e.getMessage(), e ); } }
public void addComponentDescriptor( ComponentDescriptor<?> componentDescriptor ) throws CycleDetectedInComponentGraphException { if ( componentDescriptor.getRealm() == null ) { componentDescriptor.setRealm( this.containerRealm ); // throw new ComponentImplementationNotFoundException( "ComponentDescriptor is missing realmId" ); } componentRegistry.addComponentDescriptor( componentDescriptor ); }
private ComponentRepository getComponentRepository( ContainerInitializationContext context ) throws ContainerInitializationException { ComponentRepository repository = context.getContainerConfiguration().getComponentRepository(); // Add the components defined in the container xml configuration try { PlexusConfiguration configuration = context.getContainerXmlConfiguration(); PlexusConfiguration[] componentConfigurations = configuration.getChild( "components" ).getChildren( "component" ); for ( PlexusConfiguration componentConfiguration : componentConfigurations ) { ComponentDescriptor<?> componentDescriptor = PlexusTools.buildComponentDescriptor( componentConfiguration, context.getContainer().getContainerRealm() ); componentDescriptor.setRealm( context.getContainer().getContainerRealm() ); repository.addComponentDescriptor( componentDescriptor ); } } catch ( PlexusConfigurationException e ) { throw new ContainerInitializationException( "Error initializing component repository: " + "Cannot unmarshall component descriptor: ", e ); } catch ( CycleDetectedInComponentGraphException e ) { throw new ContainerInitializationException( "A cycle has been detected in the components of the system: ", e ); } return repository; }
public <T> void addComponentDescriptor( final ComponentDescriptor<T> descriptor ) { ClassRealm realm = descriptor.getRealm(); if ( null == realm ) { realm = containerRealm; descriptor.setRealm( realm ); } synchronized ( descriptorMap ) { List<ComponentDescriptor<?>> descriptors = descriptorMap.get( realm ); if ( null == descriptors ) { descriptors = new ArrayList<ComponentDescriptor<?>>(); descriptorMap.put( realm, descriptors ); } descriptors.add( descriptor ); } if ( containerRealm == realm ) { discoverComponents( containerRealm ); // for Maven3 testing } }