【问题标题】:How to use a glob pattern for a location attribute of a property?如何将全局模式用于属性的位置属性?
【发布时间】:2018-03-20 22:27:24
【问题描述】:

我想将一个属性设置为一个文件名,我知道一个与唯一文件匹配的模式。例如,我有文件:

plugins/doc.en_20110608.zip

我在我的 ant 文件中定义:

<property name="doc.zip" location="plugins/doc.en_*.zip" />

我知道该模式只会匹配一个文件。问题是 ant 此时没有尝试匹配任何模式,并且由于没有名为 plugins/doc.en_*.zip 的文件而失败。

如果我没有使用 fileset,那是因为可以在不允许使用 fileset 的地方替换属性,例如 destfile 属性zip 任务。

<zip destfile="${doc.zip}" update="true"> ... </zip>

【问题讨论】:

    标签: ant properties design-patterns


    【解决方案1】:

    我认为答案是否定的,但您可以使用reference/path shortcuts 将文件集“字符串化”为属性。比如:

    <fileset id="doc.zip.fs" dir="plugins" includes="doc.en_*.zip"/>
    <property name="doc.zip" value="${toString:doc.zip.fs}" />
    

    【讨论】:

    • 只是一个警告:属性 doc.zip 只包含文件名,而不是完整位置。请改用 location="plugins/${toString:doc.zip.fs}"。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-22
    • 1970-01-01
    • 2019-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多