0

I have an ant condition like this:

   <condition property="create_stub">
    <and>
      <available file="${create_stub_command_file}" property="stub_script.present" />
      <isset property="packaged_stub_file"/>
    </and>
   </condition>

My understanding is: If create_stub_command_file is present then set stub_script.present=true. But I am not sure about

<isset property="packaged_stub_file"/>

What is this doing? And how does it change the overall condition. i.e In which case would the condition block evaluate to true?

4

2 回答 2

1

一个小错误?

<condition property="create_stub">
    <and>
       <available file="${create_stub_command_file}" property="stub_script.present" />
       <isset property="packaged_stub_file"/>
    </and>
</condition>

我不相信这property="stub_script.present"是在做任何事情。它应该是:

<condition property="create_stub">
    <and>
       <available file="${create_stub_command_file}"/>
       <isset property="packaged_stub_file"/>
    </and>
</condition>

该条件语句所做的只是设置一个名为create_stub. {$create_stub_command_file}如果一个名为whatever的文件或目录都存在,并且该属性packaged_stuf_file设置为任何值,它将设置该属性。只要设置了该属性,packaged_stub_file就可以将其设置为false、空字符串、trueYES! YES! YES!或任何内容。

所以现在你可以使用这个属性作为一个目标的测试

<target name="package_stub"
    if="create_stub">
    <blah...blah...blah/>
    <yadda...yadda...yadda/>
</target>

这个目标,只有在设置package_stub了属性时才会执行package_stub<condition>并且仅当上述情况为真时才会设置。

<condition>语句应该在任何目标之外,因此它将在执行任何目标之前首先执行。

于 2013-07-15T21:19:13.283 回答
0

等效伪代码:

if (File($create_stub_command_file).exists) then
   property["stub_script.present"] := true
end 

if (File($create_stub_command_file).exists AND property["property["stub_script.present"] != NULL) then
   property["create_stub"] := true
end 

原谅任何错误......我发现条件块很棘手,它们需要大量测试。最好让它们保持简单。ANT 不是一种编程语言。

于 2013-07-15T21:10:36.877 回答