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 28883] - Add regex conditions to Ant
Date Sun, 24 Sep 2006 04:57:33 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=28883>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=28883





------- Additional Comments From paulk@asert.com.au  2006-09-24 04:57 -------
Created an attachment (id=18903)
 --> (http://issues.apache.org/bugzilla/attachment.cgi?id=18903&action=view)
An alternative implementation

I created a patch for very similar functionality .. and then checked for
similar enhancement requests. Note to self ... Bugzilla is your friend.

This patch is similar to but different enough that it might be worthy of
consideration anyway. It is against the latest HEAD and uses flags as per
the other regexp tasks rather than specific attributes.

I have left out a junit test case but will happily supply it or an antunit test
if there is interest. I did create an acceptance test of sorts by adding the
following lines to testcases/taskdefs/condition.xml:

    <regexp id="myid" pattern="^[a-z]{3,4}$"/>

    <target name="matches-simple">
      <condition property="matches">
	<matches string="abc">
	  <regexp refid="myid"/>
	</matches>
      </condition>
      <echo>${matches}</echo>
    </target>

    <target name="nomatch">
      <condition property="nomatch">
	<not>
	  <matches string="abc" pattern="^b.*" />
	</not>
      </condition>
      <echo>${nomatch}</echo>
    </target>

    <target name="matches-date">
	<tstamp>
	  <format property="today" pattern="dd-MM-yyyy" locale="en"/>
	</tstamp>
      <echo>${today}</echo>
      <condition property="isValidDate">
	<matches string="${today}">
	  <regexp pattern="[0123]\d-[01]\d-[12]\d\d\d" />
	</matches>
      </condition>
      <echo>${isValidDate}</echo>
    </target>

Even though it relies on the regexp package I didn't place it under optional as
other things (e.g. TokenFilter) also rely on Regexp and aren't under optional.

The following would be the extension to AntUnit to make use of this
functionality:

  <macrodef name="assertMatches" backtrace="false">
    <attribute name="string"/>
    <attribute name="pattern"/>
    <attribute name="message"
      default="Expected '@{string}' to match pattern '@{pattern}'"/>
    <sequential>
      <au:assertTrue message="@{message}">
	<matches string="@{string}" pattern="@{pattern}"/>
      </au:assertTrue>
    </sequential>
  </macrodef>

I'll add this as a separate patch in due course if there is interest.


-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message