开发者

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

开发者 https://www.devze.com 2022-12-22 14:50 出处:网络
I have the following target: <target name=\"promptforchoice\"> <input addproperty=\"choice\">

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 co开发者_开发知识库py.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!


You probably want something like:

<target name="mycopy" if="copy.file">
   <!-- do copy -->
</target>
0

精彩评论

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