how to use<MacroDef> for recourcecount of all file in folder with different extension

105 Views Asked by At

While going through the scenario what i got is that folder collection of different extension file i have use resource count for all extension if i have 3 different extension file than try to get resource count of all file differ with extension
Eg:

    <resourcecount property="firstfile">
    <fileset dir="${basedir}">
        <include name="*.xml" />
    </fileset>
</resourcecount>
<echo message="There are ${firstfile} xml in This Folder ${basedir}" />
<resourcecount property="SecondFile">
    <fileset dir="${basedir}">
        <include name="*.jar" />
    </fileset>
</resourcecount>
<echo message="There are ${SecondFile} xml in This Folder ${basedir}" />

How can i use the macrodef for this condition which help in count all file with it

1

There are 1 best solutions below

0
Timir On

You can do this in many ways, including using plugins, such as ant-contrib, or using ant language extensions. But all of them are overkill compared to this simple build script:

<target name="count">
    <countresources type="xml" />
    <countresources type="java" />
    <countresources type="cpp" />
</target>

<macrodef name="countresources">
    <attribute name="type" />
    <sequential>
        <resourcecount property="@{type}.count">
            <fileset dir="${basedir}">
                <include name="*.@{type}" />
            </fileset>
        </resourcecount>
        <echo message="There are ${@{type}.count} @{type} files in folder ${basedir}" />
    </sequential>
</macrodef>

Hope this helps.