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: [email protected]
For additional commands, e-mail: [email protected]