Reputation: 22348
The symlink task in ant either create a single, record existing, recreate existing, or delete a single symbolic link. I want to create symbolic links to all the files within a given directory within a different directory.
Upvotes: 3
Views: 4045
Reputation: 45576
The simplest way to achieve it (in terms of coding) is with the help of antcontrib's For task
<for param="file">
<path>
<fileset dir="${src.dir}" includes="*"/>
</path>
<sequential>
<basename property="@{file}.basename" file="@{file}">
<symlink link="${dest.dir}/${@{file}.basename}" resource="@{file}"/>
</sequential>
</for>
If you don't want the dependency on ant-contrib, you may try the following (Note: I did not test it at all):
Now you have a template properties file that you will recreate with your build instructions:
<pathconvert pathsep="${line.separator}" property="file.list">
<fileset dir="${src.dir}" includes="*"/>
</pathconvert>
<echo message="${file.list}" file="${file-list.file}" append="false"/>
Now massage the file with regexp filter
<copy file="${file-list.file}" tofile="${dest-dir}/.link.properties">
<filterchain>
<tokenfilter>
<!-- I leave regex as an exercise to the reader -->
<replaceregex pattern="..." replace="..." flags="..."/>
</tokenfilter>
</filterchain>
</copy>
Finally do symlink-recreate.
<symlink action="recreate">
<fileset dir="${dest.dir}" includes=".link.properties"/>
</symlink>
Upvotes: 3