Ant task to print the contents of a directory to a file

As part of the custom ant build I play, I would like to have a design

  • Run <replaceregexp>in html document
  • To “replace” in the regular expression, I would like to iterate over the .js file directory and add a tag to each file.

I was browsing ant docs at http://ant.apache.org/manual/index.html

but I didn’t see anything to help me iterate over or list the files.

+3
source share
2 answers

You probably want to generate replacement text first by processing the directory containing the .js files.

fileset , pathconvert html . " my_dir", :

<fileset id="dir.contents" dir="my_dir">
    <include name="*.js"/>
</fileset>

<pathconvert pathsep="${line.separator}" property="js.html" refid="dir.contents">
  <chainedmapper>
    <mapper type="flatten" />
    <regexpmapper from="(.*)" 
       to='&lt;script type="text/javascript" src="http://your.url/\1"&gt;&lt;/script&gt;' />
  </chainedmapper>
</pathconvert>

<echo>${js.html}</echo>

flatten , .

:

 [echo] <script type="text/javascript" src="http://your.url/a.js"></script>
 [echo] <script type="text/javascript" src="http://your.url/b.js"></script>
 [echo] <script type="text/javascript" src="http://your.url/c.js"></script>

, ${js.html} regexp.

+1

replaceregexp . doc

<replaceregexp match="\s+" replace=" " flags="g" byline="true">
    <fileset dir="${html.dir}" includes="**/*.html"/>
</replaceregexp>

http://ant.apache.org/manual/Tasks/replaceregexp.html

, ?

0

All Articles