Reputation: 175
I have the following ant script that copies a file to DIR A if the file is different:
<copy todir="<DIR A>" verbose="true" preservelastmodified="true">
<fileset file="< file A">
<different targetdir="<DIR A>" ignorefiletimes="true"/>
</fileset>
</copy>
What I need to accomplish is to "check" if the copy happened in order to do "something else" as well.
Upvotes: 0
Views: 308
Reputation: 7041
Run a test before the copy to see if the files are different. Then run a test after the copy to see if the files are the same.
The <condition>
task's <filesmatch>
condition detects whether two files have identical content.
Here's some code:
<project name="ant-copy-changed-file-test" default="run">
<target name="run" depends="-copy,-post-copy"/>
<target name="-copy">
<condition property="copy-should-happen">
<not>
<filesmatch file1="${file_A}" file2="${dir_A}/file_A"/>
</not>
</condition>
<copy todir="${dir_A}" verbose="true" preservelastmodified="true">
<fileset file="${file_A}">
<different targetdir="${dir_A}" ignorefiletimes="true"/>
</fileset>
</copy>
<condition property="copy-happened">
<and>
<isset property="copy-should-happen"/>
<filesmatch file1="${file_A}" file2="${dir_A}/file_A"/>
</and>
</condition>
</target>
<target name="-post-copy" if="copy-happened">
<echo>Copy happened!</echo>
</target>
</project>
Upvotes: 1