I am new to ant and i want to know how the ant copy decides the copying order. Problem is, I have a folder structure like this releases/v1,v2,v3
. folders will be created for each new release. and names of the files will be similar in these folders. and it is required to copy the latest release in to a folder called 'latest' in this scenario it will be required to copy v3 into 'latest'. so my logic is to copy one by one into 'latest' folder and override the files and the latest file will be remained at the end. my code is like this.
<copy todir="${srcdist.layout.dir}/etc/wsdl/latest" flatten="true" overwrite="true">
<fileset dir="../../releases">
<include name="**/*.wsdl"/>
</fileset>
</copy>
This code works fine for me (in centOS). it starts copying from v1 and ends in v3. but i feel doubt on this copying order whether this will work every time or not. is copy todir sorting the folder names before copying ? please help me.
using sort
From Path-like Structures in the Ant documentation:
So, you cannot depend on a fileset maintaining any order.
Instead, you can resort to using JavaScript to find the "latest" release directory:
To test the script, I created several
v#
directories under areleases
directory. Each of those directories has a*.wsdl
file.The output of running the script:
I think it's not good to rely on how
<fileset>
orders the files when copying. So maybe it's better if you can try to change this logic to use a TimestampSelector from the Ant-Contrib project to select the newest wsdl file and copy only this file, not all the files of all versions. It could be done like:Or since Ant 1.7.1 you can use a Last to get the latest file. Here you can find an example.