蚂蚁失败,除非'即使财产存在也会失败

时间:2014-11-24 02:02:50

标签: java ant ant-contrib

我有一个失败的Ant脚本,它应该没有。

属性文件:

application.foo.name=foo
application.foo.path=[path-to-foo]
application.foo.file=foo.jar
appName=

代码:

<target name="deploy_app" description="Deploys app">
  <condition property="appSelected">
    <and>
      <not>
        <equals arg1="${appName}" arg2="" />
      </not>
      <isset property="${appName}" />
    </and>
  </condition>

  <if>
    <equals arg1="${appSelected}" arg2="true" />
   <then>
    <!-- do nothing! -->
   </then>
   <else>
    <input
      message="Please enter application name:"
      addproperty="newAppName"
    />
    <var name="appName" value="${newAppName}" />
  </else>
</if>
  <antcall inheritAll="true" target="deploy" />
</target>

<target name="deploy">
    <echo message="Deploying from property: application.${appName}.file" />
  <propertycopy silent="true" name="appFile" from="application.${appName}.file" />
  <propertycopy silent="true" name="appPath" from="application.${appName}.path" />
  <echo message="appFile: ${appFile}" />
  <fail unless="${appFile}" message="appfile: ${appFile} No application with the name ${appName} is defined in your properties file." />
</target>

输出:

 [echo] Deploying from property: application.foo.file
 [echo] appFile: foo.jar
ERROR: The following error occurred while executing this line:
appfile: foo.jar No application with the name foo is defined in your properties file.

它甚至打印出房产的价值,但认为它不存在!

有什么理由?

1 个答案:

答案 0 :(得分:2)

unless命令的<fail>参数采用属性名称,而不是属性值!

修正版:

<fail unless="appFile" message="No application with the name ${appName} is defined in your properties file." />