-
Notifications
You must be signed in to change notification settings - Fork 6
/
ccBuild_jacoco.xml
executable file
·210 lines (173 loc) · 7.18 KB
/
ccBuild_jacoco.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<project name="BankAccount" basedir="." default="jacoco" xmlns:jacoco="antlib:org.jacoco.ant">
<!-- Diretorios do projeto -->
<property name="src.dir" value="src"/>
<property name="web.dir" value="WebSite"/>
<property name="bin.dir" value="WebSite/WEB-INF/classes"/>
<property name="teste.dir" value="test"/>
<property name="lib.dir" value="WebSite/WEB-INF/lib"/>
<!-- Diretorios do PMD-->
<property name="pmd.out.dir" value="out/pmd"/>
<!-- Diretorios do JUnit-->
<property name="junit.out.dir" value="out/junit"/>
<!-- Diretorio para gera Deploy-->
<property name="dist.dir" value="out/dist"/>
<property name="tomcat7.dir" value="../../lib/apache-tomcat-8.0.27/webapps"/>
<!-- Diretorios do Jacoco -->
<property name="jacoco.bin.dir" value="out/bin"/>
<property name="jacoco.metadado.dir" value="out/metadado"/>
<property name="jacoco.metadado.file" value="out/metadado/jacoco.exec"/>
<property name="jacoco.relatorio.dir" value="out/relatorio"/>
<!-- Suite de Teste -->
<property name="suite.testes" value="com.facensa.bank.model.AllTests"/>
<!-- Flag indicando se o Jacoco deve ser executado -->
<property name="jacoco.deveExecutar" value="true"/>
<!-- propriedades do deploy -->
<touch file="deployid.properties"/>
<property file="deployid.properties"/>
<!-- Classpath do projeto -->
<path id="project.classpath">
<pathelement location="${bin.dir}"/>
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
</path>
<!-- Define tasks do Jacoco -->
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath refid="project.classpath"/>
</taskdef>
<!-- Define tasks do JUnit -->
<taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask">
<classpath refid="project.classpath"/>
</taskdef>
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask">
<classpath refid="project.classpath"/>
</taskdef>
<taskdef name="fit" classname="com.cmdev.fit.ant.FitTask">
<classpath refid="project.classpath"/>
</taskdef>
<taskdef name="cpd" classname="net.sourceforge.pmd.cpd.CPDTask">
<classpath refid="project.classpath"/>
</taskdef>
<!-- Inicializa o diretorio bin, que armazena as classes compiladas -->
<target name="init">
<delete dir="${bin.dir}"/>
<mkdir dir="${bin.dir}"/>
<mkdir dir="${dist.dir}"/>
<mkdir dir="${jacoco.bin.dir}"/>
<mkdir dir="${jacoco.metadado.dir}"/>
<mkdir dir="${jacoco.relatorio.dir}"/>
<mkdir dir="${pmd.out.dir}"/>
<mkdir dir="${junit.out.dir}"/>
</target>
<!-- Compila a aplicacao -->
<target name="compilaSrc" depends="init">
<javac debug="on" srcdir="${src.dir}" destdir="${bin.dir}">
<classpath refid="project.classpath"/>
</javac>
</target>
<!-- Compila os testes -->
<target name="compilaTeste">
<javac debug="on" srcdir="${teste.dir}" destdir="${bin.dir}">
<classpath refid="project.classpath"/>
</javac>
<copy todir="${bin.dir}">
<fileset dir="${teste.dir}" includes="**/*.xls"/>
</copy>
</target>
<!-- Executa os testes contra as classes da aplicacao -->
<target name="testa" depends="compilaSrc, compilaTeste">
<jacoco:coverage destfile="${jacoco.metadado.file}">
<junit haltonfailure="false" haltonerror="false" fork="true" printsummary="yes" failureproperty="unit.test.failure">
<classpath>
<pathelement location="${bin.dir}"/>
<pathelement location="${lib.dir}"/>
<path refid="project.classpath"/>
</classpath>
<formatter type="xml" />
<!--formatter type="plain" usefile="false"/-->
<test name="${suite.testes}" todir="${junit.out.dir}"/>
</junit>
</jacoco:coverage>
<junitreport todir="${junit.out.dir}">
<fileset dir="${junit.out.dir}">
<include name="TEST-*.xml" />
</fileset>
<report format="frames" todir="${junit.out.dir}/html" />
</junitreport>
<fail message="At least one unit test has failed" if="unit.test.failure" />
</target>
<target name="run-acceptance-tests">
<fit usewiki="false" destdir="${junit.out.dir}">
<fileset dir="${teste.dir}">
<include name="*.html" />
</fileset>
</fit>
</target>
<!-- Gera relatorio do Jacoco -->
<target name="jacoco" depends="testa, run-acceptance-tests, pmd, cpd">
<delete dir="${jacoco.relatorio.dir}"/>
<jacoco:report>
<!-- This task needs the collected execution data and ... -->
<executiondata>
<file file="${jacoco.metadado.file}" />
</executiondata>
<!-- the class files and optional source files ... -->
<structure name="JaCoCo Bank Account">
<classfiles>
<fileset dir="${bin.dir}" />
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src.dir}" />
</sourcefiles>
</structure>
<!-- to produce reports in different formats. -->
<html destdir="${jacoco.relatorio.dir}" />
<csv destfile="${jacoco.relatorio.dir}/report.csv" />
<xml destfile="${jacoco.relatorio.dir}/report.xml" />
</jacoco:report>
<antcall target="clean"/>
</target>
<!-- Deleta diretorios de trabalho do Jacoco -->
<target name="clean">
<delete dir="${jacoco.bin.dir}"/>
<delete dir="${jacoco.metadado.dir}"/>
</target>
<target name="pmd">
<pmd rulesetfiles="rulesets/favorites.xml">
<!--formatter type="net.sourceforge.pmd.renderers.HTMLRenderer" toFile="pmd.html"/-->
<formatter type="net.sourceforge.pmd.renderers.SummaryHTMLRenderer" toFile="${pmd.out.dir}/pmd.html"/>
<formatter type="net.sourceforge.pmd.renderers.VBHTMLRenderer" toFile="${pmd.out.dir}/pmd_vb.html"/>
<formatter type="net.sourceforge.pmd.renderers.XMLRenderer" toFile="${pmd.out.dir}/pmd_xml.xml"/>
<fileset dir="${src.dir}">
<include name="**/*.java"/>
</fileset>
</pmd>
</target>
<target name="cpd">
<cpd minimumTokenCount="30" outputFile="${pmd.out.dir}/cpd_pmd.txt">
<fileset dir="${src.dir}">
<include name="**/*.java"/>
</fileset>
</cpd>
</target>
<!-- gera o .war e copia para a pasta dist do projeto -->
<target name="war" depends="compilaSrc">
<echo>gerando war file para deploy</echo>
<propertyfile file="deployid.properties">
<entry key="build.count" default="0" type="int" operation="+" value="1" pattern="0000"/>
</propertyfile>
<property file="deployid.properties"/>
<war destfile="${dist.dir}/${ant.project.name}##${build.count}.war" webxml="${web.dir}/WEB-INF/web.xml">
<fileset dir="${web.dir}">
<include name="**/*.*"/>
<exclude name="**/*web.xml"/>
</fileset>
</war>
</target>
<!-- Deploy!! Foco em Tomcat 7 -->
<target name="deploy" depends="testa, run-acceptance-tests, pmd, cpd, war">
<move todir="${tomcat7.dir}">
<fileset dir="${dist.dir}" includes="**/*.war"/>
</move>
</target>
</project>