diff --git a/docs/manual/CoreTypes/filterchain.html b/docs/manual/CoreTypes/filterchain.html index 7002362d0..f99550528 100644 --- a/docs/manual/CoreTypes/filterchain.html +++ b/docs/manual/CoreTypes/filterchain.html @@ -1547,8 +1547,116 @@ This may be used as follows:

SortFilter

-

(documentation pending)

since Ant 1.8.0

+

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 java.util.Comparator interface to get even more + control.

+ + + + + + + + + + + + + + + + + +
Parameter NameParameter ValueRequired
reversewhether to reverse the sort order, + defaults to false. Note: this parameter is ignored if + the comparator parameter is present as well.No
comparatorClass name of a class that + implements java.util.Comparator for Strings. This + class will be used to determine the sort order of lines.No
+ +

This filter is also available using the + name sortfilter. The reverse parameter + becomes an attribute, comparator can be specified by + using a nested element.

+ +

Examples:

+ +
+  <copy todir="build">
+      <fileset dir="input" includes="*.txt"/>
+      <filterchain>
+          <sortfilter/>
+      </filterchain>
+  </copy>
+
+ +

+Sort all files *.txt from src location +into build location. The lines of each file are sorted in +ascendant order comparing the lines via the +String.compareTo(Object o) method. +

+ +
+  <copy todir="build">
+      <fileset dir="input" includes="*.txt"/>
+      <filterchain>
+          <sortfilter reverse="true"/>
+      </filterchain>
+  </copy>
+
+ +

+Sort all files *.txt from src location into reverse +order and copy them into build location. +

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

+Sort all files *.txt from src location using as +sorting criterium EvenFirstCmp class, that sorts the file +lines putting even lines first then odd lines for example. The modified files +are copied into build location. The EventFirstCmp, +has to an instanciable class via Class.newInstance(), +therefore in case of inner class has to be static. It also has to +implement java.util.Comparator interface, for example: +

+ +
+        package org.apache.tools.ant.filters;
+        ...(omitted)
+          public final class EvenFirstCmp implements <b>Comparator</b> {
+            public int compare(Object o1, Object o2) {
+            ...(omitted)
+            }
+          }
+
+ +

The example above is equivalent to:

+ +
+  <componentdef name="evenfirst"
+                classname="org.apache.tools.ant.filters.EvenFirstCmp"/>
+  <copy todir="build">
+      <fileset dir="input" includes="*.txt"/>
+      <filterchain>
+          <sortfilter>
+              <evenfirst/>
+          </sortfilter/>
+      </filterchain>
+  </copy>
+
diff --git a/src/main/org/apache/tools/ant/filters/SortFilter.java b/src/main/org/apache/tools/ant/filters/SortFilter.java index d6ec1f8ac..bbac227f2 100644 --- a/src/main/org/apache/tools/ant/filters/SortFilter.java +++ b/src/main/org/apache/tools/ant/filters/SortFilter.java @@ -47,9 +47,9 @@ import org.apache.tools.ant.types.Parameter; * * *

- * Sort all files *.txt from src location in descendant - * order and copy them into build location. The lines of each file are - * sorted in ascendant order comparing the lines via the + * Sort all files *.txt from src location and copy + * them into build location. The lines of each file are sorted + * in ascendant order comparing the lines via the * String.compareTo(Object o) method. *

* @@ -57,9 +57,7 @@ import org.apache.tools.ant.types.Parameter; * <copy todir="build"> * <fileset dir="input" includes="*.txt"/> * <filterchain> - * <sortfilter/> - * <param name="reverse" value="true"/> - * </sortfilter/> + * <sortfilter reverse="true"/> * </filterchain> * </copy> * @@ -75,9 +73,9 @@ import org.apache.tools.ant.types.Parameter; * <copy todir="build"> * <fileset dir="input" includes="*.txt"/> * <filterchain> - * <sortfilter/> + * <filterreader classname="org.apache.tools.ant.filters.SortFilter"> * <param name="comparator" value="org.apache.tools.ant.filters.EvenFirstCmp"/> - * </sortfilter/> + * </filterreader/> * </filterchain> * </copy> * @@ -102,8 +100,23 @@ import org.apache.tools.ant.types.Parameter; * } * * + *

The example above is equivalent to:

+ * + *
+ *   <componentdef name="evenfirst"
+ *                 classname="org.apache.tools.ant.filters.EvenFirstCmp"/>
+ *   <copy todir="build">
+ *       <fileset dir="input" includes="*.txt"/>
+ *       <filterchain>
+ *           <sortfilter>
+ *               <evenfirst/>
+ *           </sortfilter/>
+ *       </filterchain>
+ *   </copy>
+ * 
+ * *

If parameter comparator is present, then - * reverse parameter will not taken into account.

+ * reverse parameter will not be taken into account.

* * @since Ant 1.8.0 */