| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Cobertura example source code file (build.xml)

This example Cobertura source code file (build.xml) is included in the "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Cobertura tags/keywords

absolutely, c, c, cobertura, cobertura, copyright, copyright, general, it, lewis, license, no, public, the

The Cobertura build.xml source code

<?xml version="1.0" encoding="UTF-8"?>

<project name="cobertura.examples.functionalconditiontest" basedir="." default="help">

    Cobertura -
    Copyright (C) 2003 jcoverage ltd.
    Copyright (C) 2005 Mark Doliner
	Copyright (C) 2006 John Lewis
    Cobertura is licensed under the GNU General Public License
    Cobertura comes with ABSOLUTELY NO WARRANTY

	<property file="" />

	<path id="project.classpath">
		<path path="${java.class.path}" />
		The next two should only come into play when running this script directly as
		opposed to being called by a functional test.
		<pathelement location="../../etc" />
		<pathelement location="../../build/classes" />
		<fileset dir="../../lib">
			<include name="*.jar" />

	<taskdef resource="" classpathref="project.classpath"/>

	<target name="help">
		<echo>This example is only used for testing, and is not meant
		<echo>to be run from the command line.  It requires certain 
		<echo>classes to be on the class path to work correctly.

	<target name="compile">
		<mkdir dir="${classes.dir}" />
		<javac srcdir="${src.dir}" destdir="${classes.dir}" debug="true" />

	<target name="instrument-condition-coverage" depends="compile">
		<mkdir dir="${instrumented.dir}" />
		<cobertura-instrument datafile="${basedir}/cobertura.ser" todir="${instrumented.dir}">
			<ignore regex="org.apache.log4j.*" />
			<fileset dir="${classes.dir}">
				<include name="**/*.class" />
				<exclude name="**/*Test*" />

		<path id="test.classpath">
			<path location="${instrumented.dir}" />

	<target name="test" depends="compile">
		<junit fork="true" dir="${basedir}" haltonfailure="true">
			<classpath refid="test.classpath" />
			<classpath location="${classes.dir}" />
			<classpath path="${java.class.path}" />
			<classpath refid="project.classpath" />

			<formatter type="plain" usefile="false" />
			<test name="test.condition.Test" />

	<target name="coverage-reports">
		<mkdir dir="${coverage.xml.dir}" />
		<cobertura-report datafile="${basedir}/cobertura.ser" srcdir="${src.dir}" destdir="${coverage.xml.dir}" format="xml" />

		<mkdir dir="${coverage.html.dir}" />
		<!-- maxmemory is only specified to test the attribute -->
		<cobertura-report datafile="${basedir}/cobertura.ser" destdir="${coverage.html.dir}" maxmemory="512M">
			<fileset dir="${src.dir}">
				<include name="**/*.java" />

	<target name="coverage-check">
		<cobertura-check branchrate="34" totallinerate="100" />

	<target name="clean">
		<delete dir="${classes.dir}" />
		<delete dir="${instrumented.dir}" />
		<delete dir="${reports.dir}" failonerror="false"/>
		<delete file="cobertura.log" />
		<delete file="cobertura.ser" />
		<delete file="cobertura.ser.lock" />

	<target name="test-condition-coverage" depends="clean,compile,instrument-condition-coverage,test,coverage-reports" />
	<target name="all" depends="test-condition-coverage" />


Other Cobertura examples (source code examples)

Here is a short list of links related to this Cobertura build.xml source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.