Browse Source

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
master
Matthew Jason Benson 18 years ago
parent
commit
996bb8c9ce
2 changed files with 28 additions and 2 deletions
  1. +15
    -2
      src/main/org/apache/tools/ant/IntrospectionHelper.java
  2. +13
    -0
      src/tests/antunit/core/nested-text-test.xml

+ 15
- 2
src/main/org/apache/tools/ant/IntrospectionHelper.java View File

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

+ 13
- 0
src/tests/antunit/core/nested-text-test.xml View File

@@ -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 &lt;object&gt; type doesn't support nested text data (&quot;foo&quot;).">
<object>foo</object>
</au:expectfailure>
</target>
</project>

Loading…
Cancel
Save