Rewrite scm tag part in project file in prepare release phase.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@178323 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Emmanuel Venisse 2005-05-24 23:35:00 +00:00
parent 551ab886d7
commit 82a6d51998
3 changed files with 42 additions and 17 deletions

View File

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

View File

@ -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 );
}

View File

@ -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 )