mirror of https://github.com/apache/maven.git
[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:
parent
7305931753
commit
1eccba0026
|
@ -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;
|
||||
|
@ -753,10 +774,8 @@ 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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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,6 +100,12 @@ 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 );
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
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.
|
||||
|
@ -14,12 +14,13 @@ package org.apache.maven.artifact.manager;
|
|||
* 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 @@ 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() );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
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.
|
||||
|
@ -14,20 +14,17 @@ package org.apache.maven.artifact.manager;
|
|||
* 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()
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
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.
|
||||
|
@ -14,20 +14,17 @@ package org.apache.maven.artifact.manager;
|
|||
* 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()
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
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.
|
||||
|
@ -14,20 +14,17 @@ package org.apache.maven.artifact.manager;
|
|||
* 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()
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue