I guess I should have posted this mail on ant dev mailing list.
Is this request too late for ant 1.8.1 ?


---------- Forwarded message ----------
From: Patrick Martin <antu...@gmail.com>
Date: Sat, May 1, 2010 at 3:17 PM
Subject: loop replace mapper
To: Ant User <u...@ant.apache.org>


Hello,

I wrote a small mapper which loops on a string list and replaces a
token in the input file name.
it can be used (since ant 1.8.1) like this:
               <copy todir="test/data/destdir" enablemultiplemappings="true">
                       <fileset dir="test/data/srcdir" includes="**" />
                       <loopreplacemapper token="@dirname@" list="dir1,dir2" />
               </copy>
               <zip destfile="test/data/destzip.zip">
                       <mappedresources enablemultiplemappings="true">
                               <fileset dir="test/data/srcdir" includes="**" />
                               <loopreplacemapper token="@dirname@"
list="dir1,dir2" />
                       </mappedresources>
              </zip>

Would this fit in the next standard ant version ?

Here is the source code:

public class LoopReplaceMapper implements FileNameMapper {
       private String token;
       private ArrayList<String> list;

       public void setToken(String token) {
               this.token = token;
       }

       public String getToken() {
               return token;
       }

       public void setList(String _list) {
               StringTokenizer st = new StringTokenizer(_list, "       , ");
               this.list = new ArrayList<String>(st.countTokens());
               while (st.hasMoreTokens()) {
                       list.add(st.nextToken());
               }
       }

       public String getList() {
               return list.toString();
       }

       public String[] mapFileName(String sourceFileName) {
               String[] mappedFileNames = null;
               if (sourceFileName.contains(getToken())) {
                       mappedFileNames = new String[list.size()];
                       int index = 0;
                       for (String replacement : list) {
                               mappedFileNames[index++] =
sourceFileName.replace(getToken(), replacement);
                       }
               } else {
                       mappedFileNames = new String[1];
                       mappedFileNames[0] = sourceFileName;
               }
               return mappedFileNames;
       }

       public void setFrom(String from) {
       }

       public void setTo(String to) {
       }
}

 Rgds,

Patrick

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

Reply via email to