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

New feature (#477): connection, developerConnection, url arguments for set-scm-tag #664

Merged
Merged
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
3 changes: 1 addition & 2 deletions src/it/it-set-scm-tag-001/invoker.properties
@@ -1,2 +1 @@
invoker.goals.1=${project.groupId}:${project.artifactId}:${project.version}:set-scm-tag -DnewTag=v1.0
invoker.buildResult.1=success
invoker.goals.1=${project.groupId}:${project.artifactId}:${project.version}:set-scm-tag -DnewTag=v1.0 -Dconnection=connection -DdeveloperConnection=developerConnection -Durl=url
3 changes: 3 additions & 0 deletions src/it/it-set-scm-tag-001/pom.xml
Expand Up @@ -9,5 +9,8 @@
<name>set-scm-tag</name>
<scm>
<tag>HEAD</tag>
<connection>dummy</connection>
<developerConnection>dummy</developerConnection>
<url>dummy</url>
</scm>
</project>
32 changes: 0 additions & 32 deletions src/it/it-set-scm-tag-001/verify.bsh

This file was deleted.

6 changes: 6 additions & 0 deletions src/it/it-set-scm-tag-001/verify.groovy
@@ -0,0 +1,6 @@
pom = new File( basedir, "pom.xml" ).text;

assert pom =~ /<tag>v1\.0<\/tag>/
assert pom =~ /<connection>connection<\/connection>/
assert pom =~ /<developerConnection>developerConnection<\/developerConnection>/
assert pom =~ /<url>url<\/url>/
85 changes: 71 additions & 14 deletions src/main/java/org/codehaus/mojo/versions/SetScmTagMojo.java
Expand Up @@ -3,9 +3,10 @@
import javax.xml.stream.XMLStreamException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.model.Model;
import org.apache.maven.model.Scm;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
Expand All @@ -14,6 +15,7 @@
import org.codehaus.mojo.versions.api.PomHelper;
import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;

import static org.apache.commons.lang3.StringUtils.isAllBlank;
import static org.apache.commons.lang3.StringUtils.isBlank;

/**
Expand All @@ -23,8 +25,7 @@
* @since 2.5
*/
@Mojo( name = "set-scm-tag", requiresDirectInvocation = true, aggregator = true, threadSafe = true )
public class SetScmTagMojo
extends AbstractVersionsUpdaterMojo
public class SetScmTagMojo extends AbstractVersionsUpdaterMojo
{

/**
Expand All @@ -35,42 +36,98 @@ public class SetScmTagMojo
@Parameter( property = "newTag" )
private String newTag;

/**
* The new SCM connection property
*
* @since 2.12.0
*/
@Parameter( property = "connection" )
private String connection;

/**
* The new SCM developerConnection property
*
* @since 2.12.0
*/
@Parameter( property = "developerConnection" )
private String developerConnection;

/**
* The new SCM url property
*
* @since 2.12.0
*/
@Parameter( property = "url" )
private String url;

/**
* Called when this mojo is executed.
*
* @throws org.apache.maven.plugin.MojoExecutionException when things go wrong.
* @throws org.apache.maven.plugin.MojoFailureException when things go wrong.
*/
@Override
public void execute()
throws MojoExecutionException, MojoFailureException
public void execute() throws MojoExecutionException, MojoFailureException
{
if ( isBlank( newTag ) )
if ( isAllBlank( newTag, connection, developerConnection, url ) )
{
throw new MojoFailureException( "'newTag' cannot be empty" );
throw new MojoFailureException(
"One of: \"newTag\", \"connection\", \"developerConnection\", \"url\" should be provided." );
}

super.execute();
}

@Override
protected void update( ModifiedPomXMLEventReader pom )
throws MojoExecutionException, MojoFailureException, XMLStreamException, ArtifactMetadataRetrievalException
throws MojoExecutionException, MojoFailureException, XMLStreamException, ArtifactMetadataRetrievalException
{
try
{
Model model = PomHelper.getRawModel( pom );
Scm scm = model.getScm();
Scm scm = PomHelper.getRawModel( pom ).getScm();
if ( scm == null )
{
throw new MojoFailureException( "No <scm> was present" );
}
getLog().info( "Updating from tag " + scm.getTag() + " > " + newTag );

boolean success = PomHelper.setProjectValue( pom, "/project/scm/tag", newTag );
if ( !success )
List<String> failures = new ArrayList<>();
if ( !isBlank( newTag ) )
{
getLog().info( "Updating tag: " + scm.getTag() + " -> " + newTag );
if ( !PomHelper.setProjectValue( pom, "/project/scm/tag", newTag ) )
{
failures.add( "tag: " + newTag );
}
}
if ( !isBlank( connection ) )
{
getLog().info( "Updating connection: " + scm.getConnection() + " -> " + connection );
if ( !PomHelper.setProjectValue( pom, "/project/scm/connection", connection ) )
{
failures.add( "connection: " + connection );
}
}
if ( !isBlank( developerConnection ) )
{
getLog().info( "Updating developerConnection: " + scm.getDeveloperConnection() + " -> "
+ developerConnection );
if ( !PomHelper.setProjectValue( pom, "/project/scm/developerConnection", developerConnection ) )
{
failures.add( "developerConnection: " + developerConnection );
}
}
if ( !isBlank( url ) )
{
getLog().info( "Updating url: " + scm.getUrl() + " -> " + url );
if ( !PomHelper.setProjectValue( pom, "/project/scm/url", url ) )
{
failures.add( "url: " + url );
}
}
if ( !failures.isEmpty() )
{
throw new MojoFailureException( "Could not update the SCM tag" );
throw new MojoFailureException( "Could not update one or more SCM elements: " + String.join( ", ",
failures ) + ". Please make sure they are present in the original POM. " );
}
}
catch ( IOException e )
Expand Down