You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ca...@apache.org on 2006/05/27 05:34:26 UTC

svn commit: r409807 - in /maven/components/branches/maven-2.0.x: ./ maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/ maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/ maven-artifact-manager/src/test/resource...

Author: carlos
Date: Fri May 26 20:34:26 2006
New Revision: 409807

URL: http://svn.apache.org/viewvc?rev=409807&view=rev
Log:
Merging 409806 from trunk [MNG-2324] Added getWagon( Repository ) to WagonManager.

Added:
    maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonMock.java
      - copied unchanged from r409806, maven/components/trunk/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonMock.java
Modified:
    maven/components/branches/maven-2.0.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java
    maven/components/branches/maven-2.0.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonManager.java
    maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java
    maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonA.java
    maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonB.java
    maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonC.java
    maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/resources/org/apache/maven/artifact/manager/DefaultWagonManagerTest.xml
    maven/components/branches/maven-2.0.x/pom.xml

Modified: maven/components/branches/maven-2.0.x/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.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java?rev=409807&r1=409806&r2=409807&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java (original)
+++ maven/components/branches/maven-2.0.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java Fri May 26 20:34:26 2006
@@ -1,7 +1,7 @@
 package org.apache.maven.artifact.manager;
 
 /*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-2006 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -74,6 +74,7 @@
 
     private Map mirrors = new HashMap();
     
+    /** Map( String, XmlPlexusConfiguration ) with the repository id and the wagon configuration */
     private Map serverConfigurationMap = new HashMap();
 
     private TransferListener downloadMonitor;
@@ -84,6 +85,23 @@
 
     private boolean interactive = true;
 
+    public Wagon getWagon( Repository repository )
+        throws UnsupportedProtocolException, WagonConfigurationException
+    {
+        String protocol = repository.getProtocol();
+
+        if ( protocol == null )
+        {
+            throw new UnsupportedProtocolException( "The repository " + repository + " does not specify a protocol" );
+        }
+
+        Wagon wagon = getWagon( protocol );
+
+        configureWagon( wagon, repository.getId() );
+
+        return wagon;
+    }
+
     public Wagon getWagon( String protocol )
         throws UnsupportedProtocolException
     {
@@ -715,9 +733,12 @@
     private void configureWagon( Wagon wagon, ArtifactRepository repository )
         throws WagonConfigurationException
     {
+       configureWagon( wagon, repository.getId() );
+    }
 
-        final String repositoryId = repository.getId();
-
+    private void configureWagon( Wagon wagon, String repositoryId )
+        throws WagonConfigurationException
+    {
         if ( serverConfigurationMap.containsKey( repositoryId ) )
         {
             ComponentConfigurator componentConfigurator = null;
@@ -752,11 +773,9 @@
             }
         }
     }
-    
 
     public void addConfiguration( String repositoryId, Xpp3Dom configuration )
     {
-
         if ( repositoryId == null || configuration == null )
         {
             throw new IllegalArgumentException( "arguments can't be null" );
@@ -766,4 +785,5 @@
 
         serverConfigurationMap.put( repositoryId, xmlConf );
     }
+
 }

Modified: maven/components/branches/maven-2.0.x/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.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonManager.java?rev=409807&r1=409806&r2=409807&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonManager.java (original)
+++ maven/components/branches/maven-2.0.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonManager.java Fri May 26 20:34:26 2006
@@ -1,7 +1,7 @@
 package org.apache.maven.artifact.manager;
 
 /*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-2006 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@
 import org.apache.maven.wagon.authentication.AuthenticationInfo;
 import org.apache.maven.wagon.events.TransferListener;
 import org.apache.maven.wagon.proxy.ProxyInfo;
+import org.apache.maven.wagon.repository.Repository;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
 
 import java.io.File;
@@ -39,9 +40,31 @@
 {
     String ROLE = WagonManager.class.getName();
 
+    /**
+     * Get a Wagon provider that understands the protocol passed as argument.
+     * It doesn't configure the Wagon.
+     * 
+     * @deprecated prone to errors. use {@link #getWagon(Repository)} instead.
+     * 
+     * @param protocol the protocol the {@link Wagon} will handle
+     * @return the {@link Wagon} instance able to handle the protocol provided
+     * @throws UnsupportedProtocolException if there is no provider able to handle the protocol
+     */
     Wagon getWagon( String protocol )
         throws UnsupportedProtocolException;
 
+    /**
+     * Get a Wagon provider for the provided repository.
+     * It will configure the Wagon for that repository.
+     * 
+     * @param repository the repository
+     * @return the {@link Wagon} instance that can be used to connect to the repository
+     * @throws UnsupportedProtocolException if there is no provider able to handle the protocol
+     * @throws WagonConfigurationException if the wagon can't be configured for the repository
+     */
+    Wagon getWagon( Repository repository )
+        throws UnsupportedProtocolException, WagonConfigurationException;
+
     void getArtifact( Artifact artifact, List remoteRepositories )
         throws TransferFailedException, ResourceDoesNotExistException;
 
@@ -77,7 +100,13 @@
 
     AuthenticationInfo getAuthenticationInfo( String id );
 
+    /**
+     * Set the configuration for a repository 
+     * 
+     * @param repositoryId id of the repository to set the configuration to
+     * @param configuration dom tree of the xml with the configuration for the {@link Wagon} 
+     */
     void addConfiguration( String repositoryId, Xpp3Dom configuration );
-    
+
     void setInteractive( boolean interactive );
 }

Modified: maven/components/branches/maven-2.0.x/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.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java?rev=409807&r1=409806&r2=409807&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java (original)
+++ maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java Fri May 26 20:34:26 2006
@@ -1,25 +1,26 @@
 package org.apache.maven.artifact.manager;
 
