用Ant,检查或比较在文件中列出的所有项目出现在其他文件或目录 [英] Using ant, check or compare all items listed in a file appear in another file or list

查看:179
本文介绍了用Ant,检查或比较在文件中列出的所有项目出现在其他文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在想,如果你能帮助。我是新来的蚂蚁脚本。

I was wondering if you could help. I am new to ant scripting.

我想能够比较两个列表。 FILE1.TXT将包含大量的参数的列表和FILE2.TXT将只包含这些参数的一个部分。

I want to be able to compare two lists. File1.txt will contain a list of a lot of parameters and file2.txt will only contain a section of those parameters.

FILE1.TXT

File1.txt

dbipAddress=192.168.175.130
QAGENT_QCF=AGENT_QCF
QADJUST_INVENTORY_Q=ADJUST_INVENTORY_Q
QCREATE_ORDER_Q=CREATE_ORDER_Q
QLOAD_INVENTORY_Q=LOAD_INVENTORY_Q

FILE2.TXT

File2.txt

AGENT_QCF
ADJUST_INVENTORY_Q
CREATE_ORDER_Q

我想知道,在FILE1.TXT所有的QS都包含在FILE2.TXT,经过'=',如果他们不那么Ant脚本将停止,将显示一条消息回如果他们再该脚本将移动到下一个。

I want to know that all the Qs in file1.txt are contained in file2.txt, after the '=', if they aren't then the ant script will stop and an Echo message will be displayed if they are then the script will move to the next .

因此​​,在该脚本上面的例子会停止,因为它不包含以下Q; QLOAD_INVENTORY_Q = LOAD_INVENTORY_Q。

So in the example above the script will stop as it does not contain the following Q; QLOAD_INVENTORY_Q=LOAD_INVENTORY_Q.

推荐答案

ANT是不是一种编程语言,所以我想你需要嵌入一个。

ANT is not a programming language, so I think you need to embed one.

下面的示例使用 Groovy的

<project name="demo" default="check">

    <target name="bootstrap">
        <mkdir dir="${user.home}/.ant/lib"/>
        <get dest="${user.home}/.ant/lib/groovy.jar" src="http://search.maven.org/remotecontent?filepath=org/codehaus/groovy/groovy-all/2.1.3/groovy-all-2.1.3.jar"/>
    </target>

    <target name="check">
        <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy"/>
        <groovy>
            def props = new Properties()
            new File("File1.txt").withInputStream { stream -> props.load(stream) }
            def requiredValues = new File("File2.txt").text.split()

            requiredValues.each { check ->
                if (! props.find{it.value == check}) {
                    ant.fail "Cannot find ${check} in File1.txt"
                }
            }
        </groovy>
    </target>

</project>

这篇关于用Ant,检查或比较在文件中列出的所有项目出现在其他文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