【问题标题】:Include ant modified selector based on condition根据条件包含 ant 修改的选择器
【发布时间】:2012-10-31 15:13:40
【问题描述】:

我正在修改我现有的 ant 脚本以支持差异构建。为此,我在文件集中使用了修改后的选择器来仅查找修改后的文件。但问题是当我进行完整构建时,我需要绕过基于某些属性或参数的修改过滤器。如下所示。有没有办法做到这一点。

<project name="test" default="dt" basedir=".">
    <target name="dt1">
        <copy todir="ant_temp2">
            <fileset dir="ant_temp1">
                <if>
                    <equals arg1="${ABC}" arg2="true" />
                    <then>
                        <modified update="true" />
                    </then>
                </if>
                <exclude name="*.txt"/>
            </fileset>
        </copy>
    </target>

    <target name="dt">
        <antcall target="dt1">
            <param name="ABC" value="true" />
        </antcall>
    </target>

    <target name="dt2">
        <antcall target="dt1" />    
    </target>
</project>

如果我使用dt 目标调用上述ant 脚本,那么我需要考虑modifiedfileset 任务中的exclude。如果它是使用dt2 调用的,那么我只需要在fileset 任务中考虑exclude

我无法使用上述脚本,因为fileset 不支持嵌套的if 任务。这就是为什么我正在寻找替代方法来做到这一点。请提出一些方法来做到这一点。

P.S:我不想创建具有相同复制任务的两个目标,其中一个在 fileset 中包含 modifiedexclude ,另一个目标仅包含 exclude

【问题讨论】:

    标签: if-statement ant ant-contrib fileset


    【解决方案1】:

    您可以在targets 上使用ifunless 属性,使其执行取决于属性。您应该将条件部分移动到它自己的目标(如果尚未完成),然后将ifunless 条件添加到目标。

    从您的示例中我并不完全清楚,但这可能意味着在两个目标中包含 copy,包括仅在其中一个目标中的 modified 部分。在这种情况下,您可以使每个目标以相同的属性为条件 - 一个为if,另一个为unless

    【讨论】:

    • 嗨 sudocode,感谢您的帮助,但我不想创建两个目标,其中复制任务一个包含 modifiedexclude,其他仅包含 exclude,因为这是现有的脚本和开发人员会定期添加更多excludes。如果我创建两个目标,那么他们必须在两个地方添加 exclude
    【解决方案2】:

    我使用下面的 ant 脚本来实现我的要求。

    <project name="test" default="dt" basedir=".">
        <patternset  id="fs1">
            <exclude name="*.txt"/>
        </patternset >
    
        <target name="dt1">
            <copy todir="ant_temp2">
                <fileset dir="ant_temp1">
                    <patternset refid="fs1" />
                </fileset>
            </copy>
        </target>
    
        <target name="dt3">
            <copy todir="ant_temp2">
                <fileset dir="ant_temp1">
                    <modified update="true" />
                    <patternset refid="fs1" />
                </fileset>
            </copy>
        </target>
    </project>
    

    我创建了可重用的模式集,开发人员将更新他们在该模式集中的排除项,我正在将该模式集重用于正常和增量构建。

    【讨论】:

      猜你喜欢
      • 2012-09-04
      • 1970-01-01
      • 2019-05-18
      • 2013-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-29
      • 1970-01-01
      相关资源
      最近更新 更多