diff --git a/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/release/PrepareReleaseMojo.java b/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/release/PrepareReleaseMojo.java index fbef2368d2..baa3ef69c0 100644 --- a/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/release/PrepareReleaseMojo.java +++ b/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/release/PrepareReleaseMojo.java @@ -67,6 +67,8 @@ public class PrepareReleaseMojo private String userTag; + private String currentTag; + protected void executeTask() throws MojoExecutionException { @@ -254,6 +256,10 @@ public class PrepareReleaseMojo model.setVersion( projectVersion ); + currentTag = model.getScm().getTag(); + + model.getScm().setTag( getTagLabel() ); + try { Properties releaseProperties = new Properties(); @@ -383,6 +389,8 @@ public class PrepareReleaseMojo model.setVersion( projectVersion ); + model.getScm().setTag( currentTag ); + PomTransformer transformer = new VersionTransformer(); transformer.setOutputFile( project.getFile() ); diff --git a/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/transformer/AbstractPomTransformer.java b/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/transformer/AbstractPomTransformer.java index d545300a12..94f2df7e9a 100644 --- a/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/transformer/AbstractPomTransformer.java +++ b/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/transformer/AbstractPomTransformer.java @@ -207,28 +207,14 @@ public abstract class AbstractPomTransformer // Implementation // ---------------------------------------------------------------------- - /** - * - * @return - */ public abstract String selectProjectNodeXPathExpression(); - /** - * - * @return - */ public abstract String selectDependenciesNodesXPathExpression(); - /** - * - * @return - */ public abstract String selectPluginsNodesXPathExpression(); - /** - * - * @param node - */ + public abstract String selectScmTagNodesXPathExpression(); + public abstract void transformNode( Node node ); /** @@ -255,6 +241,8 @@ public abstract class AbstractPomTransformer XPath pluginsXpath = new Dom4jXPath( selectPluginsNodesXPathExpression() ); + XPath scmXpath = new Dom4jXPath( selectScmTagNodesXPathExpression() ); + List nodes = new ArrayList(); nodes.addAll( pomXpath.selectNodes( getDocument() ) ); @@ -263,6 +251,8 @@ public abstract class AbstractPomTransformer nodes.addAll( pluginsXpath.selectNodes( getDocument() ) ); + nodes.addAll( scmXpath.selectNodes( getDocument() ) ); + setSelectedNodes( nodes ); } diff --git a/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/transformer/VersionTransformer.java b/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/transformer/VersionTransformer.java index 449ebb70d4..5edd975686 100644 --- a/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/transformer/VersionTransformer.java +++ b/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugin/transformer/VersionTransformer.java @@ -52,10 +52,16 @@ public class VersionTransformer return "/project/build/plugins/plugin"; } + public String selectScmTagNodesXPathExpression() + { + return "/project/scm/tag"; + } + public void transformNode( Node node ) { if ( selectProjectNodeXPathExpression().equals( node.getPath() ) ) { + // Modify project version Element project = (Element) node; Node version = node.selectSingleNode( "version" ); @@ -71,6 +77,7 @@ public class VersionTransformer } else if ( selectDependenciesNodesXPathExpression().equals( node.getPath() ) ) { + // Modify dependency version Element dependency = (Element) node; Node groupId = node.selectSingleNode( "groupId" ); @@ -97,8 +104,9 @@ public class VersionTransformer type.getText() ).getVersion() ); } } - else + else if ( selectPluginsNodesXPathExpression().equals( node.getPath() ) ) { + // Modify plugin version Element plugin = (Element) node; Node groupId = node.selectSingleNode( "groupId" ); @@ -133,6 +141,25 @@ public class VersionTransformer plugin.addElement( "version" ).addText( p.getVersion() ); } } + else + { + // Modify scm tag + Element scm = (Element) node; + + Node tag = node.selectSingleNode( "tag" ); + + if ( tag == null ) + { + if ( !"HEAD".equals( getUpdatedModel().getScm().getTag() ) ) + { + scm.addElement( "tag" ).addText( getUpdatedModel().getScm().getTag() ); + } + } + else + { + tag.setText( getUpdatedModel().getScm().getTag() ); + } + } } private Dependency getDependency( String groupId, String artifactId, String type )