extends AbstractCoreComponentInitializationPhase
{
public void initializeCoreComponent( ContainerInitializationContext context )
throws ContainerInitializationException
{
ConfigurationSource existingConfigurationSource = context.getContainer().getConfigurationSource();
try
{
// is the user overriding the ConfigurationSource (role-hint: default) or only extending it?
if ( context.getContainer().hasComponent( ConfigurationSource.class, PlexusConstants.PLEXUS_DEFAULT_HINT ) )
{
// overriding
ConfigurationSource cs = context.getContainer().lookup( ConfigurationSource.class );
// swap the user provided configuration source with current one
context.getContainer().setConfigurationSource( cs );
}
else
{
// extending
List<ConfigurationSource> userConfigurationSources = context.getContainer().lookupList( ConfigurationSource.class );
if ( userConfigurationSources.size() > 0 )
{
List<ConfigurationSource> configurationSources =
new ArrayList<ConfigurationSource>( userConfigurationSources.size() + 1 );
// adding user provied ones to be able to interfere
configurationSources.addAll( userConfigurationSources );
// at the end adding the container source, to make sure config will be returned
// from plexus.xml if no user interference is given
configurationSources.add( existingConfigurationSource );
ConfigurationSource configurationSource = new ChainedConfigurationSource( configurationSources );
context.getContainer().setConfigurationSource( configurationSource );
}