How to make Ant read lines of a file in a comma separated property?

I am wondering what is the easiest way to read the contents of a file into a comma-delimited property, suitable as an argument to an attribute files filelist. I have two solutions, but I am not satisfied with any of them, and I would like to ask if anyone knows a better (shorter) way.

This only works with newer Ants, and it does not seem to be trustworthy, because each line of the input file has a prefix with basedir, which makes it necessary to call flattenmapperto delete the directory again.

<pathconvert property="files2" pathsep=",">
  <resources>
    <resourcelist>
      <file file="IMPORT"/>
    </resourcelist>
  </resources>
  <flattenmapper/>
</pathconvert>

Does anyone know how to avoid flattenmapperin this example? I tried to specify the attribute basedirin file, but it has no effect.

Another approach loadfilewith filterchain:

<loadfile property="files1" srcFile="IMPORT">
  <filterchain>
    <tokenfilter>
      <replaceregex pattern="$" replace=","/>
    </tokenfilter>
    <striplinebreaks/>
    <tokenfilter>
      <replaceregex pattern=",$" replace=""/>
    </tokenfilter>
  </filterchain>
</loadfile>

, , , .

?

+4
1

flattenmapper <mappedresources> :

<pathconvert property="files2" pathsep=",">
  <resources>
   <mappedresources>
    <resourcelist>
      <file file="IMPORT"/>
    </resourcelist>
    <globmapper from="*" to="${my.base.dir}/*"/>
   </mappedresources>
  </resources>
  <flattenmapper/>
</pathconvert>
+1

All Articles