ability to set a proxy for a wagon

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163343 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-02-08 07:48:08 +00:00
parent 67d58c8d04
commit 54222773a9
2 changed files with 43 additions and 9 deletions

View File

@ -17,11 +17,9 @@
* ====================================================================
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.AbstractArtifactComponent;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.wagon.ConnectionException;
import org.apache.maven.wagon.ResourceDoesNotExistException;
@ -30,18 +28,20 @@
import org.apache.maven.wagon.Wagon;
import org.apache.maven.wagon.authentication.AuthenticationException;
import org.apache.maven.wagon.authorization.AuthorizationException;
import org.apache.maven.wagon.observers.ChecksumObserver;
import org.apache.maven.wagon.proxy.ProxyInfo;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import org.codehaus.plexus.util.FileUtils;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class DefaultWagonManager
@ -50,6 +50,8 @@ public class DefaultWagonManager
{
private PlexusContainer container;
private Map proxies = new HashMap();
public Artifact createArtifact( String groupId, String artifactId, String version, String type )
{
Artifact artifact = new DefaultArtifact( groupId, artifactId, version, type );
@ -85,7 +87,7 @@ public void put( File source, Artifact artifact, ArtifactRepository repository )
{
Wagon wagon = getWagon( repository.getProtocol() );
wagon.connect( repository );
wagon.connect( repository, getProxy( repository.getProtocol() ) );
wagon.put( source, path( artifact ) );
@ -156,7 +158,7 @@ public void get( Artifact artifact, File destination, Set repositories )
//wagon.addTransferListener( md5SumObserver );
wagon.connect( repository );
wagon.connect( repository, getProxy( repository.getProtocol() ) );
wagon.get( path( artifact ), temp );
@ -232,6 +234,38 @@ public void get( Artifact artifact, File destination, Set repositories )
throw new TransferFailedException( "Unable to download the artifact from any repository" );
}
private ProxyInfo getProxy( String protocol )
{
return (ProxyInfo) proxies.get( protocol );
}
/**
* Set the proxy used for a particular protocol.
*
* @todo [BP] would be nice to configure this via plexus in some way
*
* @param protocol the protocol (required)
* @param host the proxy host name (required)
* @param port the proxy port (required)
* @param username the username for the proxy, or null if there is none
* @param password the password for the proxy, or null if there is none
* @param nonProxyHosts the set of hosts not to use the proxy for. Follows Java system property format:
* <code>*.foo.com|localhost</code>.
*/
public void setProxy( String protocol, String host, int port, String username, String password,
String nonProxyHosts )
{
ProxyInfo proxyInfo = new ProxyInfo();
proxyInfo.setHost( host );
proxyInfo.setType( protocol );
proxyInfo.setPort( port );
proxyInfo.setNonProxyHosts( nonProxyHosts );
proxyInfo.setUserName( username );
proxyInfo.setPassword( password );
proxies.put( protocol, proxyInfo );
}
public void contextualize( Context context )
throws ContextException
{

View File

@ -18,8 +18,6 @@
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.wagon.UnsupportedProtocolException;
@ -49,5 +47,7 @@ void get( Artifact artifact, Set remoteRepositories, ArtifactRepository localRep
void put( File source, Artifact artifact, ArtifactRepository deploymentRepository )
throws Exception;
void setProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts );
Artifact createArtifact( String groupId, String artifactId, String version, String type );
}