Rewrite scm connections

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@178416 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Emmanuel Venisse 2005-05-25 09:36:20 +00:00
parent 82a6d51998
commit f3346df4b8
2 changed files with 82 additions and 14 deletions

View File

@ -69,6 +69,10 @@ public class PrepareReleaseMojo
private String currentTag;
private String currentScmConnection;
private String currentScmDeveloperConnection;
protected void executeTask()
throws MojoExecutionException
{
@ -258,7 +262,19 @@ private void transformPomToReleaseVersionPom()
currentTag = model.getScm().getTag();
model.getScm().setTag( getTagLabel() );
currentScmConnection = model.getScm().getConnection();
currentScmDeveloperConnection = model.getScm().getDeveloperConnection();
if ( model.getScm() != null )
{
model.getScm().setTag( getTagLabel() );
model.getScm().setConnection( rewriteScmConnection( model.getScm().getConnection(), getTagLabel() ) );
model.getScm().setDeveloperConnection( rewriteScmConnection( model.getScm().getDeveloperConnection(),
getTagLabel() ) );
}
try
{
@ -389,7 +405,14 @@ private void transformPomToSnapshotVersionPom()
model.setVersion( projectVersion );
model.getScm().setTag( currentTag );
if ( model.getScm() != null )
{
model.getScm().setTag( currentTag );
model.getScm().setConnection( currentScmConnection );
model.getScm().setDeveloperConnection( currentScmDeveloperConnection );
}
PomTransformer transformer = new VersionTransformer();
@ -525,4 +548,25 @@ private void tagRelease()
throw new MojoExecutionException( "An error is occurred in the tag process.", e );
}
}
private String rewriteScmConnection( String scmConnection, String tag )
{
if ( scmConnection != null )
{
if ( scmConnection.startsWith( "svn" ) )
{
if ( scmConnection.endsWith( "trunk/") )
{
scmConnection = scmConnection.substring( 0, scmConnection.length() - "trunk/".length() );
}
if ( scmConnection.endsWith( "branches/") )
{
scmConnection = scmConnection.substring( 0, scmConnection.length() - "branches/".length() );
}
scmConnection += "tags/" + tag;
}
}
return scmConnection;
}
}

View File

@ -143,21 +143,45 @@ else if ( selectPluginsNodesXPathExpression().equals( node.getPath() ) )
}
else
{
// Modify scm tag
Element scm = (Element) node;
Node tag = node.selectSingleNode( "tag" );
if ( tag == null )
if ( getUpdatedModel().getScm() != null )
{
if ( !"HEAD".equals( getUpdatedModel().getScm().getTag() ) )
// Modify scm tag
Element scm = (Element) node;
Node tag = node.selectSingleNode( "tag" );
if ( tag == null )
{
scm.addElement( "tag" ).addText( getUpdatedModel().getScm().getTag() );
if ( !"HEAD".equals( getUpdatedModel().getScm().getTag() ) )
{
scm.addElement( "tag" ).addText( getUpdatedModel().getScm().getTag() );
}
}
else
{
tag.setText( getUpdatedModel().getScm().getTag() );
}
// Modify scmConnections
Node connection = node.selectSingleNode( "connection" );
if ( connection != null )
{
if ( !connection.getText().equals( getUpdatedModel().getScm().getConnection() ) )
{
connection.setText( getUpdatedModel().getScm().getConnection() );
}
}
Node developerConnection = node.selectSingleNode( "developerConnection" );
if ( developerConnection != null )
{
if ( !developerConnection.getText().equals( getUpdatedModel().getScm().getDeveloperConnection() ) )
{
developerConnection.setText( getUpdatedModel().getScm().getDeveloperConnection() );
}
}
}
else
{
tag.setText( getUpdatedModel().getScm().getTag() );
}
}
}