ANT xmlproperty: demux properties with multiple values

370 views Asked by At

I'm using cobertura to calculate test coverage. I want my ant script to echo coverage information about specific packages.

So far, I have:

   <target name="coverage-check">
        <loadfile property="coveragexml" srcFile="${coverage.report.dir}/coverage.xml">
          <filterchain>
            <linecontains negate="true">
              <contains value="!DOCTYPE"/>
            </linecontains>
          </filterchain>
        </loadfile>

        <xmlproperty validate="false">
            <string value="${coveragexml}"/>
        </xmlproperty>
    </target>

This works to load the various cobertura information into ant variables like: coverage.packages.package(name)=lots,of,package,names.

I'd like to find a way to appropriate a specific package name (from one variable) to coverage metrics stored in other variables. If I were using python, lisp, or the like, I'd zip them together, then search. I don't know how to do zipping or searching in ant.

1

There are 1 answers

1
Hank Lapidez On

I made an example with use of xmltask

<target name="xml-test">
        <taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" classpathref="extension.classpath"/>
        <property name="xml.file" location="coverage.xml"></property>

        <!-- package to search for -->  
        <property name="packageName" value="foo"></property>

        <!-- extract for example line-rate and echo it -->
        <xmltask source="${xml.file}">
            <copy path="/coverage/packages/package[@name='${packageName}']/@line-rate" property="line-rate" />
        </xmltask>

        <echo>
            Line Rate: ${line-rate}
        </echo>

        <!-- extract complete xml-block for package ${packageName} 
        and write it to other file
        -->

        <xmltask source="${xml.file}">
            <copy path="/coverage/packages/package[@name='${packageName}']" buffer="foo-buffer" append="true" />
        </xmltask>
        <!-- write cut out to file -->
        <xmltask dest="foo-coverage.xml">
            <insert  path="/" buffer="foo-buffer"/>
        </xmltask>
    </target>

The snipped copied from the source xml can unfortunately not echoed by default, but written to another file.

It's not a solution but an example that may be helps.

I think it would be less work to write a custom ant task your self.