Author: mbenson Date: Wed Jan 10 14:34:45 2007 New Revision: 495014 URL: http://svn.apache.org/viewvc?view=rev&rev=495014 Log: as discussed on dev@, allow <mapper refid> to refer to a FileNameMapper
Added: ant/core/trunk/src/tests/antunit/types/mapper-ref.xml (with props) Modified: ant/core/trunk/WHATSNEW ant/core/trunk/src/main/org/apache/tools/ant/types/Mapper.java Modified: ant/core/trunk/WHATSNEW URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?view=diff&rev=495014&r1=495013&r2=495014 ============================================================================== --- ant/core/trunk/WHATSNEW (original) +++ ant/core/trunk/WHATSNEW Wed Jan 10 14:34:45 2007 @@ -55,6 +55,8 @@ * Show Previous Revision in the tagdiff.xsl stylesheet Bugzilla 29143 +* Allow <mapper refid> to refer directly to a FileNameMapper instance. + Changes from Ant 1.6.5 to Ant 1.7.0 =================================== Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/Mapper.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/Mapper.java?view=diff&rev=495014&r1=495013&r2=495014 ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/types/Mapper.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/types/Mapper.java Wed Jan 10 14:34:45 2007 @@ -198,7 +198,18 @@ */ public FileNameMapper getImplementation() throws BuildException { if (isReference()) { - return getRef().getImplementation(); + dieOnCircularReference(); + Reference r = getRefid(); + Object o = r.getReferencedObject(getProject()); + if (o instanceof FileNameMapper) { + return (FileNameMapper) o; + } + if (o instanceof Mapper) { + return ((Mapper) o).getImplementation(); + } + String od = o == null ? "null" : o.getClass().getName(); + throw new BuildException(od + " at reference '" + + r.getRefId() + "' is not a valid mapper reference."); } if (type == null && classname == null && container == null) { @@ -256,6 +267,8 @@ /** * Performs the check for circular references and returns the * referenced Mapper. + * @deprecated since Ant 1.7.1 because a mapper might ref a + * FileNameMapper implementation directly. * @return the referenced Mapper */ protected Mapper getRef() { Added: ant/core/trunk/src/tests/antunit/types/mapper-ref.xml URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/types/mapper-ref.xml?view=auto&rev=495014 ============================================================================== --- ant/core/trunk/src/tests/antunit/types/mapper-ref.xml (added) +++ ant/core/trunk/src/tests/antunit/types/mapper-ref.xml Wed Jan 10 14:34:45 2007 @@ -0,0 +1,38 @@ +<!-- does not address/replace the circular reference checks, etc. + in MapperTest.java (yet). + --> + +<project xmlns:au="antlib:org.apache.ant.antunit"> + <macrodef name="test"> + <sequential> + <pathconvert property="dest"> + <string value="foo" /> + <mapper refid="mapper" /> + </pathconvert> + <au:assertTrue> + <equals arg1="${dest}" arg2="bar" /> + </au:assertTrue> + </sequential> + </macrodef> + + <target name="testBasic" description="success"> + <mapper id="mapper" type="merge" to="bar" /> + <test /> + </target> + + <target name="testFileNameMapper" description="success"> + <mergemapper id="mapper" to="bar" /> + <test /> + </target> + + <target name="testWrongType" description="failure"> + <path id="mapper" path="whocares" /> + <au:expectfailure + expectedMessage="org.apache.tools.ant.types.Path at reference 'mapper' is not a valid mapper reference."> + <test /> + </au:expectfailure> + </target> + + <target name="all" depends="testBasic,testFileNameMapper,testWrongType" /> + +</project> Propchange: ant/core/trunk/src/tests/antunit/types/mapper-ref.xml ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]