Author: bodewig
Date: Thu Oct 16 08:29:42 2008
New Revision: 705260

URL: http://svn.apache.org/viewvc?rev=705260&view=rev
Log:
Make cvstagdiff work properly for multiple modules and modules with spaces in 
their name.  Open for optimization.  PR 33501.

Added:
    ant/core/trunk/src/tests/antunit/taskdefs/cvs/repository/antmodule3/
    ant/core/trunk/src/tests/antunit/taskdefs/cvs/repository/antmodule3/yet 
another test.txt,v
Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/docs/manual/CoreTasks/cvstagdiff.html
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java
    ant/core/trunk/src/tests/antunit/taskdefs/cvs/cvs.xml
    ant/core/trunk/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/history

Modified: ant/core/trunk/WHATSNEW
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=705260&r1=705259&r2=705260&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Thu Oct 16 08:29:42 2008
@@ -257,6 +257,10 @@
    command line arguments in some cases.
    Bugzilla Report 31601.
 
+ * <cvstagdiff> crippled file names and could miss some entries if
+   multiple modules have been specified.
+   Bugzilla Report 35301.
+
 Other changes:
 --------------
 

Modified: ant/core/trunk/docs/manual/CoreTasks/cvstagdiff.html
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/cvstagdiff.html?rev=705260&r1=705259&r2=705260&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/cvstagdiff.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/cvstagdiff.html Thu Oct 16 08:29:42 
2008
@@ -133,7 +133,7 @@
   </tr>
 </table>
 
-<h3>Examples</h3>
+<h3>Parameters specified as nested elements</h3>
 
 <h4>module</h4>
 

Modified: 
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java?rev=705260&r1=705259&r2=705260&view=diff
==============================================================================
--- 
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java 
(original)
+++ 
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java 
Thu Oct 16 08:29:42 2008
@@ -25,14 +25,18 @@
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.io.UnsupportedEncodingException;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Iterator;
 import java.util.StringTokenizer;
+import java.util.Vector;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.taskdefs.AbstractCvsTask;
 import org.apache.tools.ant.util.DOMElementWriter;
 import org.apache.tools.ant.util.DOMUtils;
+import org.apache.tools.ant.util.CollectionUtils;
 import org.apache.tools.ant.util.FileUtils;
 
 import org.w3c.dom.Document;
@@ -142,6 +146,11 @@
     private boolean ignoreRemoved = false;
 
     /**
+     * temporary list of package names.
+     */
+    private List packageNames = new ArrayList();
+
+    /**
      * The package/module to analyze.
      * @param p the name of the package to analyse
      */
@@ -232,16 +241,28 @@
             addCommandArgument("-D");
             addCommandArgument(myendDate);
         }
