Author: mbenson
Date: Thu Sep 21 12:40:09 2006
New Revision: 448646
URL: http://svn.apache.org/viewvc?view=rev&rev=448646
Log:
commit the first antunit test while showing offending, un-addable text.
Bugzilla 40415.
Added:
ant/core/trunk/src/tests/antunit/core/
ant/core/trunk/src/tests/antunit/core/nested-text-test.xml (with props)
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java
Modified: ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java?view=diff&rev=448646&r1=448645&r2=448646
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java Thu
Sep 21 12:40:09 2006
@@ -73,6 +73,9 @@
}
}
+ 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 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 @@
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();
+ }
}
Added: ant/core/trunk/src/tests/antunit/core/nested-text-test.xml
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/core/nested-text-test.xml?view=auto&rev=448646
==============================================================================
--- ant/core/trunk/src/tests/antunit/core/nested-text-test.xml (added)
+++ ant/core/trunk/src/tests/antunit/core/nested-text-test.xml Thu Sep 21
12:40:09 2006
@@ -0,0 +1,13 @@
+<project xmlns:au="antlib:org.apache.ant.antunit">
+
+ <target name="testAcceptNested">
+ <echo>foo</echo>
+ </target>
+
+ <target name="testRejectNested">
+ <typedef name="object" classname="java.lang.Object" />
+ <au:expectfailure expectedMessage="The <object> type doesn't support
nested text data ("foo").">
+ <object>foo</object>
+ </au:expectfailure>
+ </target>
+</project>
Propchange: ant/core/trunk/src/tests/antunit/core/nested-text-test.xml
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]