【问题标题】:Ant: get directory of file from a **/* fileset selectorAnt:从 **/* 文件集选择器获取文件目录
【发布时间】:2012-05-16 17:41:55
【问题描述】:

我正在尝试修复 HTML5 Boilerplate ant 任务中的错误。 有一个“清单”目标可以自动创建一个 html5 缓存清单文件。

the build script 中的第 717 行是有 bug 的区域:

            <!-- add image files -->
            <echo message="Updating the site.manifest with the images"/>
            <for param="file">
                <path>
                    <fileset dir="./${dir.source}/${dir.images}/" includes="**/*"/>
                </path>
                <sequential>
                    <basename property="filename.@{file}" file="@{file}" />
                    <replaceregexp match="# image files" replace="# image files${line.separator}${dir.images}/${filename.@{file}}" file="${dir.intermediate}/${file.manifest}" />
                </sequential>
            </for>

问题是,给定一个目录结构,如:

img/image1.jpg
img/subdir/image2.jpg

输出忽略子目录:

img/image1.jpg
img/image2.jpg

解决此问题的最佳方法是什么?

【问题讨论】:

    标签: ant html5boilerplate build-tools


    【解决方案1】:

    我想通了:

                <!-- add image files -->
                <echo message="Updating the site.manifest with the images"/>
                <for param="file">
                    <path>
                        <fileset dir="./${dir.source}/${dir.images}/" includes="**/*"/>
                    </path>
    
                    <sequential>
                        <path id="fullPath.@{file}">
                            <pathelement location="@{file}" />
                        </path> 
                        <pathconvert property="relPath.@{file}" refid="fullPath.@{file}">
                            <globmapper from="${basedir}/*" to="*" />
                        </pathconvert>
                        <replaceregexp match="# image files" replace="# image files${line.separator}${relPath.@{file}}" file="${dir.intermediate}/${file.manifest}" />
                    </sequential>
                </for>
    

    它获取元素的绝对路径,然后使用 globmapper 删除 ${basedir} 部分,留下图像的相对路径。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-17
      • 2013-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多