{
ScmTranslator translator = getScmTranslators().get( scmRepository.getProvider() );
boolean result = false;
if ( translator != null )
{
Scm scm = project.getOriginalModel().getScm();
if ( scm == null )
{
scm = project.getScm();
}
String branchName = releaseDescriptor.getScmReleaseLabel();
String branchBase = releaseDescriptor.getScmBranchBase();
// TODO: svn utils should take care of prepending this
if ( branchBase != null )
{
branchBase = "scm:svn:" + branchBase;
}
String workingDirectory =
ReleaseUtil.isSymlink( project.getBasedir() ) ? project.getBasedir().getCanonicalPath()
: project.getBasedir().getAbsolutePath();
int count =
ReleaseUtil.getBaseWorkingDirectoryParentCount( commonBasedir, workingDirectory );
if ( scm.getConnection() != null )
{
String rootUrl = ReleaseUtil.realignScmUrl( count, scm.getConnection() );
String subDirectoryBranch = scm.getConnection().substring( rootUrl.length() );
if ( !subDirectoryBranch.startsWith( "/" ) )
{
subDirectoryBranch = "/" + subDirectoryBranch;
}
String scmConnectionBranch = branchBase;
if ( scmConnectionBranch != null )
{
String trunkUrl = scm.getDeveloperConnection();
if ( trunkUrl == null )
{
trunkUrl = scm.getConnection();
}
scmConnectionBranch = translateUrlPath( trunkUrl, branchBase, scm.getConnection() );
}
String value =
translator.translateBranchUrl( scm.getConnection(), branchName + subDirectoryBranch, scmConnectionBranch );
if ( !value.equals( scm.getConnection() ) )
{
rewriteElement( "connection", value, scmRoot, namespace );
result = true;
}
}
if ( scm.getDeveloperConnection() != null )
{
String rootUrl = ReleaseUtil.realignScmUrl( count, scm.getDeveloperConnection() );
String subDirectoryBranch = scm.getDeveloperConnection().substring( rootUrl.length() );
if ( !subDirectoryBranch.startsWith( "/" ) )
{
subDirectoryBranch = "/" + subDirectoryBranch;
}
String value =
translator.translateBranchUrl( scm.getDeveloperConnection(), branchName + subDirectoryBranch,
branchBase );
if ( !value.equals( scm.getDeveloperConnection() ) )
{
rewriteElement( "developerConnection", value, scmRoot, namespace );
result = true;
}
}
if ( scm.getUrl() != null )
{
String rootUrl = ReleaseUtil.realignScmUrl( count, scm.getUrl() );
String subDirectoryBranch = scm.getUrl().substring( rootUrl.length() );
if ( !subDirectoryBranch.startsWith( "/" ) )
{
subDirectoryBranch = "/" + subDirectoryBranch;
}
String tagScmUrl = branchBase;
if ( tagScmUrl != null )
{
String trunkUrl = scm.getDeveloperConnection();
if ( trunkUrl == null )
{
trunkUrl = scm.getConnection();
}
tagScmUrl = translateUrlPath( trunkUrl, branchBase, scm.getUrl() );
}
// use original branch base without protocol
String value = translator.translateBranchUrl( scm.getUrl(), branchName + subDirectoryBranch,
tagScmUrl );
if ( !value.equals( scm.getUrl() ) )
{
rewriteElement( "url", value, scmRoot, namespace );
result = true;
}
}
if ( branchName != null )
{
String value = translator.resolveTag( branchName );
if ( value != null && !value.equals( scm.getTag() ) )
{
rewriteElement( "tag", value, scmRoot, namespace );
result = true;
}
}