Browse Source

The refid attribute of the I/O redirector was not functional.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278141 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 20 years ago
parent
commit
4b343f551b
4 changed files with 100 additions and 4 deletions
  1. +2
    -0
      WHATSNEW
  2. +19
    -0
      src/etc/testcases/types/redirector.xml
  3. +74
    -4
      src/main/org/apache/tools/ant/types/RedirectorElement.java
  4. +5
    -0
      src/testcases/org/apache/tools/ant/types/RedirectorElementTest.java

+ 2
- 0
WHATSNEW View File

@@ -480,6 +480,8 @@ Fixed bugs:
* forkmode="perBatch" or "once" would ignore extension attributes that * forkmode="perBatch" or "once" would ignore extension attributes that
had been specified for <formatter>s. Bugzilla Report 32973. 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 Changes from Ant 1.6.1 to Ant 1.6.2
=================================== ===================================




+ 19
- 0
src/etc/testcases/types/redirector.xml View File

@@ -30,6 +30,25 @@
</exec> </exec>
</target> </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"> <target name="cat-check">
<property environment="env" /> <property environment="env" />
<condition property="can-cat"> <condition property="can-cat">


+ 74
- 4
src/main/org/apache/tools/ant/types/RedirectorElement.java View File

@@ -17,9 +17,12 @@
package org.apache.tools.ant.types; package org.apache.tools.ant.types;


import java.io.File; import java.io.File;
import java.util.Stack;
import java.util.Vector; import java.util.Vector;
import java.util.Iterator;
import java.util.ArrayList; import java.util.ArrayList;


import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.Redirector; import org.apache.tools.ant.taskdefs.Redirector;


@@ -287,7 +290,6 @@ public class RedirectorElement extends DataType {
if (isReference()) { if (isReference()) {
throw tooManyAttributes(); throw tooManyAttributes();
} }
//pre JDK 1.4 compatible
this.logError = ((logError) ? Boolean.TRUE : Boolean.FALSE); this.logError = ((logError) ? Boolean.TRUE : Boolean.FALSE);
} }


@@ -329,7 +331,6 @@ public class RedirectorElement extends DataType {
if (isReference()) { if (isReference()) {
throw tooManyAttributes(); throw tooManyAttributes();
} }
//pre JDK 1.4 compatible
this.append = ((append) ? Boolean.TRUE : Boolean.FALSE); this.append = ((append) ? Boolean.TRUE : Boolean.FALSE);
} }


@@ -344,7 +345,6 @@ public class RedirectorElement extends DataType {
if (isReference()) { if (isReference()) {
throw tooManyAttributes(); throw tooManyAttributes();
} }
//pre JDK 1.4 compatible
this.alwaysLog = ((alwaysLog) ? Boolean.TRUE : Boolean.FALSE); this.alwaysLog = ((alwaysLog) ? Boolean.TRUE : Boolean.FALSE);
} }


@@ -357,7 +357,6 @@ public class RedirectorElement extends DataType {
if (isReference()) { if (isReference()) {
throw tooManyAttributes(); throw tooManyAttributes();
} }
//pre JDK 1.4 compatible
this.createEmptyFiles = ((createEmptyFiles) this.createEmptyFiles = ((createEmptyFiles)
? Boolean.TRUE : Boolean.FALSE); ? Boolean.TRUE : Boolean.FALSE);
} }
@@ -432,6 +431,10 @@ public class RedirectorElement extends DataType {
* @param sourcefile <CODE>String</CODE>. * @param sourcefile <CODE>String</CODE>.
*/ */
public void configure(Redirector redirector, String sourcefile) { public void configure(Redirector redirector, String sourcefile) {
if (isReference()) {
getRef().configure(redirector, sourcefile);
return;
}
if (alwaysLog != null) { if (alwaysLog != null) {
redirector.setAlwaysLog(alwaysLog.booleanValue()); redirector.setAlwaysLog(alwaysLog.booleanValue());
} }
@@ -550,4 +553,71 @@ public class RedirectorElement extends DataType {
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;
}

} }

+ 5
- 0
src/testcases/org/apache/tools/ant/types/RedirectorElementTest.java View File

@@ -55,4 +55,9 @@ public class RedirectorElementTest extends BuildFileTest {
assertDebuglogContaining("Using input string"); assertDebuglogContaining("Using input string");
} }
} }

public void testRefid() {
executeTarget("testRefid");
}

} }

Loading…
Cancel
Save