简体   繁体   English

复制不支持Ant-contrib嵌套循环中的嵌套“ if”元素

[英]copy doesn't support the nested “if” element in Ant-contrib Nested Loop

I need to copy all dml.sql files to inside DB2_List.txt file if DML.sql file is present. 如果存在DML.sql文件,我需要将所有dml.sql文件复制到DB2_List.txt文件中。 But after executing this file i'm getting error like this: copy doesn't support the nested "if" element. 但是执行此文件后,我得到如下错误:复制不支持嵌套的“ if”元素。

Please let me know if you have any better idea about the nested loop in Ant. 如果您对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>

It is possible to accomplish what you are after, you just have to approach it quite differently in Ant. 可以完成您所追求的目标,而您只需要在Ant中使用完全不同的方法即可。 Just note that you will need to utilize separate targets. 请注意,您将需要利用单独的目标。

<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>

Take a look at Ant 1.9.1 which supports special if/unless attributes on tags. 看一下Ant 1.9.1,它支持标记上特殊的if / unless属性。 This might be possible: 可能是可能的:

 <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>

Otherwise, you'll have to use two separate copies. 否则,您将必须使用两个单独的副本。 You can't put <if> antcontrib inside tasks. 您不能在任务中放入<if> antcontrib。 Only around tasks: 仅围绕任务:

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM