Hi John!

Thanks for the improvements to the test :) I've added a couple more for other scenarios.

I made some adjustments to the implementation you put in place:
- made sure maven-artifact wasn't relying on the existence of maven- core - so it sets it's bit, then core prefixes the Maven version on there - removed the get/set from the interface - I don't think they're needed in the general case.

Hope these are ok.

Still up for discussion is the format. After reviewing the HTTP RFC, I changed it to:

Apache-Maven/2.0.10-RC2-SNAPSHOT maven-artifact/2.0.10-RC2-SNAPSHOT (Java: 1.5.0_13; Mac OS X 10.5.4)

In 2.1, this would probably be:
Apache-Maven/2.1-SNAPSHOT maven-artifact/3.0-alpha-1 (Java: 1.5.0_13; Mac OS X 10.5.4) (I'm fixing this up on there now since the ITs are failing in Continuum on trunk)

ie, Product 1 = Apache-Maven/VERSION
Product 2 = maven-artifact/VERSION
and the comment is at the end

I think the debatable things are:
- is maven-artifact the right name to use?
- maven-artifact would be used by non-Maven users of maven-artifact - but in Maven, is it needed since it can be derived from the Maven version?
- should we include the wagon (or mercury) version in Maven?

Cheers,
Brett

On 23/07/2008, at 2:01 AM, [EMAIL PROTECTED] wrote:

Author: jdcasey
Date: Tue Jul 22 09:01:10 2008
New Revision: 678784

URL: http://svn.apache.org/viewvc?rev=678784&view=rev
Log:
Improve support for User-Agent header in http wagons. Also, add a note about problems with shallow-cloning of plugin instances to ModelUtils. Finally, comment out the component configuration for the lightweight http wagon in maven-core, so we don't need to wait for the next shade plugin release to do the next maven RC.

Modified:
maven/components/branches/maven-2.0.10-RC/maven-artifact-manager/ src/main/java/org/apache/maven/artifact/manager/ DefaultWagonManager.java maven/components/branches/maven-2.0.10-RC/maven-artifact-manager/ src/main/java/org/apache/maven/artifact/manager/WagonManager.java maven/components/branches/maven-2.0.10-RC/maven-artifact-manager/ src/test/java/org/apache/maven/artifact/manager/ DefaultWagonManagerTest.java maven/components/branches/maven-2.0.10-RC/maven-core-it-runner/ pom.xml maven/components/branches/maven-2.0.10-RC/maven-core/src/main/ resources/META-INF/plexus/components.xml maven/components/branches/maven-2.0.10-RC/maven-project/src/main/ java/org/apache/maven/project/ModelUtils.java
   maven/components/branches/maven-2.0.10-RC/pom.xml

Modified: maven/components/branches/maven-2.0.10-RC/maven-artifact- manager/src/main/java/org/apache/maven/artifact/manager/ DefaultWagonManager.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.10-RC/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java?rev=678784&r1=678783&r2=678784&view=diff
= = = = = = = = ====================================================================== --- maven/components/branches/maven-2.0.10-RC/maven-artifact-manager/ src/main/java/org/apache/maven/artifact/manager/ DefaultWagonManager.java (original) +++ maven/components/branches/maven-2.0.10-RC/maven-artifact-manager/ src/main/java/org/apache/maven/artifact/manager/ DefaultWagonManager.java Tue Jul 22 09:01:10 2008
@@ -50,11 +50,15 @@
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org .codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; +import org .codehaus .plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.Xpp3Dom;

import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.NoSuchAlgorithmException;
@@ -64,16 +68,19 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import java.util.Set;

public class DefaultWagonManager
    extends AbstractLogEnabled
-    implements WagonManager, Contextualizable
+    implements WagonManager, Contextualizable, Initializable
{
    private static final String WILDCARD = "*";

    private static final String EXTERNAL_WILDCARD = "external:*";

+ private static final String MAVEN_CORE_PROPERTIES = "META-INF/ maven/org.apache.maven/maven-core/pom.properties";
+
    private PlexusContainer container;

// TODO: proxies, authentication and mirrors are via settings, and should come in via an alternate method - perhaps
@@ -102,6 +109,10 @@

    private RepositoryPermissions defaultRepositoryPermissions;

+    private String httpUserAgent;
+
+    private String httpUserAgentDetails;
+
// TODO: this leaks the component in the public api - it is never released back to the container
    public Wagon getWagon( Repository repository )
throws UnsupportedProtocolException, WagonConfigurationException
@@ -115,7 +126,7 @@

        Wagon wagon = getWagon( protocol );

-        configureWagon( wagon, repository.getId() );
+        configureWagon( wagon, repository.getId(), protocol );

        return wagon;
    }
@@ -988,21 +999,27 @@
                                 ArtifactRepository repository )
        throws WagonConfigurationException
    {
-        configureWagon( wagon, repository.getId() );
+ configureWagon( wagon, repository.getId(), repository.getProtocol() );
    }

    private void configureWagon( Wagon wagon,
-                                 String repositoryId )
+                                 String repositoryId,
+                                 String protocol )
        throws WagonConfigurationException
    {
-        if ( serverConfigurationMap.containsKey( repositoryId ) )
+ PlexusConfiguration config = (PlexusConfiguration) serverConfigurationMap.get( repositoryId );
+        if ( protocol.startsWith( "http" ) )
+        {
+            config = updateUserAgentForHttp( wagon, config );
+        }
+
+        if ( config != null )
        {
            ComponentConfigurator componentConfigurator = null;
            try
            {
componentConfigurator = (ComponentConfigurator) container.lookup( ComponentConfigurator.ROLE ); - componentConfigurator.configureComponent( wagon, (PlexusConfiguration) serverConfigurationMap - .get( repositoryId ), container.getContainerRealm() ); + componentConfigurator.configureComponent( wagon, config, container.getContainerRealm() );
            }
            catch ( final ComponentLookupException e )
            {
@@ -1032,6 +1049,50 @@
        }
    }

+ // 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" );
+        }
+
+        String userAgent = getHttpUserAgentString();
+
+        if ( userAgent != null )
+        {
+            try
+            {
+ wagon.getClass().getMethod( "setHttpHeaders", new Class[]{ Properties.class } );
+
+ PlexusConfiguration headerConfig = config.getChild( "httpHeaders", true ); + if ( headerConfig.getChild( "User-Agent", false ) == null )
+                {
+ 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( userAgent );
+                    propertyConfig.addChild( versionConfig );
+                }
+            }
+            catch ( SecurityException e )
+            {
+                // forget it. this method is public, if it exists.
+            }
+            catch ( NoSuchMethodException e )
+            {
+                // forget it.
+            }
+        }
+
+        return config;
+    }
+
    public void addConfiguration( String repositoryId,
                                  Xpp3Dom configuration )
    {
@@ -1049,4 +1110,87 @@
    {
this.defaultRepositoryPermissions = defaultRepositoryPermissions;
    }
+
+ // TODO: Remove this, once the maven-shade-plugin 1.2 release is out, allowing configuration of httpHeaders in the components.xml
+    public void initialize()
+        throws InitializationException
+    {
+        if ( httpUserAgent == null )
+        {
+            httpUserAgent = "ApacheMavenArtifact/2.0";
+        }
+
+        if ( httpUserAgentDetails == null )
+        {
+            InputStream resourceAsStream = null;
+            try
+            {
+                Properties properties = new Properties();
+ resourceAsStream = getClass ().getClassLoader().getResourceAsStream( MAVEN_CORE_PROPERTIES );
+
+                if ( resourceAsStream != null )
+                {
+                    try
+                    {
+                        properties.load( resourceAsStream );
+
+                        httpUserAgentDetails =
+ "Apache Maven " + properties.getProperty( "version" ) + "; JDK " + + System.getProperty( "java.version" ) + "; " + System.getProperty( "os.name" ) + " "
+                                + System.getProperty( "os.version" );
+                    }
+                    catch ( IOException e )
+                    {
+                        getLogger().warn(
+ "Failed to load Maven core properties from:\n" + MAVEN_CORE_PROPERTIES + + "\n\nUser-Agent HTTP header may be incorrect for artifact resolution." );
+                    }
+                }
+            }
+            finally
+            {
+                IOUtil.close( resourceAsStream );
+            }
+        }
+    }
+
+    /**
+     * [EMAIL PROTECTED]
+     */
+    public void setHttpUserAgent( String userAgent )
+    {
+        this.httpUserAgent = userAgent;
+    }
+
+    /**
+     * [EMAIL PROTECTED]
+     */
+    public String getHttpUserAgent()
+    {
+        return httpUserAgent;
+    }
+
+    /**
+     * [EMAIL PROTECTED]
+     */
+    public void setHttpUserAgentDetails( String userAgentDetails )
+    {
+        this.httpUserAgentDetails = userAgentDetails;
+    }
+
+    /**
+     * [EMAIL PROTECTED]
+     */
+    public String getUserAgentDetails()
+    {
+        return httpUserAgentDetails;
+    }
+
+    /**
+     * [EMAIL PROTECTED]
+     */
+    public String getHttpUserAgentString()
+    {
+ return httpUserAgent == null ? null : String.valueOf( httpUserAgent ) + " (" + String.valueOf( httpUserAgentDetails ) + ")";
+    }
}

