From 6d8ecab1a87d82d8bf571f6763206273ac1de742 Mon Sep 17 00:00:00 2001 From: dion Date: Fri, 9 Jul 2004 11:53:46 +0000 Subject: [PATCH] Fix for MPCHANGELOG-34. Plugin does not find the password for the CVSROOT in .cvspass if the CVSROOT in .cvspass is preceded by a "/1". git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@115740 13f79535-47bb-0310-9956-ffa450edef68 --- changelog/project.xml | 2 +- .../apache/maven/cvslib/CvsConnection.java | 49 +++++++++- .../maven/cvslib/CvsConnectionTest.java | 93 +++++++++++++++++++ changelog/xdocs/changes.xml | 3 + 4 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 changelog/src/test/org/apache/maven/cvslib/CvsConnectionTest.java diff --git a/changelog/project.xml b/changelog/project.xml index 5fbfa2e4..933571c6 100644 --- a/changelog/project.xml +++ b/changelog/project.xml @@ -23,7 +23,7 @@ 3 maven-changelog-plugin Maven Changelog Plugin - 1.7 + 1.7.1-SNAPSHOT Produce SCM changelog reports http://maven.apache.org/reference/plugins/changelog/ diff --git a/changelog/src/main/org/apache/maven/cvslib/CvsConnection.java b/changelog/src/main/org/apache/maven/cvslib/CvsConnection.java index 5210522f..501be75b 100644 --- a/changelog/src/main/org/apache/maven/cvslib/CvsConnection.java +++ b/changelog/src/main/org/apache/maven/cvslib/CvsConnection.java @@ -21,9 +21,11 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.tools.ant.util.StringUtils; import org.netbeans.lib.cvsclient.CVSRoot; import org.netbeans.lib.cvsclient.Client; import org.netbeans.lib.cvsclient.admin.StandardAdminHandler; @@ -226,11 +228,24 @@ public class CvsConnection try { + StringBuffer cvsroot = new StringBuffer(); + reader = new BufferedReader(new FileReader(passFile)); String line; while ((line = reader.readLine()) != null) { - if (line.startsWith(cvsRoot)) + 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; @@ -263,6 +278,38 @@ public class CvsConnection return password; } + static boolean compareCvsRoot(String cvsRoot, String target) + { + String s1 = completeCvsRootPort(cvsRoot); + String s2 = completeCvsRootPort(target); + if (s1 != null && s1.equals(s2)) + { + return true; + } + return false; + + } + + private static String completeCvsRootPort(String cvsRoot) + { + String result = cvsRoot; + int idx = cvsRoot.indexOf(':'); + for (int i=0; i < 2 && idx != -1; i++) + { + idx = cvsRoot.indexOf(':', idx+1); + } + if (idx != -1 && cvsRoot.charAt(idx+1) == '/') + { + StringBuffer sb = new StringBuffer(); + sb.append(cvsRoot.substring(0, idx+1)); + sb.append("2401"); + sb.append(cvsRoot.substring(idx+1)); + result = sb.toString(); + } + return result; + + } + /** * Process the CVS command passed in args[] array with all necessary * options. The only difference from main() method is, that this method diff --git a/changelog/src/test/org/apache/maven/cvslib/CvsConnectionTest.java b/changelog/src/test/org/apache/maven/cvslib/CvsConnectionTest.java new file mode 100644 index 00000000..88e80a99 --- /dev/null +++ b/changelog/src/test/org/apache/maven/cvslib/CvsConnectionTest.java @@ -0,0 +1,93 @@ +package org.apache.maven.cvslib; + +/* ==================================================================== + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +import java.io.FileInputStream; +import java.util.Collection; +import java.util.Iterator; +import junit.framework.TestCase; + +import org.apache.maven.changelog.ChangeLogEntry; + + +/** + * Test cases for {@link CvsConnection} + * @author + * @version $Id: CvsConnectionTest.java,v 1.3 2004/07/09 11:53:45 dion Exp $ + */ +public class CvsConnectionTest extends TestCase +{ + + /** the {@link CvsConnection} used for testing */ + private CvsConnection instance; + /** test data */ + private String testData = ":pserver:user@server:/home/cvs"; + private String[] testTrueData = { + ":pserver:user@server:/home/cvs", + ":pserver:user@server:2401/home/cvs" + }; + private String[] testFalseData = { + ":ext:user@server:/home/cvs", + ":pserver:admin@server:/home/cvs", + ":pserver:user@host:/home/cvs", + ":pserver:user@server:/home/cvsroot", + ":ext:user@server:2401/home/cvs", + ":pserver:admin@server:2401/home/cvs", + ":pserver:user@host:2401/home/cvs", + ":pserver:user@server:2401/home/cvsroot" + }; + + /** + * Create a test with the given name + * @param testName the name of the test + */ + public CvsConnectionTest(String testName) + { + super(testName); + } + + /** + * Test of compareCvsRoot method + * @throws Exception when there is an unexpected problem + */ + public void testCompareTrue() throws Exception + { + for (int i=0; i < testTrueData.length; i++) { + assertTrue(CvsConnection.compareCvsRoot(testData, testTrueData[i])); + } + + } + + /** + * Test of compareCvsRoot method + * @throws Exception when there is an unexpected problem + */ + public void testCompareFalse() throws Exception + { + for (int i=0; i < testFalseData.length; i++) { + assertFalse(CvsConnection.compareCvsRoot(testData, testFalseData[i])); + } + + } + + // Add test methods here, they have to start with 'test' name. + // for example: + // public void testHello() {} + + +} diff --git a/changelog/xdocs/changes.xml b/changelog/xdocs/changes.xml index 88a11081..76dd40e7 100644 --- a/changelog/xdocs/changes.xml +++ b/changelog/xdocs/changes.xml @@ -25,6 +25,9 @@ Emmanuel Venisse + + Plugin does not find the password for the CVSROOT in .cvspass if the CVSROOT in .cvspass is preceded by a "/1". + Add the possibility to specify a date format for input stream (Starteam only).