mbenson 2005/04/15 13:25:36
Modified: . WHATSNEW
src/main/org/apache/tools/ant/types RedirectorElement.java
src/etc/testcases/types redirector.xml
src/testcases/org/apache/tools/ant/types
RedirectorElementTest.java
Log:
The refid attribute of the I/O redirector was not functional.
Revision Changes Path
1.805 +2 -0 ant/WHATSNEW
Index: WHATSNEW
===================================================================
RCS file: /home/cvs/ant/WHATSNEW,v
retrieving revision 1.804
retrieving revision 1.805
diff -u -r1.804 -r1.805
--- WHATSNEW 12 Apr 2005 17:19:41 -0000 1.804
+++ WHATSNEW 15 Apr 2005 20:25:36 -0000 1.805
@@ -480,6 +480,8 @@
* forkmode="perBatch" or "once" would ignore extension attributes that
had been specified for <formatter>s. Bugzilla Report 32973.
+* The refid attribute of the I/O redirector was not functional.
+
Changes from Ant 1.6.1 to Ant 1.6.2
===================================
1.7 +74 -4
ant/src/main/org/apache/tools/ant/types/RedirectorElement.java
Index: RedirectorElement.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/types/RedirectorElement.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- RedirectorElement.java 14 Mar 2005 17:47:01 -0000 1.6
+++ RedirectorElement.java 15 Apr 2005 20:25:36 -0000 1.7
@@ -17,9 +17,12 @@
package org.apache.tools.ant.types;
import java.io.File;
+import java.util.Stack;
import java.util.Vector;
+import java.util.Iterator;
import java.util.ArrayList;
+import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.Redirector;
@@ -287,7 +290,6 @@
if (isReference()) {
throw tooManyAttributes();
}
- //pre JDK 1.4 compatible
this.logError = ((logError) ? Boolean.TRUE : Boolean.FALSE);
}
@@ -329,7 +331,6 @@
if (isReference()) {
throw tooManyAttributes();
}
- //pre JDK 1.4 compatible
this.append = ((append) ? Boolean.TRUE : Boolean.FALSE);
}
@@ -344,7 +345,6 @@
if (isReference()) {
throw tooManyAttributes();
}
- //pre JDK 1.4 compatible
this.alwaysLog = ((alwaysLog) ? Boolean.TRUE : Boolean.FALSE);
}
@@ -357,7 +357,6 @@
if (isReference()) {
throw tooManyAttributes();
}
- //pre JDK 1.4 compatible
this.createEmptyFiles = ((createEmptyFiles)
? Boolean.TRUE : Boolean.FALSE);
}
@@ -432,6 +431,10 @@
* @param sourcefile <CODE>String</CODE>.
*/
public void configure(Redirector redirector, String sourcefile) {
+ if (isReference()) {
+ getRef().configure(redirector, sourcefile);
+ return;
+ }
if (alwaysLog != null) {
redirector.setAlwaysLog(alwaysLog.booleanValue());
}
@@ -550,4 +553,71 @@
return (File[]) (list.toArray(new File[list.size()]));
}
+ /**
+ * Convenience method.
+ * @throws BuildException on error.
+ */
+ protected void dieOnCircularReference() throws BuildException {
+ if (isChecked()) {
+ return;
+ }
+ Stack s = new Stack();
+ s.push(this);
+ dieOnCircularReference(s, getProject());
+ }
+
+ /**
+ * Overrides the version of DataType to recurse on all DataType
+ * child elements that may have been added.
+ * @param stk the stack of data types to use (recursively).
+ * @param p the project to use to dereference the references.
+ * @throws BuildException on error.
+ */
+ protected void dieOnCircularReference(Stack stk, Project p)
+ throws BuildException {
+ if (isChecked()) {
+ return;
+ }
+ if (isReference()) {
+ super.dieOnCircularReference(stk, p);
+ } else {
+ Mapper[] m = new Mapper[] {inputMapper, outputMapper,
errorMapper};
+ for (int i = 0; i < m.length; i++) {
+ if (m[i] != null) {
+ stk.push(m[i]);
+ m[i].dieOnCircularReference(stk, p);
+ stk.pop();
+ }
+ }
+ Vector[] v = new Vector[]
+ {inputFilterChains, outputFilterChains, errorFilterChains};
+ for (int i = 0; i < v.length; i++) {
+ if (v[i] != null) {
+ for (Iterator fci = v[i].iterator(); fci.hasNext();) {
+ FilterChain fc = (FilterChain) fci.next();
+ stk.push(fc);
+ fc.dieOnCircularReference(stk, p);
+ stk.pop();
+ }
+ }
+ }
+ setChecked(true);
+ }
+ }
+
+ /**
+ * Perform the check for circular references, returning the
+ * referenced RedirectorElement
+ * @return the referenced RedirectorElement.
+ */
+ private RedirectorElement getRef() {
+ dieOnCircularReference();
+ Object o = getRefid().getReferencedObject(getProject());
+ if (!(o instanceof RedirectorElement)) {
+ throw new BuildException(getRefid().getRefId()
+ + " doesn\'t denote a RedirectorElement");
+ }
+ return (RedirectorElement) o;
+ }
+
}
1.5 +19 -0 ant/src/etc/testcases/types/redirector.xml
Index: redirector.xml
===================================================================
RCS file: /home/cvs/ant/src/etc/testcases/types/redirector.xml,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- redirector.xml 26 Feb 2005 21:03:44 -0000 1.4
+++ redirector.xml 15 Apr 2005 20:25:36 -0000 1.5
@@ -30,6 +30,25 @@
</exec>
</target>
+ <target name="testRefid" depends="cat-check" if="can-cat">
+ <fail message="Property testRefid.out is already set!">
+ <condition>
+ <isset property="testRefid.out" />
+ </condition>
+ </fail>
+ <redirector id="r" outputproperty="testRefid.out" inputstring="foo" />
+ <exec executable="cat">
+ <redirector refid="r" />
+ </exec>
+ <fail>
+ <condition>
+ <not>
+ <equals arg1="${testRefid.out}" arg2="foo" />
+ </not>
+ </condition>
+ </fail>
+ </target>
+
<target name="cat-check">
<property environment="env" />
<condition property="can-cat">
1.4 +5 -0
ant/src/testcases/org/apache/tools/ant/types/RedirectorElementTest.java
Index: RedirectorElementTest.java
===================================================================
RCS file:
/home/cvs/ant/src/testcases/org/apache/tools/ant/types/RedirectorElementTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- RedirectorElementTest.java 26 Feb 2005 21:03:44 -0000 1.3
+++ RedirectorElementTest.java 15 Apr 2005 20:25:36 -0000 1.4
@@ -55,4 +55,9 @@
assertDebuglogContaining("Using input string");
}
}
+
+ public void testRefid() {
+ executeTarget("testRefid");
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]