-/* ====================================================================
- *   Copyright 2001-2004 The Apache Software Foundation.
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
  *
- *   Licensed under the Apache License, Version 2.0 (the "License");
- *   you may not use this file except in compliance with the License.
- *   You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- *       http://www.apache.org/licenses/LICENSE-2.0
+ *      http://www.apache.org/licenses/LICENSE-2.0
  *
- *   Unless required by applicable law or agreed to in writing, software
- *   distributed under the License is distributed on an "AS IS" BASIS,
- *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *   See the License for the specific language governing permissions and
- *   limitations under the License.
- * ====================================================================
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 
 import org.apache.maven.wagon.UnsupportedProtocolException;
 import org.apache.maven.wagon.Wagon;
+import org.apache.maven.wagon.repository.Repository;
 import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
 
 /**
  * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
@@ -28,32 +29,75 @@
 public class DefaultWagonManagerTest
     extends PlexusTestCase
 {
+
+    private WagonManager wagonManager;
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        wagonManager = (WagonManager) lookup( WagonManager.ROLE );
+    }
+
     public void testDefaultWagonManager()
         throws Exception
     {
-        WagonManager wagonManager = (WagonManager) lookup( WagonManager.ROLE );
+        assertWagon( "a" );
 
-        Wagon wagon = null;
+        assertWagon( "b1" );
 
-        wagon = (Wagon) wagonManager.getWagon( "a" );
+        assertWagon( "b2" );
 
-        assertNotNull( wagon );
+        assertWagon( "c" );
+
+        try
+        {
+            assertWagon( "d" );
+
+            fail( "Expected :" + UnsupportedProtocolException.class.getName() );
+        }
+        catch ( UnsupportedProtocolException e )
+        {
+            //ok
+            assertTrue( true );
+        }
+    }
 
-        wagon = (Wagon) wagonManager.getWagon( "b1" );
+    public void testGetWagonRepository()
+        throws Exception
+    {
+        assertWagonRepository( "a" );
 
-        assertNotNull( wagon );
+        assertWagonRepository( "b1" );
 
-        wagon = (Wagon) wagonManager.getWagon( "b2" );
+        assertWagonRepository( "b2" );
 
-        assertNotNull( wagon );
+        assertWagonRepository( "c" );
 
-        wagon = (Wagon) wagonManager.getWagon( "c" );
+        try
+        {
+            assertWagonRepository( "d" );
 
-        assertNotNull( wagon );
+            fail( "Expected :" + UnsupportedProtocolException.class.getName() );
+        }
+        catch ( UnsupportedProtocolException e )
+        {
+            //ok
+            assertTrue( true );
+        }
+    }
 
+    public void testGetWagonRepositoryNullProtocol()
+        throws Exception
+    {
         try
         {
-            wagon = (Wagon) wagonManager.getWagon( "d" );
+            Repository repository = new Repository();
+
+            repository.setProtocol( null );
+
+            Wagon wagon = (Wagon) wagonManager.getWagon( repository );
 
             fail( "Expected :" + UnsupportedProtocolException.class.getName() );
         }
@@ -63,4 +107,41 @@
             assertTrue( true );
         }
     }
+
+    private void assertWagon( String protocol )
+        throws Exception
+    {
+        Wagon wagon = (Wagon) wagonManager.getWagon( protocol );
+
+        assertNotNull( "Check wagon, protocol=" + protocol, wagon );
+    }
+
+    private void assertWagonRepository( String protocol )
+        throws Exception
+    {
+        Repository repository = new Repository();
+
+        String s = "value=" + protocol;
+
+        repository.setId( "id=" + protocol );
+
+        repository.setProtocol( protocol );
+
+        Xpp3Dom conf = new Xpp3Dom( "configuration" );
+
+        Xpp3Dom configurableField = new Xpp3Dom( "configurableField" );
+
+        configurableField.setValue( s );
+
+        conf.addChild( configurableField );
+
+        wagonManager.addConfiguration( repository.getId(), conf );
+
+        WagonMock wagon = (WagonMock) wagonManager.getWagon( repository );
+
+        assertNotNull( "Check wagon, protocol=" + protocol, wagon );
+
+        assertEquals( "Check configuration for wagon, protocol=" + protocol, s, wagon.getConfigurableField() );
+    }
+
 }

Modified: maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonA.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonA.java?rev=409807&r1=409806&r2=409807&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonA.java (original)
+++ maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonA.java Fri May 26 20:34:26 2006
@@ -1,33 +1,30 @@
 package org.apache.maven.artifact.manager;
 
-/* ====================================================================
- *   Copyright 2001-2004 The Apache Software Foundation.
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
  *
- *   Licensed under the Apache License, Version 2.0 (the "License");
- *   you may not use this file except in compliance with the License.
- *   You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- *       http://www.apache.org/licenses/LICENSE-2.0
+ *      http://www.apache.org/licenses/LICENSE-2.0
  *
- *   Unless required by applicable law or agreed to in writing, software
- *   distributed under the License is distributed on an "AS IS" BASIS,
- *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *   See the License for the specific language governing permissions and
- *   limitations under the License.
- * ====================================================================
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 
-import org.apache.maven.wagon.providers.file.FileWagon;
-
 /**
- *
+ * Wagon for testing, for protocol <code>a</code>
  * 
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
  * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
- *
  * @version $Id$
  */
 public class WagonA
