开发者

Apache Ant - Select All Symlinks

I need a symbolic link开发者_运维技巧 selector in Apache Ant.

The following selectors are available to the Core.

Can anyone advise me on writing a <scriptselector> for selecting only the symbolic linked files under a directory? Or any other way?

The reason:

folder
|-- file-0.0.1
|-- file-0.0.2
|-- file-0.0.3
`-- file --> file-0.0.3

I just want to get the file that is symbolically linked by file. In this case file-0.0.3, but the symbolic link can change and I don't want all the other files to be in the Ant <fileset>


Please take a look at :

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

I don't have a linux machine to test now but I guess that with the something like this :

<symlink action="record" linkfilename="my.links">
 <fileset dir="${my.folder}" includes="*"/>
</symlink>

You should be able to record your symlinks into a file and then processing the files as you wish. For example you could then create a list only with the "symlinked" files and iterate over it to do what you want.

EDIT :

For this solution you will need to install the ant-contrib. Just unpack the ant-contrib-1.0b3.jar to your ant/lib directory. Then use the following build.xml file :

<project name="test" default="build">
  <!--Needed for antcontrib-->
  <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
  <target name="build">
  <property name="my.dir" value="/home/stefanos"/>
  <exec executable="bash" outputproperty="symlinks" dir="${my.dir}">
     <arg value="-c"/>
     <arg value="\ls -1 | xargs -l readlink"/>
  </exec>

<foreach list="${symlinks}" delimiter="${line.separator}" param="link" target="process.link"/>    

</target>

<target name="process.link">
   <!--Do whatever you want with the file targeted by the symlink-->
   <echo message="Processing link : ${link}"/>
</target>
</project>

The trick is the linux command which returns all the targeted files from the symlinks. Then you just iterate through them with the foreach task and you call a target in which you can do whatever you need with the files.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