From 5f81fd801113c7f3bb4b734d0be4337ef482c0fd Mon Sep 17 00:00:00 2001
From: Stefan Bodewig
Date: Fri, 10 Oct 2008 16:20:54 +0000
Subject: [PATCH] javadoc fails if bottom/gead contain line breaks. PR 43342.
Based on patch by Robert Streich.
git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@703516 13f79535-47bb-0310-9956-ffa450edef68
---
CONTRIBUTORS | 1 +
WHATSNEW | 4 ++
contributors.xml | 4 ++
docs/manual/CoreTasks/javadoc.html | 5 +-
.../apache/tools/ant/taskdefs/Javadoc.java | 54 ++++++++++++-------
src/tests/antunit/taskdefs/javadoc-test.xml | 45 ++++++++++++++++
6 files changed, 93 insertions(+), 20 deletions(-)
create mode 100644 src/tests/antunit/taskdefs/javadoc-test.xml
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index b08c6e270..3115aa7f1 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -239,6 +239,7 @@ Rick Beton
Robert Anderson
Robert Flaherty
Robert Shaw
+Robert Streich
Robert Watkins
Roberto Scaramuzzi
Robin Green
diff --git a/WHATSNEW b/WHATSNEW
index 3f611c611..aa6f7583b 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -236,6 +236,10 @@ Fixed bugs:
find the corresponding source files.
Bugzilla Report 45916.
+ * failed if the nested or contained line
+ breaks.
+ Bugzilla Report 43342.
+
Other changes:
--------------
diff --git a/contributors.xml b/contributors.xml
index d0d55e720..648e1ff34 100644
--- a/contributors.xml
+++ b/contributors.xml
@@ -972,6 +972,10 @@
Robert
Shaw
+
+ Robert
+ Streich
+
Robert
Watkins
diff --git a/docs/manual/CoreTasks/javadoc.html b/docs/manual/CoreTasks/javadoc.html
index 99151ba25..3b841eb36 100644
--- a/docs/manual/CoreTasks/javadoc.html
+++ b/docs/manual/CoreTasks/javadoc.html
@@ -413,7 +413,7 @@ to ensure that this command supports the attributes you wish to use.
in srcfiles or as nested source elements should be written to a
temporary file to make the command line shorter. Also applies to
the package names specified via the packagenames attribute or
- nested package elements.Since Ant 1.7.0, also applies
+ nested package elements. Since Ant 1.7.0, also applies
to all the other command line options.
(yes
| no
). Default is no.
all |
@@ -571,6 +571,9 @@ Same as for package
.
Same as the doctitle
attribute, but you can nest text
inside the element this way.
+If the nested text contains line breaks, you must use the
+ useexternalfile attribute and set it to true.
+
header
Similar to <doctitle>
.
diff --git a/src/main/org/apache/tools/ant/taskdefs/Javadoc.java b/src/main/org/apache/tools/ant/taskdefs/Javadoc.java
index dae34ac13..d830098ee 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Javadoc.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Javadoc.java
@@ -2243,30 +2243,46 @@ public class Javadoc extends Task {
return false;
}
- private String quoteString(String str, final char delim) {
+ private String quoteString(final String str, final char delim) {
StringBuffer buf = new StringBuffer(str.length() * 2);
buf.append(delim);
- if (str.indexOf('\\') != -1) {
- str = replace(str, '\\', "\\\\");
- }
- if (str.indexOf(delim) != -1) {
- str = replace(str, delim, "\\" + delim);
- }
- buf.append(str);
- buf.append(delim);
- return buf.toString();
- }
-
- private String replace(String str, char fromChar, String toString) {
- StringBuffer buf = new StringBuffer(str.length() * 2);
- for (int i = 0; i < str.length(); ++i) {
- char ch = str.charAt(i);
- if (ch == fromChar) {
- buf.append(toString);
+ final int len = str.length();
+ boolean lastCharWasCR = false;
+ for (int i = 0; i < len; i++) {
+ char c = str.charAt(i);
+ if (c == delim) { // can't put the non-constant delim into a case
+ buf.append('\\').append(c);
+ lastCharWasCR = false;
} else {
- buf.append(ch);
+ switch (c) {
+ case '\\':
+ buf.append("\\\\");
+ lastCharWasCR = false;
+ break;
+ case '\r':
+ // insert a line continuation marker
+ buf.append("\\\r");
+ lastCharWasCR = true;
+ break;
+ case '\n':
+ // insert a line continuation marker unless this
+ // is a \r\n sequence in which case \r already has
+ // created the marker
+ if (!lastCharWasCR) {
+ buf.append("\\\n");
+ } else {
+ buf.append("\n");
+ }
+ lastCharWasCR = false;
+ break;
+ default:
+ buf.append(c);
+ lastCharWasCR = false;
+ break;
+ }
}
}
+ buf.append(delim);
return buf.toString();
}
diff --git a/src/tests/antunit/taskdefs/javadoc-test.xml b/src/tests/antunit/taskdefs/javadoc-test.xml
new file mode 100644
index 000000000..3c6701006
--- /dev/null
+++ b/src/tests/antunit/taskdefs/javadoc-test.xml
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
+
+
+Hello World
+]]>
+
+
+
+