ant 在多个文件夹中均匀复制文件列表 [英] ant copy a list of files evenly across multiple folders

查看:21
本文介绍了ant 在多个文件夹中均匀复制文件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ant 来驱动一些测试自动化.我有一个扁平文件夹,里面有大约 100 个相同类型的文件.我想将这些文件均匀地分布在 4 个文件夹中,以将执行分布在几台机器上.因此,该项目将创建四个文件夹,然后遍历一百个文件,将一个文件传递到一个文件夹,然后继续.文件 1 转到文件夹 1、2 到 2、3 到 3、4 到 4、5 到 1 等.文件的名称和数量会波动.我可以编写一个小实用程序来执行此操作,但如果我可以将其作为 ant 执行的一部分来执行,那么维护起来会更简单.

I'm using ant to drive some test automation. I have a flattened folder that has about 100 files of the same type. I'd like to spread these files across 4 folders evenly to spread the execution across a few machines. So the project would create the four folders and then run through the hundred files passing one file to a folder and then continue on. file 1 goes to folder 1, 2 to 2, 3 to 3, 4 to 4, 5 to 1, etc. The names and numbers of files will fluctuate. I can write a small utility to do this but it would be simplier for maintanace if I could do this as part of the ant execution.

推荐答案

以下示例使用了 groovy ANT 任务,它很好地集成到 ANT 构建中:

The following example uses the groovy ANT task which integrates very well into an ANT build:

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

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

    <target name="distribute">
        <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy"/>
        <fileset id="srcFiles" dir="build/src" includes="*.txt"/>
        <groovy>
            def i = 0
            project.references.srcFiles.each {
                ant.copy(file:it, todir:"build/dir/${i % 4}", verbose:true)
                i++
            }
        </groovy>
    </target>

</project>

注意事项:

  • 使用模运算将包含在 ANT 文件集中的文件分发到不同的目录中
  • bootstrap"目标用于从 Maven 中心

这篇关于ant 在多个文件夹中均匀复制文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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