mbenson 2005/04/15 13:52:53
Modified: . Tag: ANT_16_BRANCH WHATSNEW
src/etc/testcases/types Tag: ANT_16_BRANCH redirector.xml
src/testcases/org/apache/tools/ant/types Tag: ANT_16_BRANCH
RedirectorElementTest.java
src/main/org/apache/tools/ant/types Tag: ANT_16_BRANCH
RedirectorElement.java
Log:
Merge <redirector refid="" /> fix.
Revision Changes Path
No revision
No revision
1.503.2.215 +2 -0 ant/WHATSNEW
Index: WHATSNEW
===================================================================
RCS file: /home/cvs/ant/WHATSNEW,v
retrieving revision 1.503.2.214
retrieving revision 1.503.2.215
diff -u -r1.503.2.214 -r1.503.2.215
--- WHATSNEW 11 Apr 2005 09:31:15 -0000 1.503.2.214
+++ WHATSNEW 15 Apr 2005 20:52:52 -0000 1.503.2.215
@@ -310,6 +310,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
===================================
No revision
No revision
1.1.2.2 +50 -20 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.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- redirector.xml 23 Jun 2004 19:30:14 -0000 1.1.2.1
+++ redirector.xml 15 Apr 2005 20:52:53 -0000 1.1.2.2
@@ -1,24 +1,54 @@
-<!-- Copyright 2004 The Apache Software Foundation. -->
+<!-- Copyright 2004-2005 The Apache Software Foundation. -->
<project name="redirector" basedir=".">
- <target name="test1" description="create ref">
- <redirector id="test1" output="out" />
- </target>
-
- <target name="test2" depends="test1" description="fail">
- <redirector refid="test1" output="out" />
- </target>
-
- <target name="test3" depends="test1" description="fail">
- <redirector refid="test1">
- <outputmapper type="flatten" />
- </redirector>
- </target>
-
- <target name="test4" depends="test1" description="pass">
- <redirector>
- <outputmapper type="flatten" />
- </redirector>
- </target>
+ <target name="test1" description="create ref">
+ <redirector id="test1" output="out" />
+ </target>
+
+ <target name="test2" depends="test1" description="fail">
+ <redirector refid="test1" output="out" />
+ </target>
+
+ <target name="test3" depends="test1" description="fail">
+ <redirector refid="test1">
+ <outputmapper type="flatten" />
+ </redirector>
+ </target>
+
+ <target name="test4" depends="test1" description="pass">
+ <redirector>
+ <outputmapper type="flatten" />
+ </redirector>
+ </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">
+ <or>
+ <available file="cat" filepath="${env.PATH}" property="can-cat" />
+ <available file="cat.exe" filepath="${env.PATH}" property="can-cat"
/>
+ <available file="cat.exe" filepath="${env.Path}" property="can-cat"
/>
+ </or>
+ </condition>
+ </target>
</project>
No revision
No revision
1.1.2.2 +7 -2
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.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- RedirectorElementTest.java 23 Jun 2004 19:30:14 -0000 1.1.2.1
+++ RedirectorElementTest.java 15 Apr 2005 20:52:53 -0000 1.1.2.2
@@ -1,5 +1,5 @@
/*
- * Copyright 2004 The Apache Software Foundation.
+ * Copyright 2004-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
*/
package org.apache.tools.ant.types;
+import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildFileTest;
public class RedirectorElementTest extends BuildFileTest {
@@ -25,7 +26,7 @@
}
public void setUp() {
- configureProject("src/etc/testcases/types/redirector.xml");
+ configureProject("src/etc/testcases/types/redirector.xml",
Project.MSG_VERBOSE);
}
public void test1() {
@@ -48,4 +49,8 @@
executeTarget("test4");
}
+ public void testRefid() {
+ executeTarget("testRefid");
+ }
+
}
No revision
No revision
1.2.2.3 +79 -11
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.2.2.2
retrieving revision 1.2.2.3
diff -u -r1.2.2.2 -r1.2.2.3
--- RedirectorElement.java 24 Sep 2004 22:29:09 -0000 1.2.2.2
+++ RedirectorElement.java 15 Apr 2005 20:52:53 -0000 1.2.2.3
@@ -1,5 +1,5 @@
/*
- * Copyright 2004 The Apache Software Foundation.
+ * Copyright 2004-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,14 +17,14 @@
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.Task;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.Redirector;
-import org.apache.tools.ant.types.DataType;
/**
* Element representation of a <CODE>Redirector</CODE>.
@@ -108,7 +108,7 @@
}
if (this.inputMapper != null) {
if (usingInput) {
- throw new BuildException("attribute \"input\""
+ throw new BuildException("attribute \"input\""
+ " cannot coexist with a nested <inputmapper>");
} else {
throw new BuildException("Cannot have > 1 <inputmapper>");
@@ -146,7 +146,7 @@
}
if (this.errorMapper != null) {
if (usingError) {
- throw new BuildException("attribute \"error\""
+ throw new BuildException("attribute \"error\""
+ " cannot coexist with a nested <errormapper>");
} else {
throw new BuildException("Cannot have > 1 <errormapper>");
@@ -160,6 +160,8 @@
*
* <p>You must not set another attribute or nest elements inside
* this element if you make it a reference.</p>
+ * @param r the reference to use
+ * @throws BuildException on error
*/
public void setRefid(Reference r) throws BuildException {
if (usingInput
@@ -210,7 +212,6 @@
this.inputString = inputString;
}
-
/**
* File the output of the process is redirected to. If error is not
* redirected, it too will appear in the output
@@ -273,7 +274,6 @@
if (isReference()) {
throw tooManyAttributes();
}
- //pre JDK 1.4 compatible
this.logError = ((logError) ? Boolean.TRUE : Boolean.FALSE);
}
@@ -315,7 +315,6 @@
if (isReference()) {
throw tooManyAttributes();
}
- //pre JDK 1.4 compatible
this.append = ((append) ? Boolean.TRUE : Boolean.FALSE);
}
@@ -330,7 +329,6 @@
if (isReference()) {
throw tooManyAttributes();
}
- //pre JDK 1.4 compatible
this.alwaysLog = ((alwaysLog) ? Boolean.TRUE : Boolean.FALSE);
}
@@ -343,7 +341,6 @@
if (isReference()) {
throw tooManyAttributes();
}
- //pre JDK 1.4 compatible
this.createEmptyFiles = ((createEmptyFiles)
? Boolean.TRUE : Boolean.FALSE);
}
@@ -418,6 +415,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());
}
@@ -530,7 +531,74 @@
list.add(getProject().resolveFile(name[i]));
}
}
- return (File[])(list.toArray(new File[list.size()]));
+ 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;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]