【问题标题】:Change directory of FileList when referencing it引用时更改 FileList 的目录
【发布时间】:2012-02-20 15:12:57
【问题描述】:

稍后在我的构建文件中引用 FileList 时,我想更改它的基目录。

我定义如下FileList

<filelist dir="./dev" id="sourceFiles">
    <file name="files/file.php" />
    <file name="files/class.php" />
    <file name="files/functions.php" />
</filelist>

我的目标如下

<target name="fetch">
    <copy todir="./src/files">
        <filelist refid="sourceFiles" />
    </copy>
</target>

<target name="build" depends="fetch">
    <replaceregexp match="(\d+.\d+.\d+)(.\d+)?" replace="\1.${build.number}">
        <filelist refid="sourceFiles" />
    </replaceregexp>
</target>

因此,当使用 replaceregexp 任务时,它将使用位于 ./dev 中的文件 - 但我希望该任务在之前复制的文件中替换现在位于 ./src 中的文件。

当然,我可以复制文件列表并使用另一个dir,但我非常希望在我的构建文件中只保存一次文件列表。

我怎样才能做到这一点?

【问题讨论】:

标签: ant build directory copy filelist


【解决方案1】:

我认为您正在寻找的是复制命令中的映射器,如下所示:

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

    <property name="build.number" value="1.0.1"/>

    <target name="copy">
        <copy todir="build">
            <fileset dir="src"/>
            <regexpmapper from="^(.*)\.txt$" to="\1.${build.number}"/>
        </copy>
    </target>

    <target name="clean">
        <delete dir="build"/>
    </target>

</project>

这是我的测试文件

|-- build
|   `-- files
|       |-- one
|       |   |-- file1.1.0.1
|       |   `-- file2.1.0.1
|       `-- two
|           `-- file3.1.0.1
|-- build.xml
`-- src
    `-- files
        |-- one
        |   |-- file1.txt
        |   `-- file2.txt
        `-- two
            `-- file3.txt

【讨论】:

    猜你喜欢
    • 2015-03-28
    • 2016-09-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-04
    • 1970-01-01
    • 2012-02-10
    • 1970-01-01
    • 2015-09-04
    相关资源
    最近更新 更多