diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java b/maven-compat/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java index 18a80cab84..923f403967 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java @@ -17,14 +17,19 @@ package org.apache.maven.artifact.deployer; import java.io.File; import java.io.IOException; +import java.util.Arrays; +import java.util.List; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.metadata.RepositoryMetadataDeploymentException; import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager; +import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.LegacySupport; +import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.legacy.TransferListenerAdapter; import org.apache.maven.repository.legacy.WagonManager; import org.apache.maven.repository.legacy.resolver.transform.ArtifactTransformationManager; @@ -49,6 +54,9 @@ public class DefaultArtifactDeployer @Requirement private RepositoryMetadataManager repositoryMetadataManager; + @Requirement + private RepositorySystem repositorySystem; + @Requirement private LegacySupport legacySupport; @@ -68,6 +76,8 @@ public class DefaultArtifactDeployer public void deploy( File source, Artifact artifact, ArtifactRepository deploymentRepository, ArtifactRepository localRepository ) throws ArtifactDeploymentException { + deploymentRepository = injectSession( deploymentRepository ); + try { transformationManager.transformForDeployment( artifact, deploymentRepository, localRepository ); @@ -113,4 +123,32 @@ public class DefaultArtifactDeployer return TransferListenerAdapter.newAdapter( session.getRequest().getTransferListener() ); } + private ArtifactRepository injectSession( ArtifactRepository repository ) + { + /* + * NOTE: This provides backward-compat with maven-deploy-plugin:2.4 which bypasses the repository factory when + * using an alternative deployment location. + */ + if ( repository instanceof DefaultArtifactRepository && repository.getAuthentication() == null ) + { + MavenSession session = legacySupport.getSession(); + + if ( session != null ) + { + MavenExecutionRequest request = session.getRequest(); + + if ( request != null ) + { + List repositories = Arrays.asList( repository ); + + repositorySystem.injectProxy( repositories, request.getProxies() ); + + repositorySystem.injectAuthentication( repositories, request.getServers() ); + } + } + } + + return repository; + } + } diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java index 31b5aed2cb..b55281c338 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java @@ -48,6 +48,10 @@ public class DefaultArtifactRepository private ArtifactRepositoryPolicy releases; private boolean blacklisted; + + private Authentication authentication; + + private Proxy proxy; /** * Create a local repository or a test repository. @@ -212,30 +216,24 @@ public class DefaultArtifactRepository return Collections.emptyList(); } - // - // This implementation does not support authentication - // public Authentication getAuthentication() { - return null; + return authentication; } public void setAuthentication( Authentication authentication ) { - // do nothing + this.authentication = authentication; } - - // - // This implementation does not support proxies - // + public Proxy getProxy() { - return null; + return proxy; } public void setProxy( Proxy proxy ) { - // do nothing + this.proxy = proxy; } public boolean isUniqueVersion() diff --git a/maven-compat/src/test/resources/org/apache/maven/artifact/deployer/ArtifactDeployerTest.xml b/maven-compat/src/test/resources/org/apache/maven/artifact/deployer/ArtifactDeployerTest.xml index be6d326234..f7c381fe2c 100644 --- a/maven-compat/src/test/resources/org/apache/maven/artifact/deployer/ArtifactDeployerTest.xml +++ b/maven-compat/src/test/resources/org/apache/maven/artifact/deployer/ArtifactDeployerTest.xml @@ -19,9 +19,5 @@ under the License. - - org.apache.maven.artifact.metadata.ArtifactMetadataSource - org.apache.maven.artifact.deployer.SimpleArtifactMetadataSource -