From 996bb8c9ceb82d5bab623c946eda5c76f20713ef Mon Sep 17 00:00:00 2001 From: Matthew Jason Benson Date: Thu, 21 Sep 2006 19:40:09 +0000 Subject: [PATCH] commit the first antunit test while showing offending, un-addable text. Bugzilla 40415. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@448646 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tools/ant/IntrospectionHelper.java | 17 +++++++++++++++-- src/tests/antunit/core/nested-text-test.xml | 13 +++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 src/tests/antunit/core/nested-text-test.xml 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 + + +