decouple auth info from repository, allows removing settings from project code

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@164189 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-04-22 07:55:32 +00:00
parent 7d6b029c43
commit d43cfef170
8 changed files with 47 additions and 94 deletions

View File

@ -31,7 +31,6 @@ import java.util.Set;
/**
* @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
* @version $Revision$ $Date$
* @todo improve the use of this now that plugin fields are used instead of a request object - add an <archive> element to configuration?
*/
public class MavenArchiver
{

View File

@ -20,9 +20,8 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.wagon.repository.Repository;
import org.apache.maven.settings.Settings;
import org.apache.maven.settings.Profile;
import org.apache.maven.settings.Settings;
import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
import org.codehaus.plexus.PlexusTestCase;

View File

@ -67,12 +67,6 @@ public class DefaultArtifactDeployer
ArtifactRepository localRepository )
throws ArtifactDeploymentException
{
if ( deploymentRepository.getAuthenticationInfo() == null )
{
getLogger().warn( "Deployment repository {id: \'" + deploymentRepository.getId() +
"\'} has no associated authentication info!" );
}
try
{
// TODO: better to have a transform manager, or reuse the handler manager again so we don't have these requirements duplicated all over?

View File

@ -28,6 +28,7 @@ import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.wagon.UnsupportedProtocolException;
import org.apache.maven.wagon.Wagon;
import org.apache.maven.wagon.authentication.AuthenticationException;
import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.apache.maven.wagon.authorization.AuthorizationException;
import org.apache.maven.wagon.events.TransferListener;
import org.apache.maven.wagon.observers.ChecksumObserver;
@ -56,8 +57,11 @@ public class DefaultWagonManager
{
private PlexusContainer container;
// TODO: proxies and authentication are via settings, and should come in via an alternate method - perhaps attached to ArtifactRepository before the method is called (so AR would be composed of WR, not inherit it)
private Map proxies = new HashMap();
private Map authenticationInfoMap = new HashMap();
private TransferListener downloadMonitor;
private ArtifactHandlerManager artifactHandlerManager;
@ -145,7 +149,8 @@ public class DefaultWagonManager
try
{
wagon.connect( repository, getProxy( repository.getProtocol() ) );
wagon.connect( repository, getAuthenticationInfo( repository.getId() ),
getProxy( repository.getProtocol() ) );
wagon.put( source, remotePath );
@ -303,7 +308,8 @@ public class DefaultWagonManager
try
{
wagon.connect( repository, getProxy( repository.getProtocol() ) );
wagon.connect( repository, getAuthenticationInfo( repository.getId() ),
getProxy( repository.getProtocol() ) );
wagon.get( remotePath, temp );
@ -410,6 +416,11 @@ public class DefaultWagonManager
return (ProxyInfo) proxies.get( protocol );
}
private AuthenticationInfo getAuthenticationInfo( String id )
{
return (AuthenticationInfo) authenticationInfoMap.get( id );
}
/**
* Set the proxy used for a particular protocol.
*
@ -422,7 +433,7 @@ public class DefaultWagonManager
* property format: <code>*.foo.com|localhost</code>.
* @todo [BP] would be nice to configure this via plexus in some way
*/
public void setProxy( String protocol, String host, int port, String username, String password,
public void addProxy( String protocol, String host, int port, String username, String password,
String nonProxyHosts )
{
ProxyInfo proxyInfo = new ProxyInfo();
@ -449,4 +460,20 @@ public class DefaultWagonManager
{
this.downloadMonitor = downloadMonitor;
}
public void addAuthenticationInfo( String repositoryId, String username, String password, String privateKey,
String passphrase )
{
AuthenticationInfo authInfo = new AuthenticationInfo();
authInfo.setUserName( username );
authInfo.setPassword( password );
authInfo.setPrivateKey( privateKey );
authInfo.setPassphrase( passphrase );
authenticationInfoMap.put( repositoryId, authInfo );
}
}

View File

@ -54,7 +54,10 @@ public interface WagonManager
public void getArtifactMetadata( ArtifactMetadata metadata, ArtifactRepository remoteRepository, File destination )
throws TransferFailedException, ResourceDoesNotExistException;
void setProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts );
void addProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts );
void addAuthenticationInfo( String repositoryId, String username, String password, String privateKey,
String passphrase );
void setDownloadMonitor( TransferListener downloadMonitor );
}

View File

@ -50,12 +50,6 @@ public class ArtifactRepository
this( id, url, layout, SNAPSHOT_POLICY_NEVER );
}
public ArtifactRepository( String id, String url, AuthenticationInfo authenticationInfo,
ArtifactRepositoryLayout layout )
{
this( id, url, authenticationInfo, layout, SNAPSHOT_POLICY_NEVER );
}
public ArtifactRepository( String id, String url, ArtifactRepositoryLayout layout, String snapshotPolicy )
{
super( id, url );
@ -65,16 +59,6 @@ public class ArtifactRepository
this.snapshotPolicy = snapshotPolicy;
}
public ArtifactRepository( String id, String url, AuthenticationInfo authInfo, ArtifactRepositoryLayout layout,
String snapshotPolicy )
{
super( id, url, authInfo );
this.layout = layout;
this.snapshotPolicy = snapshotPolicy;
}
public String pathOf( Artifact artifact )
throws ArtifactPathFormatException
{

View File

@ -19,7 +19,6 @@ package org.apache.maven;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResponse;
@ -29,13 +28,13 @@ import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents;
import org.apache.maven.plugin.PluginExecutionException;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.ProjectSorter;
import org.apache.maven.reactor.ReactorException;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
@ -295,9 +294,8 @@ public class DefaultMaven
protected MavenSession createSession( MavenExecutionRequest request, MavenProject project )
{
return new MavenSession( project, container, request.getSettings(),
request.getLocalRepository(), request.getEventDispatcher(), request.getLog(),
request.getGoals() );
return new MavenSession( project, container, request.getSettings(), request.getLocalRepository(),
request.getEventDispatcher(), request.getLog(), request.getGoals() );
}
/**
@ -317,10 +315,17 @@ public class DefaultMaven
if ( proxy != null )
{
wagonManager.setProxy( proxy.getProtocol(), proxy.getHost(), proxy.getPort(), proxy.getUsername(),
wagonManager.addProxy( proxy.getProtocol(), proxy.getHost(), proxy.getPort(), proxy.getUsername(),
proxy.getPassword(), proxy.getNonProxyHosts() );
}
for ( Iterator i = settings.getServers().iterator(); i.hasNext(); )
{
Server server = (Server) i.next();
wagonManager.addAuthenticationInfo( server.getId(), server.getUsername(), server.getPassword(),
server.getPrivateKey(), server.getPassphrase() );
}
}
// ----------------------------------------------------------------------

View File

@ -18,14 +18,7 @@ package org.apache.maven.artifact.repository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.settings.MavenSettingsBuilder;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.IOException;
/**
* @author jdcasey
@ -44,50 +37,6 @@ public class DefaultArtifactRepositoryFactory
ArtifactRepositoryLayout repositoryLayout,
String snapshotPolicy )
{
AuthenticationInfo authInfo = null;
if ( id != null && id.length() > 0 )
{
Settings settings = null;
try
{
settings = settingsBuilder.buildSettings();
}
catch ( IOException e )
{
getLogger().warn( "Error reading settings", e );
}
catch ( XmlPullParserException e )
{
getLogger().warn( "Error reading settings", e );
}
Server repoProfile = settings.getServer( id );
if ( repoProfile != null )
{
authInfo = new AuthenticationInfo();
authInfo.setUserName( repoProfile.getUsername() );
authInfo.setPassword( repoProfile.getPassword() );
authInfo.setPrivateKey( repoProfile.getPrivateKey() );
authInfo.setPassphrase( repoProfile.getPassphrase() );
}
}
else
{
Logger logger = getLogger();
if ( logger != null )
{
logger.warn( "Cannot associate authentication to repository with null id. The offending repository's URL is: " +
url );
}
}
ArtifactRepository repo = null;
if ( globalSnapshotPolicy != null )
@ -95,14 +44,7 @@ public class DefaultArtifactRepositoryFactory
snapshotPolicy = globalSnapshotPolicy;
}
if ( authInfo != null )
{
repo = new ArtifactRepository( id, url, authInfo, repositoryLayout, snapshotPolicy );
}
else
{
repo = new ArtifactRepository( id, url, repositoryLayout, snapshotPolicy );
}
repo = new ArtifactRepository( id, url, repositoryLayout, snapshotPolicy );
return repo;
}