// components | user
// -----------------------------------+-----------------------------------------------------------------
public static PlexusConfiguration merge( PlexusConfiguration user, PlexusConfiguration system )
{
XmlPlexusConfiguration mergedConfiguration = new XmlPlexusConfiguration( "plexus" );
// ----------------------------------------------------------------------
// Load on start
// ----------------------------------------------------------------------
PlexusConfiguration loadOnStart = user.getChild( "load-on-start" );
if ( loadOnStart.getChildCount() != 0 )
{
mergedConfiguration.addChild( loadOnStart );
}
// ----------------------------------------------------------------------
// System properties
// ----------------------------------------------------------------------
PlexusConfiguration systemProperties = user.getChild( "system-properties" );
if ( systemProperties.getChildCount() != 0 )
{
mergedConfiguration.addChild( systemProperties );
}
// ----------------------------------------------------------------------
// Configurations directory
// ----------------------------------------------------------------------
PlexusConfiguration[] configurationsDirectories = user.getChildren( "configurations-directory" );
if ( configurationsDirectories.length != 0 )
{
for ( int i = 0; i < configurationsDirectories.length; i++ )
{
mergedConfiguration.addChild( configurationsDirectories[i] );
}
}
// ----------------------------------------------------------------------
// Logging
// ----------------------------------------------------------------------
PlexusConfiguration logging = user.getChild( "logging" );
if ( logging.getChildCount() != 0 )
{
mergedConfiguration.addChild( logging );
}
else
{
mergedConfiguration.addChild( system.getChild( "logging" ) );
}
// ----------------------------------------------------------------------
// Component repository
// ----------------------------------------------------------------------
PlexusConfiguration componentRepository = user.getChild( "component-repository" );
if ( componentRepository.getChildCount() != 0 )
{
mergedConfiguration.addChild( componentRepository );
}
else
{
mergedConfiguration.addChild( system.getChild( "component-repository" ) );
}
// ----------------------------------------------------------------------
// Resources
// ----------------------------------------------------------------------
copyResources( system, mergedConfiguration );
copyResources( user, mergedConfiguration );
// ----------------------------------------------------------------------
// Component manager manager
// ----------------------------------------------------------------------
mergedConfiguration.addChild( system.getChild( "component-manager-manager" ) );
// ----------------------------------------------------------------------
// Component discoverer manager
// ----------------------------------------------------------------------
PlexusConfiguration componentDiscovererManager = user.getChild( "component-discoverer-manager" );
if ( componentDiscovererManager.getChildCount() != 0 )
{
mergedConfiguration.addChild( componentDiscovererManager );
copyComponentDiscoverers( system.getChild( "component-discoverer-manager" ), componentDiscovererManager );
}
else
{
mergedConfiguration.addChild( system.getChild( "component-discoverer-manager" ) );
}
// ----------------------------------------------------------------------
// Component factory manager
// ----------------------------------------------------------------------
PlexusConfiguration componentFactoryManager = user.getChild( "component-factory-manager" );
if ( componentFactoryManager.getChildCount() != 0 )
{
mergedConfiguration.addChild( componentFactoryManager );
copyComponentFactories( system.getChild( "component-factory-manager" ), componentFactoryManager );
}
else
{
mergedConfiguration.addChild( system.getChild( "component-factory-manager" ) );
}
// ----------------------------------------------------------------------
// Lifecycle handler managers
// ----------------------------------------------------------------------
PlexusConfiguration lifecycleHandlerManager = user.getChild( "lifecycle-handler-manager" );
if ( lifecycleHandlerManager.getChildCount() != 0 )
{
mergedConfiguration.addChild( lifecycleHandlerManager );
copyLifecycles( system.getChild( "lifecycle-handler-manager" ), lifecycleHandlerManager );
}
else
{
mergedConfiguration.addChild( system.getChild( "lifecycle-handler-manager" ) );
}
// ----------------------------------------------------------------------
// Component factory manager
// ----------------------------------------------------------------------
PlexusConfiguration componentComposerManager = user.getChild( "component-composer-manager" );
if ( componentComposerManager.getChildCount() != 0 )
{
mergedConfiguration.addChild( componentComposerManager );
copyComponentComposers( system.getChild( "component-composer-manager" ), componentComposerManager );
}
else
{
mergedConfiguration.addChild( system.getChild( "component-composer-manager" ) );
}
// ----------------------------------------------------------------------
// Components
// ----------------------------------------------------------------------
// We grab the system components first and then add the user defined
// components so that user defined components will win. When component
// descriptors are processed the last definition wins because the component
// descriptors are stored in a Map in the component repository.
// ----------------------------------------------------------------------
PlexusConfiguration components = system.getChild( "components" );
mergedConfiguration.addChild( components );
copyComponents( user.getChild( "components" ), components );
return mergedConfiguration;
}