开发者

For the Ant gurus: how do I copy and concat at the same time or in the same manner?

开发者 https://www.devze.com 2023-03-23 12:42 出处:网络
During my build process I copy files from one directory to another, filtering out some unnecessary text like so:

During my build process I copy files from one directory to another, filtering out some unnecessary text like so:

<target name="init-files">
  <copy todir="${resources}/clean" overwrite="true">
    <fileset dir = "${resources}/dirty" />
    <filterchain>
      <tokenfilter>
        <replacestring from="text_to_remove" to="" />
      </tokenfilter>
    </filterchain>
  </copy>
</target>
开发者_如何学编程

I would like to insert a line of text at the beginning and end of each file being copied. I cannot use replacestring as I can't insert a token - the source text files are generated externally.

concat looked like the answer but while I've found how to concatenate a collection of files into a single file (many sources with single destination) I don't see how to add text to each file in a collection (fixed text source with many destination).

I'd appreciate any ideas on how to accomplish this.

Thank you!


There's the replaceregex string filter that can be chained with the replacestring filter you already have in the tokenfilter:

<tokenfilter>
    <replacestring from="text_to_remove" to="" />
    <filetokenizer/>
    <replaceregex pattern="^" replace="PREFIX TEXT${line.separator}" />
    <replaceregex pattern="$" replace="${line.separator}SUFFIX TEXT" />
</tokenfilter>

The first one matches the start of each of the files, the second the end.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号