From 4b343f551b61a3ae3e743a9cfc6777e261b6fc07 Mon Sep 17 00:00:00 2001 From: Matthew Jason Benson Date: Fri, 15 Apr 2005 20:25:36 +0000 Subject: [PATCH] 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 --- WHATSNEW | 2 + src/etc/testcases/types/redirector.xml | 19 +++++ .../tools/ant/types/RedirectorElement.java | 78 ++++++++++++++++++- .../ant/types/RedirectorElementTest.java | 5 ++ 4 files changed, 100 insertions(+), 4 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 965866914..c416a9e20 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -480,6 +480,8 @@ Fixed bugs: * forkmode="perBatch" or "once" would ignore extension attributes that had been specified for 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 =================================== diff --git a/src/etc/testcases/types/redirector.xml b/src/etc/testcases/types/redirector.xml index 1bcebaaf9..1b3d11098 100755 --- a/src/etc/testcases/types/redirector.xml +++ b/src/etc/testcases/types/redirector.xml @@ -30,6 +30,25 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/main/org/apache/tools/ant/types/RedirectorElement.java b/src/main/org/apache/tools/ant/types/RedirectorElement.java index 4544e8b7e..39ce1b45a 100755 --- a/src/main/org/apache/tools/ant/types/RedirectorElement.java +++ b/src/main/org/apache/tools/ant/types/RedirectorElement.java @@ -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 @@ public class RedirectorElement extends DataType { if (isReference()) { throw tooManyAttributes(); } - //pre JDK 1.4 compatible this.logError = ((logError) ? Boolean.TRUE : Boolean.FALSE); } @@ -329,7 +331,6 @@ public class RedirectorElement extends DataType { if (isReference()) { throw tooManyAttributes(); } - //pre JDK 1.4 compatible this.append = ((append) ? Boolean.TRUE : Boolean.FALSE); } @@ -344,7 +345,6 @@ public class RedirectorElement extends DataType { if (isReference()) { throw tooManyAttributes(); } - //pre JDK 1.4 compatible this.alwaysLog = ((alwaysLog) ? Boolean.TRUE : Boolean.FALSE); } @@ -357,7 +357,6 @@ public class RedirectorElement extends DataType { if (isReference()) { throw tooManyAttributes(); } - //pre JDK 1.4 compatible this.createEmptyFiles = ((createEmptyFiles) ? Boolean.TRUE : Boolean.FALSE); } @@ -432,6 +431,10 @@ public class RedirectorElement extends DataType { * @param sourcefile String. */ 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 @@ public class RedirectorElement extends DataType { 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; + } + } diff --git a/src/testcases/org/apache/tools/ant/types/RedirectorElementTest.java b/src/testcases/org/apache/tools/ant/types/RedirectorElementTest.java index 7b5b01f43..e81cd42a4 100755 --- a/src/testcases/org/apache/tools/ant/types/RedirectorElementTest.java +++ b/src/testcases/org/apache/tools/ant/types/RedirectorElementTest.java @@ -55,4 +55,9 @@ public class RedirectorElementTest extends BuildFileTest { assertDebuglogContaining("Using input string"); } } + + public void testRefid() { + executeTarget("testRefid"); + } + }