CHANGELOG-64 properly parse cvspass file

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@188667 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
epugh 2005-06-07 02:23:22 +00:00
parent c3e6ad8894
commit 6b1bf0576b
2 changed files with 73 additions and 30 deletions

View File

@ -212,7 +212,7 @@ public class CvsConnection
* Lookup the password in the .cvspass file. This file is looked for in the
* user.home directory if the option cvs.passfile is not set
*
* @param CVSRoot the CVS root for which the password is being searched
* @param cvsRoot the CVS root for which the password is being searched
* @return the password, scrambled
*/
private static String lookupPassword(String cvsRoot)
@ -229,26 +229,7 @@ public class CvsConnection
try
{
reader = new BufferedReader(new FileReader(passFile));
String line;
while ((line = reader.readLine()) != null)
{
if (line.startsWith("/"))
{
Vector cvspass = StringUtils.split(line, ' ');
if (cvspass.size() >= 3)
{
if (compareCvsRoot(cvsRoot, (String)cvspass.get(1))) {
password = (String)cvspass.get(2);
break;
}
}
}
else if (line.startsWith(cvsRoot))
{
password = line.substring(cvsRoot.length() + 1);
break;
}
}
password = processCvspass(cvsRoot, reader);
}
catch (IOException e)
{
@ -276,7 +257,40 @@ public class CvsConnection
return password;
}
static boolean compareCvsRoot(String cvsRoot, String target)
/**
* Read in a list of return delimited lines from .cvspass and retreive
* the password. Return null if the cvsRoot can't be found.
*
* @param cvsRoot the CVS root for which the password is being searched
* @param reader A buffered reader of lines of cvspass information
* @return The password, or null if it can't be found.
* @throws IOException
*/
static String processCvspass(String cvsRoot, BufferedReader reader) throws IOException {
String line;
String password = null;
while ((line = reader.readLine()) != null)
{
if (line.startsWith("/"))
{
Vector cvspass = StringUtils.split(line, ' ');
String cvspassRoot = (String)cvspass.get(1);
if (compareCvsRoot(cvsRoot, cvspassRoot)) {
int index = line.indexOf(cvspassRoot) + cvspassRoot.length()+1;
password = line.substring(index);
break;
}
}
else if (line.startsWith(cvsRoot))
{
password = line.substring(cvsRoot.length() + 1);
break;
}
}
return password;
}
static boolean compareCvsRoot(String cvsRoot, String target)
{
String s1 = completeCvsRootPort(cvsRoot);
String s2 = completeCvsRootPort(target);

View File

@ -17,12 +17,10 @@ package org.apache.maven.cvslib;
* ====================================================================
*/
import java.io.FileInputStream;
import java.util.Collection;
import java.util.Iterator;
import junit.framework.TestCase;
import java.io.BufferedReader;
import java.io.StringReader;
import org.apache.maven.changelog.ChangeLogEntry;
import junit.framework.TestCase;
/**
@ -85,9 +83,40 @@ public class CvsConnectionTest extends TestCase
}
// Add test methods here, they have to start with 'test' name.
// for example:
// public void testHello() {}
/**
* Test of reading in .cvspass file processes different types of lines properly
* @throws Exception when there is an unexpected problem
*/
public void testProcessCvspass() throws Exception
{
String[] expectedResult = {
"A ",
null,
"Axxx ",
"Axxx xxx ",
"A ",
null,
"Axxx ",
"Axxx xxx "
};
String[] cvspassData = {
":pserver:user@server:/home/cvs A ",
":ext:user@server:/home/cvs A ",
":pserver:user@server:/home/cvs Axxx ",
":pserver:user@server:/home/cvs Axxx xxx ",
"/1 :pserver:user@server:2401/home/cvs A ",
"/1 :ext:user@server:2401/home/cvs A ",
"/1 :pserver:user@server:2401/home/cvs Axxx ",
"/1 :pserver:user@server:2401/home/cvs Axxx xxx ",
};
for (int i = 4;i<expectedResult.length;i++){
BufferedReader reader = new BufferedReader(new StringReader(cvspassData[i]));
String password = CvsConnection.processCvspass(testData,reader);
assertEquals(expectedResult[i],password);
}
}
}