Modified: maven/components/branches/maven-2.0.10-RC/maven-artifact- manager/src/main/java/org/apache/maven/artifact/manager/ WagonManager.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.10-RC/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonManager.java?rev=678784&r1=678783&r2=678784&view=diff
= = = = = = = = ====================================================================== --- maven/components/branches/maven-2.0.10-RC/maven-artifact-manager/ src/main/java/org/apache/maven/artifact/manager/WagonManager.java (original) +++ maven/components/branches/maven-2.0.10-RC/maven-artifact-manager/ src/main/java/org/apache/maven/artifact/manager/WagonManager.java Tue Jul 22 09:01:10 2008
@@ -126,4 +126,45 @@
void setDefaultRepositoryPermissions( RepositoryPermissions permissions );

ArtifactRepository getMirrorRepository( ArtifactRepository repository );
+
+    /**
+ * Allow configuration of the User-Agent HTTP header used for http wagons.
+     *
+     * @since 2.0.10
+     */
+    void setHttpUserAgent( String userAgent );
+
+    /**
+     * Retrieve the User-Agent HTTP header used for http wagons.
+     *
+     * @since 2.0.10
+     */
+    String getHttpUserAgent();
+
+    /**
+ * Allow configuration of the details of the User-Agent HTTP header (beyond + * the initial value) used for http wagons. By default, this value will + * contain specific information about the tool using maven- artifact, along
+     * with the operating system and JDK version.
+     *
+     * @since 2.0.10
+     */
+    void setHttpUserAgentDetails( String userAgentDetails );
+
+    /**
+     * Retrieve the details of the User-Agent HTTP header (beyond
+ * the initial value) used for http wagons. By default, this value will + * contain specific information about the tool using maven- artifact, along
+     * with the operating system and JDK version.
+     *
+     * @since 2.0.10
+     */
+    String getUserAgentDetails();
+
+    /**
+ * Retrieve the full User-Agent HTTP header value for use in http wagons.
+     *
+     * @since 2.0.10
+     */
+    String getHttpUserAgentString();
}

