Browse Source

as discussed on dev@, allow <mapper refid> to refer to a FileNameMapper

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@495014 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 18 years ago
parent
commit
14770e40d5
3 changed files with 54 additions and 1 deletions
  1. +2
    -0
      WHATSNEW
  2. +14
    -1
      src/main/org/apache/tools/ant/types/Mapper.java
  3. +38
    -0
      src/tests/antunit/types/mapper-ref.xml

+ 2
- 0
WHATSNEW View File

@@ -55,6 +55,8 @@ Other changes:
* 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
===================================



+ 14
- 1
src/main/org/apache/tools/ant/types/Mapper.java View File

@@ -198,7 +198,18 @@ public class Mapper extends DataType implements Cloneable {
*/
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 @@ public class Mapper extends DataType implements Cloneable {
/**
* 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() {


+ 38
- 0
src/tests/antunit/types/mapper-ref.xml View File

@@ -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>

Loading…
Cancel
Save