o using the repository system and repositories to mediate proxy use. proxies restored.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@796903 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-07-22 22:58:24 +00:00
parent 88216c6532
commit 684eed4a0c
8 changed files with 92 additions and 24 deletions

View File

@ -18,6 +18,7 @@ package org.apache.maven.artifact.repository;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.repository.Proxy;
public interface ArtifactRepository public interface ArtifactRepository
{ {
@ -58,7 +59,9 @@ public interface ArtifactRepository
// //
Artifact find( Artifact artifact ); Artifact find( Artifact artifact );
void setAuthentication( Authentication authentication ); void setAuthentication( Authentication authentication );
Authentication getAuthentication(); Authentication getAuthentication();
void setProxy( Proxy proxy );
Proxy getProxy();
} }

View File

@ -24,6 +24,7 @@ import java.io.File;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.repository.Proxy;
import org.apache.maven.wagon.repository.Repository; import org.apache.maven.wagon.repository.Repository;
/** /**
@ -216,4 +217,17 @@ public class DefaultArtifactRepository
{ {
// do nothing // do nothing
} }
//
// This implementation does not support proxies
//
public Proxy getProxy()
{
return null;
}
public void setProxy( Proxy proxy )
{
// do nothing
}
} }

View File

@ -24,6 +24,7 @@ import java.io.File;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.repository.Proxy;
//TODO: completely separate local and remote artifact repositories //TODO: completely separate local and remote artifact repositories
public class MavenArtifactRepository public class MavenArtifactRepository
@ -45,6 +46,8 @@ public class MavenArtifactRepository
private Authentication authentication; private Authentication authentication;
private Proxy proxy;
public MavenArtifactRepository() public MavenArtifactRepository()
{ {
} }
@ -353,4 +356,14 @@ public class MavenArtifactRepository
{ {
this.authentication = authentication; this.authentication = authentication;
} }
public Proxy getProxy()
{
return proxy;
}
public void setProxy( Proxy proxy )
{
this.proxy = proxy;
}
} }

View File

@ -86,6 +86,10 @@ public class LegacyRepositorySystem
@Requirement @Requirement
private PlexusContainer plexus; private PlexusContainer plexus;
private Map<String, Authentication> authentications = new HashMap<String, Authentication>();
private Map<String, Proxy> proxies = new HashMap<String,Proxy>();
public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type ) public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type )
{ {
return artifactFactory.createArtifact( groupId, artifactId, version, scope, type ); return artifactFactory.createArtifact( groupId, artifactId, version, scope, type );
@ -490,8 +494,6 @@ public class LegacyRepositorySystem
wagonManager.putRemoteFile( repository, source, remotePath, downloadMonitor ); wagonManager.putRemoteFile( repository, source, remotePath, downloadMonitor );
} }
private Map<String, Authentication> authentications = new HashMap<String, Authentication>();
// //
// serverId = repository id // serverId = repository id
// //
@ -550,6 +552,25 @@ public class LegacyRepositorySystem
artifactRepository.setAuthentication( authentication ); artifactRepository.setAuthentication( authentication );
} }
Proxy proxy = proxies.get( artifactRepository.getProtocol() );
if ( proxy != null )
{
artifactRepository.setProxy( proxy );
}
return artifactRepository; return artifactRepository;
}
public void addProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts )
{
Proxy proxy = new Proxy();
proxy.setHost( host );
proxy.setProtocol( protocol );
proxy.setPort( port );
proxy.setNonProxyHosts( nonProxyHosts );
proxy.setUserName( username );
proxy.setPassword( password );
proxies.put( protocol, proxy );
} }
} }

View File

@ -50,7 +50,7 @@ public class Proxy
/** /**
* Type of the proxy * Type of the proxy
*/ */
private String type; private String protocol;
/** /**
* The non-proxy hosts. Follows Java system property format: <code>*.foo.com|localhost</code>. * The non-proxy hosts. Follows Java system property format: <code>*.foo.com|localhost</code>.
@ -152,17 +152,17 @@ public class Proxy
* *
* @return the type of the proxy server * @return the type of the proxy server
*/ */
public String getType() public String getProtocol()
{ {
return type; return protocol;
} }
/** /**
* @param type the type of the proxy server like <i>SOCKSv4</i> * @param type the type of the proxy server like <i>SOCKSv4</i>
*/ */
public void setType( String type ) public void setProtocol( String protocol )
{ {
this.type = type; this.protocol = protocol;
} }
public String getNonProxyHosts() public String getNonProxyHosts()

