// TODO: Remove this, once the maven-shade-plugin 1.2 release is out, allowing configuration of httpHeaders in the components.xml
private PlexusConfiguration updateUserAgentForHttp( Wagon wagon, PlexusConfiguration config )
{
if ( config == null )
{
config = new XmlPlexusConfiguration( "configuration" );
}
if ( httpUserAgent != null )
{
try
{
wagon.getClass().getMethod( "setHttpHeaders", new Class[]{ Properties.class } );
PlexusConfiguration headerConfig = config.getChild( "httpHeaders", true );
PlexusConfiguration[] children = headerConfig.getChildren( "property" );
boolean found = false;
getLogger().debug( "Checking for pre-existing User-Agent configuration." );
for ( int i = 0; i < children.length; i++ )
{
PlexusConfiguration c = children[i].getChild( "name", false );
if ( c != null && "User-Agent".equals( c.getValue( null ) ) )
{
found = true;
break;
}
}
if ( !found )
{
getLogger().debug( "Adding User-Agent configuration." );
XmlPlexusConfiguration propertyConfig = new XmlPlexusConfiguration( "property" );
headerConfig.addChild( propertyConfig );
XmlPlexusConfiguration nameConfig = new XmlPlexusConfiguration( "name" );
nameConfig.setValue( "User-Agent" );
propertyConfig.addChild( nameConfig );
XmlPlexusConfiguration versionConfig = new XmlPlexusConfiguration( "value" );
versionConfig.setValue( httpUserAgent );
propertyConfig.addChild( versionConfig );
}
else
{
getLogger().debug( "User-Agent configuration found." );