Subinterval subtleties

I have ant code that runs release builds in all subdirectories:

<target name="all-release" > <subant target="sub-release" failonerror="true"> <fileset dir="." includes="*/build.xml" /> </subant> </target> 

As it is written, if any individual assembly fails, the all-release will fail quickly (none of the subsequent assemblies will be successful. If I switch failonerror = "false", the all-release will succeed all the time. It turns out that all the substrings are independent, so I really want:

run all builds for sub-releases, and then after all-release fails, if one or more sub-items did not work (ideally, with a good error message that caused the build to fail).

Any ideas?

+4
source share
2 answers

Offer to see the extensions available in ant-contrib tasks.

The task for can be adapted to your requirements.

Your all-release target, with ant -contrib taskdef, might look something like this:

 <taskdef resource="net/sf/antcontrib/antlib.xml"> <classpath> <pathelement location="lib/ant-contrib-1.0b3.jar"/> </classpath> </taskdef> <target name="all-release"> <for keepgoing="true" param="file"> <path> <fileset dir="." includes="*/build.xml" /> </path> <sequential> <ant antfile="@{file}" target="sub-release" /> </sequential> </for> </target> 

Using some other ant -contrib functions, it is possible to get a list of crashes.

Example log above build.xml:

 $ ant all-release Buildfile: build.xml all-release: [echo] /work/Scratch/dir1/build.xml sub-release: [echo] dir1 [echo] /work/Scratch/dir2/build.xml sub-release: [echo] dir2 [for] /work/Scratch/dir2/build.xml: The following error occurred while executing this line: [for] /work/Scratch/build.xml:17: The following error occurred while executing this line: [for] /work/Scratch/dir2/build.xml:6: dir2 failed [echo] /work/Scratch/dir3/build.xml sub-release: [echo] dir3 BUILD FAILED /work/Scratch/build.xml:11: Keepgoing execution: 1 of 3 iterations failed. Total time: 0 seconds 
+3
source

Antelope Ant extensions have a try-catch command that can be used for what you need:

 <taskdef name="try" classname="ise.antelope.tasks.TryTask"/> .... <try break="false" printmessage="true" > <antcall target="xmlValidate" /> <antcall target="runJunit" /> <antcall target="..." /> <catch> <property name="haderrors" value="true"/> </catch> </try> <fail message="FAILED" if="haderrors" /> 

break=false continue the next command after the failure. But failed targets set the haderrors property, which is checked at the end. I used it to create tasks (and it works great), but I'm not sure if it works for <fileset> inside <subant> . Perhaps you need to explicitly specify all calls to <subant> .

+1
source

All Articles