From a98376e90e604be7b304b0bd795d816a4a323bac Mon Sep 17 00:00:00 2001 From: ltheussl Date: Mon, 23 Jan 2006 01:11:41 +0000 Subject: [PATCH] PR: MPCHANGELOG-81 Submitted by: Dennis Lundberg Some valid scm urls are not allowed. A valid scm url should be of the form scm:, ie it has to start with 'scm:', but can be either ':' or '|'. git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@371429 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/maven/changelog/ChangeLog.java | 7 ++-- .../apache/maven/util/RepositoryUtils.java | 36 ++++++++++++++++--- .../cvslib/CvsChangeLogGeneratorTest.java | 6 ++-- .../org/apache/maven/util/RepositoryTest.java | 16 ++++++++- changelog/xdocs/changes.xml | 1 + 5 files changed, 54 insertions(+), 12 deletions(-) diff --git a/changelog/src/main/org/apache/maven/changelog/ChangeLog.java b/changelog/src/main/org/apache/maven/changelog/ChangeLog.java index bd5fac9a..64322e04 100644 --- a/changelog/src/main/org/apache/maven/changelog/ChangeLog.java +++ b/changelog/src/main/org/apache/maven/changelog/ChangeLog.java @@ -39,6 +39,7 @@ import java.util.StringTokenizer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.maven.project.Developer; +import org.apache.maven.util.RepositoryUtils; /** * Change log task. It uses a ChangeLogGenerator and ChangeLogParser to create @@ -503,7 +504,7 @@ public class ChangeLog { if ( clFactoryClass == null ) { - //Connection Format: scm:[:] + // Connection Format: scm: if ( ( connection == null ) || ( connection.length() < 5 ) || !connection.startsWith( "scm:" ) ) { @@ -511,7 +512,7 @@ public class ChangeLog } else { - int iProviderEnd = connection.indexOf( ":", 4 ); + int iProviderEnd = connection.indexOf( RepositoryUtils.getSCMConnectionSeparator( connection ) , 4 ); if ( iProviderEnd == -1 ) { // Connection = scm: @@ -523,7 +524,7 @@ public class ChangeLog if ( clFactoryClass == null ) { - LOG.warn( + LOG.warn( "Could not derive factory from connection: using CVS (valid factories are: " + FACTORIES.keySet() + ")" ); clFactoryClass = "org.apache.maven.cvslib.CvsChangeLogFactory"; diff --git a/changelog/src/main/org/apache/maven/util/RepositoryUtils.java b/changelog/src/main/org/apache/maven/util/RepositoryUtils.java index 4558c39a..3005b224 100755 --- a/changelog/src/main/org/apache/maven/util/RepositoryUtils.java +++ b/changelog/src/main/org/apache/maven/util/RepositoryUtils.java @@ -31,6 +31,27 @@ import java.util.List; */ public final class RepositoryUtils { + /** + * Get the separator used in an SCM string + * @param connection + * @return String that can be either ":" or "|" + */ + public static String getSCMConnectionSeparator( String connection ) + { + if ( connection == null ) + { + throw new NullPointerException( "repository connection is null" ); + } + + if( connection.indexOf( "|" ) != -1 ) { + return "|"; + } + else + { + return ":"; + } + } + /** * Splits an SCM string into parts * @param connection @@ -43,22 +64,27 @@ public final class RepositoryUtils throw new NullPointerException( "repository connection is null" ); } - if ( connection.length() < 4 ) + if ( connection.length() < 5 ) { throw new IllegalArgumentException( "repository connection is too short" ); } - if ( !connection.startsWith( "scm" ) ) + if ( !connection.startsWith( "scm:" ) ) { throw new IllegalArgumentException( - "repository connection must start with scm[delim]" ); + "repository connection must start with scm:" ); } - String delimiter = "" + connection.charAt( 3 ); + String delimiter = getSCMConnectionSeparator( connection ); + + // If the tokenizer is going to work correctly then the character + // following "scm" must be the same as the delimiter, which is not + // always the case. Therefor we give it a modified connection. + String modifiedConnection = "scm" + delimiter + connection.substring( 4 ); EnhancedStringTokenizer tok = - new EnhancedStringTokenizer( connection, delimiter ); + new EnhancedStringTokenizer( modifiedConnection, delimiter ); String[] tokens = tokenizerToArray( tok ); diff --git a/changelog/src/test/org/apache/maven/cvslib/CvsChangeLogGeneratorTest.java b/changelog/src/test/org/apache/maven/cvslib/CvsChangeLogGeneratorTest.java index 757ff930..cba73026 100644 --- a/changelog/src/test/org/apache/maven/cvslib/CvsChangeLogGeneratorTest.java +++ b/changelog/src/test/org/apache/maven/cvslib/CvsChangeLogGeneratorTest.java @@ -106,12 +106,12 @@ public class CvsChangeLogGeneratorTest extends TestCase IllegalArgumentException.class), new Test( null, - "scm|cvs|pserver|anoncvs@cvs.apache.org|D:\\home\\cvspublic|maven", + "scm:cvs|pserver|anoncvs@cvs.apache.org|D:\\home\\cvspublic|maven", "cvs|-d|:pserver:anoncvs@cvs.apache.org:D:\\home\\cvspublic|log", null), new Test( null, - "scm|cvs|pserver|anoncvs@cvs.apache.org|D:/home/cvspublic|maven", + "scm:cvs|pserver|anoncvs@cvs.apache.org|D:/home/cvspublic|maven", "cvs|-d|:pserver:anoncvs@cvs.apache.org:D:/home/cvspublic|log", null), new Test( @@ -121,7 +121,7 @@ public class CvsChangeLogGeneratorTest extends TestCase null) , new Test( null, - "scm|cvs|local|local|D:/home/cvspublic|maven", + "scm:cvs|local|local|D:/home/cvspublic|maven", "cvs|-d|D:/home/cvspublic|log", null), new Test( diff --git a/changelog/src/test/org/apache/maven/util/RepositoryTest.java b/changelog/src/test/org/apache/maven/util/RepositoryTest.java index 9c7860d4..accf5742 100644 --- a/changelog/src/test/org/apache/maven/util/RepositoryTest.java +++ b/changelog/src/test/org/apache/maven/util/RepositoryTest.java @@ -22,6 +22,20 @@ import junit.framework.TestCase; public class RepositoryTest extends TestCase { + public void testGetScmConnectionSeparatorColon() + { + String con = "scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:module"; + String separator = RepositoryUtils.getSCMConnectionSeparator( con ); + assertEquals( "Wrong SCM connection separator", ":", separator ); + } + + public void testGetScmConnectionSeparatorVerticalBar() + { + String con = "scm:cvs|pserver|anoncvs@cvs.apache.org|/home/cvspublic|module"; + String separator = RepositoryUtils.getSCMConnectionSeparator( con ); + assertEquals( "Wrong SCM connection separator", "|", separator ); + } + public void testSplitScmConnectionCvsPserver() { String con = "scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:module"; @@ -94,7 +108,7 @@ public class RepositoryTest public void testSplitScmConnectionSvn() { - String con = "scm|svn|http://svn.apache.org/repos"; + String con = "scm:svn|http://svn.apache.org/repos"; String[] tokens = RepositoryUtils.splitSCMConnection(con); assertEquals("Wrong number of tokens split", 3, tokens.length); } diff --git a/changelog/xdocs/changes.xml b/changelog/xdocs/changes.xml index 3e5c3357..bde96c5a 100644 --- a/changelog/xdocs/changes.xml +++ b/changelog/xdocs/changes.xml @@ -25,6 +25,7 @@ + Some valid scm urls are not allowed. Auto select factory from connection doesn't work if provider name length different from 3. Add MKS SI support. Changelog returns 0 entries on Windows with CVS (not CVSNT). New property maven.changelog.quoteDate.