Search code examples
antcopyxmltask

How can I print the filename which is being processes by xmltask?


In the below ant script snippet, I am processing all the conn.xml files in a directory to find out if there is a DB entry other than MyDB. This code only sets the DB name of the last match which is still okay as there is only one such file normally. But I want to name the exact file (out of those all included files) which has this invalid entry.

<xmltask>
   <fileset dir="${srcdir}/../apps" includes="*/conn.xml"/>
   <copy path="//Reference[@name!='MyDB']/@name" attrvalue="true" property="bad_connection_name"/>
</xmltask>

What parameter I can use in "path" field of copy command which will print the current file name as well?


Solution

  • <target name="check_connection_violations">
        <xmltask source="${file}">
            <copy path="//Reference[@className='oracle.jdeveloper.db.adapter.DatabaseProvider' and @name!='MyDB']/@name" attrvalue="true" property="bad_connection_name"/>
        </xmltask>
        <if>
            <isset property="bad_connection_name"/>
        <then>
            <echo message="${file} has connection violation due to ${bad_connection_name} entry. ${line.separator}" file="${basedir}/conn_name_violation.txt" append="true"/>
        </then>
        </if>
    </target>
    

    The above one is newly added target. Here is the original snippet which calls it in a loop :

    <foreach target="check_connection_violations" param="file">
        <fileset dir="${srcdir}/../apps" includes="*/conn.xml"/>
    </foreach>