1
votes

Folks,

When building our Android app in Ant (in Jenkins), we're running into a property scoping problem. This breaks our emma unit test coverage.

We use a global build.xml file, containing these lines:

    <target name="clean">
        <ant antfile="build.xml" dir="MyProject" target="clean"/>
        <ant antfile="build.xml" dir="MyTestProject" target="clean"/>
    </target>
    <target name="test">
        <ant antfile="build.xml" dir="MyTestProject" target="debug"/>
        <ant antfile="build.xml" dir="MyTestProject" target="installt"/>
        <ant antfile="build.xml" dir="MyTestProject" target="test"/>
   </target>
   <target name="emma">
     <ant antfile="build.xml" dir="MyTestProject" target="emma"/>
   </target>

As you can see, it starts targets in the individual projects. We build using clean emma test.

During the build, I print the value of emma.enabled, which is set to true by the emma target. However, by the time Ant reaches the debug target, emma.enabled is not set anymore. This causes our tests to be run without emma coverage enabled. According to the Ant Property task documentation, properties should retain their value:

By default, all of the properties of the current project will be available in the new project.

However, they clearly do not. I've been at this for some time now, hope you guys can help me out. Thanks!

1

1 Answers

0
votes

After trying thekbb's suggestion, I found out I could not include the build.xml from the subprojects, as this would not change the working directory. This caused all kinds of problems, I needed the build.xml of the subproject itself to be run.

In the end, I came up with this build.xml:

<target name="clean">
    <ant antfile="build.xml" dir="${env.label}-${env.omgeving}" target="clean"/>
    <ant antfile="build.xml" dir="MijnUnbrandedTest" target="clean"/>
</target>
<target name="test">
    <ant antfile="build.xml" dir="MijnUnbrandedTest">
        <target name="debug"></target>
        <target name="installd"></target>
        <target name="test"></target>
    </ant>
</target>
<target name="emmatest"> 
   <ant antfile="build.xml" dir="MijnUnbrandedTest">
      <target name="emma"></target>
      <target name="debug"></target>
      <target name="installd"></target>
      <target name="test"></target>
   </ant>
</target>

Instead of using a single target attribute, ant tasks allow the use of multiple target elements, each will be run in the same Ant tasks, and therefore scope. From the Ant task documentation:

You can specify multiple targets using nested elements instead of using the target attribute. These will be executed as if Ant had been invoked with a single target whose dependencies are the targets so specified, in the order specified.