Browse Source

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
master
Stefan Bodewig 16 years ago
parent
commit
5f81fd8011
6 changed files with 93 additions and 20 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +4
    -0
      WHATSNEW
  3. +4
    -0
      contributors.xml
  4. +4
    -1
      docs/manual/CoreTasks/javadoc.html
  5. +35
    -19
      src/main/org/apache/tools/ant/taskdefs/Javadoc.java
  6. +45
    -0
      src/tests/antunit/taskdefs/javadoc-test.xml

+ 1
- 0
CONTRIBUTORS View File

@@ -239,6 +239,7 @@ Rick Beton
Robert Anderson
Robert Flaherty
Robert Shaw
Robert Streich
Robert Watkins
Roberto Scaramuzzi
Robin Green


+ 4
- 0
WHATSNEW View File

@@ -236,6 +236,10 @@ Fixed bugs:
find the corresponding source files.
Bugzilla Report 45916.

* <javadoc> failed if the nested <bottom> or <head> contained line
breaks.
Bugzilla Report 43342.

Other changes:
--------------



+ 4
- 0
contributors.xml View File

@@ -972,6 +972,10 @@
<first>Robert</first>
<last>Shaw</last>
</name>
<name>
<first>Robert</first>
<last>Streich</last>
</name>
<name>
<first>Robert</first>
<last>Watkins</last>


+ 4
- 1
docs/manual/CoreTasks/javadoc.html View File

@@ -413,7 +413,7 @@ to ensure that this command supports the attributes you wish to use.</p>
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.<em>Since Ant 1.7.0</em>, also applies
nested package elements. <em>Since Ant 1.7.0</em>, also applies
to all the other command line options.
(<code>yes</code> | <code>no</code>). Default is no.</td>
<td align="center" valign="top">all</td>
@@ -571,6 +571,9 @@ Same as for <code>package</code>.
<p>Same as the <code>doctitle</code> attribute, but you can nest text
inside the element this way.</p>

<p>If the nested text contains line breaks, you must use the
useexternalfile attribute and set it to true.</p>

<h4>header</h4>

<p>Similar to <code>&lt;doctitle&gt;</code>.</p>


+ 35
- 19
src/main/org/apache/tools/ant/taskdefs/Javadoc.java View File

@@ -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();
}



+ 45
- 0
src/tests/antunit/taskdefs/javadoc-test.xml View File

@@ -0,0 +1,45 @@
<?xml version="1.0"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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.
-->
<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit">
<import file="../antunit-base.xml" />

<target name="testBottomWithLineBreaksWithFile">
<mkdir dir="${input}/test"/>
<echo file="${input}/test/A.java"><![CDATA[
package test;

/**
* This is a test class.
*/
public class A {
/**
* With a test method.
*/
public void foo(String bar) {}
}
]]></echo>
<javadoc destdir="${output}" useexternalfile="true">
<fileset dir="${input}"/>
<bottom><![CDATA[
<hr/>
Hello World
]]></bottom>
</javadoc>
<au:assertFileExists file="${output}/test/A.html"/>
</target>
</project>

Loading…
Cancel
Save