| 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

c, cdata, cdata, cobertura, cobertura, copyright, copyright, file, file, it, make, no, todo, unwar

The Cobertura build.xml source code

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

<project name="cobertura.examples.functionaltest1" basedir="." default="help" xmlns:cobertura="antlib:net.sourceforge.cobertura.ant">

    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

	<!-- Import the Cobertura Ant Library -->
	<property name="cobertura.local.library" location="../../antLibrary" />
	<import file="${cobertura.local.library}/library.xml" />

	<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" />
		<pathelement location="../../src" />
		<fileset dir="../../lib">
			<include name="*.jar" />

	<target name="taskdef">
		<taskdef resource="" classpathref="project.classpath" />
	<target name="taskdef-antlib">
			uri="antlib:net.sourceforge.cobertura.ant" />

	<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" classpathref="project.classpath" />

	<target name="instrument-includes-and-excludes" depends="compile,cobertura-groovy-init">
		<mkdir dir="${instrumented.dir}" />

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

	<target name="instrument-classpath" depends="compile,cobertura-groovy-init">
		<mkdir dir="${instrumented.dir}" />

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

	<target name="instrument-war" depends="compile,cobertura-groovy-init">
		<property name="tmp" value="tmp" />
		<property name="tmp.dir" value="${basedir}/${tmp}" />
		<property name="" location="${tmp.dir}/war" />
		<property name="this.test.wars" location="${tmp.dir}/wars" />
		<property name="this.test.extract" location="${tmp.dir}/extract" />
		<delete dir="${tmp.dir}" />
		<mkdir dir="${tmp.dir}" />

		<!-- Make a jar with a class from each package -->
		<zip destfile="${tmp.dir}/app.jar">
			<fileset dir="${classes.dir}">
				<include name="test/first/A.class" />
				<include name="test/second/B.class" />
				<include name="test/first/RemoteListener*.class" />
		<!-- TODO: 

		<!-- Make a war file -->
		<!-- This is required by the war task, but it can be empty -->
		<touch file="${tmp.dir}/web.xml" />
		<war destfile="${tmp.dir}/app.war" webxml="${tmp.dir}/web.xml">
			<lib dir="${tmp.dir}">
				<include name="app.jar" />
			<classes dir="${classes.dir}">
				<include name="test/first/B.class" />
				<include name="test/first/Test.class" />
				<include name="test/second/A.class" />

		<!-- Instrument the war file -->
		<mkdir dir="${instrumented.dir}" />

		<!-- Unwar and set the classpath to the unwarred stuff -->
		<unwar src="${instrumented.dir}/app.war" dest="${instrumented.dir}" />

		<delete dir="${tmp.dir}" />

		<path id="test.classpath">
			<path location="${instrumented.dir}/WEB-INF/classes" />
			<fileset dir="${instrumented.dir}/WEB-INF/lib">
				<include name="*.jar" />

	<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.first.Test" />

	<target name="coverage-reports-only" depends="cobertura-groovy-init">
	<target name="coverage-reports" depends="taskdef,coverage-reports-only" />
	<target name="coverage-reports-with-dirset" depends="cobertura-groovy-init">

	<target name="coverage-reports-with-archive" depends="cobertura-groovy-init">

	<target name="coverage-check-only" depends="cobertura-groovy-init">
	<target name="coverage-check" depends="taskdef-antlib,coverage-check-only" />

	<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-dirset" depends="taskdef-antlib,clean,compile,instrument-includes-and-excludes,test,coverage-reports-with-dirset,coverage-check-only" />
	<target name="test-includes-and-excludes" depends="taskdef,clean,compile,instrument-includes-and-excludes,test,coverage-reports-only" />
	<target name="test-classpath" depends="taskdef,clean,compile,instrument-classpath,test,coverage-reports-only" />
	<target name="test-war" depends="taskdef,clean,compile,instrument-war,test,coverage-reports-with-archive" />
	<target name="all" depends="taskdef,test-includes-and-excludes,test-classpath" />


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.