PR: MPCHANGELOG-81

Submitted by: Dennis Lundberg
Some valid scm urls are not allowed.
A valid scm url should be of the form scm:<provider><delimiter><provider-parameters>,
ie it has to start with 'scm:', but <delimiter> can be either ':' or '|'.


git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@371429 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
ltheussl
2006-01-23 01:11:41 +00:00
parent bf7bfe655b
commit a98376e90e
5 changed files with 54 additions and 12 deletions

View File

@@ -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:<provider>[:<provider specific connection string>]
// Connection Format: scm:<provider><separator><provider specific connection string>
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:<provider>
@@ -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";

View File

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

View File

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

View File

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

View File

@@ -25,6 +25,7 @@
</properties>
<body>
<release version="1.9-SNAPSHOT" date="in SVN">
<action dev="ltheussl" type="fix" issue="MPCHANGELOG-81" due-to="Dennis Lundberg">Some valid scm urls are not allowed.</action>
<action dev="ltheussl" type="fix" issue="MPCHANGELOG-72" due-to="Pascal Larin">Auto select factory from connection doesn't work if provider name length different from 3.</action>
<action dev="ltheussl" type="add" issue="MPCHANGELOG-80" due-to="Christoph Jerolimov">Add MKS SI support.</action>
<action dev="ltheussl" type="fix" issue="MPCHANGELOG-69">Changelog returns 0 entries on Windows with CVS (not CVSNT). New property <code>maven.changelog.quoteDate</code>.</action>