1<?xml version="1.0" encoding="UTF-8"?> 2 3<!-- 4 Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors 5 All rights reserved. This program and the accompanying materials 6 are made available under the terms of the Eclipse Public License v1.0 7 which accompanies this distribution, and is available at 8 http://www.eclipse.org/legal/epl-v10.html 9 10 Contributors: 11 Marc R. Hoffmann - initial API and implementation 12--> 13 14<project name="Example Ant Build with JaCoCo" default="rebuild" xmlns:jacoco="antlib:org.jacoco.ant"> 15 16 <description> 17 Example Ant build file that demonstrates how a JaCoCo coverage report 18 can be itegrated into an existing build in three simple steps. 19 </description> 20 21 <property name="src.dir" location="./src/main/java" /> 22 <property name="result.dir" location="./target" /> 23 <property name="result.classes.dir" location="${result.dir}/classes" /> 24 <property name="result.report.dir" location="${result.dir}/site/jacoco" /> 25 <property name="result.exec.file" location="${result.dir}/jacoco.exec" /> 26 27 <!-- Step 1: Import JaCoCo Ant tasks --> 28 <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml"> 29 <classpath path="../../../lib/jacocoant.jar" /> 30 </taskdef> 31 32 <target name="clean"> 33 <delete dir="${result.dir}" /> 34 </target> 35 36 <target name="compile"> 37 <mkdir dir="${result.classes.dir}" /> 38 <javac srcdir="${src.dir}" destdir="${result.classes.dir}" debug="true" includeantruntime="false" /> 39 </target> 40 41 <target name="test" depends="compile"> 42 <!-- Step 2: Wrap test execution with the JaCoCo coverage task --> 43 <jacoco:coverage destfile="${result.exec.file}"> 44 <java classname="org.jacoco.examples.parser.Main" fork="true"> 45 <classpath path="${result.classes.dir}" /> 46 <arg value="2 * 3 + 4"/> 47 <arg value="2 + 3 * 4"/> 48 <arg value="(2 + 3) * 4"/> 49 <arg value="2 * 2 * 2 * 2"/> 50 <arg value="1 + 2 + 3 + 4"/> 51 <arg value="2 * 3 + 2 * 5"/> 52 </java> 53 </jacoco:coverage> 54 </target> 55 56 <target name="report" depends="test"> 57 <!-- Step 3: Create coverage report --> 58 <jacoco:report> 59 60 <!-- This task needs the collected execution data and ... --> 61 <executiondata> 62 <file file="${result.exec.file}" /> 63 </executiondata> 64 65 <!-- the class files and optional source files ... --> 66 <structure name="JaCoCo Ant Example"> 67 <classfiles> 68 <fileset dir="${result.classes.dir}" /> 69 </classfiles> 70 <sourcefiles encoding="UTF-8"> 71 <fileset dir="${src.dir}" /> 72 </sourcefiles> 73 </structure> 74 75 <!-- to produce reports in different formats. --> 76 <html destdir="${result.report.dir}" /> 77 <csv destfile="${result.report.dir}/report.csv" /> 78 <xml destfile="${result.report.dir}/report.xml" /> 79 </jacoco:report> 80 </target> 81 82 <target name="rebuild" depends="clean,compile,test,report" /> 83 84</project>