Search code examples
javapythonantfilesetcoverage.py

In Ant, how do I specify files with comma in filename?


Here is an example-target that I tried. Turns out, it wants to delete everything because the comma separates "**/*" and "cover" -- understandable.

<target name="clean">
    <delete
        verbose="true">
        <fileset dir="." includes="**/*.pyo"></fileset>
        <fileset dir="." includes="**/*,cover"></fileset>
    </delete>
</target>

How do I specify an embedded comma?

I'm trying to learn Ant so I won't have to maintain different build-systems for different operating-systems. In this case, it's in a Python environment, where *,cover files are created by a code-coverage checking tool called Coverage.


Solution

  • You don't need to escape this. Just use <include/> instead of includes arg. Try this:

    <project name="test" default="clean">
    
        <dirname property="build.dir" file="${ant.file.test}" />
    
        <target name="clean">
            <delete>
                <fileset dir="${build.dir}/test">
                    <include name="**/*,*.xml" />
                </fileset>
            </delete>
        </target>
    
    </project>
    

    By the way. You shouldn't use . (dot) in you dir argument. If you want to delete files in directory where you have got build.xml file you should pass absolute path (to do this you can use <dirname/> like in my example). If you will use . then you will have problems with nested build. Let's imageine that you have got two builds which delete files but first build also call second build:

    maindir/build1.xml

    <delete dir="." includes="**/*.txt" />
    <!-- call clean target from build2.xml -->
    <ant file="./subdir/build2.xml" target="clean"/>
    

    maindir/subdir/build2.xml

    <delete dir="." includes="**/*.txt" />
    

    In this case build2.xml won't delete *.txt files in subdir but *.txt files in maindir because ant properties will be passed to build2.xml. Of course you can use inheritAll="false" to omit this but from my experience I know that using . in paths will bring you a lot of problems.