diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java
index 95a6b6ed69..bc176efb17 100644
--- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java
+++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java
@@ -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 @@ public class DefaultWagonManager
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 @@ public class DefaultWagonManager
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 @@ public class DefaultWagonManager
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 class DefaultWagonManager
}
}
}
-
public void addConfiguration( String repositoryId, Xpp3Dom configuration )
{
-
if ( repositoryId == null || configuration == null )
{
throw new IllegalArgumentException( "arguments can't be null" );
@@ -766,4 +785,5 @@ public class DefaultWagonManager
serverConfigurationMap.put( repositoryId, xmlConf );
}
+
}
diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonManager.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonManager.java
index 4f2b95e5a1..24adeed74d 100644
--- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonManager.java
+++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonManager.java
@@ -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.Wagon;
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 @@ public interface WagonManager
{
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 @@ public interface WagonManager
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 );
}
\ No newline at end of file
diff --git a/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java b/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java
index 6161b6da81..25e17760b9 100644
--- a/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java
+++ b/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java
@@ -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 Michal Maczka
@@ -28,32 +29,31 @@ import org.codehaus.plexus.PlexusTestCase;
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 );
-
- wagon = (Wagon) wagonManager.getWagon( "b1" );
-
- assertNotNull( wagon );
-
- wagon = (Wagon) wagonManager.getWagon( "b2" );
-
- assertNotNull( wagon );
-
- wagon = (Wagon) wagonManager.getWagon( "c" );
-
- assertNotNull( wagon );
+ assertWagon( "c" );
try
{
- wagon = (Wagon) wagonManager.getWagon( "d" );
+ assertWagon( "d" );
fail( "Expected :" + UnsupportedProtocolException.class.getName() );
}
@@ -63,4 +63,85 @@ public class DefaultWagonManagerTest
assertTrue( true );
}
}
+
+ public void testGetWagonRepository()
+ throws Exception
+ {
+ assertWagonRepository( "a" );
+
+ assertWagonRepository( "b1" );
+
+ assertWagonRepository( "b2" );
+
+ assertWagonRepository( "c" );
+
+ try
+ {
+ assertWagonRepository( "d" );
+
+ fail( "Expected :" + UnsupportedProtocolException.class.getName() );
+ }
+ catch ( UnsupportedProtocolException e )
+ {
+ //ok
+ assertTrue( true );
+ }
+ }
+
+ public void testGetWagonRepositoryNullProtocol()
+ throws Exception
+ {
+ try
+ {
+ Repository repository = new Repository();
+
+ repository.setProtocol( null );
+
+ Wagon wagon = (Wagon) wagonManager.getWagon( repository );
+
+ fail( "Expected :" + UnsupportedProtocolException.class.getName() );
+ }
+ catch ( UnsupportedProtocolException e )
+ {
+ //ok
+ 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() );
+ }
+
}
diff --git a/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonA.java b/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonA.java
index dcc6daf45d..b1ef9952b2 100644
--- a/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonA.java
+++ b/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonA.java
@@ -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 a
*
+ * @author Carlos Sanchez
* @author Jason van Zyl
- *
* @version $Id$
*/
public class WagonA
- extends FileWagon
+ extends WagonMock
{
public String[] getSupportedProtocols()
{
diff --git a/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonB.java b/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonB.java
index 4a4154560c..8269e0a86a 100644
--- a/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonB.java
+++ b/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonB.java
@@ -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 b1
and b2
*
+ * @author Carlos Sanchez
* @author Jason van Zyl
- *
* @version $Id$
*/
public class WagonB
- extends FileWagon
+ extends WagonMock
{
public String[] getSupportedProtocols()
{
diff --git a/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonC.java b/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonC.java
index d19378e2ec..7739fc9900 100644
--- a/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonC.java
+++ b/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonC.java
@@ -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 c
*
+ * @author Carlos Sanchez
* @author Jason van Zyl
- *
* @version $Id$
*/
public class WagonC
- extends FileWagon
+ extends WagonMock
{
public String[] getSupportedProtocols()
{
diff --git a/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonMock.java b/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonMock.java
new file mode 100644
index 0000000000..a17844a648
--- /dev/null
+++ b/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonMock.java
@@ -0,0 +1,48 @@
+package org.apache.maven.artifact.manager;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.wagon.providers.file.FileWagon;
+
+/**
+ * Mock of a Wagon for testing
+ *
+ * @author Carlos Sanchez
+ * @version $Id$
+ */
+public class WagonMock
+ extends FileWagon
+{
+
+ /**
+ * A field that can be configured in the Wagon
+ *
+ * @component.configuration default="configurableField"
+ */
+ private String configurableField = null;
+
+ public void setConfigurableField( String configurableField )
+ {
+ this.configurableField = configurableField;
+ }
+
+ public String getConfigurableField()
+ {
+ return configurableField;
+ }
+
+}
diff --git a/maven-artifact-manager/src/test/resources/org/apache/maven/artifact/manager/DefaultWagonManagerTest.xml b/maven-artifact-manager/src/test/resources/org/apache/maven/artifact/manager/DefaultWagonManagerTest.xml
index ad6280a212..e521a2eb0a 100644
--- a/maven-artifact-manager/src/test/resources/org/apache/maven/artifact/manager/DefaultWagonManagerTest.xml
+++ b/maven-artifact-manager/src/test/resources/org/apache/maven/artifact/manager/DefaultWagonManagerTest.xml
@@ -1,3 +1,21 @@
+
+
@@ -10,11 +28,11 @@
b1
org.apache.maven.artifact.manager.WagonB
-
- org.apache.maven.wagon.Wagon
- b2
- org.apache.maven.artifact.manager.WagonB
-
+
+ org.apache.maven.wagon.Wagon
+ b2
+ org.apache.maven.artifact.manager.WagonB
+
org.apache.maven.wagon.Wagon
c
diff --git a/pom.xml b/pom.xml
index cc49631bbb..a03e701ea6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -172,7 +172,7 @@
org.apache.maven.wagon
wagon-provider-api
- 1.0-alpha-6
+ 1.0-beta-1-SNAPSHOT
org.apache.maven.wagon