Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip specified attached artifacts from deploy #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
195 changes: 195 additions & 0 deletions src/main/java/org/apache/maven/plugins/deploy/AttachedArtifact.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
package org.apache.maven.plugins.deploy;

/*
* 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.
*/

import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.shared.utils.StringUtils;

import java.util.List;

/**
* The attached artifact data
*
* @author <a href="mailto:gregory.callea@gmail.com">Gregory Callea</a>
*
*/
@Mojo( name = "artifact" )
public class AttachedArtifact
{

/**
* GroupId of the attached artifact
*/
@Parameter( property = "groupId" )
private String groupId;

/**
* ArtifactId of the attached artifact
*/
@Parameter( property = "artifactId" )
private String artifactId;

/**
* Version of the attached artifact
*/
@Parameter( property = "version" )
private String version;


/**
* Packaging of the attached artifact
*/
@Parameter( property = "packaging" )
private String packaging;

/**
* Classifier to the attached artifact
*/
@Parameter( property = "classifier" )
private String classifier;


public AttachedArtifact( )
{

}

AttachedArtifact( String groupId, String artifactId, String version, String packaging )
{
this.groupId = groupId;
this.artifactId = artifactId;
this.version = version;
this.packaging = packaging;
}

/**
* Validate the attached artifact
*
* @throws MojoExecutionException If the attached artifact misses some required parameter
*/
private void validate() throws MojoExecutionException
{

if ( StringUtils.isEmpty( groupId ) || StringUtils.isEmpty( artifactId )
|| StringUtils.isEmpty( version ) || StringUtils.isEmpty( packaging ) )
{
throw new MojoExecutionException(
"The artifact information is incomplete: 'groupId', 'artifactId', "
+ "'version', 'packaging' are required" );
}

}

/**
* Check if attached artifact exists on provided lists
*
* @param attachedArtifacts The attached artifact lists
* @return The found attached artifact
* @throws MojoExecutionException If no attached artifact that matches the current one is found
*/
Artifact checkIfExists( final List<Artifact> attachedArtifacts ) throws MojoExecutionException
{
this.validate();
for ( final Artifact attachedArtifact : attachedArtifacts )
{
if ( this.groupId.equals( attachedArtifact.getGroupId() )
&& this.artifactId.equals( attachedArtifact.getArtifactId() )
&& this.version.equals( attachedArtifact.getVersion() )
&& this.packaging.equals( attachedArtifact.getType() )
&& (
this.classifier == null && attachedArtifact.getClassifier() == null
|| ( this.classifier != null
&& attachedArtifact.getClassifier() != null
&& this.classifier.equals( attachedArtifact.getClassifier() )
)
) )
{
return attachedArtifact;
}
}
throw new MojoExecutionException(
"No attached artifact " + this.toString() + " to exclude from deploy found" );
}

public String getGroupId()
{
return groupId;
}

public String getArtifactId()
{
return artifactId;
}

public String getPackaging()
{
return packaging;
}

public String getClassifier()
{
return classifier;
}

public String getVersion()
{
return version;
}

public AttachedArtifact setGroupId( String groupId )
{
this.groupId = groupId;
return this;
}

public AttachedArtifact setArtifactId( String artifactId )
{
this.artifactId = artifactId;
return this;
}

public AttachedArtifact setPackaging( String packaging )
{
this.packaging = packaging;
return this;
}

public AttachedArtifact setClassifier( String classifier )
{
this.classifier = classifier;
return this;
}

public AttachedArtifact setVersion( String version )
{
this.version = version;
return this;
}

@Override
public String toString()
{
return this.groupId + ":" + this.artifactId + ":" + this.packaging
+ ( this.classifier == null ? "" : ":" + this.classifier ) + ":" + this.version;
}
}
32 changes: 27 additions & 5 deletions src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.MojoExecutionException;
Expand All @@ -42,7 +43,7 @@

/**
* Deploys an artifact to remote repository.
*
*
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
* @author <a href="mailto:jdcasey@apache.org">John Casey (refactoring only)</a>
* @version $Id$
Expand Down Expand Up @@ -75,7 +76,7 @@ public class DeployMojo
* Whether every project should be deployed during its own deploy-phase or at the end of the multimodule build. If
* set to {@code true} and the build fails, none of the reactor projects is deployed.
* <strong>(experimental)</strong>
*
*
* @since 2.8
*/
@Parameter( defaultValue = "false", property = "deployAtEnd" )
Expand All @@ -98,7 +99,7 @@ public class DeployMojo

/**
* The alternative repository to use when the project has a snapshot version.
*
*
* @since 2.8
* @see DeployMojo#altDeploymentRepository
*/
Expand All @@ -107,7 +108,7 @@ public class DeployMojo

/**
* The alternative repository to use when the project has a final version.
*
*
* @since 2.8
* @see DeployMojo#altDeploymentRepository
*/
Expand All @@ -116,12 +117,20 @@ public class DeployMojo

/**
* Set this to 'true' to bypass artifact deploy
*
*
* @since 2.4
*/
@Parameter( property = "maven.deploy.skip", defaultValue = "false" )
private boolean skip;

/**
* The attached artifacts to exclude from deploy
*
* @since 3.0
*/
@Parameter( property = "skipAttachedArtifacts" )
private List<AttachedArtifact> skipAttachedArtifacts;

/**
* Component used to deploy project.
*/
Expand Down Expand Up @@ -154,6 +163,19 @@ public void execute()

ArtifactRepository repo = getDeploymentRepository( pdr );

final List<Artifact> attachedArtifacts = pdr.getProject().getAttachedArtifacts();
if ( skipAttachedArtifacts != null )
{
for ( final AttachedArtifact attachedArtifactToSkip : skipAttachedArtifacts )
{
final Artifact toSkip = attachedArtifactToSkip.checkIfExists( attachedArtifacts );
attachedArtifacts.remove( toSkip );
getLog().info( "Skipping artifact ["
+ toSkip
+ "]" );
}
}

if ( !deployAtEnd )
{
deployProject( getSession().getProjectBuildingRequest(), pdr, repo );
Expand Down
31 changes: 31 additions & 0 deletions src/site/fml/faq.fml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,37 @@ under the License.
</plugin>]]></source>
</answer>
</faq>
<faq id="skipAttachedArtifacts">
<question>I don't want to deploy some attached artifact on a specific module. Can I skip deployment for specific attached artifacts?</question>
<answer>
<p>
Yes, you can skip deployment of several attached artifacts by configuring the Deploy Plugin as follows:
</p>
<source>
<![CDATA[<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>X.Y</version>
<configuration>
<skipAttachedArtifacts>
<artifact>
<groupId>group</groupId>
<artifactId>id</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<classifier>classifier</classifier>
</artifact>
<artifact>
<groupId>group</groupId>
<artifactId>id</artifactId>
<version>1.0</version>
<packaging>zip</packaging>
</artifact>
</skipAttachedArtifacts>
</configuration>
</plugin>]]></source>
</answer>
</faq>
<faq id="deploy_deploy">
<question>What does the message "The packaging for this project did not assign a file to the build artifact" mean when I run <code>deploy:deploy</code>?</question>
<answer>
Expand Down