You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2013/09/13 21:30:48 UTC
svn commit: r1523070 - in /maven/plugins/trunk/maven-deploy-plugin: pom.xml
src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java
src/test/java/org/apache/maven/plugin/deploy/DeployMojoTest.java
Author: rfscholte
Date: Fri Sep 13 19:30:48 2013
New Revision: 1523070
URL: http://svn.apache.org/r1523070
Log:
[MDEPLOY-68] altDeploymentRepository allows dangerous deploy processes
Modified:
maven/plugins/trunk/maven-deploy-plugin/pom.xml
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java
maven/plugins/trunk/maven-deploy-plugin/src/test/java/org/apache/maven/plugin/deploy/DeployMojoTest.java
Modified: maven/plugins/trunk/maven-deploy-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-deploy-plugin/pom.xml?rev=1523070&r1=1523069&r2=1523070&view=diff
==============================================================================
--- maven/plugins/trunk/maven-deploy-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-deploy-plugin/pom.xml Fri Sep 13 19:30:48 2013
@@ -96,6 +96,12 @@ under the License.
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>1.9.5</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
Modified: maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java?rev=1523070&r1=1523069&r2=1523070&view=diff
==============================================================================
--- maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java (original)
+++ maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java Fri Sep 13 19:30:48 2013
@@ -20,6 +20,7 @@ package org.apache.maven.plugin.deploy;
*/
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -107,6 +108,24 @@ public class DeployMojo
private String altDeploymentRepository;
/**
+ * The alternative repository to use when the project has a snapshot version.
+ *
+ * @since 2.8
+ * @see DeployMojo#altDeploymentRepository
+ */
+ @Parameter( property = "altSnapshotDeploymentRepository" )
+ private String altSnapshotDeploymentRepository;
+
+ /**
+ * The alternative repository to use when the project has a final version.
+ *
+ * @since 2.8
+ * @see DeployMojo#altDeploymentRepository
+ */
+ @Parameter( property = "altReleaseDeploymentRepository" )
+ private String altReleaseDeploymentRepository;
+
+ /**
* @deprecated either use project.getAttachedArtifacts() or reactorProjects.get(i).getAttachedArtifacts()
*/
@Parameter( defaultValue = "${project.attachedArtifacts}", required = true, readonly = true )
@@ -241,20 +260,34 @@ public class DeployMojo
}
}
- private ArtifactRepository getDeploymentRepository( MavenProject project )
+ ArtifactRepository getDeploymentRepository( MavenProject project )
throws MojoExecutionException, MojoFailureException
{
ArtifactRepository repo = null;
- if ( altDeploymentRepository != null )
+ String altDeploymentRepo;
+ if ( ArtifactUtils.isSnapshot( project.getVersion() ) && altSnapshotDeploymentRepository != null )
+ {
+ altDeploymentRepo = altSnapshotDeploymentRepository;
+ }
+ else if ( !ArtifactUtils.isSnapshot( project.getVersion() ) && altReleaseDeploymentRepository != null )
+ {
+ altDeploymentRepo = altReleaseDeploymentRepository;
+ }
+ else
+ {
+ altDeploymentRepo = altDeploymentRepository;
+ }
+
+ if ( altDeploymentRepo != null )
{
- getLog().info( "Using alternate deployment repository " + altDeploymentRepository );
+ getLog().info( "Using alternate deployment repository " + altDeploymentRepo );
- Matcher matcher = ALT_REPO_SYNTAX_PATTERN.matcher( altDeploymentRepository );
+ Matcher matcher = ALT_REPO_SYNTAX_PATTERN.matcher( altDeploymentRepo );
if ( !matcher.matches() )
{
- throw new MojoFailureException( altDeploymentRepository, "Invalid syntax for repository.",
+ throw new MojoFailureException( altDeploymentRepo, "Invalid syntax for repository.",
"Invalid syntax for alternative repository. Use \"id::layout::url\"." );
}
else
Modified: maven/plugins/trunk/maven-deploy-plugin/src/test/java/org/apache/maven/plugin/deploy/DeployMojoTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-deploy-plugin/src/test/java/org/apache/maven/plugin/deploy/DeployMojoTest.java?rev=1523070&r1=1523069&r2=1523070&view=diff
==============================================================================
--- maven/plugins/trunk/maven-deploy-plugin/src/test/java/org/apache/maven/plugin/deploy/DeployMojoTest.java (original)
+++ maven/plugins/trunk/maven-deploy-plugin/src/test/java/org/apache/maven/plugin/deploy/DeployMojoTest.java Fri Sep 13 19:30:48 2013
@@ -19,11 +19,19 @@ package org.apache.maven.plugin.deploy;
* under the License.
*/
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
import java.io.File;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Properties;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.deploy.stubs.ArtifactDeployerStub;
import org.apache.maven.plugin.deploy.stubs.ArtifactRepositoryStub;
@@ -525,6 +533,44 @@ public class DeployMojoTest
FileUtils.deleteDirectory( sshFile );
}
+
+ public void testAltSnapshotDeploymentRepository() throws Exception
+ {
+ DeployMojo mojo = new DeployMojo();
+
+ setVariableValueToObject( mojo, "altSnapshotDeploymentRepository", "altSnapshotDeploymentRepository::default::http://localhost" );
+
+ ArtifactRepositoryLayout repositoryLayout = mock( ArtifactRepositoryLayout.class );
+ setVariableValueToObject( mojo, "repositoryLayouts", Collections.singletonMap( "default", repositoryLayout ) );
+
+ ArtifactRepositoryFactory repositoryFactory = mock( ArtifactRepositoryFactory.class );
+ ArtifactRepository repository = mock( ArtifactRepository.class);
+ when( repositoryFactory.createDeploymentArtifactRepository( "altSnapshotDeploymentRepository", "http://localhost", repositoryLayout, true ) ).thenReturn( repository );
+ setVariableValueToObject( mojo, "repositoryFactory", repositoryFactory );
+
+ project.setVersion( "1.0-SNAPSHOT" );
+
+ assertEquals( repository, mojo.getDeploymentRepository( project ) );
+ }
+
+ public void testAltReleaseDeploymentRepository() throws Exception
+ {
+ DeployMojo mojo = new DeployMojo();
+
+ setVariableValueToObject( mojo, "altReleaseDeploymentRepository", "altReleaseDeploymentRepository::default::http://localhost" );
+
+ ArtifactRepositoryLayout repositoryLayout = mock( ArtifactRepositoryLayout.class );
+ setVariableValueToObject( mojo, "repositoryLayouts", Collections.singletonMap( "default", repositoryLayout ) );
+
+ ArtifactRepositoryFactory repositoryFactory = mock( ArtifactRepositoryFactory.class );
+ ArtifactRepository repository = mock( ArtifactRepository.class);
+ when( repositoryFactory.createDeploymentArtifactRepository( "altReleaseDeploymentRepository", "http://localhost", repositoryLayout, true ) ).thenReturn( repository );
+ setVariableValueToObject( mojo, "repositoryFactory", repositoryFactory );
+
+ project.setVersion( "1.0" );
+
+ assertEquals( repository, mojo.getDeploymentRepository( project ) );
+ }
private void addFileToList( File file, List<String> fileList )