|
|
@@ -1547,8 +1547,116 @@ This may be used as follows: |
|
|
|
|
|
|
|
|
|
|
|
<h3><a name="sortfilter">SortFilter</a></h3> |
|
|
|
<p><strong>(documentation pending)</strong></p> |
|
|
|
<p><em>since Ant 1.8.0</em></p> |
|
|
|
|
|
|
|
<p>The sort filter reads all lines and sorts them. The sort order can |
|
|
|
be reversed and it is possible to specify a custom implementation of |
|
|
|
the <code>java.util.Comparator</code> interface to get even more |
|
|
|
control.</p> |
|
|
|
|
|
|
|
<table cellSpacing=0 cellPadding=2 border=1> |
|
|
|
<tr> |
|
|
|
<td vAlign=top><b>Parameter Name</b></td> |
|
|
|
<td vAlign=top><b>Parameter Value</b></td> |
|
|
|
<td vAlign=top align="center"><b>Required</b></td> |
|
|
|
</tr> |
|
|
|
<tr> |
|
|
|
<td vAlign=top>reverse</td> |
|
|
|
<td vAlign=top align="center">whether to reverse the sort order, |
|
|
|
defaults to false. <b>Note:</b> this parameter is ignored if |
|
|
|
the comparator parameter is present as well.</td> |
|
|
|
<td vAlign=top align="center">No</td> |
|
|
|
</tr> |
|
|
|
<tr> |
|
|
|
<td vAlign=top>comparator</td> |
|
|
|
<td vAlign=top align="center">Class name of a class that |
|
|
|
implements <code>java.util.Comparator</code> for Strings. This |
|
|
|
class will be used to determine the sort order of lines.</td> |
|
|
|
<td vAlign=top align="center">No</td> |
|
|
|
</tr> |
|
|
|
</table> |
|
|
|
|
|
|
|
<p>This filter is also available using the |
|
|
|
name <code>sortfilter</code>. The <code>reverse</code> parameter |
|
|
|
becomes an attribute, <code>comparator</code> can be specified by |
|
|
|
using a nested element.</p> |
|
|
|
|
|
|
|
<h4>Examples:</h4> |
|
|
|
|
|
|
|
<blockquote><pre> |
|
|
|
<copy todir="build"> |
|
|
|
<fileset dir="input" includes="*.txt"/> |
|
|
|
<filterchain> |
|
|
|
<sortfilter/> |
|
|
|
</filterchain> |
|
|
|
</copy> |
|
|
|
</pre></blockquote> |
|
|
|
|
|
|
|
<p> |
|
|
|
Sort all files <code>*.txt</code> from <i>src</i> location |
|
|
|
into <i>build</i> location. The lines of each file are sorted in |
|
|
|
ascendant order comparing the lines via the |
|
|
|
<code>String.compareTo(Object o)</code> method. |
|
|
|
</p> |
|
|
|
|
|
|
|
<blockquote><pre> |
|
|
|
<copy todir="build"> |
|
|
|
<fileset dir="input" includes="*.txt"/> |
|
|
|
<filterchain> |
|
|
|
<sortfilter reverse="true"/> |
|
|
|
</filterchain> |
|
|
|
</copy> |
|
|
|
</pre></blockquote> |
|
|
|
|
|
|
|
<p> |
|
|
|
Sort all files <code>*.txt</code> from <i>src</i> location into reverse |
|
|
|
order and copy them into <i>build</i> location. |
|
|
|
</p> |
|
|
|
|
|
|
|
<blockquote><pre> |
|
|
|
<copy todir="build"> |
|
|
|
<fileset dir="input" includes="*.txt"/> |
|
|
|
<filterchain> |
|
|
|
<filterreader classname="org.apache.tools.ant.filters.SortFilter"> |
|
|
|
<param name="comparator" value="org.apache.tools.ant.filters.EvenFirstCmp"/> |
|
|
|
</filterreader/> |
|
|
|
</filterchain> |
|
|
|
</copy> |
|
|
|
</pre></blockquote> |
|
|
|
|
|
|
|
<p> |
|
|
|
Sort all files <code>*.txt</code> from <i>src</i> location using as |
|
|
|
sorting criterium <code>EvenFirstCmp</code> class, that sorts the file |
|
|
|
lines putting even lines first then odd lines for example. The modified files |
|
|
|
are copied into <i>build</i> location. The <code>EventFirstCmp</code>, |
|
|
|
has to an instanciable class via <code>Class.newInstance()</code>, |
|
|
|
therefore in case of inner class has to be <em>static</em>. It also has to |
|
|
|
implement <code>java.util.Comparator</code> interface, for example: |
|
|
|
</p> |
|
|
|
|
|
|
|
<pre> |
|
|
|
package org.apache.tools.ant.filters; |
|
|
|
...(omitted) |
|
|
|
public final class EvenFirstCmp implements <b>Comparator</b> { |
|
|
|
public int compare(Object o1, Object o2) { |
|
|
|
...(omitted) |
|
|
|
} |
|
|
|
} |
|
|
|
</pre> |
|
|
|
|
|
|
|
<p>The example above is equivalent to:</p> |
|
|
|
|
|
|
|
<blockquote><pre> |
|
|
|
<componentdef name="evenfirst" |
|
|
|
classname="org.apache.tools.ant.filters.EvenFirstCmp"/> |
|
|
|
<copy todir="build"> |
|
|
|
<fileset dir="input" includes="*.txt"/> |
|
|
|
<filterchain> |
|
|
|
<sortfilter> |
|
|
|
<evenfirst/> |
|
|
|
</sortfilter/> |
|
|
|
</filterchain> |
|
|
|
</copy> |
|
|
|
</pre></blockquote> |
|
|
|
|
|
|
|
</body></html> |