[MNG-2324] Added getWagon( Repository ) to WagonManager

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@409806 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Carlos Sanchez Gonzalez 2006-05-27 03:27:04 +00:00
parent 7305931753
commit 1eccba0026
9 changed files with 280 additions and 93 deletions

View File

@ -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 void setInteractive( boolean interactive )
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 @@ private void configureWagon( Wagon wagon, ArtifactRepository repository )
}
}
}
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 void addConfiguration( String repositoryId, Xpp3Dom configuration )
serverConfigurationMap.put( repositoryId, xmlConf );
}
}

View File

@ -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 @@ 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 @@ void addAuthenticationInfo( String repositoryId, String username, String passwor
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 );
}

View File

@ -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,31 @@
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 void testDefaultWagonManager()
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() );
}
}

View File

@ -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()
{

View File

@ -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()
{

View File

@ -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()
{

View File

@ -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 <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
* @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;
}
}

View File

@ -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>

View File

@ -172,7 +172,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>