ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 17199] New: - patch to allow custom conditions (+ filters..)
Date Wed, 19 Feb 2003 12:36:19 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=17199>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=17199

patch to allow custom conditions (+ filters..)

           Summary: patch to allow custom conditions (+ filters..)
           Product: Ant
           Version: 1.6Alpha (nightly)
          Platform: All
               URL: file:///home/preilly/proj/net-cvs/custom-patch.gz
        OS/Version: Other
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Core tasks
        AssignedTo: dev@ant.apache.org
        ReportedBy: peter.reilly@corvil.com


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.

Mime
View raw message