【问题标题】:copy doesn't support the nested "if" element in Ant-contrib Nested Loop副本不支持 Ant-contrib 嵌套循环中的嵌套“if”元素
【发布时间】:2013-10-03 08:52:42
【问题描述】:

如果存在 DML.sql 文件,我需要将所有 dml.sql 文件复制到 DB2_List.txt 文件中。但执行此文件后,我收到如下错误: 副本不支持嵌套的“if”元素。

如果您对 Ant 中的嵌套循环有更好的了解,请告诉我。

<available file="DB/DML.sql" property="db.check.present"/>
<copy file="DB/DDL.sql" tofile="DB2/DB2_List.txt" >
<if> 
 <equals arg1="${db.check.present}" arg2="true"/>
 <then> 
 <filterchain> 
    <concatfilter append="DB/DML.sql" /> 
    <tokenfilter delimoutput="${line.separator}" /> 
</filterchain> 
</then> 
</if> 
</copy>

【问题讨论】:

    标签: ant copy ant-contrib


    【解决方案1】:

    有可能实现你所追求的,你只需要在 Ant 中以完全不同的方式处理它。请注意,您需要使用单独的目标。

    <target name="db.check">
      <available file="DB/DML.sql" property="db.check.present"/>
    </target>
    <target name="db.copy" depends="db.check" if="db.check.present">
      <copy file="DB/DDL.sql" tofile="DB2/DB2_List.txt" >
        <filterchain> 
          <concatfilter append="DB/DML.sql" /> 
          <tokenfilter delimoutput="${line.separator}" /> 
        </filterchain> 
      </copy>
    </target>
    

    【讨论】:

      【解决方案2】:

      看看 Ant 1.9.1,它支持标签上的特殊 if/unless 属性。这可能是可能的:

       <project name="mysterious.moe" basedir="."  default="package"
          xmlns:if="ant:if"
          xmlns:unless="ant:unless"/>
      
          <target name="db.copy">
              <available file="DB/DML.sql" property="db.check.present"/>
              <copy file="DB/DDL.sql" 
                  tofile="DB2/DB2_List.txt">
                  <filterchain if:true="db.ceck.present"> 
                      <concatfilter append="DB/DML.sql" /> 
                      <tokenfilter delimoutput="${line.separator}" /> 
                  </filterchain> 
             </copy>
          <target>
      ...
      </project>
      

      否则,您将不得不使用两个单独的副本。您不能将&lt;if&gt;antcontrib 放入任务中。仅围绕任务:

      <available file="DB/DML.sql" property="db.check.present"/>
      <if> 
          <equals arg1="${db.check.present}" arg2="true"/>
          <then> 
              <copy file="DB/DDL.sql" tofile="DB2/DB2_List.txt" >
                  <filterchain> 
                      <concatfilter append="DB/DML.sql" /> 
                      <tokenfilter delimoutput="${line.separator}" /> 
                  </filterchain>
              </copy>
              </then>
              <else>
                  <copy file="DB/DDL.sql" tofile="DB2/DB2_List.txt" >
              </else>
          </if> 
      </copy>
      

      【讨论】:

      • 嗨大卫,如果有四个 db 文件,我需要检查所有四个文件的可用性,并且根据可用性我需要将可用文件中的内容复制到单个文本文件中。例如:如果有 dbddl、dbdml、normalddl 和 normaldml 四个 db 文件,那么我需要检查以下情况。在第一种情况下,如果所有四个文件都可用(存在),则从所有四个文件中复制内容并粘贴到一个文本文件中。在第二种情况下,如果只有三个文件,则从所有三个文件中复制内容并粘贴到文本文件中。等等。
      • 看看&lt;macrodef/&gt; 任务。您可以创建一个&lt;copydb&gt; 宏任务来验证,如果需要,将 db 文件复制到您的文本文件中。
      猜你喜欢
      • 1970-01-01
      • 2015-10-27
      • 2012-05-13
      • 2015-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-05
      • 2018-09-19
      相关资源
      最近更新 更多