1

I'm trying to concatenate an unknown number of HTML files into one XML file. That's no problem with:

<concat destfile="${temp.dir}/file.xml" encoding="UTF-8" outputencoding="UTF-8">
    <fileset dir="${html.dir}" includes="**/*.html" />
</concat>

Now what I would like to do is, for each file of the fileset, insert its path into the concatenated file.

Example

I have the following HTML files in C:\whatever\sources:

  • A.html
  • B.html

In the result XML file, I'd like to get:

  <allfiles>
   <html url="C:\whatever\sources\A.html>...content of A.html...</html>
   <html url="C:\whatever\sources\B.html>...content of B.html...</html>
  </allfiles>

Is there a way to do that simply without reinventing the wheel and if possible without using ant-contrib?

kenorb
  • 155,785
  • 88
  • 678
  • 743
Flag
  • 497
  • 1
  • 3
  • 17
  • See the answer from Martin Clayton in [Getting file name inside Ant copy task filter](http://stackoverflow.com/questions/4376795/getting-file-name-inside-ant-copy-task-filter/4377913#4377913). Although that answer uses ``, a `` can also be used with ``. – Chad Nouis Sep 29 '15 at 14:23
  • Thanks for the info, seems impossible without using ant-contrib then? mmh :( – Flag Sep 29 '15 at 14:28

1 Answers1

0

As mentioned, you can use a scriptfilter inside filterchain task to run Javascript inside your Ant build.

For example:

<concat destfile="${temp.dir}/file.xml" encoding="UTF-8" outputencoding="UTF-8">
    <fileset dir="${html.dir}" includes="**/*.html" id="my-files"/>
    <filterchain>
        <tokenfilter>
            <filetokenizer />
                 <scriptfilter language="javascript" byline="false"><![CDATA[
                     content = self.getToken();
                     // Modify content of token.
                     //content=content.replaceAll("(?s)/\\*.*?\\*/","");
                     self.setToken(content);
            ]]></scriptfilter>
        </tokenfilter>
        <striplinecomments>
            <comment value="//"/>
        </striplinecomments>
        <striplinebreaks/>
    </filterchain>
</concat>

Find more examples at:

kenorb
  • 155,785
  • 88
  • 678
  • 743