-        // support multiple packages
-        StringTokenizer myTokenizer = new StringTokenizer(mypackage);
-        while (myTokenizer.hasMoreTokens()) {
-            addCommandArgument(myTokenizer.nextToken());
-        }
+
         // force command not to be null
         setCommand("");
         File tmpFile = null;
         try {
-            tmpFile = FILE_UTILS.createTempFile("cvstagdiff", ".log", null, 
true, true);
+            if (mypackage != null) {
+                // support multiple packages
+                StringTokenizer myTokenizer = new StringTokenizer(mypackage);
+                while (myTokenizer.hasMoreTokens()) {
+                    String pack = myTokenizer.nextToken();
+                    packageNames.add(pack);
+                    addCommandArgument(pack);
+                }
+            }
+            for (Iterator iter = getModules().iterator(); iter.hasNext();) {
+                AbstractCvsTask.Module m = (AbstractCvsTask.Module) 
iter.next();
+                packageNames.add(m.getName());
+                // will be added to command line in super.execute()
+            }
+
+            tmpFile = FILE_UTILS.createTempFile("cvstagdiff", ".log", null,
+                                                true, true);
             setOutput(tmpFile);
 
             // run the cvs command
@@ -254,6 +275,7 @@
             writeTagDiff(entries);
 
         } finally {
+            packageNames.clear();
             if (tmpFile != null) {
                 tmpFile.delete();
             }
@@ -289,20 +311,13 @@
             // File testantoine/antoine.bat is removed; TESTANTOINE_1 revision 
1.1.1.1
             //
             // get rid of 'File module/"
-            String toBeRemoved = FILE_STRING + mypackage + "/";
-            int headerLength = toBeRemoved.length();
             Vector entries = new Vector();
 
             String line = reader.readLine();
 
             while (null != line) {
-                if (line.length() > headerLength) {
-                    if (line.startsWith(toBeRemoved)) {
-                        line = line.substring(headerLength);
-                    } else {
-                        line = line.substring(FILE_STRING.length());
-                    }
-
+                line = removePackageName(line, packageNames);
+                if (line != null) {
                     // use || in a perl like fashion
                     boolean processed
                         =  doFileIsNew(entries, line)
@@ -417,7 +432,8 @@
             }
 
             root.setAttribute("cvsroot", getCvsRoot());
-            root.setAttribute("package", mypackage);
+            root.setAttribute("package",
+                              CollectionUtils.flattenToString(packageNames));
             DOM_WRITER.openElement(root, writer, 0, "\t");
             writer.println();
             for (int i = 0, c = entries.length; i < c; i++) {
@@ -470,7 +486,7 @@
      * @exception BuildException if a parameter is not correctly set
      */
     private void validate() throws BuildException {
-        if (null == mypackage) {
+        if (null == mypackage && getModules().size() == 0) {
             throw new BuildException("Package/module must be set.");
         }
 
@@ -496,4 +512,29 @@
                                      + "be set.");
         }
     }
+
+    /**
+     * removes a "File: module/" prefix if present.
+     *
+     * @return null if the line was shorter than expected.
+     */
+    private static String removePackageName(String line, List packageNames) {
+        boolean matched = false;
+        for (Iterator iter = packageNames.iterator(); iter.hasNext(); ) {
+            String toBeRemoved = FILE_STRING + iter.next() + "/";
+            int len = toBeRemoved.length();
+            if (line.length() > len) {
+                if (line.startsWith(toBeRemoved)) {
+                    matched = true;
+                    line = line.substring(len);
+                    break;
+                }
+            }
+        }
+        if (!matched && line.length() > FILE_STRING.length()) {
+            line = line.substring(FILE_STRING.length());
+            matched = true;
+        }
+        return !matched ? null : line;
+    }
 }

Modified: ant/core/trunk/src/tests/antunit/taskdefs/cvs/cvs.xml
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/cvs/cvs.xml?rev=705260&r1=705259&r2=705260&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/cvs/cvs.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/cvs/cvs.xml Thu Oct 16 08:29:42 
2008
@@ -48,4 +48,31 @@
                   destfile="${output}/report.xml"/>
     <au:assertFileExists file="${output}/report.xml"/>
   </target>
+
+  <target name="testCvsTagDiffWithSpaceInModule">
+    <mkdir dir="${output}"/>
+    <cvstagdiff cvsroot="${cvsroot}"
+                startDate="2008-01-01"
+                endDate="2009-01-01"
+                destfile="${output}/tagdiff.xml">
+      <module name="ant module 2"/>
+    </cvstagdiff>
+    <au:assertFileExists file="${output}/tagdiff.xml"/>
+    <au:assertResourceContains resource="${output}/tagdiff.xml"
+                               value="[test.txt]"/>
+  </target>
+
+  <target name="testCvsTagDiffWithMultipleModules">
+    <mkdir dir="${output}"/>
+    <cvstagdiff cvsroot="${cvsroot}"
+                startDate="2008-01-01"
+                endDate="2009-01-01"
+                destfile="${output}/tagdiff.xml"
+                package="antmodule1 antmodule3"/>
+    <au:assertFileExists file="${output}/tagdiff.xml"/>
+    <au:assertResourceContains resource="${output}/tagdiff.xml"
+                               value="[foo.txt]"/>
+    <au:assertResourceContains resource="${output}/tagdiff.xml"
+                               value="[yet another test.txt]"/>
+  </target>
 </project>

Modified: 
ant/core/trunk/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/history
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/history?rev=705260&r1=705259&r2=705260&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/history 
(original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/history 
Thu Oct 16 08:29:42 2008
@@ -12,3 +12,7 @@
 O48f75185|stefan|/tmp/testoutput/*0|ant module 2||ant module 2
 O48f75186|stefan|/tmp/testoutput/*0|antmodule1||antmodule1
 O48f75196|stefan|/tmp/testoutput/*0|ant module 2||ant module 2
+O48f75279|stefan|/tmp/testoutput/*0|ant module 2||ant module 2
+O48f75282|stefan|/tmp/testoutput/*0|ant module 2||ant module 2
+O48f75d32|stefan|/tmp/testoutput/*0|ant module 2||ant module 2
+O48f75d34|stefan|/tmp/testoutput/*0|antmodule1||antmodule1

Added: ant/core/trunk/src/tests/antunit/taskdefs/cvs/repository/antmodule3/yet 
another test.txt,v
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/cvs/repository/antmodule3/yet%20another%20test.txt%2Cv?rev=705260&view=auto
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/cvs/repository/antmodule3/yet 
another test.txt,v (added)
+++ ant/core/trunk/src/tests/antunit/taskdefs/cvs/repository/antmodule3/yet 
another test.txt,v Thu Oct 16 08:29:42 2008
@@ -0,0 +1,41 @@
+head     1.1;
+branch   1.1.1;
+access   ;
+symbols  start:1.1.1.1 ant:1.1.1;
+locks    ; strict;
+comment  @# @;
+
+
+1.1
+date     2008.10.16.14.51.11;  author stefan;  state Exp;
+branches 1.1.1.1;
+next     ;
+commitid        7f8d48f754df4567;
+
+1.1.1.1
+date     2008.10.16.14.51.11;  author stefan;  state Exp;
+branches ;
+next     ;
+commitid        7f8d48f754df4567;
+
+
+desc
+@@
+
+
+
+1.1
+log
[EMAIL PROTECTED] revision
+@
+text
[EMAIL PROTECTED] and cloudy.
+@
+
+
+1.1.1.1
+log
[EMAIL PROTECTED] times is a charm
+@
+text
+@@


Reply via email to