diff --git a/src/it/it-set-scm-tag-001/invoker.properties b/src/it/it-set-scm-tag-001/invoker.properties index d6f553b788..62d509b5b2 100644 --- a/src/it/it-set-scm-tag-001/invoker.properties +++ b/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 diff --git a/src/it/it-set-scm-tag-001/pom.xml b/src/it/it-set-scm-tag-001/pom.xml index 52c747ae7c..ff6cdb58b5 100644 --- a/src/it/it-set-scm-tag-001/pom.xml +++ b/src/it/it-set-scm-tag-001/pom.xml @@ -9,5 +9,8 @@ set-scm-tag HEAD + dummy + dummy + dummy diff --git a/src/it/it-set-scm-tag-001/verify.bsh b/src/it/it-set-scm-tag-001/verify.bsh deleted file mode 100644 index fb60555c17..0000000000 --- a/src/it/it-set-scm-tag-001/verify.bsh +++ /dev/null @@ -1,32 +0,0 @@ -import java.io.*; -import java.util.regex.*; - -try -{ - File file = new File( basedir, "pom.xml" ); - - BufferedReader in = new BufferedReader( new InputStreamReader( new FileInputStream( file ), "UTF-8" ) ); - StringBuilder buf = new StringBuilder(); - String line = in.readLine(); - while ( line != null ) - { - buf.append( line ); - buf.append( " " ); - line = in.readLine(); - } - - Pattern p = Pattern.compile( "\\Q\\E\\s*\\Q\\Ev1\\.0\\Q\\E\\s*\\Q\\E" ); - Matcher m = p.matcher( buf.toString() ); - if ( !m.find() ) - { - System.out.println( "Setting new tag" ); - return false; - } -} -catch( Throwable t ) -{ - t.printStackTrace(); - return false; -} - -return true; diff --git a/src/it/it-set-scm-tag-001/verify.groovy b/src/it/it-set-scm-tag-001/verify.groovy new file mode 100644 index 0000000000..ff47e6ab50 --- /dev/null +++ b/src/it/it-set-scm-tag-001/verify.groovy @@ -0,0 +1,6 @@ +pom = new File( basedir, "pom.xml" ).text; + +assert pom =~ /v1\.0<\/tag>/ +assert pom =~ /connection<\/connection>/ +assert pom =~ /developerConnection<\/developerConnection>/ +assert pom =~ /url<\/url>/ \ No newline at end of file diff --git a/src/main/java/org/codehaus/mojo/versions/SetScmTagMojo.java b/src/main/java/org/codehaus/mojo/versions/SetScmTagMojo.java index 8c7300331a..b88bbdc8c2 100644 --- a/src/main/java/org/codehaus/mojo/versions/SetScmTagMojo.java +++ b/src/main/java/org/codehaus/mojo/versions/SetScmTagMojo.java @@ -3,6 +3,9 @@ import javax.xml.stream.XMLStreamException; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.model.Model; @@ -23,8 +26,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 { /** @@ -35,6 +37,30 @@ 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. * @@ -42,8 +68,7 @@ public class SetScmTagMojo * @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 ) ) { @@ -55,7 +80,7 @@ public void execute() @Override protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException, ArtifactMetadataRetrievalException + throws MojoExecutionException, MojoFailureException, XMLStreamException, ArtifactMetadataRetrievalException { try { @@ -67,10 +92,37 @@ protected void update( ModifiedPomXMLEventReader pom ) } getLog().info( "Updating from tag " + scm.getTag() + " > " + newTag ); - boolean success = PomHelper.setProjectValue( pom, "/project/scm/tag", newTag ); - if ( !success ) + List failures = new ArrayList<>(); + if ( !PomHelper.setProjectValue( pom, "/project/scm/tag", newTag ) ) + { + failures.add( "tag: " + newTag ); + } + if ( !isBlank( connection ) ) + { + if ( !PomHelper.setProjectValue( pom, "/project/scm/connection", connection ) ) + { + failures.add( "connection: " + connection ); + } + } + if ( !isBlank( developerConnection ) ) + { + if ( !PomHelper.setProjectValue( pom, "/project/scm/developerConnection", developerConnection ) ) + { + failures.add( "developerConnection: " + developerConnection ); + } + } + if ( !isBlank( 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: " + failures.stream() + .collect( Collectors.joining( ", " ) ) + + ". Please make sure they are present in the original POM. " ); } } catch ( IOException e )