代码之家  ›  专栏  ›  技术社区  ›  Grodriguez

Ant正在复制哪些“空目录”?

ant
  •  1
  • Grodriguez  · 技术社区  · 6 年前

    在一个使用 ant 作为一个构建工具,我有以下简化的目录结构:

    src/
       com/
          foo/
             bar/
                (some files)
             bar2/
                (some other files)
    

    以及以下简化的Ant脚本:

    <project default="all">
        <target name="all">
            <delete dir="dst"/>
            <mkdir dir="dst"/>
            <copy todir="dst">
                <fileset dir="src" excludes="com/foo/bar/*"/>
            </copy>
        </target>
    </project>
    

    当我运行这个Ant脚本时,我看到以下输出:

    all:
       [delete] Deleting directory /home/grodriguez/workspace/_test/anttest/dst
        [mkdir] Created dir: /home/grodriguez/workspace/_test/anttest/dst
         [copy] Copying 1 file to /home/grodriguez/workspace/_test/anttest/dst
         [copy] Copied 4 empty directories to 1 empty directory under /home/grodriguez/workspace/_test/anttest/dst
    

    问:为什么Ant报告正在复制“4个空目录”?那不应该是1个空目录吗(com/foo/bar)?

    1 回复  |  直到 6 年前
        1
  •  1
  •   martin clayton egrunin    6 年前

    正在创建目录 com/foo/bar 意味着先创造 com 然后 com/foo -即三个目录。

    我的Ant版本稍微详细一点,显示了每个创建操作:

    $ ant -v
    Apache Ant(TM) version 1.10.2 compiled on February 3 2018
    ... deleted for brevity ....
        [mkdir] Created dir: /stack/ant/dst
         [copy] com/foo/bar2/x.txt added as com/foo/bar2/x.txt doesn't exist.
         [copy]  omitted as /stack/ant/dst is up to date.
    1    [copy] com added as com doesn't exist.
    2    [copy] com/foo added as com/foo doesn't exist.
    3    [copy] com/foo/bar added as com/foo/bar doesn't exist.
    4    [copy] com/foo/bar2 added as com/foo/bar2 doesn't exist.
         [copy] Copying 1 file to /stack/ant/dst
         [copy] Copying /stack/ant/src/com/foo/bar2/x.txt to /stack/ant/dst/com/foo/bar2/x.txt
         [copy] Copied 4 empty directories to 1 empty directory under /stack/ant/dst
    

    什么时候? bar2 创建时,它(显然)是空的,因此包含在四个计数中,即使在复制完成时它是非空的。