Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

/**
* Installs the artifact in the remote repository.
*
*
* @author <a href="mailto:[email protected]">Allan Ramirez</a>
*/
@Mojo( name = "deploy-file", requiresProject = false, threadSafe = true )
Expand Down Expand Up @@ -131,15 +131,15 @@ public class DeployFileMojo

/**
* The bundled API docs for the artifact.
*
*
* @since 2.6
*/
@Parameter( property = "javadoc" )
private File javadoc;

/**
* The bundled sources for the artifact.
*
*
* @since 2.6
*/
@Parameter( property = "sources" )
Expand Down Expand Up @@ -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!
*/
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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 <code>null</code>.
* @throws MojoExecutionException When the model of the project could not be built.
* @throws MojoFailureException When building the project failed.
Expand Down Expand Up @@ -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 <code>null</code>.
*/
private File getLocalRepoFile()
Expand All @@ -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 <code>null</code>.
*/
private void processModel( Model model )
Expand Down Expand Up @@ -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 <code>null</code>.
* @return The model from the POM file, never <code>null</code>.
* @throws MojoExecutionException If the file doesn't exist of cannot be read.
Expand Down Expand Up @@ -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 <code>null</code>.
* @throws MojoExecutionException If the generation failed.
*/
Expand Down Expand Up @@ -657,7 +669,7 @@ private File generatePomFile()

/**
* Generates a minimal model from the user-supplied artifact information.
*
*
* @return The generated model, never <code>null</code>.
*/
private Model generateModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class DeployFileMojoTest
extends AbstractMojoTestCase
{
private String LOCAL_REPO = getBasedir() + "/target/local-repo";

private List<String> expectedFiles;

private List<String> fileList;
Expand All @@ -52,10 +52,10 @@ public class DeployFileMojoTest

@Mock
private MavenSession session;

@InjectMocks
private DeployFileMojo mojo;

public void setUp()
throws Exception
{
Expand Down Expand Up @@ -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" );
Expand All @@ -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 );
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<String> fileList )
{
if ( !file.isDirectory() )
Expand Down Expand Up @@ -301,4 +347,3 @@ private int getSizeOfExpectedFiles( List<String> fileList, List<String> expected
}

}

38 changes: 38 additions & 0 deletions src/test/resources/unit/deploy-file-skip/plugin-config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

<project>
<build>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<groupId>org.apache.maven.test</groupId>
<artifactId>maven-deploy-file-test</artifactId>
<version>1.0</version>
<skip>true</skip>
<file>${basedir}/src/test/resources/unit/deploy-file-skip/target/deploy-test-file.zip</file>
<repositoryId>deploy-test</repositoryId>
<url>file://${basedir}/target/remote-repo/deploy-file-skip</url>
<generatePom>true</generatePom>
</configuration>
</plugin>
</plugins>
</build>
</project>