Author: evenisse Date: Thu May 17 13:55:52 2007 New Revision: 539110 URL: http://svn.apache.org/viewvc?view=rev&rev=539110 Log: Fix scm URLs rewriting when tagBqse is present qnd urls different
Added: maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-release/basic-pom-with-tag-base-and-varying-scm-urls/ maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-release/basic-pom-with-tag-base-and-varying-scm-urls/expected-pom.xml (with props) maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-release/basic-pom-with-tag-base-and-varying-scm-urls/pom.xml (with props) Modified: maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhase.java maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhaseTest.java Modified: maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhase.java URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhase.java?view=diff&rev=539110&r1=539109&r2=539110 ============================================================================== --- maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhase.java (original) +++ maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhase.java Thu May 17 13:55:52 2007 @@ -108,12 +108,22 @@ Scm rootScm = rootProject.getScm(); if ( scm.getConnection() != null ) { - if ( rootScm.getConnection() != null && - scm.getConnection().indexOf( rootScm.getConnection() ) == 0 ) + if ( rootScm.getConnection() != null && scm.getConnection().indexOf( rootScm.getConnection() ) == 0 ) { subDirectoryTag = scm.getConnection().substring( rootScm.getConnection().length() ); } - String value = translator.translateTagUrl( scm.getConnection(), tag + subDirectoryTag, tagBase ); + String scmConnectionTag = tagBase; + if ( scmConnectionTag != null ) + { + String trunkUrl = scm.getDeveloperConnection(); + if ( trunkUrl == null ) + { + trunkUrl = scm.getConnection(); + } + scmConnectionTag = this.translateUrlPath( trunkUrl, tagBase, scm.getConnection() ); + } + String value = + translator.translateTagUrl( scm.getConnection(), tag + subDirectoryTag, scmConnectionTag ); if ( !value.equals( scm.getConnection() ) ) { rewriteElement( "connection", value, scmRoot, namespace ); @@ -126,8 +136,8 @@ if ( rootScm.getDeveloperConnection() != null && scm.getDeveloperConnection().indexOf( rootScm.getDeveloperConnection() ) == 0 ) { - subDirectoryTag = scm.getDeveloperConnection().substring( - rootScm.getDeveloperConnection().length() ); + subDirectoryTag = + scm.getDeveloperConnection().substring( rootScm.getDeveloperConnection().length() ); } String value = translator.translateTagUrl( scm.getDeveloperConnection(), tag + subDirectoryTag, tagBase ); @@ -140,14 +150,23 @@ if ( scm.getUrl() != null ) { - if ( rootScm.getUrl() != null && - scm.getUrl().indexOf( rootScm.getUrl() ) == 0 ) + if ( rootScm.getUrl() != null && scm.getUrl().indexOf( rootScm.getUrl() ) == 0 ) { subDirectoryTag = scm.getUrl().substring( rootScm.getUrl().length() ); } + + String tagScmUrl = tagBase; + if ( tagScmUrl != null ) + { + String trunkUrl = scm.getDeveloperConnection(); + if ( trunkUrl == null ) + { + trunkUrl = scm.getConnection(); + } + tagScmUrl = this.translateUrlPath( trunkUrl, tagBase, scm.getUrl() ); + } // use original tag base without protocol - String value = translator.translateTagUrl( scm.getUrl(), tag + subDirectoryTag, - releaseDescriptor.getScmTagBase() ); + String value = translator.translateTagUrl( scm.getUrl(), tag + subDirectoryTag, tagScmUrl ); if ( !value.equals( scm.getUrl() ) ) { rewriteElement( "url", value, scmRoot, namespace ); @@ -198,5 +217,48 @@ { return null; } + } + + /** + * Determines the relative path from trunk to tag, and adds this relative path + * to the url. + * + * @param trunkPath - The trunk url + * @param tagPath - The tag base + * @param urlPath - scm.url or scm.connection + * @return The url path for the tag. + */ + private String translateUrlPath( String trunkPath, String tagPath, String urlPath ) + { + trunkPath = trunkPath.trim(); + tagPath = tagPath.trim(); + //Strip the slash at the end if one is present + if ( trunkPath.endsWith( "/" ) ) + { + trunkPath = trunkPath.substring( 0, trunkPath.length() - 1 ); + } + if ( tagPath.endsWith( "/" ) ) + { + tagPath = tagPath.substring( 0, tagPath.length() - 1 ); + } + char[] tagPathChars = trunkPath.toCharArray(); + char[] trunkPathChars = tagPath.toCharArray(); + // Find the common path between trunk and tags + int i = 0; + while ( tagPathChars[i] == trunkPathChars[i] ) + { + ++i; + } + // If there is nothing common between trunk and tags, or the relative + // path does not exist in the url, then just return the tag. + if ( i == 0 || !urlPath.contains( trunkPath.substring( i ) ) ) + { + return tagPath; + } + else + { + return urlPath.replace( trunkPath.substring( i ), tagPath.substring( i ) ); + } + } } Modified: maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhaseTest.java URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhaseTest.java?view=diff&rev=539110&r1=539109&r2=539110 ============================================================================== --- maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhaseTest.java (original) +++ maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhaseTest.java Thu May 17 13:55:52 2007 @@ -190,6 +190,19 @@ assertTrue( compareFiles( reactorProjects ) ); } + public void testRewriteBasicPomWithTagBaseAndVaryingScmUrls() + throws Exception + { + List reactorProjects = createReactorProjects( "basic-pom-with-tag-base-and-varying-scm-urls" ); + ReleaseDescriptor config = this.createDescriptorFromProjects( reactorProjects ); + config.setScmTagBase( "file://localhost/tmp/scm-repo/allprojects/releases" ); + mapNextVersion( config, "groupId:artifactId" ); + + phase.execute( config, null, reactorProjects ); + + assertTrue( compareFiles( reactorProjects ) ); + } + public void testRewriteBasicPomWithCvsFromTag() throws Exception { Added: maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-release/basic-pom-with-tag-base-and-varying-scm-urls/expected-pom.xml URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-release/basic-pom-with-tag-base-and-varying-scm-urls/expected-pom.xml?view=auto&rev=539110 ============================================================================== --- maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-release/basic-pom-with-tag-base-and-varying-scm-urls/expected-pom.xml (added) +++ maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-release/basic-pom-with-tag-base-and-varying-scm-urls/expected-pom.xml Thu May 17 13:55:52 2007 @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<project> + <modelVersion>4.0.0</modelVersion> + <groupId>groupId</groupId> + <artifactId>artifactId</artifactId> + <version>1.0</version> + + <prerequisites> + <maven>2.0.4</maven> + </prerequisites> + + <scm> + <connection>scm:svn:file://localhost/tmp/anon-scm-repo/allprojects/releases/release-label</connection> + <developerConnection>scm:svn:file://localhost/tmp/scm-repo/allprojects/releases/release-label</developerConnection> + <url>file://localhost/tmp/viewvc/allprojects/releases/release-label</url> + </scm> +</project> Propchange: maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-release/basic-pom-with-tag-base-and-varying-scm-urls/expected-pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-release/basic-pom-with-tag-base-and-varying-scm-urls/expected-pom.xml ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-release/basic-pom-with-tag-base-and-varying-scm-urls/pom.xml URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-release/basic-pom-with-tag-base-and-varying-scm-urls/pom.xml?view=auto&rev=539110 ============================================================================== --- maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-release/basic-pom-with-tag-base-and-varying-scm-urls/pom.xml (added) +++ maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-release/basic-pom-with-tag-base-and-varying-scm-urls/pom.xml Thu May 17 13:55:52 2007 @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<project> + <modelVersion>4.0.0</modelVersion> + <groupId>groupId</groupId> + <artifactId>artifactId</artifactId> + <version>1.0-SNAPSHOT</version> + + <prerequisites> + <maven>2.0.4</maven> + </prerequisites> + + <scm> + <connection>scm:svn:file://localhost/tmp/anon-scm-repo/myproject/trunk</connection> + <developerConnection>scm:svn:file://localhost/tmp/scm-repo/myproject/trunk</developerConnection> + <url>file://localhost/tmp/viewvc/myproject/trunk</url> + </scm> +</project> Propchange: maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-release/basic-pom-with-tag-base-and-varying-scm-urls/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/release/trunk/maven-release-manager/src/test/resources/projects/rewrite-for-release/basic-pom-with-tag-base-and-varying-scm-urls/pom.xml ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision"