You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by ep...@apache.org on 2005/06/07 04:23:23 UTC

svn commit: r188667 - in /maven/maven-1/plugins/trunk/changelog/src: main/org/apache/maven/cvslib/CvsConnection.java test/org/apache/maven/cvslib/CvsConnectionTest.java

Author: epugh
Date: Mon Jun  6 19:23:22 2005
New Revision: 188667

URL: http://svn.apache.org/viewcvs?rev=188667&view=rev
Log:
CHANGELOG-64 properly parse cvspass file

Modified:
    maven/maven-1/plugins/trunk/changelog/src/main/org/apache/maven/cvslib/CvsConnection.java
    maven/maven-1/plugins/trunk/changelog/src/test/org/apache/maven/cvslib/CvsConnectionTest.java

Modified: maven/maven-1/plugins/trunk/changelog/src/main/org/apache/maven/cvslib/CvsConnection.java
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/changelog/src/main/org/apache/maven/cvslib/CvsConnection.java?rev=188667&r1=188666&r2=188667&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/changelog/src/main/org/apache/maven/cvslib/CvsConnection.java (original)
+++ maven/maven-1/plugins/trunk/changelog/src/main/org/apache/maven/cvslib/CvsConnection.java Mon Jun  6 19:23:22 2005
@@ -212,7 +212,7 @@
      * 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 @@
         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 @@
         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);

Modified: maven/maven-1/plugins/trunk/changelog/src/test/org/apache/maven/cvslib/CvsConnectionTest.java
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/changelog/src/test/org/apache/maven/cvslib/CvsConnectionTest.java?rev=188667&r1=188666&r2=188667&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/changelog/src/test/org/apache/maven/cvslib/CvsConnectionTest.java (original)
+++ maven/maven-1/plugins/trunk/changelog/src/test/org/apache/maven/cvslib/CvsConnectionTest.java Mon Jun  6 19:23:22 2005
@@ -17,12 +17,10 @@
  * ====================================================================
  */
 
-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 @@
 
     }
 
-    // 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);
+    		}
+	}
 
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org