Modified: maven/components/branches/maven-2.0.10-RC/maven-artifact- manager/src/test/java/org/apache/maven/artifact/manager/ DefaultWagonManagerTest.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.10-RC/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java?rev=678784&r1=678783&r2=678784&view=diff
= = = = = = = = ====================================================================== --- maven/components/branches/maven-2.0.10-RC/maven-artifact-manager/ src/test/java/org/apache/maven/artifact/manager/ DefaultWagonManagerTest.java (original) +++ maven/components/branches/maven-2.0.10-RC/maven-artifact-manager/ src/test/java/org/apache/maven/artifact/manager/ DefaultWagonManagerTest.java Tue Jul 22 09:01:10 2008
@@ -53,7 +53,7 @@
public class DefaultWagonManagerTest
    extends PlexusTestCase
{
-    private DefaultWagonManager wagonManager;
+    private WagonManager wagonManager;

    private TransferListener transferListener = new Debug();

@@ -64,7 +64,7 @@
    {
        super.setUp();

- wagonManager = (DefaultWagonManager) lookup( WagonManager.ROLE );
+        wagonManager = (WagonManager) lookup( WagonManager.ROLE );

artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
    }

Modified: maven/components/branches/maven-2.0.10-RC/maven-core-it- runner/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.10-RC/maven-core-it-runner/pom.xml?rev=678784&r1=678783&r2=678784&view=diff
= = = = = = = = ====================================================================== --- maven/components/branches/maven-2.0.10-RC/maven-core-it-runner/ pom.xml (original) +++ maven/components/branches/maven-2.0.10-RC/maven-core-it-runner/ pom.xml Tue Jul 22 09:01:10 2008
@@ -23,7 +23,7 @@
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.apache.maven</groupId>
-    <version>2.0.10-RC1-SNAPSHOT</version>
+    <version>2.0.10-RC2-SNAPSHOT</version>
    <artifactId>maven-core-it-runner</artifactId>
    <name>Integration Test Executor</name>


Modified: maven/components/branches/maven-2.0.10-RC/maven-core/src/ main/resources/META-INF/plexus/components.xml
URL: 
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.10-RC/maven-core/src/main/resources/META-INF/plexus/components.xml?rev=678784&r1=678783&r2=678784&view=diff
= = = = = = = = ====================================================================== --- maven/components/branches/maven-2.0.10-RC/maven-core/src/main/ resources/META-INF/plexus/components.xml (original) +++ maven/components/branches/maven-2.0.10-RC/maven-core/src/main/ resources/META-INF/plexus/components.xml Tue Jul 22 09:01:10 2008
@@ -584,6 +584,8 @@
      </requirements>
    </component>

+ <!-- TODO: Re-enable this once maven-shade-plugin 1.2 is release and can be + used to merge this configuration with that of the wagon artifacts.
    <component>
      <role>org.apache.maven.wagon.Wagon</role>
      <role-hint>http</role-hint>
@@ -616,5 +618,6 @@
        </httpHeaders>
      </configuration>
    </component>
+    -->
  </components>
</component-set>

Modified: maven/components/branches/maven-2.0.10-RC/maven-project/ src/main/java/org/apache/maven/project/ModelUtils.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.10-RC/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java?rev=678784&r1=678783&r2=678784&view=diff
= = = = = = = = ====================================================================== --- maven/components/branches/maven-2.0.10-RC/maven-project/src/main/ java/org/apache/maven/project/ModelUtils.java (original) +++ maven/components/branches/maven-2.0.10-RC/maven-project/src/main/ java/org/apache/maven/project/ModelUtils.java Tue Jul 22 09:01:10 2008
@@ -562,6 +562,8 @@
    public static Model cloneModel( Model model )
    {
// TODO: would be nice for the modello:java code to generate this as a copy constructor + // FIXME: Fix deep cloning issues with existing plugin instances (setting + // a version when resolved will pollute the original model instance)
        Model newModel = new Model();
ModelInheritanceAssembler assembler = new DefaultModelInheritanceAssembler();
        newModel.setModelVersion( model.getModelVersion() );

Modified: maven/components/branches/maven-2.0.10-RC/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.10-RC/pom.xml?rev=678784&r1=678783&r2=678784&view=diff
= = = = = = = = ======================================================================
--- maven/components/branches/maven-2.0.10-RC/pom.xml (original)
+++ maven/components/branches/maven-2.0.10-RC/pom.xml Tue Jul 22 09:01:10 2008
@@ -205,6 +205,7 @@
            <excludes>
<!-- TODO: These represent method ADDITIONS from 2.0.9, and should be removed after
                   2.0.10 is released. -->
+ <exclude>org/apache/maven/artifact/manager/ WagonManager*</exclude> <exclude>org/apache/maven/artifact/metadata/ ArtifactMetadataSource*</exclude> <exclude>org/apache/maven/project/ MavenProjectBuilder*</exclude> <exclude>org/apache/maven/project/ ProjectBuilderConfiguration*</exclude>



--
Brett Porter
[EMAIL PROTECTED]
http://blogs.exist.com/bporter/


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to