Refactoring SCM processing
PR: MAVEN-383 git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@113320 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
49ef9e2de4
commit
8618cf1f8d
@ -59,13 +59,13 @@ package org.apache.maven.cvslib;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.StringTokenizer;
|
||||
import java.text.SimpleDateFormat;
|
||||
// commons imports
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
// maven imports
|
||||
import org.apache.maven.changelog.AbstractChangeLogGenerator;
|
||||
import org.apache.maven.project.Repository;
|
||||
import org.apache.maven.util.AsyncStreamReader;
|
||||
// ant imports
|
||||
import org.apache.tools.ant.types.Commandline;
|
||||
@ -83,47 +83,33 @@ import org.apache.tools.ant.types.Commandline;
|
||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
|
||||
* @author <a href="mailto:pete-apache-dev@kazmier.com">Pete Kazmier</a>
|
||||
* @version
|
||||
* $Id: CvsChangeLogGenerator.java,v 1.5 2003/04/09 10:48:30 bwalding Exp $
|
||||
* $Id: CvsChangeLogGenerator.java,v 1.6 2003/04/11 18:53:19 bwalding Exp $
|
||||
*/
|
||||
class CvsChangeLogGenerator extends AbstractChangeLogGenerator
|
||||
{
|
||||
/** Log */
|
||||
private static final Log LOG = LogFactory.getLog(CvsChangeLogGenerator.class);
|
||||
|
||||
public static final int POS_SCM = 0;
|
||||
public static final int POS_SCM_TYPE = 1;
|
||||
public static final int POS_SCM_SUBTYPE = 2;
|
||||
public static final int POS_SCM_USERHOST = 3;
|
||||
public static final int POS_SCM_PATH = 4;
|
||||
public static final int POS_SCM_MODULE = 5;
|
||||
|
||||
|
||||
/**
|
||||
* @return the cvs command line to be executed.
|
||||
*/
|
||||
protected Commandline getScmLogCommand()
|
||||
{
|
||||
if (getConnection() == null)
|
||||
{
|
||||
throw new IllegalArgumentException("repository connection string" + " not specified");
|
||||
}
|
||||
|
||||
String connection = getConnection();
|
||||
if (connection.length() < 4)
|
||||
{
|
||||
throw new IllegalArgumentException("repository connection string doesn't start with scm<delim>");
|
||||
}
|
||||
|
||||
String inputDelim = connection.substring(3, 4);
|
||||
|
||||
StringTokenizer tokenizer = new StringTokenizer(getConnection(), inputDelim);
|
||||
if (tokenizer.countTokens() < 6)
|
||||
{
|
||||
throw new IllegalArgumentException("repository connection string contains less than six tokens");
|
||||
}
|
||||
String tokens[] = Repository.splitSCMConnection(getConnection());
|
||||
|
||||
if (tokenizer.countTokens() > 6)
|
||||
{
|
||||
throw new IllegalArgumentException("repository connection string contains more than six tokens");
|
||||
}
|
||||
|
||||
tokenizer.nextToken(); // skip 'scm'
|
||||
if (!tokenizer.nextToken().equals("cvs"))
|
||||
if (!tokens[POS_SCM_TYPE].equals("cvs"))
|
||||
{
|
||||
throw new IllegalArgumentException("repository connection string" + " does not specify 'cvs' as the scm");
|
||||
}
|
||||
|
||||
Commandline command = new Commandline();
|
||||
|
||||
command.setExecutable("cvs");
|
||||
@ -133,31 +119,27 @@ class CvsChangeLogGenerator extends AbstractChangeLogGenerator
|
||||
// to format:
|
||||
// :pserver:anoncvs@cvs.apache.org:/home/cvspublic
|
||||
// use tokens 3+4+5
|
||||
StringBuffer connectionBuffer = new StringBuffer(":");
|
||||
String connectionType = tokenizer.nextToken();
|
||||
|
||||
if (connectionType.equalsIgnoreCase("local"))
|
||||
String connectionBuffer = "";
|
||||
|
||||
if (tokens[POS_SCM_SUBTYPE].equalsIgnoreCase("local"))
|
||||
{
|
||||
// throw away the next token 'user@host'
|
||||
tokenizer.nextToken();
|
||||
// use the local repository directory eg. '/home/cvspublic'
|
||||
connectionBuffer = new StringBuffer(tokenizer.nextToken());
|
||||
connectionBuffer = tokens[POS_SCM_PATH];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (connectionType.equalsIgnoreCase("lserver"))
|
||||
if (tokens[POS_SCM_SUBTYPE].equalsIgnoreCase("lserver"))
|
||||
{
|
||||
//create the cvsroot as the local socket cvsroot
|
||||
connectionBuffer = new StringBuffer();
|
||||
connectionBuffer.append(tokenizer.nextToken()).append(":").append(
|
||||
tokenizer.nextToken());
|
||||
connectionBuffer = tokens[POS_SCM_USERHOST] + ":" + tokens[POS_SCM_PATH];
|
||||
}
|
||||
else
|
||||
{
|
||||
//create the cvsroot as the remote cvsroot
|
||||
connectionBuffer = new StringBuffer(":");
|
||||
connectionBuffer.append(connectionType).append(":").append(tokenizer.nextToken()).append(":").append(
|
||||
tokenizer.nextToken());
|
||||
connectionBuffer =
|
||||
":" + tokens[POS_SCM_SUBTYPE]
|
||||
+ ":" + tokens[POS_SCM_USERHOST]
|
||||
+ ":" + tokens[POS_SCM_PATH];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -59,13 +59,15 @@ package org.apache.maven.cvslib;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.project.Repository;
|
||||
import org.apache.maven.util.EnhancedStringTokenizer;
|
||||
import org.apache.tools.ant.types.Commandline;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @author <a href="bwalding@jakarta.org">Ben Walding</a>
|
||||
* @version $Id: CvsChangeLogGeneratorTest.java,v 1.4 2003/04/09 10:48:29 bwalding Exp $
|
||||
* @version $Id: CvsChangeLogGeneratorTest.java,v 1.5 2003/04/11 18:53:19 bwalding Exp $
|
||||
*/
|
||||
class ExposeGenerator extends CvsChangeLogGenerator
|
||||
{
|
||||
@ -78,7 +80,7 @@ class ExposeGenerator extends CvsChangeLogGenerator
|
||||
|
||||
/**
|
||||
* @author <a href="bwalding@jakarta.org">Ben Walding</a>
|
||||
* @version $Id: CvsChangeLogGeneratorTest.java,v 1.4 2003/04/09 10:48:29 bwalding Exp $
|
||||
* @version $Id: CvsChangeLogGeneratorTest.java,v 1.5 2003/04/11 18:53:19 bwalding Exp $
|
||||
*/
|
||||
public class CvsChangeLogGeneratorTest extends TestCase
|
||||
{
|
||||
@ -99,6 +101,7 @@ public class CvsChangeLogGeneratorTest extends TestCase
|
||||
|
||||
Test[] tests =
|
||||
{
|
||||
new Test(null, "", NullPointerException.class),
|
||||
new Test("asd:asd", "", IllegalArgumentException.class),
|
||||
new Test(
|
||||
"scm:csvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:jakarta-turbine-maven",
|
||||
@ -141,7 +144,7 @@ public class CvsChangeLogGeneratorTest extends TestCase
|
||||
|
||||
public void testParse(Test test) throws Throwable
|
||||
{
|
||||
String[] expected = tokenizerToArray(new EnhancedStringTokenizer(test.args, "|"));
|
||||
String[] expected = Repository.tokenizerToArray(new EnhancedStringTokenizer(test.args, "|"));
|
||||
|
||||
ExposeGenerator eg = new ExposeGenerator();
|
||||
try
|
||||
@ -178,31 +181,7 @@ public class CvsChangeLogGeneratorTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a tokenizer to an array of strings
|
||||
* @param tok
|
||||
* @return String[]
|
||||
*/
|
||||
public static String[] tokenizerToArray(EnhancedStringTokenizer tok)
|
||||
{
|
||||
List l = new ArrayList();
|
||||
while (tok.hasMoreTokens())
|
||||
{
|
||||
l.add(tok.nextToken());
|
||||
}
|
||||
return (String[]) l.toArray(new String[l.size()]);
|
||||
}
|
||||
|
||||
public void testTokenizer()
|
||||
{
|
||||
EnhancedStringTokenizer tok = new EnhancedStringTokenizer("a,b,b,c,d", ",", false);
|
||||
String[] result = tokenizerToArray(tok);
|
||||
assertEquals("result.length", 5, result.length);
|
||||
assertEquals("result[0]", "a", result[0]);
|
||||
assertEquals("result[1]", "b", result[1]);
|
||||
assertEquals("result[2]", "b", result[2]);
|
||||
assertEquals("result[3]", "c", result[3]);
|
||||
assertEquals("result[4]", "d", result[4]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user