Hi,

The included patch allows custom conditions.

Background:

Currently in ant one can implement custom mappers, selectors and
filters (see Java Development with Ant, chapter 20).
However there is no way to implement custom conditions. Also
the usage of the custom filters, mappers and selectors in build files
is not nice, in comparison to custom tasks and datatypes.

The idea of the patch is to allow the current custom datatypes to be
used as conditions (and mapper, filters and selectors). The classes
handling conditions, filters and selectors implement DynamicConfigurator
create the custom object from the datatype api.

The following examples are from the testsuite.
example: custom condition

<target name="custom-condition">

    <path id="testclasses">
      <pathelement location="../../../../build/testcases" />
      <pathelement path="${java.class.path}" />
    </path>

    <typedef
      name="custom_condition" 
      classname="org.apache.tools.ant.taskdefs.condition.CustomCondition"
      classpathref="testclasses"
    />
    <condition property="custom-condition-true">
      <custom_condition testvalue="true"/>
    </condition>
    <echo>${custom-condition-true}</echo>
  </target>

custom filter:

  <target name="test-custom-filter">
    <path id="testclasses">
      <pathelement location="../../../../build/testcases" />
      <pathelement path="${java.class.path}" />
    </path>
    
    <typedef
      name="custom_filter" 
      classname="org.apache.tools.ant.types.CustomFilter"
      classpathref="testclasses"
    />

    <delete file="dest_custom.txt"/>
    <copy file="custom_filter.txt" tofile="dest_custom.txt">
      <filterchain>
        <custom_filter replace="@" with="*"/>
      </filterchain>
    </copy>
  </target>

Mappers are done differently:
the datatype is used as an attribute.

  <target name="custom_mapper">
    <path id="testclasses">
      <pathelement location="../../../../build/testcases" />
      <pathelement path="${java.class.path}" />
    </path>
    
    <typedef
      name="custom_mapper" 
      classname="org.apache.tools.ant.types.CustomMapper"
      classpathref="testclasses"
    />
    <mkdir dir="customcopytest"/>
    <copy todir="customcopytest">
      <fileset dir="../../../main">
        <include name="**/taskdefs/*.java"/>
      </fileset>
      <mapper type="custom_mapper"/>
    </copy>
  </target>


---------------------

Changes to src/main/org/apache/tools/ant:

TaskAdapter.java:
    The setProject() method has been overridden to set the project on the
    proxied task. If this is not done, createDynamicElement in
    taskdefs/condition/ConditionBase is called before setProject.


taskdefs/condition/ConditionBase.java:
    Implements DynamicConfigurator.createDynamicElement(String name).
    this method creates the datatype (name), checks if it is a condition
    and addes it to the conditions.

types/FilterChain.java:
    same as ConditionBase

types/AbstractFileSet.java:
    same as ConditionBase.

types/Mapper.java:
    *** THIS IS A CHANGE TO THE CURRENT API *******
    The setType(MapperType type) method has been changed to
    setType(String type).
    ****************************************************
    The getImplementation() method has been modified to
    check if the name is a known mapper and if not to treat
    it as a datatype and use the getProject().createDataType()
    api call to create the mapper.


taskdefs/optional/RenameExtensions.java:
   This as been modified to use the Mapper.setType(String) method.


Changes to unit tests:

tests have been added to ensure that the mechanism works. Also
the mapper java test code has been changed to reflect the new
api.

Patch information:
The patch is against the current cvs (or a few hours ago) and
generated using:

diff -Naur ant ant-custom > custom-patch

The patch was then applied to a copy of ant (cvs source) 
and the unit tests were run.

I have made an entry in bugzilla - 17199.

I have tried to follow the ant task guidelines.
however.
 I do not have access to java1.1, the changes should work in that env.
 doc changes are not yet done
 the cvs diff -u command did not inclued added files (neither did
  cvs diff -Nu, cvs diff -u --new-file)
diff -Naur ant/src/etc/testcases/taskdefs/condition.xml ant-custom/src/etc/testcases/taskdefs/condition.xml
--- ant/src/etc/testcases/taskdefs/condition.xml	2002-06-01 13:26:36.000000000 +0100
+++ ant-custom/src/etc/testcases/taskdefs/condition.xml	2003-02-18 12:46:00.000000000 +0000
@@ -347,7 +347,25 @@
     </condition>
     <echo>${isfalse-incomplete}</echo>
   </target>
