Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant Copying Empty Directories

Tags:

copy

ant

I am still very new to ant and, although I know coldfusion, I don't know very much about java conventions, but I know that ant is built using java conventions. That being said I am working on an ant process to copy a project to a temp folder, change some code in the project, and then push the temp directory up to an FTP. I am trying to exclude all of my git, eclipse, and ant files from the copy so that my testing platform doesn't get cluttered. I setup a target to do the copy, but it seems that Ant not only is ignoring my excludes (which I am sure I wrote wrong), but it is only copying top level directories and files. No recursive copy. My current target is:

<target name="moveToTemp" depends="init">
    <delete dir="./.ant/temp" />
    <mkdir dir="./.ant/temp" />
    <copy todir="./.ant/temp">
        <fileset dir=".">
            <include name="*" />
            <exclude name=".*/**" />
            <exclude name=".*" />
            <exclude name="build.xml" />
            <exclude name="settings.xml" />
            <exclude name="WEB-INF/**" />
        </fileset>
        <filterset>
            <filter token="set(environment='design')" value="set(environment='testing')" />
        </filterset>
    </copy>
</target>

I know that I am not doing my excludes right, but I don't know what I am doing wrong with them. I see double asterisks (**) used all the time in Ant but I can't figure out

like image 443
Dave Long Avatar asked Feb 19 '11 21:02

Dave Long


People also ask

How do you remove multiple empty directories?

Delete Empty Files in a Directory First, search all the empty files in the given directory and then, delete all those files. This particular part of the command, find . -type f -empty -print, will find all the empty files in the given directory recursively. Then, we add the -delete option to delete all those files.

What is FileSet in Ant?

A FileSet is a group of files. These files can be found in a directory tree starting in a base directory and are matched by patterns taken from a number of PatternSets and Selectors. PatternSets can be specified as nested <patternset> elements.

How do you check if a directory is empty or not?

File. list() is used to obtain the list of the files and directories in the specified directory defined by its path name. This list of files is stored in a string array. If the length of this string array is greater than 0, then the specified directory is not empty.


1 Answers

By default an Ant fileset will (recursively) include all files under the specified directory, equivalent to:

<include name="**/*" />

That's the implicit include. If you supply an include, it overrides the implicit one.

Your include

<include name="*" />

Says 'match any file in the fileset directory', but that excludes traversal of subdirectories, hence your issue. Only files and the top-level directories are being copied.

See Patterns in the Ant docs for directory-based tasks: ** matches any directory tree (zero or more directories).

For your case you should be able to simply remove the 'include', so that the implicit 'include all' applies.

Suggest you also investigate the defaultexcludes task, which lets you set up this sort of thing once for the whole project.

like image 67
martin clayton Avatar answered Sep 26 '22 12:09

martin clayton