View File

@ -114,5 +114,7 @@ public interface RepositorySystem
void retrieve( ArtifactRepository repository, File destination, String remotePath, TransferListener downloadMonitor ) void retrieve( ArtifactRepository repository, File destination, String remotePath, TransferListener downloadMonitor )
throws TransferFailedException, ResourceDoesNotExistException; throws TransferFailedException, ResourceDoesNotExistException;
void addAuthenticationForArtifactRepository( String repositoryId, String username, String password ); void addAuthenticationForArtifactRepository( String repositoryId, String username, String password );
void addProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts );
} }

View File

@ -223,25 +223,42 @@ public class DefaultWagonManager
{ {
if ( repository.getAuthentication() != null ) if ( repository.getAuthentication() != null )
{ {
// wagon.connect( new Repository( repository.getId(), repository.getUrl() ), authenticationInfo( repository ) );
// We have authentication we have been asked to deal with. }
// else if ( repository.getProxy() != null )
AuthenticationInfo ai = new AuthenticationInfo(); {
ai.setUserName( repository.getAuthentication().getUsername() ); wagon.connect( new Repository( repository.getId(), repository.getUrl() ), proxyInfo( repository ) );
ai.setPassword( repository.getAuthentication().getPassword() ); }
else if ( repository.getAuthentication() != null && repository.getProxy() != null )
wagon.connect( new Repository( repository.getId(), repository.getUrl() ), ai ); {
wagon.connect( new Repository( repository.getId(), repository.getUrl() ), authenticationInfo( repository ), proxyInfo( repository ) );
} }
else else
{ {
wagon.connect( new Repository( repository.getId(), repository.getUrl() ) ); wagon.connect( new Repository( repository.getId(), repository.getUrl() ) );
} }
//
// ProxyInfo proxyInfo = new ProxyInfo();
//
} }
private AuthenticationInfo authenticationInfo( ArtifactRepository repository )
{
AuthenticationInfo ai = new AuthenticationInfo();
ai.setUserName( repository.getAuthentication().getUsername() );
ai.setPassword( repository.getAuthentication().getPassword() );
return ai;
}
private ProxyInfo proxyInfo( ArtifactRepository repository )
{
ProxyInfo proxyInfo = new ProxyInfo();
proxyInfo.setHost( repository.getProxy().getHost() );
proxyInfo.setType( repository.getProxy().getProtocol() );
proxyInfo.setPort( repository.getProxy().getPort() );
proxyInfo.setNonProxyHosts( repository.getProxy().getNonProxyHosts() );
proxyInfo.setUserName( repository.getProxy().getUserName() );
proxyInfo.setPassword( repository.getProxy().getPassword() );
return proxyInfo;
}
public void getRemoteFile( ArtifactRepository repository, File destination, String remotePath, TransferListener downloadMonitor, String checksumPolicy, boolean force ) public void getRemoteFile( ArtifactRepository repository, File destination, String remotePath, TransferListener downloadMonitor, String checksumPolicy, boolean force )
throws TransferFailedException, ResourceDoesNotExistException throws TransferFailedException, ResourceDoesNotExistException
{ {

View File

@ -186,7 +186,6 @@ public class DefaultMavenExecutionRequestPopulator
// </proxy> // </proxy>
// </proxies> // </proxies>
/*
Proxy proxy = settings.getActiveProxy(); Proxy proxy = settings.getActiveProxy();
if ( proxy != null ) if ( proxy != null )
@ -198,7 +197,6 @@ public class DefaultMavenExecutionRequestPopulator
repositorySystem.addProxy( proxy.getProtocol(), proxy.getHost(), proxy.getPort(), proxy.getUsername(), proxy.getPassword(), proxy.getNonProxyHosts() ); repositorySystem.addProxy( proxy.getProtocol(), proxy.getHost(), proxy.getPort(), proxy.getUsername(), proxy.getPassword(), proxy.getNonProxyHosts() );
} }
*/
for ( Server server : settings.getServers() ) for ( Server server : settings.getServers() )
{ {