devdaily home | apple | java | perl | unix | directory | blog

What this is

This file 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.

Other links

The source code

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

<project name="cobertura" default="coverage" basedir=".">

	<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" />

	<path id="base.path">
		<fileset dir="${lib.dir}">
			<include name="**/*.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">
			<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">
			<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">
			<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">
		<mkdir dir="${build.test.classes.dir}" />
		<javac fork="true" srcdir="${test.src.dir}" destdir="${build.test.classes.dir}" debug="true">
			<compilerarg value="-Xlint:unchecked" compiler="javac1.5"/>
			<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}" />
		</javac>

		<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>
			<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="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" failureProperty="test.failed" printsummary="true" timeout="300000">
			<sysproperty key="net.sourceforge.cobertura.datafile" file="${build.dir}/cobertura.ser" />
			<sysproperty key="basedir" value="${basedir}"/>
			<!--
			<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>
				<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>

		<fail message="Tests failed." if="test.failed" />
	</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>

		<cobertura-check datafile="${build.dir}/cobertura.ser"
		                 totalbranchrate="50"
		                 totallinerate="50" />
	</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" linksource="true" serialwarn="false" source="1.3" version="true" windowtitle="Cobertura API">
			<fileset dir="${src.dir}" />
			<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 todir="${build.dist.dir}/package-bin/cobertura-${version}">
			<fileset dir="${basedir}">
				<include name="ChangeLog" />
				<include name="cobertura-*.bat" />
				<include name="cobertura-*.sh" />
				<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="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 todir="${build.dist.dir}/package-src/cobertura-${version}">
			<fileset dir="${basedir}">
				<include name="ChangeLog" />
				<include name="cobertura-*.bat" />
				<include name="cobertura-*.sh" />
				<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 -->
		<tar basedir="${build.dist.dir}/package-bin" destfile="${ant.project.name}-${version}-bin.tar.bz2" compression="bzip2"/>
		<tar basedir="${build.dist.dir}/package-src" destfile="${ant.project.name}-${version}-src.tar.bz2" compression="bzip2"/>

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

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

		<!-- Make an Eclipse plugin zip -->
		<zip destfile="${ant.project.name}-${version}-eclipse-plugin.zip" encoding="UTF-8">
			<zipfileset prefix="com.${ant.project.name}_${version}" dir="${basedir}">
				<include name="ChangeLog" />
				<include name="COPYING" />
				<include name="COPYRIGHT" />
				<include name="README" />
				<include name="lib/**" />
			</zipfileset>

			<zipfileset prefix="com.${ant.project.name}_${version}" dir="${build.dist.eclipse.dir}">
				<include name="${ant.project.name}.jar" />
				<include name="${ant.project.name}-main.jar" />
			</zipfileset>

			<zipfileset prefix="com.${ant.project.name}_${version}" dir="${etc.dir}">
				<include name="plugin.properties" />
			</zipfileset>

			<zipfileset prefix="com.${ant.project.name}_${version}" dir="${build.dir}">
				<include name="plugin.xml" />
			</zipfileset>
		</zip>

	</target>

	<target name="install-eclipse-plugin">
		<apply dir="${eclipse.dir}/plugins" executable="unzip">
			<arg value="-o" />
			<fileset dir="dist">
				<include name="${ant.project.name}-${version}-eclipse-plugin.zip" />
			</fileset>
		</apply>
	</target>

	<target name="clean" description="Remove all files created by the build process.">
		<delete dir="${build.dir}" />
		<delete>
			<fileset dir="${basedir}">
				<include name="cobertura.jar" />
				<include name="cobertura.ser" />
				<include name="cobertura.ser.lock" />
				<include name="cobertura-*-bin.*" />
				<include name="cobertura-*-src.*" />
				<include name="cobertura-*-eclipse-plugin.zip" />
			</fileset>
		</delete>
	</target>

	<target name="coverage" depends="compile,compile-tests,instrument,test,coverage-report" description="Compile, instrument ourself, run the tests and generate JUnit and coverage reports." />
	<target name="release" depends="clean,compile,compile-tests,test,jar,javadoc,dist" description="Full build cycle, producing a distribution." />

</project>




Copyright 1998-2008 Alvin Alexander
All Rights Reserved.
 
devdaily.com is based in louisville, kentucky, and this web site is hosted by godaddy.com