diff --git a/src/main/org/apache/tools/ant/IntrospectionHelper.java b/src/main/org/apache/tools/ant/IntrospectionHelper.java index d426f6ac6..05f675f66 100644 --- a/src/main/org/apache/tools/ant/IntrospectionHelper.java +++ b/src/main/org/apache/tools/ant/IntrospectionHelper.java @@ -73,6 +73,9 @@ public final class IntrospectionHelper implements BuildListener { } } + private static final int MAX_REPORT_NESTED_TEXT = 20; + private static final String ELLIPSIS = "..."; + /** * Map from attribute names to attribute types * (String to Class). @@ -430,14 +433,16 @@ public final class IntrospectionHelper implements BuildListener { public void addText(Project project, Object element, String text) throws BuildException { if (addText == null) { + text = text.trim(); // Element doesn't handle text content - if (text.trim().length() == 0) { + if (text.length() == 0) { // Only whitespace - ignore return; } else { // Not whitespace - fail String msg = project.getElementName(element) - + " doesn't support nested text data."; + + " doesn't support nested text data (\"" + + condenseText(text) + "\")."; throw new BuildException(msg); } } @@ -1493,4 +1498,12 @@ public final class IntrospectionHelper implements BuildListener { return matchedMethod; } + private String condenseText(final String text) { + if (text.length() <= MAX_REPORT_NESTED_TEXT) { + return text; + } + int ends = (MAX_REPORT_NESTED_TEXT - ELLIPSIS.length()) / 2; + return new StringBuffer(text).replace(ends, text.length() - ends, + ELLIPSIS).toString(); + } } diff --git a/src/tests/antunit/core/nested-text-test.xml b/src/tests/antunit/core/nested-text-test.xml new file mode 100644 index 000000000..8813c0df4 --- /dev/null +++ b/src/tests/antunit/core/nested-text-test.xml @@ -0,0 +1,13 @@ + + + + foo + + + + + + foo + + +