Grodriguez
Grodriguez

Reputation: 21995

Which "empty directories" are being copied by ant?

On a project that uses ant as a build tool, I have the following simplified directory structure:

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

And the following simplified ant script:

<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>

When I run this ant script, I see the following output:

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

Question: Why is ant reporting that "4 empty directories" are being copied? Shouldn't that be 1 empty directory (com/foo/bar)?

Upvotes: 1

Views: 120

Answers (1)

martin clayton
martin clayton

Reputation: 78105

Creating the directory com/foo/bar implies first creating com and then com/foo - i.e. three directories.

My version of Ant is slightly more verbose and shows each creation action:

$ 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

When bar2 is created it is (obviously) empty and so gets included in the count of four, even though it is non-empty by the time the copy completes.

Upvotes: 1

Related Questions