-    extends FileWagon
+    extends WagonMock
 {
     public String[] getSupportedProtocols()
     {

Modified: maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonB.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonB.java?rev=409807&r1=409806&r2=409807&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonB.java (original)
+++ maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonB.java Fri May 26 20:34:26 2006
@@ -1,33 +1,30 @@
 package org.apache.maven.artifact.manager;
 
-/* ====================================================================
- *   Copyright 2001-2004 The Apache Software Foundation.
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
  *
- *   Licensed under the Apache License, Version 2.0 (the "License");
- *   you may not use this file except in compliance with the License.
- *   You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- *       http://www.apache.org/licenses/LICENSE-2.0
+ *      http://www.apache.org/licenses/LICENSE-2.0
  *
- *   Unless required by applicable law or agreed to in writing, software
- *   distributed under the License is distributed on an "AS IS" BASIS,
- *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *   See the License for the specific language governing permissions and
- *   limitations under the License.
- * ====================================================================
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 
-import org.apache.maven.wagon.providers.file.FileWagon;
-
 /**
- *
+ * Wagon for testing, for protocols <code>b1</code> and <code>b2</code>
  * 
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
  * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
- *
  * @version $Id$
  */
 public class WagonB
-    extends FileWagon
+    extends WagonMock
 {
     public String[] getSupportedProtocols()
     {

Modified: maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonC.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonC.java?rev=409807&r1=409806&r2=409807&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonC.java (original)
+++ maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonC.java Fri May 26 20:34:26 2006
@@ -1,33 +1,30 @@
 package org.apache.maven.artifact.manager;
 
-/* ====================================================================
- *   Copyright 2001-2004 The Apache Software Foundation.
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
  *
- *   Licensed under the Apache License, Version 2.0 (the "License");
- *   you may not use this file except in compliance with the License.
- *   You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- *       http://www.apache.org/licenses/LICENSE-2.0
+ *      http://www.apache.org/licenses/LICENSE-2.0
  *
- *   Unless required by applicable law or agreed to in writing, software
- *   distributed under the License is distributed on an "AS IS" BASIS,
- *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *   See the License for the specific language governing permissions and
- *   limitations under the License.
- * ====================================================================
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 
-import org.apache.maven.wagon.providers.file.FileWagon;
-
 /**
- *
+ * Wagon for testing, for protocol <code>c</code>
  * 
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
  * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
- *
  * @version $Id$
  */
 public class WagonC
-    extends FileWagon
+    extends WagonMock
 {
     public String[] getSupportedProtocols()
     {

Modified: maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/resources/org/apache/maven/artifact/manager/DefaultWagonManagerTest.xml
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/resources/org/apache/maven/artifact/manager/DefaultWagonManagerTest.xml?rev=409807&r1=409806&r2=409807&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/resources/org/apache/maven/artifact/manager/DefaultWagonManagerTest.xml (original)
+++ maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/resources/org/apache/maven/artifact/manager/DefaultWagonManagerTest.xml Fri May 26 20:34:26 2006
@@ -1,3 +1,21 @@
+<!--
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+
 <plexus>
   <components>
     <component>
@@ -10,11 +28,11 @@
       <role-hint>b1</role-hint>
       <implementation>org.apache.maven.artifact.manager.WagonB</implementation>
     </component>
-     <component>
-        <role>org.apache.maven.wagon.Wagon</role>
-        <role-hint>b2</role-hint>
-        <implementation>org.apache.maven.artifact.manager.WagonB</implementation>
-      </component>
+    <component>
+      <role>org.apache.maven.wagon.Wagon</role>
+      <role-hint>b2</role-hint>
+      <implementation>org.apache.maven.artifact.manager.WagonB</implementation>
+    </component>
     <component>
       <role>org.apache.maven.wagon.Wagon</role>
       <role-hint>c</role-hint>

Modified: maven/components/branches/maven-2.0.x/pom.xml
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/pom.xml?rev=409807&r1=409806&r2=409807&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/pom.xml (original)
+++ maven/components/branches/maven-2.0.x/pom.xml Fri May 26 20:34:26 2006
@@ -298,7 +298,7 @@
       <dependency>
         <groupId>org.apache.maven.wagon</groupId>
         <artifactId>wagon-provider-api</artifactId>
-        <version>1.0-alpha-6</version>
+        <version>1.0-beta-1-SNAPSHOT</version>
       </dependency>
       <dependency>
         <groupId>org.apache.maven.wagon</groupId>