diff --git a/artifact/src/main/org/apache/maven/artifact/deployer/ArtifactDeployer.java b/artifact/src/main/org/apache/maven/artifact/deployer/ArtifactDeployer.java index 5e63dc3f..8a88e6b1 100644 --- a/artifact/src/main/org/apache/maven/artifact/deployer/ArtifactDeployer.java +++ b/artifact/src/main/org/apache/maven/artifact/deployer/ArtifactDeployer.java @@ -35,7 +35,7 @@ import org.apache.maven.repository.ArtifactTypeHandler; * In case of snapshots the process in even more complex. * * @author Michal Maczka - * @version $Id: ArtifactDeployer.java,v 1.6 2004/09/06 04:26:10 felipeal Exp $ + * @version $Id$ */ public interface ArtifactDeployer { diff --git a/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java b/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java index 7c0e2699..16934910 100644 --- a/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java +++ b/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java @@ -30,6 +30,7 @@ import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.TransferFailedException; 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.observers.ChecksumObserver; import org.apache.maven.wagon.providers.file.FileWagon; @@ -51,6 +52,7 @@ import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.TimeZone; +import java.security.NoSuchAlgorithmException; /** * Default implementation of Artifact Deployer interface. @@ -247,7 +249,7 @@ public class DefaultArtifactDeployer { Repository repository = new Repository( "local", "file:" + project.getContext().getMavenRepoLocal() ); String repositoryPath = handler.constructRepositoryFullPath( type, project, version ); - deployFiles( repository, Collections.singletonList( file ), Collections.singletonList( repositoryPath ) ); + deployFile( repository, file, repositoryPath ); } catch ( Exception e ) { @@ -351,9 +353,10 @@ public class DefaultArtifactDeployer String repo = repos[i].trim(); LOG.info( "Deploying to repository: " + repo ); Repository repository = RepositoryBuilder.getRepository( project, repo ); + AuthenticationInfo authenticationInfo = RepositoryBuilder.getAuthenticationInfo( project, repo ); try { - deployFiles( repository, srcFiles, destFiles ); + deployFiles( repository, srcFiles, destFiles, authenticationInfo ); success = true; } catch ( Exception e ) @@ -371,9 +374,17 @@ public class DefaultArtifactDeployer } } - private void deployFiles( Repository repository, List srcFiles, List destFiles ) + private void deployFile( Repository repository, File src, String dest ) + throws ResourceDoesNotExistException, MalformedURLException, NoSuchAlgorithmException, TransferFailedException, + ConnectionException, AuthenticationException, AuthorizationException + { + deployFiles( repository, Collections.singletonList( src ), Collections.singletonList( dest ), null ); + } + + private void deployFiles( Repository repository, List srcFiles, List destFiles, + AuthenticationInfo authenticationInfo ) throws ConnectionException, AuthenticationException, ResourceDoesNotExistException, TransferFailedException, - AuthorizationException, MalformedURLException + AuthorizationException, MalformedURLException, NoSuchAlgorithmException { if ( srcFiles.size() != destFiles.size() ) @@ -389,7 +400,7 @@ public class DefaultArtifactDeployer try { - wagon.connect( repository ); + wagon.connect( repository, authenticationInfo ); Iterator srcIterator = srcFiles.iterator(); Iterator destIterator = destFiles.iterator(); while ( srcIterator.hasNext() ) diff --git a/artifact/src/main/org/apache/maven/artifact/deployer/RepositoryBuilder.java b/artifact/src/main/org/apache/maven/artifact/deployer/RepositoryBuilder.java index ab4e4980..6748c1d9 100755 --- a/artifact/src/main/org/apache/maven/artifact/deployer/RepositoryBuilder.java +++ b/artifact/src/main/org/apache/maven/artifact/deployer/RepositoryBuilder.java @@ -44,23 +44,6 @@ public class RepositoryBuilder Repository repository = new Repository( id, url ); - String username = (String) project.getContext().getVariable( "maven.repo." + id + ".username" ); - String password = (String) project.getContext().getVariable( "maven.repo." + id + ".password" ); - String passphrase = (String) project.getContext().getVariable( "maven.repo." + id + ".passphrase" ); - String privateKey = (String) project.getContext().getVariable( "maven.repo." + id + ".privatekey" ); - - if ( username == null ) - { - username = (String) project.getContext().getVariable( "maven.username" ); - } - - AuthenticationInfo authenticationInfo = new AuthenticationInfo(); - authenticationInfo.setUserName( username ); - authenticationInfo.setPassword( password ); - authenticationInfo.setPrivateKey( privateKey ); - authenticationInfo.setPassphrase( passphrase ); - repository.setAuthenticationInfo( authenticationInfo ); - String dir = (String) project.getContext().getVariable( "maven.repo." + id + ".directory" ); repository.setBasedir( dir ); @@ -177,4 +160,24 @@ public class RepositoryBuilder proxyInfo.setPassword( proxyPassword ); } + public static AuthenticationInfo getAuthenticationInfo( Project project, String id ) + { + String username = (String) project.getContext().getVariable( "maven.repo." + id + ".username" ); + String password = (String) project.getContext().getVariable( "maven.repo." + id + ".password" ); + String passphrase = (String) project.getContext().getVariable( "maven.repo." + id + ".passphrase" ); + String privateKey = (String) project.getContext().getVariable( "maven.repo." + id + ".privatekey" ); + + if ( username == null ) + { + username = (String) project.getContext().getVariable( "maven.username" ); + } + + AuthenticationInfo authenticationInfo = new AuthenticationInfo(); + authenticationInfo.setUserName( username ); + authenticationInfo.setPassword( password ); + authenticationInfo.setPrivateKey( privateKey ); + authenticationInfo.setPassphrase( passphrase ); + + return authenticationInfo; + } }