Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to conditionally copy a file using ant?

Tags:

java

ant

I have the following target:

<target name="promptforchoice">

  <input addproperty="choice">
     Copy the file?.  [Y, n]
  </input>

    <condition property="copy.file">
        <or>
            <equals arg1="Y" arg2="${choice}"/>
            <equals arg1="y" arg2="${choice}"/>
        </or>
    </condition>

</target>

In another target, I'd like to conditionally copy a file depending on whether or not the copy.file property is set. Is this possible? Is there some other way to accomplish it?


My Solution

Here's what I came up with based on ChrisH's response.

<target name="promptforchoice">

  <input addproperty="choice">
     Copy the file?.  [Y, n]
  </input>

    <condition property="copy.file">
        <or>
            <equals arg1="Y" arg2="${choice}"/>
            <equals arg1="y" arg2="${choice}"/>
        </or>
    </condition>

</target>

<target name="copyfile" if="copy.file">
    <copy file="file1.cfg" tofile="file2.cfg"/>
</target>

<target name="build" depends="promptforchoice">
    <antcall target="copyfile"/>

    <!--  Other stuff goes here -->

</target>

Thanks!

like image 203
braveterry Avatar asked Mar 12 '10 16:03

braveterry


1 Answers

You probably want something like:

<target name="mycopy" if="copy.file">
   <!-- do copy -->
</target>
like image 124
ChrisH Avatar answered Nov 15 '22 20:11

ChrisH