PR: MNG-440

support "servers" element from settings for obtaining authentication info



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@189489 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-06-08 01:49:48 +00:00
parent e2e1a3830c
commit 223d37a7ad
7 changed files with 82 additions and 10 deletions

View File

@ -32,18 +32,15 @@
</copy>
<artifact:install file="target/maven-artifact-ant-2.0-SNAPSHOT.jar">
<localRepository refid="local.repository"/>
<pom refid="maven.project"/>
</artifact:install>
<artifact:deploy file="target/maven-artifact-ant-2.0-SNAPSHOT.jar">
<localRepository refid="local.repository"/>
<remoteRepository refid="deploy.repository"/>
<pom refid="maven.project"/>
</artifact:deploy>
<artifact:deploy file="target/maven-artifact-ant-2.0-SNAPSHOT.jar">
<localRepository refid="local.repository"/>
<remoteRepository url="scp://localhost/tmp/deployment-repo">
<authentication username="brett" privateKey="${user.home}/.ssh/id_dsa"/>
</remoteRepository>

View File

@ -19,6 +19,7 @@ package org.apache.maven.artifact.ant;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
import org.apache.tools.ant.BuildException;
@ -72,7 +73,17 @@ public abstract class AbstractArtifactTask
authentication.getPrivateKey(), authentication.getPassphrase() );
}
return new ArtifactRepository( "remote", repository.getUrl(), repositoryLayout );
ArtifactRepository artifactRepository;
if ( repository.getSnapshotPolicy() != null )
{
artifactRepository = new ArtifactRepository( "remote", repository.getUrl(), repositoryLayout,
repository.getSnapshotPolicy() );
}
else
{
artifactRepository = new ArtifactRepository( "remote", repository.getUrl(), repositoryLayout );
}
return artifactRepository;
}
protected Object lookup( String role )
@ -177,4 +188,19 @@ public abstract class AbstractArtifactTask
}
return settings;
}
protected RemoteRepository createAntRemoteRepository( org.apache.maven.model.Repository pomRepository )
{
RemoteRepository r = new RemoteRepository();
r.setUrl( pomRepository.getUrl() );
r.setSnapshotPolicy( pomRepository.getSnapshotPolicy() );
r.setLayout( pomRepository.getLayout() );
Server server = getSettings().getServer( pomRepository.getId() );
if ( server != null )
{
r.addAuthentication( new Authentication( server ) );
}
return r;
}
}

View File

@ -1,7 +1,5 @@
package org.apache.maven.artifact.ant;
import org.apache.maven.wagon.authentication.AuthenticationInfo;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
@ -18,6 +16,9 @@ import org.apache.maven.wagon.authentication.AuthenticationInfo;
* limitations under the License.
*/
import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.apache.maven.settings.Server;
/**
* Ant Wrapper for wagon authentication.
*
@ -27,4 +28,16 @@ import org.apache.maven.wagon.authentication.AuthenticationInfo;
public class Authentication
extends AuthenticationInfo
{
public Authentication()
{
super();
}
public Authentication( Server server )
{
setUserName( server.getUsername() );
setPassword( server.getPassword() );
setPassphrase( server.getPassphrase() );
setPrivateKey( server.getPrivateKey() );
}
}

View File

@ -82,6 +82,13 @@ public class DependenciesTask
pom.initialise( projectBuilder, localRepo );
dependencies = pom.getDependencies();
for ( Iterator i = pom.getRepositories().iterator(); i.hasNext(); )
{
org.apache.maven.model.Repository pomRepository = (org.apache.maven.model.Repository) i.next();
remoteRepositories.add( createAntRemoteRepository( pomRepository ) );
}
}
Set artifacts = metadataSource.createArtifacts( dependencies, null, null );
@ -94,7 +101,7 @@ public class DependenciesTask
ArtifactResolutionResult result;
try
{
List remoteArtifactRepositories = createRemoteArtifactRepositories();
List remoteArtifactRepositories = createRemoteArtifactRepositories( getRemoteRepositories() );
result = resolver.resolveTransitively( artifacts, remoteArtifactRepositories, localRepo, metadataSource );
}
catch ( ArtifactResolutionException e )
@ -152,10 +159,10 @@ public class DependenciesTask
}
}
private List createRemoteArtifactRepositories()
private List createRemoteArtifactRepositories( List remoteRepositories )
{
List list = new ArrayList();
for ( Iterator i = getRemoteRepositories().iterator(); i.hasNext(); )
for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); )
{
list.add( createRemoteArtifactRepository( (RemoteRepository) i.next() ) );
}
@ -166,6 +173,7 @@ public class DependenciesTask
{
if ( remoteRepositories.isEmpty() )
{
// TODO: could we utilise the super POM for this?
RemoteRepository remoteRepository = new RemoteRepository();
remoteRepository.setUrl( "http://repo1.maven.org/maven2" );
remoteRepositories.add( remoteRepository );

View File

@ -52,9 +52,24 @@ public class DeployTask
localRepository = getDefaultLocalRepository();
}
if ( pom == null )
{
throw new BuildException( "A POM element is required to deploy to the repository" );
}
ArtifactRepository localRepo = createLocalArtifactRepository( localRepository );
pom.initialise( (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE ), localRepo );
if ( remoteRepository == null )
{
if ( pom.getDistributionManagement() == null || pom.getDistributionManagement().getRepository() == null )
{
throw new BuildException( "A distributionManagement element is required in your POM to deploy" );
}
remoteRepository = createAntRemoteRepository( pom.getDistributionManagement().getRepository() );
}
ArtifactRepository deploymentRepository = createRemoteArtifactRepository( remoteRepository );
// Deploy the POM

View File

@ -29,6 +29,8 @@ public class RemoteRepository
private Authentication authentication;
private String snapshotPolicy;
public String getUrl()
{
return ( (RemoteRepository) getInstance() ).url;
@ -48,4 +50,14 @@ public class RemoteRepository
{
this.authentication = authentication;
}
public void setSnapshotPolicy( String snapshotPolicy )
{
this.snapshotPolicy = snapshotPolicy;
}
public String getSnapshotPolicy()
{
return snapshotPolicy;
}
}

View File

@ -24,7 +24,8 @@ import org.apache.tools.ant.ProjectComponent;
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public abstract class Repository extends ProjectComponent
public abstract class Repository
extends ProjectComponent
{
private String refid;