简体   繁体   中英

Does Ant guarantee order of filesets?

in our project we use Ant to distribute files. There is hierarchy of files, and they overwrite files from previous level. Like this: default - level1 - level2. Currently it is made the way:

<copy todir="...">
 <fileset dir="${root}/default" includes="**/*" excludes="file1" />
 <fileset dir="${root}/level1" includes="**/*" />
 <fileset dir="${root}/level2" includes="**/*" excludes="file2"/>
</copy>

So we expected that all the folders contain file with the same name, it will be taken from level2 directory.

Not long ago we moved to a new build box with another version of Java and we discovered that the order of filesets is broken.

Is there a way to fix this issue without modifying ant config files? We have a big number of it. If there is no way, how can I got it off cheap? Thank you.

I don't know if the order of filesets is quaranteed, but the order of copy tasks is. So, following the suggestion of this answer , it might be a good idea to write several copy tasks with overwrite="true":

<copy todir="...">
  <fileset dir="${root}/default" includes="**/*" excludes="file1" />
</copy>
<copy todir="...">
  <fileset dir="${root}/level1" includes="**/*" overwrite="true" />
</copy>
<copy todir="...">
  <fileset dir="${root}/level2" includes="**/*" excludes="file2" overwrite="true" />
</copy>

You can wrap a sort resource collection around your fileset s and ensure the order used by copy this way. Sort itself only likes a single resource collection as child element, so you need to wrap the fileset inside a union or resources container.

See http://ant.apache.org/manual/Types/resources.html#sort

Something like

<sort>
  <resources>
    <fileset dir="${root}/default" includes="**/*" excludes="file1" />
    <fileset dir="${root}/level1" includes="**/*" />
    <fileset dir="${root}/level2" includes="**/*" excludes="file2"/>
  </resources>
  <name/>
</sort>

to sort the files by name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM