diff --git a/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java b/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java
index 43044218..5522708c 100644
--- a/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java
+++ b/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java
@@ -68,7 +68,7 @@
/**
* Installs the artifact in the remote repository.
- *
+ *
* @author Allan Ramirez
*/
@Mojo( name = "deploy-file", requiresProject = false, threadSafe = true )
@@ -131,7 +131,7 @@ public class DeployFileMojo
/**
* The bundled API docs for the artifact.
- *
+ *
* @since 2.6
*/
@Parameter( property = "javadoc" )
@@ -139,7 +139,7 @@ public class DeployFileMojo
/**
* The bundled sources for the artifact.
- *
+ *
* @since 2.6
*/
@Parameter( property = "sources" )
@@ -179,7 +179,7 @@ public class DeployFileMojo
/**
* Whether to deploy snapshots with a unique version or not.
- *
+ *
* @deprecated As of Maven 3, this isn't supported anymore and this parameter is only present to break the build if
* you use it!
*/
@@ -208,6 +208,13 @@ public class DeployFileMojo
@Parameter( property = "files" )
private String files;
+ /**
+ * Whether to skip bypass artifact deploy. "true" means skip deployment.
+ * Defaults to "false"
+ */
+ @Parameter( property = "maven.deploy.file.skip", defaultValue = "false" )
+ private boolean skip;
+
@Component
private RepositoryManager repoManager;
@@ -316,6 +323,11 @@ public void execute()
+ " from the maven-deploy-plugin. "
+ "Please see the >>Major Version Upgrade to version 3.0.0<< on the plugin site." );
}
+ if ( skip )
+ {
+ getLog().info( "Skipping artifact deployment" );
+ return;
+ }
failIfOffline();
@@ -494,7 +506,7 @@ public void execute()
* Creates a Maven project in-memory from the user-supplied groupId, artifactId and version. When a classifier is
* supplied, the packaging must be POM because the project with only have attachments. This project serves as basis
* to attach the artifacts to deploy to.
- *
+ *
* @return The created Maven project, never null.
* @throws MojoExecutionException When the model of the project could not be built.
* @throws MojoFailureException When building the project failed.
@@ -532,7 +544,7 @@ private MavenProject createMavenProject()
/**
* Gets the path of the artifact constructed from the supplied groupId, artifactId, version, classifier and
* packaging within the local repository. Note that the returned path need not exist (yet).
- *
+ *
* @return The absolute path to the artifact when installed, never null.
*/
private File getLocalRepoFile()
@@ -549,7 +561,7 @@ private File getLocalRepoFile()
/**
* Process the supplied pomFile to get groupId, artifactId, version, and packaging
- *
+ *
* @param model The POM to extract missing artifact coordinates from, must not be null.
*/
private void processModel( Model model )
@@ -584,7 +596,7 @@ private void processModel( Model model )
/**
* Extract the model from the specified POM file.
- *
+ *
* @param pomFile The path of the POM file to parse, must not be null.
* @return The model from the POM file, never null.
* @throws MojoExecutionException If the file doesn't exist of cannot be read.
@@ -621,7 +633,7 @@ Model readModel( File pomFile )
/**
* Generates a minimal POM from the user-supplied artifact information.
- *
+ *
* @return The path to the generated POM file, never null.
* @throws MojoExecutionException If the generation failed.
*/
@@ -657,7 +669,7 @@ private File generatePomFile()
/**
* Generates a minimal model from the user-supplied artifact information.
- *
+ *
* @return The generated model, never null.
*/
private Model generateModel()
diff --git a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java
index 6c7064bb..f5708a76 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java
@@ -43,7 +43,7 @@ public class DeployFileMojoTest
extends AbstractMojoTestCase
{
private String LOCAL_REPO = getBasedir() + "/target/local-repo";
-
+
private List expectedFiles;
private List fileList;
@@ -52,10 +52,10 @@ public class DeployFileMojoTest
@Mock
private MavenSession session;
-
+
@InjectMocks
private DeployFileMojo mojo;
-
+
public void setUp()
throws Exception
{
@@ -87,15 +87,15 @@ public void testBasicDeployFile()
mojo = (DeployFileMojo) lookupMojo( "deploy-file", testPom );
MockitoAnnotations.initMocks( this );
-
+
assertNotNull( mojo );
-
+
ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( LOCAL_REPO ) );
when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
-
+
String groupId = (String) getVariableValueFromObject( mojo, "groupId" );
String artifactId = (String) getVariableValueFromObject( mojo, "artifactId" );
@@ -110,6 +110,8 @@ public void testBasicDeployFile()
String url = (String) getVariableValueFromObject( mojo, "url" );
+ boolean skip = (boolean) getVariableValueFromObject( mojo, "skip" );
+
assertEquals( "org.apache.maven.test", groupId );
assertEquals( "maven-deploy-file-test", artifactId );
@@ -118,12 +120,14 @@ public void testBasicDeployFile()
assertEquals( "jar", packaging );
+ assertTrue( !skip );
+
assertTrue( file.exists() );
assertEquals( "deploy-test", repositoryId );
assertEquals( "file://" + getBasedir() + "/target/remote-repo/deploy-file-test", url );
-
+
mojo.execute();
//check the generated pom
@@ -188,9 +192,9 @@ public void testDeployIfClassifierIsSet()
mojo = (DeployFileMojo) lookupMojo( "deploy-file", testPom );
MockitoAnnotations.initMocks( this );
-
+
assertNotNull( mojo );
-
+
ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
@@ -236,9 +240,9 @@ public void testDeployIfArtifactIsNotJar()
mojo = (DeployFileMojo) lookupMojo( "deploy-file", testPom );
MockitoAnnotations.initMocks( this );
-
+
assertNotNull( mojo );
-
+
ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
@@ -266,6 +270,48 @@ public void testDeployIfArtifactIsNotJar()
assertTrue( file.exists() );
}
+ public void testDeployIsSkip()
+ throws Exception
+ {
+ File testPom = new File( getBasedir(), "target/test-classes/unit/deploy-file-skip/plugin-config.xml" );
+
+ mojo = (DeployFileMojo) lookupMojo( "deploy-file", testPom );
+
+ MockitoAnnotations.initMocks( this );
+
+ assertNotNull( mojo );
+
+ ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
+ when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
+ MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
+ repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( LOCAL_REPO ) );
+ when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
+
+ String groupId = (String) getVariableValueFromObject( mojo, "groupId" );
+
+ String artifactId = (String) getVariableValueFromObject( mojo, "artifactId" );
+
+ String version = (String) getVariableValueFromObject( mojo, "version" );
+
+ boolean skip = (boolean) getVariableValueFromObject( mojo, "skip" );
+
+ assertEquals( "org.apache.maven.test", groupId );
+
+ assertTrue( skip );
+
+ assertEquals( "maven-deploy-file-test", artifactId );
+
+ assertEquals( "1.0", version );
+
+ mojo.execute();
+
+ File file = new File( remoteRepo, "deploy-file-skip/" + groupId.replace( '.', '/' ) +
+ "/" + artifactId + "/" + version + "/" + artifactId +
+ "-" + version + ".zip");
+
+ assertTrue( !file.exists() );
+ }
+
private void addFileToList( File file, List fileList )
{
if ( !file.isDirectory() )
@@ -301,4 +347,3 @@ private int getSizeOfExpectedFiles( List fileList, List expected
}
}
-
diff --git a/src/test/resources/unit/deploy-file-skip/plugin-config.xml b/src/test/resources/unit/deploy-file-skip/plugin-config.xml
new file mode 100755
index 00000000..e847eac9
--- /dev/null
+++ b/src/test/resources/unit/deploy-file-skip/plugin-config.xml
@@ -0,0 +1,38 @@
+
+
+
+
+
+
+ maven-deploy-plugin
+
+ org.apache.maven.test
+ maven-deploy-file-test
+ 1.0
+ true
+ ${basedir}/src/test/resources/unit/deploy-file-skip/target/deploy-test-file.zip
+ deploy-test
+ file://${basedir}/target/remote-repo/deploy-file-skip
+ true
+
+
+
+
+