-  
+
+  <target name="custom-condition">
+
+    <path id="testclasses">
+      <pathelement location="../../../../build/testcases" />
+      <pathelement path="${java.class.path}" />
+    </path>
+
+    <typedef
+      name="custom_condition" 
+      classname="org.apache.tools.ant.taskdefs.condition.CustomCondition"
+      classpathref="testclasses"
+    />
+    <condition property="custom-condition-true">
+      <custom_condition testvalue="true"/>
+    </condition>
+    <echo>${custom-condition-true}</echo>
+  </target>
+
   <target name="cleanup" >
     <delete file="match1.txt" />
     <delete file="match2.txt" />
diff -Naur ant/src/etc/testcases/types/custom_filter.txt ant-custom/src/etc/testcases/types/custom_filter.txt
--- ant/src/etc/testcases/types/custom_filter.txt	1970-01-01 01:00:00.000000000 +0100
+++ ant-custom/src/etc/testcases/types/custom_filter.txt	2003-02-18 12:45:06.000000000 +0000
@@ -0,0 +1,2 @@
+This is a test file for filters @aaaa@
+It has two lines @bbbb@
diff -Naur ant/src/etc/testcases/types/fileset.xml ant-custom/src/etc/testcases/types/fileset.xml
--- ant/src/etc/testcases/types/fileset.xml	1970-01-01 01:00:00.000000000 +0100
+++ ant-custom/src/etc/testcases/types/fileset.xml	2003-02-18 14:17:03.000000000 +0000
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+
+<project name="custom-selector-test" basedir="." default="custom-selector">
+
+  <target name="custom-selector">
+    <path id="testclasses">
+      <pathelement location="../../../../build/testcases" />
+      <pathelement path="${java.class.path}" />
+    </path>
+    
+    <typedef
+      name="custom_selector" 
+      classname="org.apache.tools.ant.types.CustomSelector"
+      classpathref="testclasses"
+    />
+    <delete dir="customselectortest"/>
+    <mkdir dir="customselectortest"/>
+    <copy todir="customselectortest">
+      <fileset dir="../../../main">
+        <include name="**/taskdefs/*.java"/>
+        <custom_selector name="**/An*"/>
+      </fileset>
+    </copy>
+  </target>
+
+  <target name="cleanup">
+  </target>
+
+</project>
diff -Naur ant/src/etc/testcases/types/filterset_custom.txt ant-custom/src/etc/testcases/types/filterset_custom.txt
--- ant/src/etc/testcases/types/filterset_custom.txt	1970-01-01 01:00:00.000000000 +0100
+++ ant-custom/src/etc/testcases/types/filterset_custom.txt	2003-02-18 12:27:41.000000000 +0000
@@ -0,0 +1,2 @@
+This is a test file for filters @aaaa@
+It has two lines @bbbb@
diff -Naur ant/src/etc/testcases/types/filterset.xml ant-custom/src/etc/testcases/types/filterset.xml
--- ant/src/etc/testcases/types/filterset.xml	2002-09-27 10:30:37.000000000 +0100
+++ ant-custom/src/etc/testcases/types/filterset.xml	2003-02-18 12:44:26.000000000 +0000
@@ -48,10 +48,32 @@
     </filterset>
   </target>
 
+  <target name="test-custom-filter">
+    <path id="testclasses">
+      <pathelement location="../../../../build/testcases" />
+      <pathelement path="${java.class.path}" />
+    </path>
+    
+    <typedef
+      name="custom_filter" 
+      classname="org.apache.tools.ant.types.CustomFilter"
+      classpathref="testclasses"
+    />
+
+    <delete file="dest_custom.txt"/>
+    <copy file="custom_filter.txt" tofile="dest_custom.txt">
+      <filterchain>
+        <custom_filter replace="@" with="*"/>
+      </filterchain>
+    </copy>
+  </target>
+
+
   <target name="cleanup">
     <delete file="dest1.txt" quiet="true" />
     <delete file="dest2.txt" quiet="true" />
     <delete file="dest3.txt" quiet="true" />
+    <delete file="dest_custom.txt" quiet="true" />
   </target>
 
 </project>
