forked from edureka-git/devops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.xml
474 lines (435 loc) · 22.9 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
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
<?xml version="1.0" encoding="UTF-8"?>
<!-- ====================================================================== -->
<!-- Ant build file (http://ant.apache.org/) for Ant 1.7.2 or above. -->
<!-- ====================================================================== -->
<project name="addressbook" default="zip" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant" xmlns:ac="antlib:net.sf.antcontrib" xmlns:sonar="antlib:org.sonar.ant">
<tstamp><format property="MYTIME" pattern="yyyyMMddHHmmss" /></tstamp>
<!-- ====================================================================== -->
<!-- Defining classpaths & Task Defs -->
<!-- ====================================================================== -->
<property environment="env"/>
<property name="installpath.pmd" value="${env.PMD_HOME}/lib"/>
<property name="pmd.installpath" value="${env.PMD_HOME}/lib"/>
<property name="pmd.classpath" value="${env.PMD_HOME}/lib"/>
<!-- For Cobertura -->
<property name="lib.cobertura.dir" value="c:/apps/cobertura-1.9.4.1" />
<property name="cobertura.jar.file" value="${lib.cobertura.dir}/cobertura.jar" />
<path id="pmd.classpath">
<fileset dir="${pmd.installpath}"/>
</path>
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="pmd.classpath"/>
<path id="maven-ant-tasks.classpath" path="${ant.home}/lib/maven-ant-tasks-2.1.3.jar" />
<typedef resource="org/apache/maven/artifact/ant/antlib.xml"
uri="antlib:org.apache.maven.artifact.ant"
classpathref="maven-ant-tasks.classpath" />
<path id="ant.contrib.classpath" path="${ant.home}/lib/ant-contrib.jar"/>
<typedef resource="net/sf/antcontrib/antlib.xml" classpathref="ant.contrib.classpath"/>
<!-- ====================================================================== -->
<!-- Build environment properties -->
<!-- ====================================================================== -->
<property name="environment.type.default" value="dev"/>
<if>
<equals arg1="${basesrcdir}" arg2="$${basesrcdir}"/>
<then>
<property name="build.basesrcdir" value="."/>
</then>
<else>
<property name="build.basesrcdir" value="${basesrcdir}"/>
</else>
</if>
<if>
<equals arg1="${buildtype}" arg2="$${buildtype}"/>
<then>
<property name="maven.build.resourceDir" value="${build.basesrcdir}/src/main/resources/${environment.type.default}"/>
<property name="actualbuildtype" value="${environment.type.default}"/>
</then>
<else>
<property name="maven.build.resourceDir" value="${build.basesrcdir}/src/main/resources/${buildtype}"/>
<property name="actualbuildtype" value="${buildtype}"/>
</else>
</if>
<echo message="resource dir: ${maven.build.resourceDir}, Source Dir: ${build.basesrcdir}/src/main/java"/>
<property file="${build.basesrcdir}/build.properties"/>
<artifact:pom id="pom" file="pom.xml" />
<property name="actualbuildname" value="${pom.artifactId}"/>
<property name="actualversion" value="${pom.version}"/>
<echo message="Artifact ID/Version: ${actualbuildname}/${actualversion}"/>
<property name="build.version" value="${version}"/>
<property name="maven.build.finalName" value="${actualbuildname}-${actualversion}"/>
<property name="maven.build.dir" value="${build.basesrcdir}/target"/>
<property name="maven.build.outputDir" value="${maven.build.dir}/classes"/>
<property name="maven.build.srcDir" value="${build.basesrcdir}/src/main/java"/>
<property name="maven.build.testDir" value="${build.basesrcdir}/src/test/java"/>
<property name="maven.build.testResourceDir" value="${build.basesrcdir}/src/test/resources"/>
<property name="maven.build.testOutputDir" value="${maven.build.dir}/test-classes"/>
<property name="maven.test.reports" value="${maven.build.dir}/test-reports"/>
<property name="maven.reporting.outputDirectory" value="reports"/>
<property name="project.3rdpartylibdir" value="${build.basesrcdir}/lib"/>
<property name="maven.build.pmddir" value="${build.basesrcdir}/src/main/pmd"/>
<property name="sonar.host.url" value="${env.SONAR_URL}" />
<property name="sonar.jdbc.url" value="jdbc:mysql://${env.SONAR_DBSERVER}:${env.SONAR_DBPORT}/${env.SONAR_DBNAME}?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance" />
<property name="sonar.jdbc.username" value="${env.SONAR_DBUSER}"/>
<property name="sonar.jdbc.password" value="${env.SONAR_DBPASSWORD}"/>
<property name="sonar.projectKey" value="${ant.project.name}"/>
<property name="sonar.projectName" value="${ant.project.name}"/>
<property name="sonar.projectVersion" value="${actualversion}"/>
<property name="sonar.sources" value="${build.basesrcdir}/src/main/java"/>
<!-- For Cobertura -->
<property name="cob.ser.file" value="cobertura.ser" />
<property name="cobertura.dir" value="./cobertura" />
<property name="cob.instrumented.dir" value="${cobertura.dir}/instrumented" />
<property name="cob.reports.dir" value="${cobertura.dir}/reports" />
<property name="cob.reports.xml.dir" value="${cob.reports.dir}/junit-xml" />
<property name="cob.reports.html.dir" value="${cob.reports.dir}/junit-html" />
<property name="cob.coverage.xml.dir" value="${cob.reports.dir}/cobertura-xml" />
<property name="cob.coverage.html.dir" value="${cob.reports.dir}/cobertura-html" />
<path id="libpath">
<fileset dir="${project.3rdpartylibdir}"/>
</path>
<path id="build.test.classpath">
<pathelement location="${project.3rdpartylibdir}/junit-4.11.jar"/>
</path>
<echo message="***************************************************************************"/>
<echo message="Start the build for: ${ant.project.name} "/>
<echo message="Base Dir: ${build.basesrcdir} ${actualbuildtype}"/>
<mkdir dir="${project.3rdpartylibdir}"/>
<echo message="PMD Libraries installed in: ${pmd.installpath}"/>
<echo message="***************************************************************************"/>
<echo message="Skip Test? ${maven.test.skip}"/>
<!-- ====================================================================== -->
<!-- Cleaning up target -->
<!-- ====================================================================== -->
<target name="clean" description="Clean the output directory">
<delete dir="${maven.build.dir}"/>
<delete dir="${project.3rdpartylibdir}"/>
<delete dir="${maven.reporting.outputDirectory}"/>
<delete dir="./.sonar"/>
<delete dir="reports"/>
<delete file="${cob.ser.file}"/>
<delete dir="${cobertura.dir}"/>
</target>
<!-- ====================================================================== -->
<!-- Copy Maven dependencies -->
<!-- ====================================================================== -->
<target name="maven_dep_copy" depends="clean" description="Copies Maven Dependencies into local Lib folder">
<artifact:dependencies filesetId="deps.fileset" scopes="provided, test, runtime, compile">
<pom file="pom.xml"/>
</artifact:dependencies>
<mkdir dir="${project.3rdpartylibdir}"/>
<copy todir="${project.3rdpartylibdir}">
<fileset refid="deps.fileset" />
<mapper type="flatten" />
</copy>
</target>
<!-- ====================================================================== -->
<!-- Compilation target -->
<!-- ====================================================================== -->
<target name="compile" depends="maven_dep_copy" description="Compiles the code. Does a validation on PMD Rules">
<mkdir dir="${maven.build.outputDir}"/>
<javac includeantruntime="false" destdir="${maven.build.outputDir}"
nowarn="false" debug="true"
optimize="false" deprecation="true"
target="1.6" verbose="false"
fork="false" source="1.6">
<src>
<pathelement location="${maven.build.srcDir}"/>
</src>
<classpath>
<fileset dir="${project.3rdpartylibdir}"/>
</classpath>
</javac>
<copy todir="${maven.build.outputDir}">
<fileset dir="${maven.build.resourceDir}"/>
</copy>
</target>
<!-- ====================================================================== -->
<!-- Test-compilation target -->
<!-- ====================================================================== -->
<target name="compile-tests"
depends="compile"
description="Compiles the test code, unless maven's skip test property is unset">
<mkdir dir="${maven.build.testOutputDir}"/>
<javac includeantruntime="false" destdir="${maven.build.testOutputDir}"
nowarn="false" debug="true"
optimize="false" deprecation="true"
target="1.8" verbose="false"
fork="false" source="1.7">
<src>
<pathelement location="${maven.build.testDir}"/>
</src>
<classpath>
<fileset dir="${project.3rdpartylibdir}"/>
<pathelement location="${maven.build.outputDir}"/>
<fileset dir="${lib.cobertura.dir}"/>
</classpath>
</javac>
<copy todir="${maven.build.testOutputDir}">
<fileset dir="${maven.build.testResourceDir}"/>
</copy>
</target>
<!-- ====================================================================== -->
<!-- Run all tests -->
<!-- ====================================================================== -->
<target name="test"
depends="compile-tests"
description="Runs the test cases">
<mkdir dir="${maven.test.reports}"/>
<junit haltonerror="no" failureproperty="test.failed" haltonfailure="no" printSummary="yes" fork="true" dir=".">
<sysproperty key="basedir" value="."/>
<formatter type="xml"/>
<formatter type="plain" usefile="false"/>
<classpath>
<fileset dir="${project.3rdpartylibdir}"/>
<pathelement location="${maven.build.outputDir}"/>
<pathelement location="${maven.build.testOutputDir}"/>
</classpath>
<batchtest skipNonTests="false" todir="${maven.test.reports}">
<fileset dir="${maven.build.testDir}">
<include name="**/Test*.java"/>
<include name="**/*Test.java"/>
<include name="**/*TestCase.java"/>
<exclude name="**/*Abstract*Test.java"/>
</fileset>
</batchtest>
</junit>
<junitreport todir="${maven.test.reports}">
<fileset dir="${maven.test.reports}">
<include name="TEST-*.xml" />
</fileset>
<report format="noframes" todir="${maven.test.reports}\html\" />
</junitreport>
<fail message="Test failure detected, check test results." if="test.failed" />
</target>
<target name="test-junit-present" description="Checks if JUNIT is present">
<available classname="junit.framework.Test" property="junit.present" classpathref="build.test.classpath"/>
<echo message="${junit.present}"/>
</target>
<target name="test-junit-status"
depends="test-junit-present" description="Set condition if JUNIT tests are to be run.">
<condition property="junit.missing">
<and>
<isfalse value="${junit.present}"/>
<isfalse value="${maven.test.skip}"/>
</and>
</condition>
<condition property="junit.skipped">
<or>
<isfalse value="${junit.present}"/>
<istrue value="${maven.test.skip}"/>
</or>
</condition>
</target>
<target name="junit-missing"
depends="test-junit-status"
if="junit.missing" description="Reports if JUNIT library is missing so to avoid running JUNIT Tests">
<echo>=================================== WARNING ==========================================</echo>
<echo> JUnit is not present in the test classpath or your $ANT_HOME/lib directory. Tests not executed. </echo>
<echo>=======================================================================================</echo>
</target>
<!-- ====================================================================== -->
<!-- Javadoc target -->
<!-- ====================================================================== -->
<target name="javadoc" description="Generates the Javadoc of the application">
<javadoc sourcepath="${maven.build.srcDir}"
packagenames="*"
destdir="${maven.reporting.outputDirectory}/apidocs"
access="protected"
old="false"
verbose="false"
version="true"
use="true"
author="true"
splitindex="false"
nodeprecated="false"
nodeprecatedlist="false"
notree="false"
noindex="false"
nohelp="false"
nonavbar="false"
serialwarn="false"
charset="ISO-8859-1"
linksource="false"
breakiterator="false"
additionalparam="-Xdoclint:none" />
</target>
<!-- ====================================================================== -->
<!-- PMD Report -->
<!-- ====================================================================== -->
<target name="pmdreport" description="Generates PMD Reported issues list as a browsable HTML">
<mkdir dir="${maven.reporting.outputDirectory}"/>
<pmd shortFilenames="true" failonerror="false" failOnRuleViolation="false" minimumPriority="5" failuresPropertyName="pmderrors" rulesetfiles="${maven.build.pmddir}/ruleset_j2ee.xml,${maven.build.pmddir}/ruleset_basics.xml"> <sourceLanguage name="java" version="1.6"/>
<formatter type="xml" toFile="${maven.reporting.outputDirectory}/pmd_report.xml">
<param name="linkPrefix" value="http://pmd.sourceforge.net/xref/"/>
</formatter>
<fileset dir="${maven.build.srcDir}"/>
</pmd>
<xslt in="${maven.reporting.outputDirectory}/pmd_report.xml" style="${maven.build.pmddir}/pmd.xsl" out="${maven.reporting.outputDirectory}/pmd_report_${ant.project.name}.html" />
<delete file="${maven.reporting.outputDirectory}/pmd_report.xml"/>
<if>
<equals arg1="${pmderrors}" arg2="$${pmderrors}"/>
<then>
<property name="pmdreporterrcnt" value="0"/>
</then>
<else>
<property name="pmdreporterrcnt" value="${pmderrors}"/>
</else>
</if>
<echo message="Number of PMD Errors: ${pmdreporterrcnt}"/>
</target>
<!-- ====================================================================== -->
<!-- Package target -->
<!-- ====================================================================== -->
<target name="package" depends="compile,test" description="Package the application as a JAR/WAR whatever">
<pathconvert property="manifest.classpath" pathsep=" ">
<path refid="libpath"/>
<mapper>
<chainedmapper>
<flattenmapper/>
<globmapper from="*.jar" to="${project.3rdpartylibdir}/*.jar"/>
</chainedmapper>
</mapper>
</pathconvert>
<jar jarfile="${maven.build.dir}/${maven.build.finalName}.jar"
compress="true" index="false"
basedir="${maven.build.outputDir}" excludes="**/package.html">
<manifest>
<attribute name="Built-By" value="${user.name}"/>
<attribute name="Created-By" value="Build Tool V1"/>
<attribute name="Implementation-Title" value="${actualbuildname}.jar"/>
<attribute name="Implementation-Version" value="${maven.build.version}-${MYTIME}"/>
<attribute name="Implementation-Vendor" value="SeshagiriSriram"/>
<attribute name="Class-Path" value="${manifest.classpath}"/>
</manifest>
</jar>
</target>
<!-- ====================================================================== -->
<!-- A dummy target for the package named after the type it creates -->
<!-- ====================================================================== -->
<target name="jar" depends="package" description="Builds the jar for the application"/>
<!-- ====================================================================== -->
<!-- Zips files into a zip for deployment -->
<!-- ====================================================================== -->
<target name="zip" depends="package" description="Zips all Resources">
<if>
<equals arg1="${zipoutput}" arg2="$${zipoutput}"/>
<then>
<property name="zipoutputdir" value="${maven.build.dir}"/>
</then>
<else>
<property name="zipoutputdir" value="${zipoutput}"/>
</else>
</if>
<echo message="Copying files from ${maven.build.resourceDir} to ${maven.build.dir}/tmp"/>
<mkdir dir="${maven.build.dir}/tmp"/>
<mkdir dir="${zipoutputdir}"/>
<echo message="Resource Directory: ${maven.build.resourceDir}" />
<copy todir="${maven.build.dir}/tmp" overwrite="true">
<fileset dir="${maven.build.resourceDir}"/>
<file name="${maven.build.dir}/${maven.build.finalName}.jar"/>
</copy>
<zip destfile="${zipoutputdir}/${maven.build.finalName}.zip">
<zipfileset dir="${maven.build.dir}/tmp" includes="*.properties,*.xml,*.txt, ${maven.build.finalName}.jar"/>
<zipfileset dir="./lib" prefix="lib"/>
</zip>
<delete dir="${maven.build.dir}/tmp"/>
<delete dir="${project.3rdpartylibdir}"/>
<mkdir dir="${project.3rdpartylibdir}"/>
<delete file="${maven.build.dir}/../${maven.build.finalName}.zip"/>
</target>
<!-- ====================================================================== -->
<!-- Download dependencies target -->
<!-- ====================================================================== -->
<target name="test-offline" description="Checks if Maven has been configured to run in offline mode">
<condition property="maven.mode.offline">
<equals arg1="${maven.settings.offline}" arg2="true"/>
</condition>
</target>
<!-- ====================================================================== -->
<!-- Installs components to Artifactory -->
<!-- ====================================================================== -->
<target name="install" depends="zip" description="Installs the JAR to artifactory">
<echo message="Maven is found in: ${env.MAVEN_HOME}"/>
<artifact:deploy file="${maven.build.dir}/${maven.build.finalName}.jar">
<pom file="pom.xml"/>
<remoteRepository url="${env.BUILD_URL}"/>
</artifact:deploy>
</target>
<!-- ====================================================================== -->
<!-- Performs SonarQube Analysis on code -->
<!-- ====================================================================== -->
<target name="sonar" description="Performs SonarQube Analysis on code">
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml" classpathref="maven-ant-tasks.classpath" />
<!-- Execute the SonarQube analysis -->
<sonar:sonar />
</target>
<!-- ====================================================================== -->
<!-- Copy files required for instrumentation -->
<!-- ====================================================================== -->
<target name="prepare" depends="clean, maven_dep_copy">
<mkdir dir="${maven.reporting.outputDirectory}" />
<!-- cobertura directories -->
<mkdir dir="${cobertura.dir}" />
<mkdir dir="${cob.instrumented.dir}" />
<mkdir dir="${cob.reports.xml.dir}" />
<mkdir dir="${cob.reports.html.dir}" />
<mkdir dir="${cob.coverage.xml.dir}" />
<mkdir dir="${cob.coverage.html.dir}" />
<!-- WE DO NOT HAVE LIBS IN OUR APPLICTION - SO WE DEFINE THE TASK AFTER GETTING THE FILE -->
<path id="cobertura.classpath">
<fileset dir="${lib.cobertura.dir}">
<include name="cobertura.jar" />
<include name="lib/**/*.jar" />
</fileset>
<fileset dir="${project.3rdpartylibdir}"/>
</path>
<taskdef resource="tasks.properties" classpathref="cobertura.classpath"/>
</target>
<!-- ====================================================================== -->
<!-- Do Actual Instrumentation -->
<!-- ====================================================================== -->
<target name="instrument" depends="prepare,compile-tests">
<echo>Class Path: ${toString:cobertura.classpath}</echo>
<cobertura-instrument todir="${cob.instrumented.dir}">
<fileset dir="${maven.build.outputDir}">
<include name="**/*.class"/>
</fileset>
</cobertura-instrument>
</target>
<!-- ====================================================================== -->
<!-- Call Instrumentation -->
<!-- ====================================================================== -->
<target name="cover-test" depends="instrument">
<echo message="Instrumented dir:${cob.instrumented.dir}"/>
<junit printSummary="yes" haltonerror="no" haltonfailure="no" fork="yes" dir=".">
<sysproperty key="basedir" value="."/>
<sysproperty key="net.sourceforge.cobertura.datafile"
file="${cob.ser.file}" />
<!--
Note the classpath order: instrumented classes are before the
original (uninstrumented) classes. This is important.
-->
<classpath location="${cob.instrumented.dir}" />
<classpath location="${maven.build.outputDir}" />
<classpath refid="cobertura.classpath" />
<classpath>
<fileset dir="${project.3rdpartylibdir}"/>
<pathelement location="${maven.build.testOutputDir}"/>
</classpath>
<batchtest skipNonTests="false" todir="${maven.test.reports}">
<fileset dir="${maven.build.testDir}">
<include name="**/Test*.java"/>
<include name="**/*Test.java"/>
<include name="**/*TestCase.java"/>
<exclude name="**/*Abstract*Test.java"/>
</fileset>
</batchtest>
</junit>
</target>
<!-- ====================================================================== -->
<!-- Report on this.... -->
<!-- ====================================================================== -->
<!-- run this target to generate the coverage reports -->
<target name="coverage-report" depends="cover-test">
<cobertura-report srcdir="${src.dir}" destdir="${cobertura.dir}"/>
</target>
</project>