if ( componentDescriptors != null )
{
for ( Iterator k = componentDescriptors.iterator(); k.hasNext(); )
{
ComponentDescriptor componentDescriptor = (ComponentDescriptor) k.next();
componentDescriptor.setComponentSetDescriptor( componentSet );
// If the user has already defined a component descriptor for this particular
// component then do not let the discovered component descriptor override
// the user defined one.
// Use the parent realm to search for the original descriptor. It won't
// be in the current realm (yet).
ComponentDescriptor orig = container.getComponentDescriptor( componentDescriptor
.getRole(), componentDescriptor.getRoleHint(), realm );
// System.out.println("Found new descriptor: " + componentDescriptor.getHumanReadableKey() + "
// realm="+ componentDescriptor.getRealmId() );
// System.out.println(" Existing descriptor: " + (orig == null ? "none":
// orig.getHumanReadableKey() + " realm= " + orig.getRealmId() ) );
if ( orig == null )
{
container.addComponentDescriptor( componentDescriptor );
// We only want to add components that have not yet been
// discovered in a parent realm. We don't quite have fine
// grained control over this right now but this is for
// dynamic additions which are only happening from maven
// at the moment. And plugins have a parent realm and
// a grand parent realm so if the component has been
// discovered it's most likely in those realms.
// I actually need to keep track of what realm a component
// was discovered in so that i can accurately search the
// parents.
discoveredComponentDescriptors.add( componentDescriptor );
}
else if ( override && orig.getRealmId() != null
&& !orig.getRealmId().equals( componentDescriptor.getRealmId() ) )
{
container.getLogger().debug( "Duplicate component found, merging:" + "\n Original: "
+ orig.getRealmId() + ": " + orig.getRole() + " [" + orig.getRoleHint() + "] impl="
+ orig.getImplementation() + "\n Config: " + orig.getConfiguration()
+ "\n New: " + componentDescriptor.getRealmId() + ": "
+ componentDescriptor.getRole() + " [" + orig.getRoleHint() + "] impl="
+ componentDescriptor.getImplementation() + "\n Config: " + orig.getConfiguration() );
PlexusComponentDescriptorMerger.merge( componentDescriptor, orig );
}
}
}