-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathbuild-common.xml
More file actions
927 lines (832 loc) · 43.4 KB
/
build-common.xml
File metadata and controls
927 lines (832 loc) · 43.4 KB
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
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
<project name="build-common" xmlns:ivy="antlib:org.apache.ivy.ant" xmlns:antcontrib="antlib:net.sf.antcontrib" xmlns:jacoco="antlib:org.jacoco.ant">
<!-- Set properties that can be used in all projects. -->
<dirname property="zimbra.root.dir" file="${ant.file.build-common}/../"/>
<dirname property="zm-mailbox.basedir" file="${ant.file.build-common}"/>
<!-- Java -->
<property name="javac.target" value="1.8"/>
<!-- base path for ivy cache, local repository, ant libraries, etc -->
<property name="dev.home" value="${user.home}"/>
<!-- Add "init-ivy" depends to your "resolve" target and the following will
automatically download and install ivy if necessary. -->
<property name="ivy.jar.dir" location="${dev.home}/.ant/lib" />
<property name="ivy.install.version" value="2.3.0" />
<property name="ivy.jar.file" value="${ivy.jar.dir}/ivy-2.3.0.jar" />
<property name="ivy.status" value="integration" />
<property name="ivy.organisation" value="zimbra" />
<property name="ivy.publish.src.artifacts.pattern" value="build/[artifact]-[revision].[ext]" />
<property name="ivy.deliver.ivy.pattern" value="${dev.home}/.zcs-deps/[organisation]/[module]/[module]-[revision].[ext]" />
<property name="ivy.module" value="${ant.project.name}" />
<target name="test.if.ivy.available">
<condition property="ivy.installed">
<available file="${ivy.jar.file}" type="file"/>
</condition>
</target>
<target name="download-ivy" description="Install ivy" unless="ivy.installed" depends="test.if.ivy.available">
<mkdir dir="${ivy.jar.dir}"/>
<get src="https://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar"
dest="${ivy.jar.file}" usetimestamp="true"/>
</target>
<target name="init-ivy" depends="download-ivy">
<!-- If ivy is not downloaded yet, try to load ivy here from ivy home. -->
<path id="ivy.lib.path">
<fileset dir="${ivy.jar.dir}" includes="*.jar"/>
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
</target>
<!-- common resolve target that should work to resolve dependencies based on ivy.xml for most projects -->
<target name="resolve" depends="init-ivy" description="resolve dependencies">
<ivy:settings id="dev.settings" file="../build-ivysettings.xml"/>
<ivy:resolve settingsRef="dev.settings" />
<ivy:cachepath pathid="class.path" />
</target>
<target name="3rd-party-defines" description="Declare 3rd party ANT tasks" depends="resolve">
<taskdef uri="antlib:net.sf.antcontrib" classpathref="class.path"/>
</target>
<!-- Ignore the classpath from the shell running ant. This avoids dependency
on the user's environment and suppresses the warning about includeAntRuntime. -->
<property name="build.sysclasspath" value="ignore"/>
<!-- Standard directory paths -->
<property name="src.dir" location="src" />
<property name="src.java.dir" location="src/java" />
<property name="src.bin.dir" location="src/bin" />
<property name="src.libexec.dir" location="src/libexec" />
<property name="src.zimlet.dir" location="src/zimlet" />
<property name="jars.dir" location="jars" />
<property name="build.dir" location="build" />
<property name="build.tmp.dir" location="${build.dir}/tmp" />
<property name="dist.dir" location="${build.dir}/dist" />
<property name="dist.lib.dir" location="${dist.dir}/lib"/>
<property name="dist.lib.ext.dir" location="${dist.lib.dir}/ext"/>
<property name="build.classes.dir" location="${build.dir}/classes" />
<property name="build.instrumented.dir" location="${build.dir}/classes-inst" />
<property name="build.coverage.dir" location="${build.dir}/coverage" />
<property name="build.zimlet.dir" location="${build.dir}/zimlet" />
<property name="test.dir" location="${build.dir}/test"/>
<property name="itest.dir" location="${build.dir}/itest"/>
<property name="test.pattern" value="**/*Test.java"/>
<property name="test.src.dir" location="src/java-test"/>
<property name="test.classes.dir" location="${build.dir}/test-classes"/>
<path id="all.java.path">
<pathelement location="${src.java.dir}" />
</path>
<!-- Standard build dependencies path -->
<property name="build.deps.dir" location="${dev.home}/.zcs-deps"/>
<!-- Standard install paths -->
<property name="zimbra.home.dir" location="/opt/zimbra" />
<property name="jetty.home.dir" location="${zimbra.home.dir}/jetty"/>
<property name="jetty.webapps.dir" location="${jetty.home.dir}/webapps"/>
<property name="common.jars.dir" location="${zimbra.home.dir}/lib/jars"/>
<property name="jetty.endorsed.jars.dir" location="${jetty.home.dir}/common/endorsed"/>
<property name="jetty.common.jars.dir" location="${jetty.home.dir}/common/lib"/>
<property name="ext-common.jars.dir" location="${zimbra.home.dir}/lib/ext-common"/>
<property name="common.sourcejars.dir" location="${zimbra.home.dir}/jars-src"/>
<!-- ZimbraCommon -->
<property name="common.dir" location="${zm-mailbox.basedir}/common"/>
<property name="common.src.java.dir" location="${common.dir}/src/java"/>
<property name="common.classes.dir" location="${common.dir}/build/classes"/>
<property name="common.jarfile" location="${common.dir}/build/zimbracommon.jar"/>
<property name="common.internal.jars.dir" location="../jars-internal/jars"/>
<!-- ZimbraNative -->
<property name="native.dir" location="${zm-mailbox.basedir}/native" />
<property name="native.classes.dir" location="${native.dir}/build/classes" />
<!-- ZimbraServer -->
<property name="server.dir" location="${zm-mailbox.basedir}/store"/>
<property name="server.classes.dir" location="${server.dir}/build/classes"/>
<property name="server.test.classes.dir" location="${server.dir}/build/test-classes"/>
<property name="server.jarfile" location="${server.dir}/build/zimbrastore.jar"/>
<property name="server.jars.dir" location="${zimbra.home.dir}/jars"/>
<property name="server.conf.dir" location="${server.dir}/conf"/>
<!-- ZimbraSoap -->
<property name="soap.dir" location="${zm-mailbox.basedir}/soap"/>
<property name="soap.classes.dir" location="${soap.dir}/build/classes"/>
<property name="soap.jarfile" location="${soap.dir}/build/zimbrasoap.jar"/>
<!-- ZimbraClient -->
<property name="client.dir" location="${zm-mailbox.basedir}/client"/>
<property name="client.classes.dir" location="${client.dir}/build/classes"/>
<property name="client.jarfile" location="${client.dir}/build/zimbraclient.jar"/>
<property name="msgs.dir" location="${zm-mailbox.basedir}/store-conf/conf/msgs"/>
<!-- Classpath for running unit test, it needs classes from build dir -->
<path id="test.class.path">
<path refid="class.path"/>
<pathelement location="${build.classes.dir}" />
<pathelement location="${test.classes.dir}" />
<pathelement location="${msgs.dir}" />
</path>
<!-- Platform -->
<condition property="native.os" value="MacOSX">
<os name="Mac OS X"/>
</condition>
<condition property="native.os" value="Linux">
<os name="Linux"/>
</condition>
<condition property="native.so" value="jnilib">
<os name="Mac OS X"/>
</condition>
<condition property="native.so" value="so">
<not><os name="Mac OS X"/></not>
</condition>
<condition property="native.arch" value="">
<os name="Mac OS X"/>
</condition>
<condition property="native.arch" value=".${os.arch}">
<not>
<os name="Mac OS X"/>
</not>
</condition>
<condition property="is-windows">
<os family="windows"/>
</condition>
<condition property="is-unix">
<not><os family="windows"/></not>
</condition>
<target name="require-version">
<fail message="Missing build version. use ant proper ZCS version like -Dzimbra.buildinfo.version=8.7.6_GA_1001">
<condition>
<not>
<isset property="zimbra.buildinfo.version"/>
</not>
</condition>
</fail>
<echo message="Using version ${zimbra.buildinfo.version}"/>
</target>
<target name="set-dev-version" depends="require-version,3rd-party-defines">
<antcontrib:if>
<not>
<isset property="jar.file"/>
</not>
<then>
<exec executable="git" outputproperty="git.timestamp">
<arg value="log"/>
<arg value="-1"/>
<arg value="--pretty=format:%at"/>
</exec>
<!-- Build version -->
<tstamp/>
<antcontrib:propertyregex property="zimbra.buildinfo.majorversion"
input="${zimbra.buildinfo.version}"
regexp="([0-9]+)\.([0-9]+)\.([0-9]+)"
select="\1"
casesensitive="false" />
<antcontrib:propertyregex property="zimbra.buildinfo.minorversion"
input="${zimbra.buildinfo.version}"
regexp="([0-9]+)\.([0-9]+)\.([0-9]+)"
select="\2"
casesensitive="false" />
<antcontrib:propertyregex property="zimbra.buildinfo.microversion"
input="${zimbra.buildinfo.version}"
regexp="([0-9]+)\.([0-9]+)\.([0-9]+)"
select="\3"
casesensitive="false" />
<antcontrib:propertyregex property="zimbra.buildinfo.relclass"
defaultValue="GA"
input="${zimbra.buildinfo.version}"
regexp="([0-9]+)\.([0-9]+)\.([0-9]+)_([A-Z]+)"
select="\4"
casesensitive="false" />
<antcontrib:propertyregex property="zimbra.buildinfo.buildnum"
input="${zimbra.buildinfo.version}"
regexp="([0-9]+)\.([0-9]+)\.([0-9]+)_([A-Z]+)_([0-9]+)"
select="\5"
casesensitive="false" />
<condition property="zimbra.buildinfo.relnum" value="0">
<not><isset property="${zimbra.buildinfo.relnum}"/></not>
</condition>
<condition property="zimbra.buildinfo.type" value="">
<not><isset property="${zimbra.buildinfo.type}"/></not>
</condition>
<condition property="zimbra.buildinfo.release" value="${user.name}">
<not><isset property="${zimbra.buildinfo.release}"/></not>
</condition>
<condition property="zimbra.buildinfo.date" value="${DSTAMP}-${TSTAMP}">
<not><isset property="${zimbra.buildinfo.date}"/></not>
</condition>
<condition property="zimbra.buildinfo.host" value="${zimbra.server.hostname}">
<not><isset property="${zimbra.buildinfo.host}"/></not>
</condition>
<property name="zimbra.buildinfo.microtag" value="${zimbra.buildinfo.microversion}_${zimbra.buildinfo.relclass}"/>
<property name="zimbra.buildinfo.all"
value="Version: ${zimbra.buildinfo.version}; Type: ${zimbra.buildinfo.type}; Release: ${zimbra.buildinfo.release}; Built: ${zimbra.buildinfo.date}; Host: ${zimbra.buildinfo.host}"/>
<property name="dev.version" value="${zimbra.buildinfo.majorversion}.${zimbra.buildinfo.minorversion}.${zimbra.buildinfo.microversion}.${git.timestamp}"/>
<property name="jar.file" value="${ant.project.name}-${dev.version}.jar"/>
</then>
</antcontrib:if>
</target>
<target name="clean">
<delete dir="${build.dir}"/>
<delete dir="${dist.dir}"/>
</target>
<target name="build-init" depends="require-version">
<mkdir dir="${build.classes.dir}"/>
<mkdir dir="${dist.dir}"/>
</target>
<target name="compile" depends="build-init,resolve,3rd-party-defines" description="Compiles from src/java into build/classes.">
<mkdir dir="${build.classes.dir}" />
<javac destdir="${build.classes.dir}" debug="true" classpathref="class.path" target="${javac.target}" encoding="utf-8">
<src refid="all.java.path" />
</javac>
</target>
<target name="test-compile" depends="compile,3rd-party-defines">
<antcontrib:if>
<available file="${test.src.dir}" type="dir"/>
<antcontrib:then>
<mkdir dir="${test.classes.dir}"/>
<javac destdir="${test.classes.dir}" srcdir="${test.src.dir}" classpathref="test.class.path"
debug="true" target="${javac.target}" encoding="utf-8" />
<copy todir="${test.classes.dir}">
<fileset dir="${test.src.dir}" excludes="**/*.java"/>
</copy>
</antcontrib:then>
</antcontrib:if>
</target>
<target name="test" depends="test-compile" description="Run unit tests">
<property name="test-results-file" value="${zm-mailbox.basedir}/build/test-results.txt"/>
<antcontrib:if>
<available file="${test.src.dir}" type="dir"/>
<then>
<property name="test.path" refid="test.class.path"/>
<delete dir="${test.dir}" quiet="true"/>
<mkdir dir="${test.dir}/output"/>
<mkdir dir="${test.dir}/report"/>
<mkdir dir="${test.dir}/extensions"/>
<move todir="${test.dir}/extensions/com/zimbra/extensions" failonerror="false">
<fileset dir="${test.classes.dir}/com/zimbra/extensions" />
</move>
<copy file="${test.src.dir}/log4j-test.properties" tofile="${test.classes.dir}/log4j.properties" failonerror="false"/>
<junit haltonfailure="${halt-on-failure}" printsummary="on" showoutput="true" failureproperty="junit.failure" tempdir="${test.dir}" fork="true">
<classpath refid="test.class.path"/>
<assertions><enable/></assertions>
<formatter type="xml"/>
<jvmarg value="-Xverify:none"/>
<jvmarg value="-Dserver.dir=${server.dir}"/>
<jvmarg value="-Dzimbra.config=${server.dir}/src/java-test/localconfig-test.xml"/>
<jvmarg value="-Dfile.encoding=UTF-8"/>
<batchtest todir="${test.dir}/output">
<fileset dir="${test.src.dir}">
<include name="${test.pattern}"/>
<exclude name="**/Abstract*Test.java"/>
<exclude name="**/mailbox/ContactTest.java"/>
<exclude name="**/filter/FileIntoCopyTest.java"/>
<exclude name="**/cs/redolog/op/CreateMessageTest.java"/>
<exclude name="**/cs/service/mail/SearchActionTest.java"/>
<exclude name="**/cs/filter/RuleManagerWithCustomActionFilterTest.java"/>
</fileset>
</batchtest>
</junit>
<junitreport todir="${test.dir}/report">
<fileset dir="${test.dir}/output"/>
<report todir="${test.dir}/report"/>
</junitreport>
<echo>Test Report: ${test.dir}/report/index.html</echo>
<antcontrib:if>
<isset property="junit.failure"/>
<then><echo append="true" file="${test-results-file}" message="${test.dir} - FAILED
"/></then>
<else><echo append="true" file="${test-results-file}" message="${test.dir} - PASSED
"/></else>
</antcontrib:if>
</then>
<else>
<echo>${test.src.dir} not found. Will not run unit tests</echo>
</else>
</antcontrib:if>
</target>
<target name="test-hudson" depends="test-compile" description="Run hudson unit tests">
<property name="test.path" refid="test.class.path"/>
<delete dir="${test.dir}" quiet="true"/>
<mkdir dir="${test.dir}/output"/>
<mkdir dir="${test.dir}/report"/>
<mkdir dir="${test.dir}/extensions"/>
<move todir="${test.dir}/extensions/com/zimbra/extensions" failonerror="false">
<fileset dir="${test.classes.dir}/com/zimbra/extensions" />
</move>
<copy file="${test.src.dir}/log4j-test.properties" tofile="${test.classes.dir}/log4j.properties" failonerror="false"/>
<junit printsummary="on" showoutput="true" failureproperty="junit.failure" tempdir="${test.dir}">
<classpath refid="test.class.path"/>
<assertions><enable/></assertions>
<formatter type="xml"/>
<jvmarg value="-Xverify:none"/>
<batchtest todir="${test.dir}/output">
<fileset dir="${test.src.dir}">
<include name="**/*Test.java"/>
<exclude name="**/*ITest.java"/>
<exclude name="**/Abstract*Test.java"/>
</fileset>
</batchtest>
</junit>
<junitreport todir="${test.dir}/report">
<fileset dir="${test.dir}/output"/>
<report todir="${test.dir}/report"/>
</junitreport>
<echo>Test Report: ${test.dir}/report/index.html</echo>
<fail if="junit.failure" message="Unit test failed"/>
</target>
<!-- e.g. ant -Dtest.name=com.zimbra.cs.mailbox.ContactTest single-test -->
<target name="single-test" depends="test-compile" description="Run single unit test">
<fail message="test.name must be set - Need e.g. ant -Dtest.name=com.zimbra.cs.mailbox.ContactTest single-test"
unless="test.name"/>
<property name="single.test.dir" value="${test.dir}-${test.name}"/>
<delete dir="${single.test.dir}" quiet="true"/>
<mkdir dir="${single.test.dir}/output"/>
<mkdir dir="${single.test.dir}/report"/>
<mkdir dir="${test.dir}/extensions"/>
<move todir="${test.dir}/extensions/com/zimbra/extensions" failonerror="false">
<fileset dir="${test.classes.dir}/com/zimbra/extensions" />
</move>
<copy file="${test.src.dir}/log4j-test.properties" tofile="${test.classes.dir}/log4j.properties" failonerror="false"/>
<junit fork="yes" printsummary="on" showoutput="true" failureproperty="junit.failure" tempdir="${single.test.dir}">
<classpath refid="test.class.path"/>
<assertions><enable/></assertions>
<formatter type="xml"/>
<jvmarg value="-Xverify:none"/>
<jvmarg value="-Dserver.dir=${server.dir}"/>
<jvmarg value="-Dzimbra.config=${server.dir}/src/java-test/localconfig-test.xml"/>
<jvmarg value="-Dfile.encoding=UTF-8"/>
<test name="${test.name}" todir="${single.test.dir}/output" />
</junit>
<junitreport todir="${single.test.dir}/report">
<fileset dir="${single.test.dir}/output"/>
<report todir="${single.test.dir}/report"/>
</junitreport>
<echo>Test Report: ${single.test.dir}/report/index.html</echo>
<fail if="junit.failure" message="Single Unit test failed"/>
</target>
<!-- Detect if JaCoCo + ASM jars already exist -->
<condition property="jacoco.skip">
<and>
<available file="${zimbra.root.dir}/zm-mailbox/lib/jacocoant.jar"/>
<available file="${zimbra.root.dir}/zm-mailbox/lib/jacocoagent.jar"/>
<available file="${zimbra.root.dir}/zm-mailbox/lib/jacococore.jar"/>
<available file="${zimbra.root.dir}/zm-mailbox/lib/jacocoreport.jar"/>
<available file="${zimbra.root.dir}/zm-mailbox/lib/asm-9.5.jar"/>
<available file="${zimbra.root.dir}/zm-mailbox/lib/asm-commons-9.5.jar"/>
<available file="${zimbra.root.dir}/zm-mailbox/lib/asm-tree-9.5.jar"/>
<available file="${zimbra.root.dir}/zm-mailbox/lib/asm-util-9.5.jar"/>
</and>
</condition>
<target name="download-jacoco" depends="init-ivy" unless="jacoco.skip">
<mkdir dir="${build.dir}"/>
<mkdir dir="${zimbra.root.dir}/zm-mailbox/lib"/>
<!-- Temporary Ivy file -->
<echo file="${build.dir}/ivy-jacoco.xml"><![CDATA[
<ivy-module version="2.0">
<info organisation="zimbra" module="jacoco-temp"/>
<dependencies>
<dependency org="org.jacoco" name="org.jacoco.ant" rev="0.8.14"/>
<dependency org="org.jacoco" name="org.jacoco.agent" rev="0.8.14"/>
<dependency org="org.jacoco" name="org.jacoco.core" rev="0.8.14"/>
<dependency org="org.jacoco" name="org.jacoco.report" rev="0.8.14"/>
<dependency org="org.ow2.asm" name="asm" rev="9.5"/>
<dependency org="org.ow2.asm" name="asm-commons" rev="9.5"/>
<dependency org="org.ow2.asm" name="asm-tree" rev="9.5"/>
<dependency org="org.ow2.asm" name="asm-util" rev="9.5"/>
</dependencies>
</ivy-module>
]]></echo>
<!-- Resolve -->
<ivy:resolve file="${build.dir}/ivy-jacoco.xml" settingsRef="dev.settings"/>
<ivy:retrieve file="${build.dir}/ivy-jacoco.xml"
pattern="${zimbra.root.dir}/zm-mailbox/lib/[artifact]-[revision].[ext]"
settingsRef="dev.settings"/>
<!-- Rename JaCoCo jars -->
<move todir="${zimbra.root.dir}/zm-mailbox/lib">
<fileset dir="${zimbra.root.dir}/zm-mailbox/lib">
<include name="org.jacoco.*-0.8.14.jar"/>
</fileset>
<mapper type="regexp"
from="org\.jacoco\.(ant|agent|core|report)-0\.8\.14\.jar"
to="jacoco\1.jar"/>
</move>
<delete file="${build.dir}/ivy-jacoco.xml" quiet="true"/>
</target>
<target name="define-jacoco-tasks" depends="download-jacoco">
<taskdef uri="antlib:org.jacoco.ant"
resource="org/jacoco/ant/antlib.xml">
<classpath>
<fileset dir="${zimbra.root.dir}/zm-mailbox/lib">
<include name="jacoco*.jar"/>
<include name="asm-9.5.jar"/>
<include name="asm-commons-9.5.jar"/>
<include name="asm-tree-9.5.jar"/>
<include name="asm-util-9.5.jar"/>
</fileset>
</classpath>
</taskdef>
</target>
<target name="coverage" depends="test-compile, define-jacoco-tasks, 3rd-party-defines" description="Run unit tests with JaCoCo coverage" unless="skipCoverage">
<delete dir="${build.coverage.dir}" quiet="true"/>
<mkdir dir="${build.coverage.dir}"/>
<mkdir dir="${build.coverage.dir}/html"/>
<!-- Create a separate test directory for coverage to avoid conflicts -->
<property name="coverage.test.dir" value="${build.dir}/coverage-test"/>
<delete dir="${coverage.test.dir}" quiet="true"/>
<mkdir dir="${coverage.test.dir}/output"/>
<mkdir dir="${coverage.test.dir}/extensions"/>
<jacoco:coverage destfile="${build.coverage.dir}/jacoco.exec">
<junit fork="true" printsummary="on" showoutput="true" failureproperty="junit.failure" tempdir="${coverage.test.dir}">
<classpath refid="test.class.path"/>
<assertions><enable/></assertions>
<formatter type="plain"/>
<!-- Include tests from all components -->
<batchtest todir="${coverage.test.dir}/output">
<!-- Store component tests -->
<fileset dir="${server.dir}/src/java-test">
<include name="**/*Test.java"/>
<exclude name="**/*ITest.java"/>
<exclude name="**/Abstract*Test.java"/>
</fileset>
<!-- Soap component tests -->
<fileset dir="${soap.dir}/src/java-test">
<include name="**/*Test.java"/>
<exclude name="**/*ITest.java"/>
<exclude name="**/Abstract*Test.java"/>
</fileset>
<!-- Common component tests -->
<fileset dir="${common.dir}/src/java-test">
<include name="**/*Test.java"/>
<exclude name="**/*ITest.java"/>
<exclude name="**/Abstract*Test.java"/>
</fileset>
<!-- Client component tests -->
<fileset dir="${client.dir}/src/java-test">
<include name="**/*Test.java"/>
<exclude name="**/*ITest.java"/>
<exclude name="**/Abstract*Test.java"/>
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
<!-- Use the already defined antcontrib namespace -->
<antcontrib:trycatch>
<antcontrib:try>
<antcall target="generate-coverage-report" inheritAll="true"/>
</antcontrib:try>
<antcontrib:catch>
<echo message="Coverage report generation failed (ignored)."/>
</antcontrib:catch>
<antcontrib:finally>
<echo message="Coverage report generation completed."/>
</antcontrib:finally>
</antcontrib:trycatch>
<fail if="junit.failure" message="Unit test failed" unless="ignore.junit.failure"/>
</target>
<target name="generate-coverage-report" depends="define-jacoco-tasks">
<!-- ============================= -->
<!-- STORE COVERAGE REPORT -->
<!-- ============================= -->
<jacoco:report>
<executiondata>
<file file="${build.coverage.dir}/jacoco.exec"/>
</executiondata>
<structure name="zm-mailbox/store">
<classfiles>
<fileset dir="${server.classes.dir}"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${server.dir}/src/java"/>
</sourcefiles>
</structure>
<html destdir="${server.dir}/build/coverage/html"/>
<xml destfile="${server.dir}/build/coverage/report.xml"/>
<csv destfile="${server.dir}/build/coverage/report.csv"/>
</jacoco:report>
<!-- ============================= -->
<!-- SOAP COVERAGE REPORT -->
<!-- ============================= -->
<jacoco:report>
<executiondata>
<file file="${build.coverage.dir}/jacoco.exec"/>
</executiondata>
<structure name="zm-mailbox/soap">
<classfiles>
<fileset dir="${soap.classes.dir}"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${soap.dir}/src/java"/>
</sourcefiles>
</structure>
<html destdir="${soap.dir}/build/coverage/html"/>
<xml destfile="${soap.dir}/build/coverage/report.xml"/>
<csv destfile="${soap.dir}/build/coverage/report.csv"/>
</jacoco:report>
<!-- ============================= -->
<!-- COMMON COVERAGE REPORT -->
<!-- ============================= -->
<jacoco:report>
<executiondata>
<file file="${build.coverage.dir}/jacoco.exec"/>
</executiondata>
<structure name="zm-mailbox/common">
<classfiles>
<fileset dir="${common.classes.dir}"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${common.dir}/src/java"/>
</sourcefiles>
</structure>
<html destdir="${common.dir}/build/coverage/html"/>
<xml destfile="${common.dir}/build/coverage/report.xml"/>
<csv destfile="${common.dir}/build/coverage/report.csv"/>
</jacoco:report>
<!-- ============================= -->
<!-- CLIENT COVERAGE REPORT -->
<!-- ============================= -->
<jacoco:report>
<executiondata>
<file file="${build.coverage.dir}/jacoco.exec"/>
</executiondata>
<structure name="zm-mailbox/client">
<classfiles>
<fileset dir="${client.classes.dir}"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${client.dir}/src/java"/>
</sourcefiles>
</structure>
<html destdir="${client.dir}/build/coverage/html"/>
<xml destfile="${client.dir}/build/coverage/report.xml"/>
<csv destfile="${client.dir}/build/coverage/report.csv"/>
</jacoco:report>
<echo message="Module-wise coverage reports generated successfully."/>
</target>
<target name="integration-test" depends="test-compile" description="Run integration tests">
<property name="test.path" refid="class.path"/>
<delete dir="${itest.dir}" quiet="true"/>
<mkdir dir="${itest.dir}/output"/>
<mkdir dir="${itest.dir}/report"/>
<junit printsummary="on" failureproperty="junit.failure" tempdir="${itest.dir}">
<classpath refid="class.path"/>
<classpath path="${test.classes.dir}"/>
<assertions><enable/></assertions>
<formatter type="xml"/>
<batchtest todir="${itest.dir}/output">
<fileset dir="${test.src.dir}">
<include name="**/*ITest.java"/>
</fileset>
</batchtest>
</junit>
<junitreport todir="${itest.dir}/report">
<fileset dir="${itest.dir}/output"/>
<report todir="${itest.dir}/report"/>
</junitreport>
<echo>Test Report: ${itest.dir}/report/index.html</echo>
<fail if="junit.failure" message="Integration test failed"/>
</target>
<target name="generate-jar-version" description="Creates the Version class that prints the version of the jarfile. This class is the Main-Class in the jarfile's manifest." depends="3rd-party-defines">
<fail unless="build.dir" />
<fail unless="build.classes.dir" />
<antcontrib:if>
<not><available file="${build.dir}/buildinfo/com/zimbra/buildinfo/Version.java"/></not>
<then>
<mkdir dir="${build.dir}/buildinfo/com/zimbra/buildinfo"/>
<echo file="${build.dir}/buildinfo/com/zimbra/buildinfo/Version.java">
package com.zimbra.buildinfo;
public class Version {
public static void main(String[] args) {
Package p = Version.class.getPackage();
System.out.println("Implementation-Title: " + p.getImplementationTitle() +
"\nImplementation-Version: " + p.getImplementationVersion() +
"\nImplementation-Vendor: " + p.getImplementationVendor() + "\n");
}
}
</echo>
</then>
</antcontrib:if>
<javac destdir="${build.classes.dir}" debug="true" target="${javac.target}" srcdir="${build.dir}/buildinfo" />
</target>
<target name="zimbra-jar" depends="generate-jar-version,set-dev-version,3rd-party-defines" description="Builds a standard jar file that prints its version info when executed. Optionally sets the Zimbra-Extension-Class attribute in the manifest if the zimbra.extension.class property is set.">
<condition property="jar.file" value="${ant.project.name}-${dev.version}.jar">
<not><isset property="jar.file"/></not>
</condition>
<fail unless="implementation.title"/>
<antcontrib:if>
<not>
<isset property="jar.build.dir"/>
</not>
<then>
<property name="jar.build.dir" value="${build.classes.dir}"/>
</then>
</antcontrib:if>
<antcontrib:if>
<not>
<isset property="excludes"/>
</not>
<then>
<property name="excludes" value=""/>
</then>
</antcontrib:if>
<antcontrib:if>
<not>
<isset property="includes"/>
</not>
<then>
<property name="includes" value=""/>
</then>
</antcontrib:if>
<echo>building jar from ${jar.build.dir}</echo>
<antcontrib:if>
<isset property="zimbra.extension.class"/>
<then>
<jar destfile="${build.dir}/${jar.file}" basedir="${jar.build.dir}" includes="${includes}" excludes="${excludes}">
<manifest>
<attribute name="Main-Class" value="com.zimbra.buildinfo.Version" />
<attribute name="Implementation-Vendor" value="Zimbra Software, LLC"/>
<attribute name="Implementation-Title" value="${implementation.title}"/>
<attribute name="Implementation-Version" value="${zimbra.buildinfo.version}"/>
<attribute name="Specification-Vendor" value="Zimbra Software, LLC"/>
<attribute name="Specification-Title" value="Zimbra Collaboration Suite"/>
<attribute name="Specification-Version" value="${zimbra.buildinfo.majorversion}.${zimbra.buildinfo.minorversion}.${zimbra.buildinfo.microversion}"/>
<attribute name="Zimbra-Extension-Class" value="${zimbra.extension.class}"/>
</manifest>
</jar>
</then>
<else>
<jar destfile="${build.dir}/${jar.file}" basedir="${jar.build.dir}" includes="${includes}" excludes="${excludes}">
<manifest>
<attribute name="Main-Class" value="com.zimbra.buildinfo.Version" />
<attribute name="Implementation-Vendor" value="Zimbra Software, LLC"/>
<attribute name="Implementation-Title" value="${implementation.title}"/>
<attribute name="Implementation-Version" value="${zimbra.buildinfo.version}"/>
<attribute name="Specification-Vendor" value="Zimbra Software, LLC"/>
<attribute name="Specification-Title" value="Zimbra Collaboration Suite"/>
<attribute name="Specification-Version" value="${zimbra.buildinfo.majorversion}.${zimbra.buildinfo.minorversion}.${zimbra.buildinfo.microversion}"/>
</manifest>
</jar>
</else>
</antcontrib:if>
</target>
<target name="clean-cache" description="Delete ivy cache">
<delete dir="${dev.home}/.ivy2/cache/zimbra/${ant.project.name}"/>
<delete dir="${dev.home}/.zcs-deps/zimbra/${ant.project.name}"/>
<delete>
<fileset dir="${dev.home}/.ivy2/cache" includes="*${ant.project.name}*"/>
</delete>
</target>
<target name="publish-local" depends="clean-cache,jar,set-dev-version,init-ivy">
<ivy:publish settingsRef="dev.settings" pubrevision="${dev.version}" resolver="local" overwrite="true" />
</target>
<target name="zmlocalconfig">
<echo>Running localconfig with with argument: ${localconfig-args}</echo>
<java classname="com.zimbra.cs.localconfig.LocalConfigCLI" fork="true" classpathref="class.path" failonerror="true">
<arg line="${localconfig-args}"/>
</java>
</target>
<target name="dist.dependencies">
<antcall target="depend.${ant.project.name}"/>
</target>
<target name="publish-foss-local">
<ant dir="${native.dir}" target="publish-local" inheritAll="false"/>
<ant dir="${common.dir}" target="publish-local" inheritAll="false"/>
<ant dir="${soap.dir}" target="publish-local" inheritAll="false"/>
<ant dir="${client.dir}" target="publish-local" inheritAll="false"/>
<ant dir="${server.dir}" target="publish-local" inheritAll="false"/>
</target>
<target name="deploy-foss">
<ant dir="${native.dir}" target="deploy-no-start" inheritAll="false"/>
<ant dir="${common.dir}" target="deploy-no-start" inheritAll="false"/>
<ant dir="${soap.dir}" target="deploy-no-start" inheritAll="false"/>
<ant dir="${client.dir}" target="deploy-no-start" inheritAll="false"/>
<ant dir="${server.dir}" target="deploy" inheritAll="false"/>
</target>
<target name="stop-webserver">
<ant dir="${server.dir}" target="stop-webserver" inheritAll="false"/>
</target>
<target name="start-webserver">
<ant dir="${server.dir}" target="start-webserver" inheritAll="false"/>
</target>
<target name="sonar-scan" depends="compile" unless="skipSonarScan" description="Run SonarQube analysis">
<property environment="env"/>
<pathconvert property="sonar.java.libraries" refid="class.path" pathsep=","/>
<pathconvert property="sonar.java.test.libraries" refid="test.class.path" pathsep=","/>
<fail message="SONAR_HOST_URL environment variable not set" unless="env.SONAR_HOST_URL"/>
<fail message="SONAR_TOKEN environment variable not set" unless="env.SONAR_TOKEN"/>
<echo message="Running SonarQube scan for zm-mailbox"/>
<path id="sonar.sources">
<pathelement location="${server.dir}/src/java"/>
<pathelement location="${common.dir}/src/java"/>
<pathelement location="${soap.dir}/src/java"/>
<pathelement location="${client.dir}/src/java"/>
<pathelement location="${native.dir}/src/java"/>
</path>
<pathconvert property="sonar.sources.paths" refid="sonar.sources" pathsep=","/>
<condition property="sonar.sources.arg" value="-Dsonar.sources=${sonar.sources.paths}" else="">
<isset property="sonar.sources.paths"/>
</condition>
<echo message="Resolved sonar.sources : ${sonar.sources.arg}"/>
<path id="sonar.java.binaries">
<dirset dir="${server.dir}">
<include name="build/classes"/>
</dirset>
<dirset dir="${common.dir}">
<include name="build/classes"/>
</dirset>
<dirset dir="${soap.dir}">
<include name="build/classes"/>
</dirset>
<dirset dir="${client.dir}">
<include name="build/classes"/>
</dirset>
<dirset dir="${native.dir}">
<include name="build/classes"/>
</dirset>
</path>
<pathconvert property="sonar.java.binaries.paths" refid="sonar.java.binaries" pathsep=","/>
<condition property="sonar.java.binaries.arg" value="-Dsonar.java.binaries=${sonar.java.binaries.paths}" else="">
<isset property="sonar.java.binaries.paths"/>
</condition>
<echo message="Resolved sonar.java.binaries : ${sonar.java.binaries.arg}"/>
<path id="sonar.test.sources">
<dirset dir="${server.dir}">
<include name="src/java-test"/>
</dirset>
<dirset dir="${common.dir}">
<include name="src/java-test"/>
</dirset>
<dirset dir="${soap.dir}">
<include name="src/java-test"/>
</dirset>
<dirset dir="${client.dir}">
<include name="src/java-test"/>
</dirset>
</path>
<pathconvert property="sonar.tests.paths" refid="sonar.test.sources" pathsep=","/>
<condition property="sonar.tests.arg" value="-Dsonar.tests=${sonar.tests.paths}" else="">
<isset property="sonar.tests.paths"/>
</condition>
<echo message="Resolved sonar.tests : ${sonar.tests.arg}"/>
<path id="sonar.junit.reports">
<dirset dir="${server.dir}">
<include name="build/test/report"/>
</dirset>
<dirset dir="${common.dir}">
<include name="build/test/report"/>
</dirset>
<dirset dir="${soap.dir}">
<include name="build/test/report"/>
</dirset>
<dirset dir="${client.dir}">
<include name="build/test/report"/>
</dirset>
</path>
<pathconvert property="sonar.junit.reports.paths" refid="sonar.junit.reports" pathsep=","/>
<condition property="sonar.junit.arg" value="-Dsonar.junit.reportPaths=${sonar.junit.reports.paths}" else="">
<isset property="sonar.junit.reports.paths"/>
</condition>
<echo message="Resolved sonar.junit.reportPaths : ${sonar.junit.arg}"/>
<path id="sonar.coverage.reports">
<fileset dir="${server.dir}">
<include name="build/coverage/report.xml"/>
</fileset>
<fileset dir="${common.dir}">
<include name="build/coverage/report.xml"/>
</fileset>
<fileset dir="${soap.dir}">
<include name="build/coverage/report.xml"/>
</fileset>
<fileset dir="${client.dir}">
<include name="build/coverage/report.xml"/>
</fileset>
</path>
<pathconvert property="sonar.coverage.paths" refid="sonar.coverage.reports" pathsep=","/>
<condition property="sonar.coverage.arg" value="-Dsonar.coverage.jacoco.xmlReportPaths=${sonar.coverage.paths}" else="">
<isset property="sonar.coverage.paths"/>
</condition>
<echo message="Resolved sonar.coverage.jacoco.xmlReportPaths : ${sonar.coverage.arg}"/>
<path id="sonar.test.binaries">
<dirset dir="${server.dir}">
<include name="build/test-classes"/>
</dirset>
<dirset dir="${common.dir}">
<include name="build/test-classes"/>
</dirset>
<dirset dir="${soap.dir}">
<include name="build/test-classes"/>
</dirset>
<dirset dir="${client.dir}">
<include name="build/test-classes"/>
</dirset>
</path>
<pathconvert property="sonar.test.binaries.paths" refid="sonar.test.binaries" pathsep=","/>
<condition property="sonar.test.binaries.arg" value="-Dsonar.java.test.binaries=${sonar.test.binaries.paths}" else="">
<isset property="sonar.test.binaries.paths"/>
</condition>
<condition property="sonar.test.libs.arg" value="-Dsonar.java.test.libraries=${sonar.test.binaries.paths}" else="">
<isset property="sonar.test.binaries.paths"/>
</condition>
<echo message="Resolved sonar.java.test.binaries : ${sonar.test.binaries.arg}"/>
<echo message="Resolved sonar.java.test.libraries : ${sonar.test.libs.arg}"/>
<exec executable="sonar-scanner" failonerror="true">
<arg value="-Dsonar.projectKey=zm-mailbox"/>
<arg value="-Dsonar.projectName=zm-mailbox"/>
<arg value="-Dsonar.projectBaseDir=${zimbra.root.dir}/zm-mailbox"/>
<arg value="-Dsonar.java.source=${javac.target}"/>
<arg line="${sonar.sources.arg}"/>
<arg line="${sonar.java.binaries.arg}"/>
<arg value="-Dsonar.java.libraries=${sonar.java.libraries}"/>
<arg value="-Dsonar.host.url=${env.SONAR_HOST_URL}"/>
<arg value="-Dsonar.token=${env.SONAR_TOKEN}"/>
<arg line="${sonar.tests.arg}"/>
<arg line="${sonar.test.binaries.arg}"/>
<arg line="${sonar.test.libs.arg}"/>
<arg line="${sonar.junit.arg}"/>
<arg line="${sonar.coverage.arg}"/>
</exec>
</target>
</project>