Browse Source

make order of compositemapper's results predictable. PR 44873.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@699263 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
36786a3b76
3 changed files with 15 additions and 2 deletions
  1. +3
    -0
      WHATSNEW
  2. +3
    -0
      docs/manual/CoreTypes/mapper.html
  3. +9
    -2
      src/main/org/apache/tools/ant/util/CompositeMapper.java

+ 3
- 0
WHATSNEW View File

@@ -382,6 +382,9 @@ Other changes:
<signjar>. <signjar>.
Bugzilla Report 39189. Bugzilla Report 39189.


* <compositemapper>'s order of results is now predictable.
Bugzilla Report 44873

Changes from Ant 1.7.0 TO Ant 1.7.1 Changes from Ant 1.7.0 TO Ant 1.7.1
============================================= =============================================




+ 3
- 0
docs/manual/CoreTypes/mapper.html View File

@@ -629,6 +629,9 @@ with <code>&lt;uptodate&gt;</code> and <code>&lt;junit&gt;</code> output.</p>
File mapping is performed by passing the source filename to each nested File mapping is performed by passing the source filename to each nested
<code>&lt;mapper&gt;</code> in turn, returning all results. <code>&lt;mapper&gt;</code> in turn, returning all results.
The <i>to</i> and <i>from</i> attributes are ignored.</p> The <i>to</i> and <i>from</i> attributes are ignored.</p>
<p>Starting with Ant 1.8.0 the order of the mapped results is the
same as the order of the nested mappers; prior to Ant 1.8.0 the
order has been undefined.</p>
<b>Examples:</b> <b>Examples:</b>
<blockquote><pre> <blockquote><pre>
&lt;compositemapper&gt; &lt;compositemapper&gt;


+ 9
- 2
src/main/org/apache/tools/ant/util/CompositeMapper.java View File

@@ -20,6 +20,7 @@ package org.apache.tools.ant.util;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;


/** /**
* A <CODE>ContainerMapper</CODE> that unites the results of its constituent * A <CODE>ContainerMapper</CODE> that unites the results of its constituent
@@ -30,6 +31,7 @@ public class CompositeMapper extends ContainerMapper {
/** {@inheritDoc}. */ /** {@inheritDoc}. */
public String[] mapFileName(String sourceFileName) { public String[] mapFileName(String sourceFileName) {
HashSet results = new HashSet(); HashSet results = new HashSet();
LinkedList sortedResults = new LinkedList();


FileNameMapper mapper = null; FileNameMapper mapper = null;
for (Iterator mIter = getMappers().iterator(); mIter.hasNext();) { for (Iterator mIter = getMappers().iterator(); mIter.hasNext();) {
@@ -37,12 +39,17 @@ public class CompositeMapper extends ContainerMapper {
if (mapper != null) { if (mapper != null) {
String[] mapped = mapper.mapFileName(sourceFileName); String[] mapped = mapper.mapFileName(sourceFileName);
if (mapped != null) { if (mapped != null) {
results.addAll(Arrays.asList(mapped));
for (int i = 0; i < mapped.length; i++) {
if (!results.contains(mapped[i])) {
results.add(mapped[i]);
sortedResults.addLast(mapped[i]);
}
}
} }
} }
} }
return (results.size() == 0) ? null return (results.size() == 0) ? null
: (String[]) results.toArray(new String[results.size()]);
: (String[]) sortedResults.toArray(new String[results.size()]);
} }


} }


Loading…
Cancel
Save