diff -Naur ant/src/etc/testcases/types/gold/custom_filter.txt ant-custom/src/etc/testcases/types/gold/custom_filter.txt
--- ant/src/etc/testcases/types/gold/custom_filter.txt	1970-01-01 01:00:00.000000000 +0100
+++ ant-custom/src/etc/testcases/types/gold/custom_filter.txt	2003-02-18 12:28:02.000000000 +0000
@@ -0,0 +1,2 @@
+This is a test file for filters *aaaa*
+It has two lines *bbbb*
diff -Naur ant/src/etc/testcases/types/mapper.xml ant-custom/src/etc/testcases/types/mapper.xml
--- ant/src/etc/testcases/types/mapper.xml	2002-01-08 09:46:26.000000000 +0000
+++ ant-custom/src/etc/testcases/types/mapper.xml	2003-02-18 13:31:38.000000000 +0000
@@ -15,8 +15,29 @@
     </copy>
   </target>
 
+  <target name="custom_mapper">
+    <path id="testclasses">
+      <pathelement location="../../../../build/testcases" />
+      <pathelement path="${java.class.path}" />
+    </path>
+    
+    <typedef
+      name="custom_mapper" 
+      classname="org.apache.tools.ant.types.CustomMapper"
+      classpathref="testclasses"
+    />
+    <mkdir dir="customcopytest"/>
+    <copy todir="customcopytest">
+      <fileset dir="../../../main">
+        <include name="**/taskdefs/*.java"/>
+      </fileset>
+      <mapper type="custom_mapper"/>
+    </copy>
+  </target>
+
   <target name="cleanup">
     <delete dir="copytest" />
+    <delete dir="customcopytest"/>
   </target>
 
 </project>
diff -Naur ant/src/main/org/apache/tools/ant/TaskAdapter.java ant-custom/src/main/org/apache/tools/ant/TaskAdapter.java
--- ant/src/main/org/apache/tools/ant/TaskAdapter.java	2003-02-10 14:13:30.000000000 +0000
+++ ant-custom/src/main/org/apache/tools/ant/TaskAdapter.java	2003-02-18 09:35:03.000000000 +0000
@@ -67,6 +67,18 @@
 
     /** Object to act as a proxy for. */
     private Object proxy;
+
+    /**
+     * Set the project of the taskadapter and the
+     * project of the proxy object.
+     */
+    public void setProject(Project project) {
+        super.setProject(project);
+        if (proxy == null)
+            log("TaskAdapter: proxy is null", Project.MSG_VERBOSE);
+        else
+            setProxyProject();
+    }
     
     /**
      * Checks whether or not a class is suitable to be adapted by TaskAdapter.
@@ -108,14 +120,14 @@
             throw new BuildException(message);
         }
     }
-    
+
+
     /**
-     * Executes the proxied task.
-     * 
+     * set the project on the proxied task.
+     *
      * @exception BuildException if the project could not be set
-     * or the method could not be executed.
      */
