alvinalexander.com | 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 DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Cobertura tags/keywords

cobertura, cobertura, copying, copying, copyright, copyright, create, eclipse, file, readme, the, this, utf-8, utf-8

The Cobertura build.xml source code

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

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

	<description>
    Cobertura - http://cobertura.sourceforge.net/
    The copyright for this program is retained by its contributors
    See the included COPYRIGHT file for a complete list of contributors
    Cobertura is licensed under the GNU General Public License
    Cobertura comes with ABSOLUTELY NO WARRANTY
	</description>

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


	<path id="base.path">
		<fileset dir="${lib.dir}">
			<include name="**/*.jar" />
		</fileset>
		<fileset dir="${jetty.dir}">
			<include name="lib/servlet-api*.jar" />
		</fileset>
	</path>

	<path id="cobertura.classpath">
		<pathelement location="cobertura.jar" />
		<fileset dir="${lib.dir}">
			<include name="**/*.jar" />
		</fileset>
	</path>

	<macrodef name="cobertura-taskdef">
		<sequential>
			<taskdef classpathref="cobertura.classpath" resource="tasks.properties" />

			<!--
				This is probably a bug in Eclipse, but the Eclipse ant
				editor seems to lock the classpath of the last taskdef,
				so we do a taskdef of one of the core ant tasks so that
				cobertura.jar does not become locked.
			-->
			<taskdef name="not-used" classname="org.apache.tools.ant.taskdefs.Delete">
				<classpath>
					<pathelement path="${java.class.path}" />
				</classpath>
			</taskdef>
		</sequential>
	</macrodef>

	<target name="init">
		<!-- Insert our version number in a file. -->
		<filter token="version" value="${version}" />
		<copy file="${etc.dir}/plugin.xml" todir="${build.dir}" filtering="true" overwrite="true" />
	</target>

	<target name="compile" depends="init">
		<mkdir dir="${build.classes.dir}" />
		<javac fork="true" srcdir="${src.dir}" destdir="${build.classes.dir}" debug="true" encoding="UTF-8"
			target="${javac.target}">
			<compilerarg value="-Xlint:unchecked" compiler="javac1.5"/>
			<classpath location="${build.classes.dir}" />
			<classpath refid="base.path" />
		</javac>

		<mkdir dir="${build.otherclasses.dir}" />
		<javac fork="true" srcdir="${othersrc.dir}" destdir="${build.otherclasses.dir}" debug="true" encoding="UTF-8"
			target="${javac.target}">
			<compilerarg value="-Xlint:unchecked" compiler="javac1.5"/>
			<classpath location="${build.classes.dir}" />
			<classpath refid="base.path" />
		</javac>

		<mkdir dir="${build.functionalconditiontest.dir}" />
		<javac fork="true" srcdir="${examples.functionalconditiontest.dir}" destdir="${build.functionalconditiontest.dir}" debug="true" encoding="UTF-8"
			target="${javac.target}">
			<compilerarg value="-Xlint:unchecked" compiler="javac1.5"/>
			<classpath location="${build.classes.dir}" />
			<classpath refid="base.path" />
		</javac>

		<!-- Copy jar resources (css, images, log4j property file, etc.) -->
		<copy todir="${build.classes.dir}">
			<fileset dir="${src.dir}">
				<exclude name="**/*.java" />
			</fileset>
		</copy>
	</target>

	<target name="compile-tests" depends="init,compile,cobertura-groovy-init">
		<mkdir dir="${build.test.classes.dir}" />
		<cobertura:groovyc srcdir="${test.src.dir}" destdir="${build.test.classes.dir}" encoding="UTF-8">
			<classpath location="${build.classes.dir}" />
			<classpath location="${build.test.classes.dir}" />
			<classpath refid="base.path" />
			<classpath location="${build.otherclasses.dir}" />
			<classpath location="${build.functionalconditiontest.dir}" />
			<classpath path="${java.class.path}"/>
			<javac debug="true" encoding="UTF-8" >
				<compilerarg value="-Xlint:unchecked" compiler="javac1.5"/>
			</javac>
		</cobertura:groovyc>

		<copy todir="${build.test.classes.dir}">
			<fileset dir="${test.src.dir}">
				<exclude name="**/*.java" />
			</fileset>
		</copy>
	</target>

	<target name="jar" depends="init,compile">
		<mkdir dir="${build.dist.dir}" />

		<!-- the standard jar for Cobertura -->
		<jar jarfile="${basedir}/${ant.project.name}.jar" compress="true">
			<fileset dir="${build.classes.dir}">
				<include name="**/*.class" />
			</fileset>
			<fileset dir="${etc.dir}">
				<include name="log4j.properties" />
				<include name="tasks.properties" />
			</fileset>
			<fileset dir="${src.dir}">
				<exclude name="**/*.java" />
				<exclude name="**/package.html" />
			</fileset>
			<fileset dir="${basedir}">
				<include name="COPYING" />
				<include name="COPYRIGHT" />
				<include name="README" />
			</fileset>
			<manifest>
				<attribute name="Specification-Title" value="${description}"/>
				<attribute name="Specification-Vendor" value="Cobertura"/>
				<attribute name="Specification-Version" value="${version}"/>
				<attribute name="Implementation-Title" value="${description}"/>
				<attribute name="Implementation-Vendor" value="Cobertura"/>
				<attribute name="Implementation-Vendor-Id" value="net.sourceforge.cobertura"/>
				<attribute name="Implementation-Version" value="${version}"/>
			</manifest>
		</jar>

		<!--
			Eclipse needs the ANT tasks and the runtime of Cobertura to be split into
			separate jars, otherwise lots of bad things happen in eclipse to do with
			class loading.
		-->
		<mkdir dir="${build.dist.eclipse.dir}" />
		<jar jarfile="${build.dist.eclipse.dir}/${ant.project.name}.jar">
			<fileset dir="${build.classes.dir}">
				<include name="net/sourceforge/cobertura/ant/**/*.class" />
			</fileset>
			<fileset dir="${etc.dir}">
				<include name="tasks.properties" />
			</fileset>
			<manifest>
				<attribute name="Specification-Title" value="${description}"/>
				<attribute name="Specification-Vendor" value="Cobertura"/>
				<attribute name="Specification-Version" value="${version}"/>
				<attribute name="Implementation-Title" value="${description}"/>
				<attribute name="Implementation-Vendor" value="Cobertura"/>
				<attribute name="Implementation-Vendor-Id" value="net.sourceforge.cobertura"/>
				<attribute name="Implementation-Version" value="${version}"/>
			</manifest>
		</jar>
		<jar jarfile="${build.dist.eclipse.dir}/${ant.project.name}-main.jar">
			<fileset dir="${build.classes.dir}">
				<exclude name="net/sourceforge/cobertura/ant/**/*.class" />
			</fileset>
			<fileset dir="${etc.dir}">
				<include name="log4j.properties" />
				<include name="tasks.properties" />
			</fileset>
			<manifest>
				<attribute name="Specification-Title" value="${description}"/>
				<attribute name="Specification-Vendor" value="Cobertura"/>
				<attribute name="Specification-Version" value="${version}"/>
				<attribute name="Implementation-Title" value="${description}"/>
				<attribute name="Implementation-Vendor" value="Cobertura"/>
				<attribute name="Implementation-Vendor-Id" value="net.sourceforge.cobertura"/>
				<attribute name="Implementation-Version" value="${version}"/>
			</manifest>
		</jar>
	</target>
	
	<target name="war" depends="cobertura-groovy-init">
		<cobertura:groovy>
			//load buildUtil definitions
			evaluate(new File("buildUtil.groovy"))
			
			buildWar(new File("coberturaFlush.war"))
		</cobertura:groovy>
	</target>

	<target name="instrument" depends="jar">
		<delete file="${basedir}/cobertura.ser" />
		<delete file="${build.dir}/cobertura.ser" /> 

		<cobertura-taskdef />

		<cobertura-instrument datafile="${build.dir}/cobertura.ser" todir="${build.instrumented.dir}">
		    <fileset dir="${build.classes.dir}">
		        <include name="**/*.class" />
		        <exclude name="**/*Test.class" />
				<exclude name="net/sourceforge/cobertura/javancss/**/*.class" />
		    </fileset>
		    <fileset dir="${build.otherclasses.dir}">
		        <include name="**/*.class" />
		        <exclude name="**/*Test.class" />
		    </fileset>
		</cobertura-instrument>
	</target>

	<!--
		This target is used when testing both instrumented and
		non-instrumented code.  The net.sourceforge.cobertura.datafile
		sysproperty is only used if we're testing instrumented code.
	-->
	<target name="test" depends="compile-tests">
		<delete dir="${build.reports.dir}/junit-xml" failonerror="false" />
		<delete dir="${test.work.dir}" failonerror="false" />
		<mkdir dir="${build.reports.dir}/junit-xml" />

		<junit fork="true" forkmode="once" haltonfailure="false" failureProperty="test.failed" printsummary="true" timeout="900000">
			<sysproperty key="net.sourceforge.cobertura.datafile" file="${build.dir}/cobertura.ser" />
			<sysproperty key="basedir" value="${basedir}"/>
			<jvmarg value="-Xmx512M" />
			<!--
			<jvmarg value="-Xdebug" />
			<jvmarg value="-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y" />
			-->
			<classpath location="${build.test.classes.dir}" />
			<classpath location="${build.instrumented.dir}" />
			<classpath location="${build.classes.dir}" />
			<classpath location="${build.otherclasses.dir}" />
			<classpath location="${etc.dir}" />
			<classpath refid="base.path" />
			<classpath refid="cobertura.common.local.library" />
			<classpath>
				<fileset dir="${java.home}/../">
					<include name="lib/tools.jar"/>
				</fileset>
			</classpath>
			<formatter type="xml" />
			<formatter type="plain" usefile="false" />
			<test name="${testcase}" todir="${build.reports.dir}/junit-xml" if="testcase" />
			<batchtest todir="${build.reports.dir}/junit-xml" unless="testcase">
				<fileset dir="${build.test.classes.dir}">
					<include name="**/*Test.class" />
					<exclude name="test/first/Test.class" />
					<exclude name="test/condition/Test.class" />
				</fileset>
			</batchtest>
		</junit>

		<delete dir="${build.reports.dir}/junit-html" failonerror="false" />
		<mkdir dir="${build.reports.dir}/junit-html" />

		<junitreport todir="${build.reports.dir}/junit-html">
			<fileset dir="${build.reports.dir}/junit-xml">
				<include name="TEST-*.xml" />
			</fileset>
			<report format="frames" todir="${build.reports.dir}/junit-html" />
		</junitreport>

	</target>

	<target name="coverage-report">
		<cobertura-taskdef />

		<delete dir="${build.reports.dir}/coverage-html" failonerror="false" />
		<mkdir dir="${build.reports.dir}/coverage-html" />
		<cobertura-report datafile="${build.dir}/cobertura.ser"
		                  destdir="${build.reports.dir}/coverage-html"
		                  format="html"
		                  >
			<fileset dir="${src.dir}">
				<include name="**/*.java" />
			</fileset>				  
			<fileset dir="${othersrc.dir}">
				<include name="**/*.java" />
			</fileset>
	    </cobertura-report>

		<delete dir="${build.reports.dir}/coverage-xml" />
		<mkdir dir="${build.reports.dir}/coverage-xml" />
		<cobertura-report datafile="${build.dir}/cobertura.ser"
		                  destdir="${build.reports.dir}/coverage-xml"
		                  format="xml"
					      >
			<fileset dir="${src.dir}">
				<include name="**/*.java" />
			</fileset>				  
			<fileset dir="${othersrc.dir}">
				<include name="**/*.java" />
			</fileset>
		</cobertura-report>

	</target>

	<!--
	<target name="format">
		<property name="dir.jalopy" value="${lib.dir}/jalopy" />
		<taskdef name="jalopy" classname="de.hunsicker.jalopy.plugin.ant.AntPlugin">
			<classpath>
				<fileset dir="${dir.jalopy}">
					<include name="*.jar" />
				</fileset>
			</classpath>
		</taskdef>

		<jalopy fileformat="unix"
			convention="etc/jalopy.xml"
			loglevel="info"
			classpathref="base.path">
			<fileset dir="${src.dir}">
				<include name="**/*.java" />
			</fileset>
			<fileset dir="${test.src.dir}">
				<include name="**/*.java" />
			</fileset>
		</jalopy>
	</target>
	-->

	<target name="javadoc">
		<delete dir="${build.api.dir}" />
		<mkdir dir="${build.api.dir}" />

		<javadoc access="private" author="true" breakiterator="true" destdir="${build.api.dir}" failonerror="true" encoding="UTF-8" linksource="true" serialwarn="false" version="true" windowtitle="Cobertura API">
			<fileset dir="${src.dir}">
				<include name="**/*.java" />
			</fileset>
			<classpath location="${ant.home}/lib/ant.jar" />
			<classpath refid="base.path" />
		</javadoc>
	</target>

	<target name="dist" depends="jar,javadoc">
		<!--
			Copy the files needed for the binary jar to a clean directory
			tree.  The "binary" jar contains the minimum files needed to
			use Cobertura.
		-->
		<copy-unix-scripts todir="${build.dist.dir}/package-bin/cobertura-${version}" />
				
		<copy todir="${build.dist.dir}/package-bin/cobertura-${version}">
			<fileset dir="${basedir}">
				<include name="ChangeLog" />
				<include name="cobertura-*.bat" />
				<include name="COPYING" />
				<include name="COPYRIGHT" />
				<include name="README" />
				<include name="lib/**" />

				<!-- Exclude jars that are only used by the JUnit tests -->
				<exclude name="lib/jaxen*" />
				<exclude name="lib/jdom*" />
				<exclude name="lib/junit*" />
				<exclude name="lib/xerces/**" />
				<exclude name="lib/xalan*" />

				<include name="cobertura.jar" />
				<include name="coberturaFlush.war" />
				<include name="examples/basic/README" />
				<include name="examples/basic/build.properties" />
				<include name="examples/basic/*.xml" />
				<include name="examples/basic/src/**" />
			</fileset>
		</copy>

		<!--
			Copy the files needed for the source jar to a clean directory
			tree.  The "source" jar contains everything needed to build
			Cobertura.
		-->
		<copy-unix-scripts todir="${build.dist.dir}/package-src/cobertura-${version}" />

		<copy todir="${build.dist.dir}/package-src/cobertura-${version}">
			<fileset dir="${basedir}">
				<include name="antLibrary/**" />
				<include name="ChangeLog" />
				<include name="cobertura-*.bat" />
				<include name="COPYING" />
				<include name="COPYRIGHT" />
				<include name="README" />
				<include name="build.properties" />
				<include name="build.xml" />
				<include name="etc/**" />
				<include name="lib/**" />
				<include name="resources/**" />
				<include name="src/**" />
				<include name="src-2/**" />
				<include name="test/**" />

				<include name="examples/*/README" />
				<include name="examples/*/build.properties" />
				<include name="examples/*/*.xml" />
				<include name="examples/*/src/**" />
			</fileset>
		</copy>

		<!-- Create bz2 files -->
		<create-tar basedir="${build.dist.dir}/package-bin" destfile="${ant.project.name}-${version}-bin.tar.bz2" compression="bzip2"/>
		<create-tar basedir="${build.dist.dir}/package-src" destfile="${ant.project.name}-${version}-src.tar.bz2" compression="bzip2"/>

		<!-- Create gz files -->
		<create-tar basedir="${build.dist.dir}/package-bin" destfile="${ant.project.name}-${version}-bin.tar.gz" compression="gzip"/>
		<create-tar basedir="${build.dist.dir}/package-src" destfile="${ant.project.name}-${version}-src.tar.gz" compression="gzip"/>

		<!-- Create zip files -->
		<create-zip basedir="${build.dist.dir}/package-bin" destfile="${ant.project.name}-${version}-bin.zip"/>
		<create-zip basedir="${build.dist.dir}/package-src" destfile="${ant.project.name}-${version}-src.zip"/>

		<!-- Make an Eclipse plugin zip -->
		<!--

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-2024 Alvin Alexander, alvinalexander.com
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.