Skip to content

Instantly share code, notes, and snippets.

@marchof
Created January 14, 2013 20:35
Show Gist options
  • Save marchof/4533161 to your computer and use it in GitHub Desktop.
Save marchof/4533161 to your computer and use it in GitHub Desktop.
This example uses JaCoCo's offline instrumentation capabilities to collect code coverage for JDK classes.
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2009, 2013 Mountainminds GmbH & Co. KG and Contributors
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html
Contributors:
Marc R. Hoffmann - initial API and implementation
-->
<project name="JDK classes code coverage examples" default="rebuild" xmlns:jacoco="antlib:org.jacoco.ant">
<description>
This example uses JaCoCo's offline instrumentation capabilities to collect
code coverage for JDK classes.
</description>
<property name="jdk.rt.file" location="${java.home}/lib/rt.jar"/>
<property name="scope.includes" value="java/util/BitSet.class"/>
<property name="src.dir" location="./src"/>
<property name="target.dir" location="./target"/>
<property name="target.classes.dir" location="${target.dir}/classes"/>
<property name="target.instr.dir" location="${target.dir}/instr"/>
<property name="target.exec.file" location="${target.dir}/jacoco.exec"/>
<property name="target.report.dir" location="${target.dir}/report"/>
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="./lib/jacocoant.jar" />
</taskdef>
<target name="instrument">
<mkdir dir="${target.instr.dir}"/>
<jacoco:instrument destdir="${target.instr.dir}">
<zipfileset src="${jdk.rt.file}">
<include name="${scope.includes}"/>
</zipfileset>
</jacoco:instrument>
</target>
<target name="compile">
<mkdir dir="${target.classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${target.classes.dir}" includeantruntime="false"/>
</target>
<target name="test" depends="compile,instrument">
<java classname="org.jacoco.examples.jrecoverage.Main" fork="true" failonerror="true">
<bootclasspath >
<pathelement path="./lib/jacocoagent.jar"/>
<pathelement path="${target.instr.dir}" />
<pathelement path="${jdk.rt.file}" />
</bootclasspath>
<sysproperty key="jacoco-agent.destfile" file="${target.exec.file}"/>
<classpath>
<pathelement path="${target.classes.dir}" />
</classpath>
</java>
</target>
<target name="report" depends="test">
<mkdir dir="${target.report.dir}"/>
<jacoco:report>
<executiondata>
<file file="${target.exec.file}" />
</executiondata>
<structure name="Code Coverage for JRE Classes">
<classfiles>
<zipfileset src="${jdk.rt.file}">
<include name="${scope.includes}"/>
</zipfileset>
</classfiles>
</structure>
<html destdir="${target.report.dir}" />
<csv destfile="${target.report.dir}/report.csv" />
<xml destfile="${target.report.dir}/report.xml" />
</jacoco:report>
</target>
<target name="clean">
<delete dir="${target.dir}" quiet="true"/>
</target>
<target name="rebuild" depends="clean,test,report"/>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment