diff --git a/WHATSNEW b/WHATSNEW index 3d8269a8c..8392e5db0 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -257,6 +257,10 @@ Fixed bugs: command line arguments in some cases. Bugzilla Report 31601. + * crippled file names and could miss some entries if + multiple modules have been specified. + Bugzilla Report 35301. + Other changes: -------------- diff --git a/docs/manual/CoreTasks/cvstagdiff.html b/docs/manual/CoreTasks/cvstagdiff.html index 62ed8da4a..b0bcab3cb 100644 --- a/docs/manual/CoreTasks/cvstagdiff.html +++ b/docs/manual/CoreTasks/cvstagdiff.html @@ -133,7 +133,7 @@ operation may fail when using such an incompatible client. -

Examples

+

Parameters specified as nested elements

module

diff --git a/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java b/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java index 9089cbef7..98bbc1a4e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java +++ b/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java @@ -25,14 +25,18 @@ import java.io.IOException; 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; @@ -141,6 +145,11 @@ public class CvsTagDiff extends AbstractCvsTask { */ 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 @@ public class CvsTagDiff extends AbstractCvsTask { 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 @@ public class CvsTagDiff extends AbstractCvsTask { writeTagDiff(entries); } finally { + packageNames.clear(); if (tmpFile != null) { tmpFile.delete(); } @@ -289,20 +311,13 @@ public class CvsTagDiff extends AbstractCvsTask { // 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 @@ public class CvsTagDiff extends AbstractCvsTask { } 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 @@ public class CvsTagDiff extends AbstractCvsTask { * @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 @@ public class CvsTagDiff extends AbstractCvsTask { + "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; + } } diff --git a/src/tests/antunit/taskdefs/cvs/cvs.xml b/src/tests/antunit/taskdefs/cvs/cvs.xml index 6d0fb5b57..aca5810db 100644 --- a/src/tests/antunit/taskdefs/cvs/cvs.xml +++ b/src/tests/antunit/taskdefs/cvs/cvs.xml @@ -48,4 +48,31 @@ destfile="${output}/report.xml"/> + + + + + + + + + + + + + + + + + diff --git a/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/history b/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/history index f739dfe37..b99218a3d 100644 --- a/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/history +++ b/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/history @@ -12,3 +12,7 @@ O48f75161|stefan|/tmp/testoutput/*0|ant module 2||ant module 2 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 diff --git a/src/tests/antunit/taskdefs/cvs/repository/antmodule3/yet another test.txt,v b/src/tests/antunit/taskdefs/cvs/repository/antmodule3/yet another test.txt,v new file mode 100644 index 000000000..3514e950f --- /dev/null +++ b/src/tests/antunit/taskdefs/cvs/repository/antmodule3/yet another test.txt,v @@ -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 +@Initial revision +@ +text +@dark and cloudy. +@ + + +1.1.1.1 +log +@three times is a charm +@ +text +@@