Code : ANT : Copy src

I have a project structure like this

  • src
    • component-X
      • src
        • net/sujee/X/X.java
    • component-Y
      • src
        • net/sujee/Y/Y.java
This is a pretty common directory structure if you have java projects or Eclipse plugins.  I want to consolidate them into one source directory as follows
  • single_src
    • net
      • sujee
        • X
          • X.java
        • Y
          • Y.java
This might be needed because some code-scanning tools want all files under a single source directory.

Here is the Ant snippet.  It basically strips out 'component-X/src' while copying the files.  Uses regular expressions

<!--
regex grouped () are accessed by \1 \2 ..etc
here \1 = every thing upto src, component-X/src
\2 the rest of the file name: 'net/sujee/X/X'
-->
<target name="copy-src">
<copy todir="single_src_dir">
<fileset dir="original_src">
<include name="**/*.java"/>
</fileset>
<regexpmapper from="^(.*src)(.*)\.java$$" to="\2.java"/>
</copy>
</target>