-    public void execute() throws BuildException {
+    private void setProxyProject() {
         Method setProjectM = null;
         try {
             Class c = proxy.getClass();
@@ -132,7 +144,17 @@
                 Project.MSG_ERR);
             throw new BuildException(ex);
         }
-
+    }
+    
+    /**
+     * Executes the proxied task.
+     * 
+     * @exception BuildException if the project could not be set
+     * or the method could not be executed.
+     */
+    public void execute() throws BuildException {
+        setProxyProject();
+    
 
         Method executeM = null;
         try {
diff -Naur ant/src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java ant-custom/src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java
--- ant/src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java	2003-02-10 14:13:42.000000000 +0000
+++ ant-custom/src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java	2003-02-18 09:49:57.000000000 +0000
@@ -56,6 +56,9 @@
 
 import java.util.Enumeration;
 import java.util.Vector;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DynamicConfigurator;
+import org.apache.tools.ant.Project;
 import org.apache.tools.ant.ProjectComponent;
 import org.apache.tools.ant.taskdefs.Available;
 import org.apache.tools.ant.taskdefs.Checksum;
@@ -70,7 +73,9 @@
  * @since Ant 1.4
  * @version $Revision: 1.17 $
  */
-public abstract class ConditionBase extends ProjectComponent {
+public abstract class ConditionBase extends ProjectComponent 
+    implements DynamicConfigurator
+{
     private Vector conditions = new Vector();
 
     /**
@@ -202,5 +207,38 @@
      * @since Ant 1.6
      */
     public void addIsReference(IsReference i) {conditions.addElement(i);}
+    
+
+    /**
+     * create the named datatype and check if it
+     * is a condition.
+     *
+     * @throws BuildException if unknown datatype or incorrect datatype
+     * @since Ant 1.6 (...)
+     */
+    
+    public Object createDynamicElement(String name)
+    {
+        if (getProject() == null)
+            throw new BuildException("Unable to get the project");
+
+        Object obj = getProject().createDataType(name);
+        if (obj == null)
+            throw new BuildException("Unknown type " + name);
+        if (! (obj instanceof Condition))
+            throw new BuildException(
+                "type " + name + " is not a condition");
+        conditions.addElement(obj);
+        return obj;
+    }
+    /**
+     * Needed for dynamic element support.
+     *
+     * @throws BuildException always
+     */
+    
+    public void setDynamicAttribute(String name, String value) {
+        throw new BuildException("Unknown attribute " + name);
+    }
 
 }
diff -Naur ant/src/main/org/apache/tools/ant/taskdefs/optional/RenameExtensions.java ant-custom/src/main/org/apache/tools/ant/taskdefs/optional/RenameExtensions.java
--- ant/src/main/org/apache/tools/ant/taskdefs/optional/RenameExtensions.java	2003-02-10 14:13:45.000000000 +0000
+++ ant-custom/src/main/org/apache/tools/ant/taskdefs/optional/RenameExtensions.java	2003-02-18 10:51:08.000000000 +0000
@@ -86,14 +86,10 @@
     private boolean replace = false;
     private File srcDir;
 
-    private Mapper.MapperType globType;
-
 
     /** Creates new RenameExtensions */
     public RenameExtensions() {
         super();
-        globType = new Mapper.MapperType();
-        globType.setValue("glob");
     }
 
     /**
@@ -161,7 +157,7 @@
         move.addFileset(fileset);
 
         Mapper me = move.createMapper();
-        me.setType(globType);
+        me.setType("glob");
         me.setFrom("*" + fromExtension);
         me.setTo("*" + toExtension);
 
diff -Naur ant/src/main/org/apache/tools/ant/types/AbstractFileSet.java ant-custom/src/main/org/apache/tools/ant/types/AbstractFileSet.java
--- ant/src/main/org/apache/tools/ant/types/AbstractFileSet.java	2003-02-10 14:14:30.000000000 +0000
+++ ant-custom/src/main/org/apache/tools/ant/types/AbstractFileSet.java	2003-02-18 10:26:51.000000000 +0000
@@ -60,6 +60,7 @@
 import java.util.Vector;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.DynamicConfigurator;
 import org.apache.tools.ant.FileScanner;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.util.FileUtils;
@@ -625,4 +626,36 @@
         appendSelector(selector);
     }
 
+    /**
+     * create the named datatype and check if it
+     * is a selector.
+     *
+     * @throws BuildException if unknown datatype or incorrect datatype
+     * @since Ant 1.6 (??)
+     */
+    
+    public Object createDynamicElement(String name)
+    {
+        if (getProject() == null)
+            throw new BuildException("Unable to get the project");
+
+        Object obj = getProject().createDataType(name);
+        if (obj == null)
+            throw new BuildException("Unknown type " + name);
+        if (! (obj instanceof FileSelector))
+            throw new BuildException(
+                "type " + name + " is not a fileselector");
+        appendSelector((FileSelector) obj);
+        return obj;
+    }
+
+    /**
+     * Needed for dynamic element support.
+     *
+     * @throws BuildException always
+     */
+    
+    public void setDynamicAttribute(String name, String value) {
+        throw new BuildException("Unknown attribute " + name);
+    }
 }
diff -Naur ant/src/main/org/apache/tools/ant/types/FilterChain.java ant-custom/src/main/org/apache/tools/ant/types/FilterChain.java
--- ant/src/main/org/apache/tools/ant/types/FilterChain.java	2003-02-10 14:14:30.000000000 +0000
+++ ant-custom/src/main/org/apache/tools/ant/types/FilterChain.java	2003-02-18 12:53:05.000000000 +0000
@@ -53,8 +53,11 @@
  */
 package org.apache.tools.ant.types;
 
+import java.io.FilterReader;
 import java.util.Vector;
 import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DynamicConfigurator;
+import org.apache.tools.ant.Project;
 import org.apache.tools.ant.filters.ClassConstants;
 import org.apache.tools.ant.filters.ExpandProperties;
 import org.apache.tools.ant.filters.HeadFilter;
@@ -73,7 +76,9 @@
  *
  * @author Magesh Umasankar
  */
-public final class FilterChain extends DataType implements Cloneable {
+public final class FilterChain extends DataType
+    implements Cloneable, DynamicConfigurator
+{
 
     private Vector filterReaders = new Vector();
 
@@ -163,4 +168,38 @@
 
         super.setRefid(r);
     }
+
+    /**
+     * create the named datatype and check if it
+     * is a filter.
+     *
+     * @throws BuildException if unknown datatype or incorrect datatype
+     * @since Ant 1.6 (...)
+     */
+    
+    public Object createDynamicElement(String name)
+    {
+        if (getProject() == null)
+            throw new BuildException("Unable to get the project");
+
+        Object obj = getProject().createDataType(name);
+        if (obj == null)
+            throw new BuildException("Unknown type " + name);
+        if (! (obj instanceof FilterReader))
+            throw new BuildException(
+                "type " + name + " is not a filterreader");
+        filterReaders.addElement(obj);
+        return obj;
+    }
+
+    /**
+     * Needed for dynamic element support.
+     *
+     * @throws BuildException always
+     */
+    
+    public void setDynamicAttribute(String name, String value) {
+        throw new BuildException("Unknown attribute " + name);
+    }
+
 }
diff -Naur ant/src/main/org/apache/tools/ant/types/Mapper.java ant-custom/src/main/org/apache/tools/ant/types/Mapper.java
--- ant/src/main/org/apache/tools/ant/types/Mapper.java	2003-02-10 14:14:30.000000000 +0000
+++ ant-custom/src/main/org/apache/tools/ant/types/Mapper.java	2003-02-18 10:49:09.000000000 +0000
@@ -68,7 +68,7 @@
  */
 public class Mapper extends DataType implements Cloneable {
 
-    protected MapperType type = null;
+    protected String type = null;
 
     public Mapper(Project p) {
         setProject(p);
@@ -77,7 +77,7 @@
     /**
      * Set the type of FileNameMapper to use.
      */
-    public void setType(MapperType type) {
+    public void setType(String type) {
         if (isReference()) {
             throw tooManyAttributes();
         }
@@ -190,20 +190,40 @@
         }
 
         try {
+            FileNameMapper m = null;
             if (type != null) {
-                classname = type.getImplementation();
+                try {
+                    MapperType mapperType = new MapperType();
+                    mapperType.setValue(type);
+                    classname = mapperType.getImplementation();
+                }
+                catch (BuildException ex) {
+                    // Not one of the defined types :-
+                    // check if it is a datatype
+                    Object obj = getProject().createDataType(type);
+                    if (obj == null)
+                        throw new BuildException(
+                            "Unknown type " + type);
+                    if (! (obj instanceof FileNameMapper))
+                        throw new BuildException(
+                            "Type " + type + " is not a FileNameMapper");
+                    m = (FileNameMapper) obj;
+                }
             }
 
-            Class c = null;
-            if (classpath == null) {
-                c = Class.forName(classname);
-            } else {
-                AntClassLoader al = getProject().createClassLoader(classpath);
-                c = al.loadClass(classname);
-                AntClassLoader.initializeClass(c);
+            if (m == null) {
+                Class c = null;
+                if (classpath == null) {
+                    c = Class.forName(classname);
+                } else {
+                    AntClassLoader al =
+                        getProject().createClassLoader(classpath);
+                    c = al.loadClass(classname);
+                    AntClassLoader.initializeClass(c);
+                }
+                
+                m = (FileNameMapper) c.newInstance();
             }
-
-            FileNameMapper m = (FileNameMapper) c.newInstance();
             m.setFrom(from);
             m.setTo(to);
             return m;
diff -Naur ant/src/testcases/org/apache/tools/ant/taskdefs/condition/CustomCondition.java ant-custom/src/testcases/org/apache/tools/ant/taskdefs/condition/CustomCondition.java
--- ant/src/testcases/org/apache/tools/ant/taskdefs/condition/CustomCondition.java	1970-01-01 01:00:00.000000000 +0100
+++ ant-custom/src/testcases/org/apache/tools/ant/taskdefs/condition/CustomCondition.java	2003-02-18 11:57:34.000000000 +0000
@@ -0,0 +1,82 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "Ant" and "Apache Software
+ *    Foundation" must not be used to endorse or promote products derived
+ *    from this software without prior written permission. For written
+ *    permission, please contact [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ *    nor may "Apache" appear in their names without prior written
+ *    permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+package org.apache.tools.ant.taskdefs.condition;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.ProjectComponent;
+
+/**
+ * A custom condition.
+ */
+public class CustomCondition implements Condition {
+
+    private boolean value=false;
+
+    /**
+     * set the value to be tested; let ant eval it to true/false
+     */ 
+    
+    public void setTestValue(boolean value) {
+        this.value = value;
+    }
+
+    /**
+     * return the value;
+     */ 
+    public boolean eval()  {
+        return value;
+    }
+
+}
diff -Naur ant/src/testcases/org/apache/tools/ant/taskdefs/ConditionTest.java ant-custom/src/testcases/org/apache/tools/ant/taskdefs/ConditionTest.java
--- ant/src/testcases/org/apache/tools/ant/taskdefs/ConditionTest.java	2003-02-10 14:14:45.000000000 +0000
+++ ant-custom/src/testcases/org/apache/tools/ant/taskdefs/ConditionTest.java	2003-02-18 12:13:39.000000000 +0000
@@ -257,12 +257,14 @@
         expectPropertySet("isfalse-false","isfalse-false"); 
     } 
 
-    
     public void testIsfalseIncomplete1() {
         expectSpecificBuildException("isfalse-incomplete", 
                     "Missing attribute",
                     "Nothing to test for falsehood"); 
     }     
-    
+
+    public void testCustomCondition() {
+        expectPropertySet("custom-condition","custom-condition-true", "true"); 
+    }
 }
 
diff -Naur ant/src/testcases/org/apache/tools/ant/types/AbstractFileSetTest.java ant-custom/src/testcases/org/apache/tools/ant/types/AbstractFileSetTest.java
--- ant/src/testcases/org/apache/tools/ant/types/AbstractFileSetTest.java	2003-02-10 14:14:55.000000000 +0000
+++ ant-custom/src/testcases/org/apache/tools/ant/types/AbstractFileSetTest.java	2003-02-18 14:23:01.000000000 +0000
@@ -55,6 +55,7 @@
 package org.apache.tools.ant.types;
 
 import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileTest;
 import org.apache.tools.ant.Project;
 
 import junit.framework.TestCase;
@@ -280,4 +281,35 @@
         File dir = f1.getDir(project);
         assertEquals("Dir is basedir", dir, project.getBaseDir());
     }
+
+
+    public void testCustom() {
+        /*
+        MyTest t = new MyTest("custom_mapper");
+         try {
+            t.setUp();
+            t.custom_selector();
+        } finally {
+            t.tearDown();
+        }
+        */
+   }
+
+    private class MyTest extends BuildFileTest {
+        public MyTest(String name) {
+            super(name);
+        }
+
+        public void setUp() { 
+            configureProject("src/etc/testcases/types/fileset.xml");
+        }
+
+        public void tearDown() {
+            executeTarget("cleanup");
+        }
+
+        public void custom_selector() { 
+            executeTarget("custom-selector");
+        }
+    }
 }
diff -Naur ant/src/testcases/org/apache/tools/ant/types/CustomFilter.java ant-custom/src/testcases/org/apache/tools/ant/types/CustomFilter.java
--- ant/src/testcases/org/apache/tools/ant/types/CustomFilter.java	1970-01-01 01:00:00.000000000 +0100
+++ ant-custom/src/testcases/org/apache/tools/ant/types/CustomFilter.java	2003-02-18 12:50:15.000000000 +0000
@@ -0,0 +1,107 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "Ant" and "Apache Software
+ *    Foundation" must not be used to endorse or promote products derived
+ *    from this software without prior written permission. For written
+ *    permission, please contact [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ *    nor may "Apache" appear in their names without prior written
+ *    permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+package org.apache.tools.ant.types;
+
+import java.io.IOException;
+import java.io.Reader;
+
+import org.apache.tools.ant.filters.BaseFilterReader;
+import org.apache.tools.ant.filters.ChainableReader;
+
+/**
+ * Simple CustomFilter to replace a particular character in the stream,
+ */
+
+public class CustomFilter
+    extends BaseFilterReader
+    implements ChainableReader
+{
+    char replace = 'x';
+    char with    = 'y';
+
+    
+    public CustomFilter() {
+        super();
+    }
+
+    public CustomFilter(Reader r) {
+        super(r);
+    }
+
+    public void setReplace(char replace) {
+        this.replace = replace;
+    }
+
+    public void setWith(char with) {
+        this.with = with;
+    }
+
+    public int read()
+        throws IOException
+    {
+        int c = super.read();
+        if (c == replace)
+            return with;
+        else
+            return c;
+    }
+
+    public Reader chain(final Reader rdr) {
+        CustomFilter newFilter = new CustomFilter(rdr);
+        newFilter.setReplace(replace);
+        newFilter.setWith(with);
+        return newFilter;
+    }
+}
diff -Naur ant/src/testcases/org/apache/tools/ant/types/CustomMapper.java ant-custom/src/testcases/org/apache/tools/ant/types/CustomMapper.java
--- ant/src/testcases/org/apache/tools/ant/types/CustomMapper.java	1970-01-01 01:00:00.000000000 +0100
+++ ant-custom/src/testcases/org/apache/tools/ant/types/CustomMapper.java	2003-02-18 13:27:07.000000000 +0000
@@ -0,0 +1,67 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "Ant" and "Apache Software
+ *    Foundation" must not be used to endorse or promote products derived
+ *    from this software without prior written permission. For written
+ *    permission, please contact [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ *    nor may "Apache" appear in their names without prior written
+ *    permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+package org.apache.tools.ant.types;
+
+import org.apache.tools.ant.util.FileNameMapper;
+import org.apache.tools.ant.util.FlatFileNameMapper;
+
+/**
+ * Custom mapper just do the same as flatten
+ */
+
+public class CustomMapper
+    extends FlatFileNameMapper
+{
+}
diff -Naur ant/src/testcases/org/apache/tools/ant/types/CustomSelector.java ant-custom/src/testcases/org/apache/tools/ant/types/CustomSelector.java
--- ant/src/testcases/org/apache/tools/ant/types/CustomSelector.java	1970-01-01 01:00:00.000000000 +0100
+++ ant-custom/src/testcases/org/apache/tools/ant/types/CustomSelector.java	2003-02-18 14:18:42.000000000 +0000
@@ -0,0 +1,66 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2003 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ *    any, must include the following acknowlegement:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "Ant" and "Apache Software
+ *    Foundation" must not be used to endorse or promote products derived
+ *    from this software without prior written permission. For written
+ *    permission, please contact [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ *    nor may "Apache" appear in their names without prior written
+ *    permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+package org.apache.tools.ant.types;
+
+import org.apache.tools.ant.types.selectors.FilenameSelector;
+
+/**
+ * Simple CustomSelector to show that the mechanizm works.
+ */
+
+public class CustomSelector
+    extends FilenameSelector
+{
+}
diff -Naur ant/src/testcases/org/apache/tools/ant/types/FilterSetTest.java ant-custom/src/testcases/org/apache/tools/ant/types/FilterSetTest.java
--- ant/src/testcases/org/apache/tools/ant/types/FilterSetTest.java	2003-02-10 14:14:55.000000000 +0000
+++ ant-custom/src/testcases/org/apache/tools/ant/types/FilterSetTest.java	2003-02-18 12:45:24.000000000 +0000
@@ -104,6 +104,13 @@
                                                       "src/etc/testcases/types/dest3.txt"));
     }
 
+    public void testcustomfilter() {
+        executeTarget("test-custom-filter");
+        assertTrue("Custom Filter Failed",
+                   compareFiles("src/etc/testcases/types/gold/custom_filter.txt",
+                                "src/etc/testcases/types/dest_custom.txt"));
+    }
+    
     /**
      * This will test the recursive FilterSet.  Which means that if
      * the filter value @test@ contains another filter value, it will
diff -Naur ant/src/testcases/org/apache/tools/ant/types/MapperTest.java ant-custom/src/testcases/org/apache/tools/ant/types/MapperTest.java
--- ant/src/testcases/org/apache/tools/ant/types/MapperTest.java	2003-02-10 14:14:55.000000000 +0000
+++ ant-custom/src/testcases/org/apache/tools/ant/types/MapperTest.java	2003-02-18 13:26:32.000000000 +0000
@@ -114,9 +114,7 @@
                          be.getMessage());
         }
         try {
-            Mapper.MapperType mt = new Mapper.MapperType();
-            mt.setValue("glob");
-            m.setType(mt);
+            m.setType("glob");
             fail("Can set type in Mapper that is a reference.");
         } catch (BuildException be) {
             assertEquals("You must not specify more than one attribute when using refid",
@@ -164,9 +162,7 @@
         m2.setRefid(new Reference("dummy3"));
         m3 = new Mapper(project);
         project.addReference("dummy3", m3);
-        Mapper.MapperType mt = new Mapper.MapperType();
-        mt.setValue("glob");
-        m3.setType(mt);
+        m3.setType("glob");
         m3.setFrom("*.java");
         m3.setTo("*.class");
         FileNameMapper fmm = m1.getImplementation();
@@ -186,6 +182,16 @@
         }
     }
 
+    public void testCustomMapper() {
+        TaskdefForCopyTest t = new TaskdefForCopyTest("custom_mapper");
+        try {
+            t.setUp();
+            t.custom_mapper();
+        } finally {
+            t.tearDown();
+        }
+    }
+
     private class TaskdefForCopyTest extends BuildFileTest {
         TaskdefForCopyTest(String name) {
             super(name);
@@ -202,5 +208,9 @@
         public void test1() { 
             executeTarget("test1");
         }
+
+        public void custom_mapper() { 
+            executeTarget("custom_mapper");
+        }
     }
 }
diff -Naur ant/src/testcases/org/apache/tools/ant/types/selectors/DependSelectorTest.java ant-custom/src/testcases/org/apache/tools/ant/types/selectors/DependSelectorTest.java
--- ant/src/testcases/org/apache/tools/ant/types/selectors/DependSelectorTest.java	2003-02-10 14:14:57.000000000 +0000
+++ ant-custom/src/testcases/org/apache/tools/ant/types/selectors/DependSelectorTest.java	2003-02-18 10:54:52.000000000 +0000
@@ -122,12 +122,9 @@
         String results;
         File subdir;
         Mapper m;
-        Mapper.MapperType identity = new Mapper.MapperType();
-        identity.setValue("identity");
-        Mapper.MapperType glob = new Mapper.MapperType();
-        glob.setValue("glob");
-        Mapper.MapperType merge = new Mapper.MapperType();
-        merge.setValue("merge");
+        String identity = "identity";
+        String glob = "glob";
+        String merge = "merge";
 
         try {
             makeBed();
diff -Naur ant/src/testcases/org/apache/tools/ant/types/selectors/PresentSelectorTest.java ant-custom/src/testcases/org/apache/tools/ant/types/selectors/PresentSelectorTest.java
--- ant/src/testcases/org/apache/tools/ant/types/selectors/PresentSelectorTest.java	2003-02-10 14:14:57.000000000 +0000
+++ ant-custom/src/testcases/org/apache/tools/ant/types/selectors/PresentSelectorTest.java	2003-02-18 10:56:10.000000000 +0000
@@ -121,14 +121,10 @@
         PresentSelector s;
         String results;
         Mapper m;
-        Mapper.MapperType identity = new Mapper.MapperType();
-        identity.setValue("identity");
-        Mapper.MapperType glob = new Mapper.MapperType();
-        glob.setValue("glob");
-        Mapper.MapperType merge = new Mapper.MapperType();
-        merge.setValue("merge");
-        Mapper.MapperType flatten = new Mapper.MapperType();
-        flatten.setValue("flatten");
+        String identity = "identity";
+        String glob = "glob";
+        String merge = "merge";
+        String flatten = "flatten";
 
         try {
             makeBed();

Reply via email to