-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.xml
124 lines (106 loc) · 4.64 KB
/
build.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2009, 2019 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="Junit Ant Build with JaCoCo" default="report" basedir="." xmlns:jacoco="antlib:org.jacoco.ant" xmlns:sonar="antlib:org.sonar.ant">
<description>
Example Ant build file that demonstrates how a JaCoCo coverage report
can be itegrated into an existing build in three simple steps.
</description>
<property file="build.properties" />
<path id="project.classpath">
<fileset dir="${lib.dir}">
<include name="*.jar" />
</fileset>
</path>
<!-- Step 1: Import JaCoCo Ant tasks -->
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="./lib/jacocoant.jar" />
</taskdef>
<target name="clean" description="Remove all files created by the build/test process.">
<delete dir="${classes.dir}" />
<delete dir="${result.dir}" />
</target>
<target name="init" depends="clean">
<mkdir dir="${classes.dir}" />
<mkdir dir="${result.report.dir}" />
</target>
<target name="compile" depends="init">
<javac srcdir="${src.dir}" destdir="${classes.dir}" debug="yes" />
<javac srcdir="${test.dir}" destdir="${classes.dir}" debug="yes">
<classpath refid="project.classpath" />
</javac>
</target>
<target name="test" depends="compile">
<mkdir dir="${result.report.dir}"/>
<jacoco:coverage destfile="${result.exec.file}">
<junit fork="yes" dir="${basedir}" failureProperty="test.failed" haltonfailure="yes" showoutput="true">
<!--
Note the classpath order: instrumented classes are before the
original (uninstrumented) classes. This is important.
-->
<classpath refid="project.classpath" />
<classpath location="${classes.dir}" />
<formatter type="xml" />
<test name="${testcase}" todir="${result.report.dir}" if="testcase" />
<batchtest todir="${result.report.dir}" unless="testcase">
<fileset dir="${test.dir}">
<include name="**/*Test*.java" />
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
</target>
<target name="report" depends="test">
<!-- Step 3: Create coverage report -->
<jacoco:report>
<!-- This task needs the collected execution data and .... -->
<executionData>
<file file="${result.exec.file}" />
</executionData>
<!-- the class files and optoinal source files ... -->
<structure name="JaCoCo Ant Example">
<classfiles>
<fileset dir="${classes.dir}" />
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src.dir}" />
</sourcefiles>
</structure>
<!-- to produce reports in different formats. -->
<html destdir="${result.report.dir}" />
<xml destfile="${result.report.dir}/report.xml" />
<csv destfile="${result.report.dir}/report.csv" />
</jacoco:report>
</target>
<!-- Define the SonarQube global properties (the most usual way is to pass these properties via the command line) -->
<!--
<property name="sonar.host.url" value="http://localhost:9000" />
-->
<property name="sonar.host.url" value="https://sonarcloud.io" />
<property name="sonar.login" value="7aaa9001337d6a0911ffbf3637eec5335810e3e7" />
<property name="sonar.organization" value="wudc-github" />
<property name="sonar.projectBaseDir" value="." />
<property name="sonar.junit.reportPaths" value="${sonar.projectBaseDir}/report" />
<property name="sonar.projectKey" value="unit-test-jacoco:sonarqube-scanner-ant" />
<property name="sonar.projectName" value="Junit Test Project integrated with SonarQube and JaCoCo" />
<property name="sonar.projectVersion" value="1.0" />
<property name="sonar.jacoco.reportPaths" value="${result.exec.file}"/>
<target name="sonar" depends="report" description="Integrate this project with SonarQube">
<property name="sonar.sources" value="${src.dir}, ${test.dir}" />
<property name="sonar.java.binaries" value="${classes.dir}" />
<property name="sonar.java.libraries" value="${lib.dir}/*.jar" />
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath refid="project.classpath" />
<!-- put the "sonarqube-ant-task-*.jar" file in your "$HOME/.ant/lib" folder -->
</taskdef>
<!-- Execute SonarQube scanner for ANT project analysis -->
<sonar:sonar />
</target>
</project>