forked from vufind-org/vufind
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.xml
1420 lines (1320 loc) · 58.2 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
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
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="UTF-8"?>
<project name="vufind" basedir="." default="main">
<property name="sh" value="/bin/sh" />
<property name="tmp" value="/tmp" />
<property name="package" value="${phing.project.name}" override="true" />
<property name="builddir" value="${tmp}/build/${phing.project.name}" override="true" />
<property name="srcdir" value="${project.basedir}" override="true" />
<property name="downloadsdir" value="${srcdir}/downloads" override="true" />
<!--
Use builddir/local as the local directory if defaultconfigs=true. This allows the
tests to be run without any custom configuration possibly interfering in the
normal local directory.
-->
<if>
<equals arg1="${defaultconfigs}" arg2="true" />
<then>
<property name="localdir" value="${builddir}/local" override="true" />
</then>
<else>
<property name="localdir" value="${srcdir}/local" override="false" />
</else>
</if>
<property name="apacheconfdir" value="/etc/apache2/conf.d" />
<property name="apachectl" value="" /><!-- set to apachectl path to spin up Apache instance -->
<property name="seleniumjar" value="" /><!-- set to Selenium jar path to spin up Selenium instance -->
<!-- command for extra cleanup during shutdown; e.g. to change cache ownership after testing w/ Apache so deletion won't fail: -->
<property name="extra_startup_command" value="" />
<property name="extra_shutdown_cleanup" value="" />
<property name="vufindurl" value="http://localhost/vufind" />
<property name="vufinddb" value="vufind_test" />
<property name="vufinddbuser" value="vufindtest" />
<property name="vufinddbpass" value="vufindtestpass" />
<property name="dbtype" value="mysql" /><!-- use pgsql for PostgreSQL -->
<property name="mysqlhost" value="localhost" />
<property name="mysqlport" value="3306" />
<property name="mysqlprotocol" value="" />
<property name="mysqlrootuser" value="root" />
<property name="mysqlrootpass" value="password" />
<property name="pgsqlhost" value="localhost" />
<property name="pgsqlrootuser" value="postgres" />
<property name="disable_csp" value="false" /> <!-- set value to "true" to disable Content Security Policy -->
<property name="phpunit_command" value="${srcdir}/vendor/bin/phpunit" />
<property name="phpunit_extra_params" value="" />
<property name="composer_version" value="2.7.7" />
<property name="composer_extra_params" value="" />
<property name="mink_driver" value="selenium" />
<property name="screenshot_dir" value="" /><!-- set to a directory name to capture screenshots of failed tests -->
<property name="selenium_browser" value="firefox" />
<property name="snooze_multiplier" value="1" /><!-- can be used to slow down Mink tests; increase when tests fail on slow systems -->
<property name="default_test_timeout" value="5000" /><!-- default timeout (in ms) for Mink tests; increase when tests fail on slow systems -->
<property name="solr_startup_sleep" value="0" />
<property name="solr_additional_jvm_options" value="-Dlog4j2.formatMsgNoLookups=true" />
<property name="solr_version" value="9.5.0" />
<property name="solr_port" value="8983" />
<property name="skip_phpdoc" value="false" />
<property name="phpdoc_version" value="3.3.1" />
<property name="html_validator" value="" /><!-- set to base address of NU Validator (e.g. http://localhost:8888/) for HTML validation during Mink tests -->
<property name="html_validator_fail_tests" value="1" /><!-- set to 0 to just log HTML validation errors without causing tests to fail -->
<property name="html_validator_log_file" value="" /><!-- set to a file name to log HTML validation messages to -->
<property name="html_validator_quiet" value="" /><!-- set to 1 to prevent the HTML validation from outputting results to the console -->
<property name="phpunit_remote_coverage" value="" /><!-- set to 1 to enable code coverage for Mink tests -->
<property name="retain_coverage_files" value="false" /><!-- set to true to keep temporary coverage files from Mink tests -->
<property name="test_theme" value="" /><!-- set to a theme name to override the default theme for Mink tests -->
<property name="psql_needs_sudo" value="true" /><!-- set to false if psql (Postgresql) must be run with current user instead of sudo -->
<property name="solr_pid_file" value="${localdir}/solr-${solr_port}.pid" />
<property name="marc_bib_dir" value="${srcdir}/tests/data" /><!-- directory containing MARC bib records for test environment -->
<property name="marc_authority_dir" value="${marc_bib_dir}/authority" /><!-- directory containing MARC authority records for test environment -->
<property name="version" value="10.0" />
<property name="mysqlconnectionargs" value="-h ${mysqlhost} -P ${mysqlport} -u ${mysqlrootuser}" />
<!-- Add password if not empty -->
<if>
<not>
<equals arg1="${mysqlrootpass}" arg2="" />
</not>
<then>
<property name="mysqlconnectionargs" override="true" value="${mysqlconnectionargs} -p${mysqlrootpass}" />
</then>
</if>
<!-- Add protocol if not empty -->
<if>
<not>
<equals arg1="${mysqlprotocol}" arg2="" />
</not>
<then>
<property name="mysqlconnectionargs" override="true" value="${mysqlconnectionargs} --protocol ${mysqlprotocol}" />
</then>
</if>
<!-- Main Target -->
<target name="main" description="main target">
<phingcall target="startup" />
<phingcall target="ci-tasks-with-shutdown" />
</target>
<!-- Continuous Integration Tasks with guaranteed shutdown -->
<target name="ci-tasks-with-shutdown" description="continuous integration tasks (with shutdown on success or failure)">
<trycatch property="exceptionmsg">
<try>
<phingcall target="ci-tasks" />
</try>
<catch>
<phingcall target="shutdown" />
<fail>Unexpected error during continuous integration tasks -- ${exceptionmsg}</fail>
</catch>
</trycatch>
<phingcall target="shutdown" />
</target>
<!-- Run tests, shut down if anything fails (useful when chaining multiple phpunitfast runs in continuous
integration with different settings; e.g. to repeat tests with different themes) -->
<target name="phpunitfast-with-shutdown-on-fail" description="run phpunitfast task; shutdown if anything fails">
<trycatch property="exceptionmsg">
<try>
<phingcall target="phpunitfast" />
</try>
<catch>
<phingcall target="shutdown" />
<fail>${exceptionmsg}</fail>
</catch>
</trycatch>
</target>
<!-- Continuous Integration Tasks -->
<target name="ci-tasks" description="continuous integration tasks">
<!-- Create dirs -->
<mkdir dir="${builddir}/reports"/>
<mkdir dir="${builddir}/reports/coverage"/>
<!-- Call standard tasks -->
<phingcall target="phpcs"/>
<phingcall target="php-cs-fixer-dryrun"/>
<phingcall target="phpunit"/>
<phingcall target="phpdoc"/>
<phingcall target="phpmd"/>
<phingcall target="pdepend"/>
<phingcall target="eslint-report"/>
<phingcall target="jshint-report"/>
<phingcall target="phpstan-checkstyle"/>
<phingcall target="check-bootstrap5"/>
</target>
<!-- Quality Assurance Tasks -->
<target name="qa-console" description="quality assurance tasks">
<!-- Call standard tasks -->
<phingcall target="qa-js-and-less"/>
<phingcall target="qa-php"/>
<phingcall target="check-bootstrap5"/>
</target>
<!-- Quality Assurance Javascript Tasks -->
<target name="qa-js-and-less" description="quality assurance js and less tasks">
<phingcall target="eslint"/>
<phingcall target="jshint"/>
<phingcall target="checkLessToSass"/>
<phingcall target="checkSassBuild"/>
</target>
<!-- Quality Assurance PHP Tasks -->
<target name="qa-php" description="quality assurance php tasks">
<phingcall target="phpunitfast"/>
<phingcall target="phpcs-console"/>
<phingcall target="php-cs-fixer-dryrun"/>
<phingcall target="phpstan-console"/>
</target>
<!-- Fix PHP Tasks -->
<target name="fix-php" description="quality assurance php tasks">
<phingcall target="php-cs-fixer"/>
<phingcall target="phpcbf"/>
</target>
<!-- Report rule violations with PHPMD (mess detector) -->
<target name="phpmd">
<exec executable="${srcdir}/vendor/bin/phpmd">
<arg line="${srcdir}/module xml ${srcdir}/tests/phpmd.xml --exclude ${srcdir}/module/VuFind/tests,${srcdir}/module/VuFindSearch/tests --reportfile ${builddir}/reports/phpmd.xml" />
</exec>
</target>
<!-- PHP_Depend code analysis -->
<target name="pdepend">
<exec executable="${srcdir}/vendor/bin/pdepend">
<arg line="--jdepend-xml=${builddir}/reports/jdepend.xml --jdepend-chart=${builddir}/reports/dependencies.svg --overview-pyramid=${builddir}/reports/pdepend-pyramid.svg ${srcdir}/module" />
</exec>
</target>
<!-- PHP CodeSniffer -->
<target name="phpcbf">
<!-- Run phpcs first to find any problems (faster than phpcbf): -->
<exec executable="${srcdir}/vendor/bin/phpcs" escape="false" returnProperty="phpcs_retval" outputProperty="phpcs_output">
<arg line="--cache=${srcdir}/tests/phpcs.cache.json --standard=${srcdir}/tests/phpcs.xml" />
</exec>
<if>
<not><equals arg1="${phpcs_retval}" arg2="0" /></not>
<then>
<echo msg="Trying to fix the following issues: " />
<echo msg="${phpcs_output}" />
<!-- Extract file names from phpcs output: -->
<property name="phpcbf_filelist" value="${phpcs_output}">
<filterchain>
<linecontainsregexp>
<regexp pattern="^FILE: (.*)" />
</linecontainsregexp>
<striplinebreaks />
<replaceregexp>
<regexp pattern="FILE: " replace=" " />
</replaceregexp>
</filterchain>
</property>
<!-- Finally, run phpcbf: -->
<exec executable="${srcdir}/vendor/bin/phpcbf" escape="false" passthru="true">
<arg line="--standard=${srcdir}/tests/phpcs.xml ${phpcbf_filelist}" />
</exec>
</then>
</if>
</target>
<target name="phpcs">
<exec executable="${srcdir}/vendor/bin/phpcs" escape="false">
<arg line="--cache=${srcdir}/tests/phpcs.cache.json --standard=${srcdir}/tests/phpcs.xml --report=checkstyle > ${builddir}/reports/checkstyle.xml" />
</exec>
</target>
<target name="phpcs-console">
<exec executable="${srcdir}/vendor/bin/phpcs" escape="false" passthru="true" checkreturn="true">
<arg line="--cache=${srcdir}/tests/phpcs.cache.json --standard=${srcdir}/tests/phpcs.xml" />
</exec>
</target>
<!-- Phpstan -->
<target name="phpstan-checkstyle">
<exec executable="${srcdir}/vendor/bin/phpstan" escape="false" passthru="true" checkreturn="true">
<arg line="--configuration=${srcdir}/tests/phpstan.neon --memory-limit=2G --error-format=checkstyle analyse > ${builddir}/reports/phpstan-checkstyle.xml" />
</exec>
</target>
<target name="phpstan-console">
<exec executable="${srcdir}/vendor/bin/phpstan" escape="false" passthru="true" checkreturn="true">
<arg line="--configuration=${srcdir}/tests/phpstan.neon --memory-limit=2G analyse" />
</exec>
</target>
<!-- php-cs-fixer (first task applies fixes, second task simply checks if they are needed) -->
<target name="php-cs-fixer">
<exec executable="${srcdir}/vendor/bin/php-cs-fixer" passthru="true" escape="false">
<arg line="fix --config=${srcdir}/tests/vufind.php-cs-fixer.php -vvv" />
</exec>
<exec executable="${srcdir}/vendor/bin/php-cs-fixer" passthru="true" escape="false">
<arg line="fix --config=${srcdir}/tests/vufind_templates.php-cs-fixer.php -vvv" />
</exec>
</target>
<target name="php-cs-fixer-dryrun">
<exec executable="${srcdir}/vendor/bin/php-cs-fixer" passthru="true" escape="false" checkreturn="true">
<arg line="fix --config=${srcdir}/tests/vufind.php-cs-fixer.php --dry-run -vvv --diff" />
</exec>
<exec executable="${srcdir}/vendor/bin/php-cs-fixer" passthru="true" escape="false" checkreturn="true">
<arg line="fix --config=${srcdir}/tests/vufind_templates.php-cs-fixer.php --dry-run -vvv --diff" />
</exec>
</target>
<!-- ESLint -->
<target name="eslint">
<exec executable="npx" escape="false" checkreturn="true" passthru="true">
<arg line="eslint ${srcdir}/themes/**/*.js -c ${srcdir}/.eslintrc.js" />
</exec>
</target>
<target name="eslint-fix">
<exec executable="npx" escape="false" passthru="true">
<arg line="eslint ${srcdir}/themes/**/*.js -c ${srcdir}/.eslintrc.js --fix" />
</exec>
</target>
<target name="eslint-report">
<exec executable="npx" escape="false">
<arg line="eslint ${srcdir}/themes/**/*.js -c ${srcdir}/.eslintrc.js --format checkstyle -o ${builddir}/reports/eslint-checkstyle.xml" />
</exec>
</target>
<!-- JSHint -->
<target name="jshint">
<exec executable="npx" checkreturn="true" passthru="true">
<arg line="jshint --config=${srcdir}/tests/jshint.json --exclude=themes/*/js/vendor,themes/*/node_modules ${srcdir}/themes" />
</exec>
</target>
<target name="jshint-report">
<exec executable="npx">
<arg line="jshint --config=${srcdir}/tests/jshint.json --exclude=themes/*/js/vendor,themes/*/node_modules --reporter=checkstyle ${srcdir}/themes > ${builddir}/reports/jshint-checkstyle.xml" />
</exec>
</target>
<!-- Run Sass build, error if it fails -->
<target name="checkSassBuild">
<exec executable="npm" checkreturn="true" passthru="true">
<arg line="run check:scss" />
</exec>
</target>
<!-- Run LessToSass, error if there are uncommitted changes (used by continuous integration) -->
<target name="checkLessToSass">
<exec executable="npm" checkreturn="true" passthru="true">
<arg line="run lessToSass" />
</exec>
<exec executable="git" checkreturn="true" passthru="true">
<arg line="diff --exit-code *.scss" />
</exec>
</target>
<!-- PHP API Documentation -->
<target name="phpdoc">
<!-- Skip the whole phpdoc task when disabled -->
<if>
<not><equals arg1="${skip_phpdoc}" arg2="true" /></not>
<then>
<!-- GET phpDocumentor.phar -->
<if>
<not><available file="${srcdir}/vendor/bin/phpDocumentor-${phpdoc_version}.phar" /></not>
<then>
<httpget followRedirects="true" url="https://github.com/phpDocumentor/phpDocumentor2/releases/download/v${phpdoc_version}/phpDocumentor.phar" dir="${srcdir}/vendor/bin" filename="phpDocumentor-${phpdoc_version}.phar" />
<chmod mode="0755">
<fileset dir="${srcdir}/vendor/bin">
<include name="phpDocumentor-${phpdoc_version}.phar" />
</fileset>
</chmod>
</then>
</if>
<!-- Run phpdoc -->
<mkdir dir="${builddir}/apidocs" />
<mkdir dir="${builddir}/docs_cache" />
<!-- Old embedded version; no longer works correctly...
<phpdoc2 title="VuFind API Documentation"
pharlocation="${srcdir}/vendor/bin/phpDocumentor-${phpdoc_version}.phar"
destdir="${builddir}/apidocs">
<fileset dir=".">
<include name="module/*/src/**/*.php" />
</fileset>
</phpdoc2>
-->
<exec executable="php" passthru="true">
<arg line="${srcdir}/vendor/bin/phpDocumentor-${phpdoc_version}.phar --cache-folder=${builddir}/docs_cache --title="VuFind API Documentation" -t ${builddir}/apidocs -d ${srcdir}/module" />
</exec>
</then>
</if>
</target>
<!-- PHPUnit -->
<target name="phpunit" description="Run tests">
<!-- Clean up any previous tmp files but keep the directory if it exists to avoid changing its permissions -->
<property name="coveragedir" value="${builddir}/reports/coverage" />
<if>
<available file="${coveragedir}/tmp" type="dir" />
<then>
<delete>
<fileset dir="${coveragedir}/tmp">
<include name="**/*" />
</fileset>
</delete>
</then>
<else>
<mkdir dir="${coveragedir}/tmp" />
</else>
</if>
<!-- Run tests -->
<if>
<istrue value="${phpunit_remote_coverage}" />
<then>
<property name="remote_coverage_dir" value="${coveragedir}/tmp" />
</then>
<else>
<property name="remote_coverage_dir" value="" />
</else>
</if>
<exec dir="${srcdir}/module/VuFind/tests" executable="${sh}" passthru="true" checkreturn="true">
<arg line="-c '${phpunit_command} --log-junit ${builddir}/reports/phpunit.xml --coverage-php ${coveragedir}/tmp/unit.cov ${phpunit_extra_params}'" />
<env key="XDEBUG_MODE" value="coverage" />
<env key="VUFIND_MINK_DRIVER" value="${mink_driver}" />
<env key="VUFIND_SCREENSHOT_DIR" value="${screenshot_dir}" />
<env key="VUFIND_HTML_VALIDATOR" value="${html_validator}" />
<env key="VUFIND_HTML_VALIDATOR_FAIL_TESTS" value="${html_validator_fail_tests}" />
<env key="VUFIND_HTML_VALIDATOR_LOG_FILE" value="${html_validator_log_file}" />
<env key="VUFIND_HTML_VALIDATOR_QUIET" value="${html_validator_quiet}" />
<env key="VUFIND_SELENIUM_BROWSER" value="${selenium_browser}" />
<env key="VUFIND_SNOOZE_MULTIPLIER" value="${snooze_multiplier}" />
<env key="VUFIND_DEFAULT_TEST_TIMEOUT" value="${default_test_timeout}" />
<env key="VUFIND_LOCAL_DIR" value="${localdir}" />
<env key="VUFIND_URL" value="${vufindurl}" />
<env key="VUFIND_TEST_THEME" value="${test_theme}" />
<env key="SOLR_PORT" value="${solr_port}" />
<env key="VUFIND_REMOTE_COVERAGE_DIR" value="${remote_coverage_dir}" />
</exec>
<!-- Produce coverage reports -->
<exec executable="${srcdir}/vendor/bin/phpcov" passthru="true" checkreturn="true">
<arg line="merge --clover ${coveragedir}/clover.xml --html ${coveragedir} ${coveragedir}/tmp" />
</exec>
<!-- Clean up any tmp files unless told not to, but keep the directory to avoid changing its permissions -->
<if>
<isfalse value="${retain_coverage_files}" />
<then>
<delete>
<fileset dir="${coveragedir}/tmp">
<include name="**/*" />
</fileset>
</delete>
</then>
</if>
</target>
<!-- PHPUnit without logging output -->
<target name="phpunitfast" description="Run tests">
<exec dir="${srcdir}/module/VuFind/tests" executable="${sh}" passthru="true" checkreturn="true">
<arg line="-c '${phpunit_command} ${phpunit_extra_params}'" />
<env key="VUFIND_MINK_DRIVER" value="${mink_driver}" />
<env key="VUFIND_SCREENSHOT_DIR" value="${screenshot_dir}" />
<env key="VUFIND_HTML_VALIDATOR" value="${html_validator}" />
<env key="VUFIND_HTML_VALIDATOR_FAIL_TESTS" value="${html_validator_fail_tests}" />
<env key="VUFIND_HTML_VALIDATOR_LOG_FILE" value="${html_validator_log_file}" />
<env key="VUFIND_HTML_VALIDATOR_QUIET" value="${html_validator_quiet}" />
<env key="VUFIND_SELENIUM_BROWSER" value="${selenium_browser}" />
<env key="VUFIND_SNOOZE_MULTIPLIER" value="${snooze_multiplier}" />
<env key="VUFIND_DEFAULT_TEST_TIMEOUT" value="${default_test_timeout}" />
<env key="VUFIND_LOCAL_DIR" value="${localdir}" />
<env key="VUFIND_URL" value="${vufindurl}" />
<env key="VUFIND_TEST_THEME" value="${test_theme}" />
<env key="SOLR_PORT" value="${solr_port}" />
</exec>
</target>
<!-- PHPUnit without logging output, stopping at first error or failure -->
<target name="phpunitfaster" description="Run tests until first failure">
<exec dir="${srcdir}/module/VuFind/tests" executable="${sh}" passthru="true" checkreturn="true">
<arg line="-c '${phpunit_command} --stop-on-defect ${phpunit_extra_params}'" />
<env key="VUFIND_MINK_DRIVER" value="${mink_driver}" />
<env key="VUFIND_SCREENSHOT_DIR" value="${screenshot_dir}" />
<env key="VUFIND_HTML_VALIDATOR" value="${html_validator}" />
<env key="VUFIND_HTML_VALIDATOR_FAIL_TESTS" value="${html_validator_fail_tests}" />
<env key="VUFIND_HTML_VALIDATOR_LOG_FILE" value="${html_validator_log_file}" />
<env key="VUFIND_HTML_VALIDATOR_QUIET" value="${html_validator_quiet}" />
<env key="VUFIND_SELENIUM_BROWSER" value="${selenium_browser}" />
<env key="VUFIND_SNOOZE_MULTIPLIER" value="${snooze_multiplier}" />
<env key="VUFIND_DEFAULT_TEST_TIMEOUT" value="${default_test_timeout}" />
<env key="VUFIND_LOCAL_DIR" value="${localdir}" />
<env key="VUFIND_URL" value="${vufindurl}" />
<env key="VUFIND_TEST_THEME" value="${test_theme}" />
<env key="SOLR_PORT" value="${solr_port}" />
</exec>
</target>
<target name="installsolr" description="Install Solr">
<!-- load previously installed version from marker file, if present -->
<if>
<available file="${srcdir}/solr/vendor/.installedVersion" />
<then>
<loadfile property="existing_solr_version" file="${srcdir}/solr/vendor/.installedVersion" />
</then>
</if>
<!-- only attempt to install Solr if the desired version is not already there,
and a marker file has not been created to disable Solr installation. -->
<if>
<and>
<not><equals arg1="${existing_solr_version}" arg2="${solr_version}" /></not>
<not><available file="${srcdir}/solr/.disableAutomaticInstall" /></not>
</and>
<then>
<!-- make sure we don't run out of memory or time during installation: -->
<php expression="ini_set('memory_limit', '1G');" />
<php expression="ini_set('default_socket_timeout', '600');" />
<!-- download from Apache if not already present in the downloads cache -->
<if>
<not><available file="${downloadsdir}/solr-${solr_version}.tgz" /></not>
<then>
<mkdir dir="${downloadsdir}" />
<httpget url="https://archive.apache.org/dist/solr/solr/${solr_version}/solr-${solr_version}.tgz" dir="${downloadsdir}" />
</then>
</if>
<!-- unpack the archive into solr/vendor -->
<mkdir dir="${builddir}/solr" />
<if>
<available file="${srcdir}/solr/vendor" type="dir" />
<then>
<delete dir="${srcdir}/solr/vendor" includeemptydirs="true" failonerror="false" />
</then>
</if>
<untar file="${downloadsdir}/solr-${solr_version}.tgz" todir="${srcdir}/solr/vendor" removepath="solr-${solr_version}" />
<!-- make scripts executable -->
<chmod mode="0755">
<fileset dir="${srcdir}/solr/vendor/bin">
<include name="**/**" />
<exclude name="**/*.cmd" />
</fileset>
</chmod>
<!-- update the marker file with the installed version -->
<echo file="${srcdir}/solr/vendor/.installedVersion" message="${solr_version}" />
</then>
</if>
</target>
<target name="installswaggerui">
<delete dir="${srcdir}/public/swagger-ui" includeemptydirs="true" failonerror="false" />
<copy todir="${srcdir}/public/swagger-ui">
<fileset dir="${srcdir}/vendor/swagger-api/swagger-ui/dist" defaultexcludes="false" />
</copy>
<reflexive>
<fileset dir="${srcdir}/public/swagger-ui">
<include pattern="swagger-initializer.js" />
</fileset>
<filterchain>
<replaceregexp>
<regexp pattern="url: ".*"" replace="url: "../api/v1?openapi"" />
</replaceregexp>
</filterchain>
</reflexive>
</target>
<target name="composer" description="Install dependencies with Composer">
<property name="composer_filename" value="composer-${composer_version}.phar" />
<mkdir dir="${downloadsdir}" />
<if>
<equals arg1="${composer_version}" arg2="latest-2.x" />
<then>
<httpget url="https://getcomposer.org/composer-2.phar" dir="${downloadsdir}" filename="${composer_filename}" />
</then>
<else>
<!-- download if not already present in the downloads cache -->
<if>
<not><available file="${downloadsdir}/${composer_filename}" /></not>
<then>
<httpget url="https://getcomposer.org/download/${composer_version}/composer.phar" dir="${downloadsdir}" filename="${composer_filename}" />
</then>
</if>
</else>
</if>
<echo message="Installing dependencies..." />
<exec executable="php" passthru="true" checkreturn="true">
<arg line="${downloadsdir}/${composer_filename} install ${composer_extra_params}" />
</exec>
</target>
<!-- Install and Activate VuFind -->
<target name="startup" description="install and activate demo">
<!-- fail if the system is already running -->
<if>
<available file="${solr_pid_file}" />
<then>
<fail>Solr PID file (${solr_pid_file}) detected. Is the system already running?</fail>
</then>
</if>
<if>
<available file="${srcdir}/env.bat" />
<then>
<fail>Environment file (env.bat) detected. Is the system already running?</fail>
</then>
</if>
<if>
<available file="${srcdir}/env.sh" />
<then>
<fail>Environment file (env.sh) detected. Is the system already running?</fail>
</then>
</if>
<phingcall target="check_local_config" />
<!-- Install / update dependencies -->
<phingcall target="composer" />
<!-- run extra startup action, if any -->
<if>
<not>
<equals arg1="${extra_startup_command}" arg2="" />
</not>
<then>
<echo message="Running extra startup command" />
<exec executable="${sh}" passthru="true">
<arg line="-c '${extra_startup_command}'" />
<env key="VUFIND_HOME" value="${srcdir}" />
<env key="VUFIND_LOCAL_DIR" value="${localdir}" />
</exec>
</then>
</if>
<!-- set up appropriate read/write permissions for Apache -->
<exec executable="chmod">
<arg line="-R a+w ${localdir}/cache" />
</exec>
<exec executable="touch">
<arg line="${srcdir}/vufind-mail.log" />
</exec>
<exec executable="chmod">
<arg line="a+w ${srcdir}/vufind-mail.log" />
</exec>
<exec executable="touch">
<arg line="${srcdir}/vufind-exception.log" />
</exec>
<exec executable="chmod">
<arg line="a+w ${srcdir}/vufind-exception.log" />
</exec>
<phingcall target="configure_install" />
<!-- Activate Selenium (if a path has been provided) -->
<if>
<not>
<equals arg1="${seleniumjar}" arg2="" />
</not>
<then>
<exec executable="xvfb-run" passthru="true" spawn="true" checkreturn="true">
<arg line="--server-args="-screen 0 1024x768x24" java -jar ${seleniumjar}" />
</exec>
</then>
</if>
<!-- Activate Apache (if an apachectl path has been provided) -->
<if>
<not>
<equals arg1="${apachectl}" arg2="" />
</not>
<then>
<copy file="${localdir}/httpd-vufind.conf" tofile="${apacheconfdir}/vufindtest.conf" />
<if>
<istrue value="${phpunit_remote_coverage}" />
<then>
<reflexive file="${apacheconfdir}/vufindtest.conf">
<filterchain>
<replaceregexp>
<regexp pattern="#SetEnv VUFIND_CODE_COVERAGE 1" replace="SetEnv VUFIND_CODE_COVERAGE 1" />
</replaceregexp>
</filterchain>
</reflexive>
</then>
</if>
<exec executable="${sh}" passthru="true">
<arg line="-c '${apachectl} restart'" />
</exec>
</then>
</if>
<!-- build and configure the requested database type -->
<phingcall target="setup_database" />
<!-- start Solr -->
<phingcall target="setup_solr" />
<phingcall target="import_biblios" />
<phingcall target="import_authorities" />
<phingcall target="delete_fake_records" />
<phingcall target="build_alphabrowse" />
</target>
<!-- A helper task to check for existing configuration -->
<target name="check_local_config" description="check for local configuration and fail if it exists">
<!-- fail if a local config.ini already exists -->
<property name="local_config_ini" value="${localdir}/config/vufind/config.ini" />
<if>
<available file="${local_config_ini}" />
<then>
<fail>${local_config_ini} already exists</fail>
</then>
</if>
</target>
<!-- Setup basic configuration and run the install command -->
<target name="configure_install" description="configure and run installation">
<phingcall target="check_local_config" />
<!-- Generate basic configuration -->
<php expression="substr(parse_url('${vufindurl}', PHP_URL_PATH), 1)" returnProperty="basepath" />
<exec executable="php" passthru="true" checkreturn="true">
<arg line="${srcdir}/install.php --basepath=/${basepath} --non-interactive --solr-port=${solr_port}" />
</exec>
<!-- Update config.ini to activate DB connection, exception logging and test mode -->
<if>
<equals arg1="${dbtype}" arg2="pgsql" />
<then>
<property name="db_connection_string" value="pgsql://${vufinddbuser}:${vufinddbpass}@${pgsqlhost}/${vufinddb}" />
</then>
<else>
<property name="db_connection_string" value="mysql://${vufinddbuser}:${vufinddbpass}@${mysqlhost}:${mysqlport}/${vufinddb}" />
</else>
</if>
<copy file="${srcdir}/config/vufind/config.ini" tofile="${localdir}/config/vufind/config.ini">
<filterchain>
<replaceregexp>
<regexp pattern="mysql://root@localhost/vufind" replace="${db_connection_string}" />
<regexp pattern=";file\s+= /var/log/vufind.log:alert,error,notice,debug" replace="file = ${srcdir}/vufind-exception.log:alert-5,error-5" />
<regexp pattern="(\[System\]\s+)" replace="\1runningTestSuite=1" />
<regexp pattern="(url\s+= http://localhost):8983/solr" replace="\1:${solr_port}/solr" />
</replaceregexp>
</filterchain>
</copy>
<copy file="${srcdir}/config/vufind/Search2.ini" tofile="${localdir}/config/vufind/Search2.ini">
<filterchain>
<replaceregexp>
<regexp pattern="(url\s+= http://localhost):8983/solr" replace="\1:${solr_port}/solr" />
</replaceregexp>
</filterchain>
</copy>
<if>
<not><istrue value="${disable_csp}" /></not>
<then>
<!-- Update contentsecuritypolicy.ini to enforce the CSP. -->
<copy file="${srcdir}/config/vufind/contentsecuritypolicy.ini" tofile="${localdir}/config/vufind/contentsecuritypolicy.ini">
<filterchain>
<replaceregexp>
<regexp pattern="(enabled\[.+\]) = .*" replace="\1 = true" />
</replaceregexp>
</filterchain>
</copy>
</then>
</if>
<!-- Add local translations for tests -->
<if>
<not>
<available file="${localdir}/languages" type="dir" />
</not>
<then>
<mkdir dir="${localdir}/languages" />
</then>
</if>
<if>
<not>
<available file="${localdir}/languages/Facets" type="dir" />
</not>
<then>
<mkdir dir="${localdir}/languages/Facets" />
</then>
</if>
<append destFile="${localdir}/languages/en.ini" text="location_main = Main Library${line.separator}" />
<append destFile="${localdir}/languages/Facets/en.ini" text="0/level1a/ = Top Level, Sorted Last${line.separator}" />
<append destFile="${localdir}/languages/Facets/en.ini" text="0/level1z/ = Top Level, Sorted First${line.separator}" />
<append destFile="${localdir}/languages/Facets/en.ini" text="1/level1z/level2y/ = Second Level, Sorted Last${line.separator}" />
<append destFile="${localdir}/languages/Facets/en.ini" text="1/level1z/level2z/ = Second Level, Sorted First${line.separator}" />
<!-- Add templates to a minktest theme for tests -->
<property name="themedir" value="${srcdir}/themes/minktest" />
<property name="contentdir" value="${themedir}/templates/content" />
<if>
<not>
<available file="${contentdir}/test/sub" type="dir" />
</not>
<then>
<!-- avoid PHP Errors by creating each level separately -->
<mkdir dir="${themedir}" />
<mkdir dir="${themedir}/templates" />
<mkdir dir="${themedir}/templates/ajax" />
<mkdir dir="${contentdir}" />
<mkdir dir="${contentdir}/test" />
<mkdir dir="${contentdir}/test/sub" />
</then>
</if>
<echo file="${themedir}/theme.config.php"><?php
return [
'extends' => 'sandal',
];
</echo>
<copy file="${srcdir}/themes/bootstrap3/templates/ajax/status-full.phtml" tofile="${themedir}/templates/ajax/status-full.phtml" overwrite="true" />
<!-- Add a script for testing that inline scripts work -->
<echo file="${themedir}/templates/ajax/status-full.phtml" append="true">
<div class="js-status-test hidden"></div>
<script nonce="foo">
document.querySelector('.js-status-test').classList.remove('hidden');
</script>
</echo>
<echo file="${contentdir}/content.phtml"><?php include $this->parentTemplate('content/content.phtml');?>
<div class="content-footer">Content page footer</div>
</echo>
<echo file="${contentdir}/test.phtml"><h1>MAIN LEVEL TEST</h1></echo>
<echo file="${contentdir}/test.phtml"><h1>MAIN LEVEL TEST</h1></echo>
<echo file="${contentdir}/test_fi.phtml"><h1>FINNISH TEST</h1></echo>
<echo file="${contentdir}/test/test.phtml"><h1>SUB LEVEL PHTML</h1></echo>
<echo file="${contentdir}/test/testmd.md"># SUB LEVEL MD</echo>
<echo file="${contentdir}/test/sub/test.phtml"><h1>SUB SUB LEVEL PHTML</h1></echo>
</target>
<target name="setup_database" description="setup demo database">
<if>
<equals arg1="${dbtype}" arg2="pgsql" />
<then>
<!-- build database -->
<if>
<equals arg1="${psql_needs_sudo}" arg2="false" />
<then>
<exec executable="psql">
<arg line="-c "DROP DATABASE ${vufinddb};" ${pgsqlrootuser}" />
</exec>
<exec executable="psql">
<arg line="-c "DROP USER ${vufinddbuser};" ${pgsqlrootuser}" />
</exec>
<exec executable="psql" checkreturn="true">
<arg line="-c "CREATE DATABASE ${vufinddb};" ${pgsqlrootuser}" />
</exec>
<exec executable="psql" checkreturn="true">
<arg line="-c "CREATE USER ${vufinddbuser} PASSWORD '${vufinddbpass}';" ${pgsqlrootuser}" />
</exec>
<exec executable="psql" checkreturn="true">
<arg line="-c "GRANT ALL ON DATABASE ${vufinddb} TO ${vufinddbuser};" ${pgsqlrootuser}" />
</exec>
</then>
<else>
<exec executable="sudo">
<arg line="su -c "psql -c \"DROP DATABASE ${vufinddb};\"" ${pgsqlrootuser}" />
</exec>
<exec executable="sudo">
<arg line="su -c "psql -c \"DROP USER ${vufinddbuser};\"" ${pgsqlrootuser}" />
</exec>
<exec executable="sudo" checkreturn="true">
<arg line="su -c "psql -c \"CREATE DATABASE ${vufinddb};\"" ${pgsqlrootuser}" />
</exec>
<exec executable="sudo" checkreturn="true">
<arg line="su -c "psql -c \"CREATE USER ${vufinddbuser} PASSWORD '${vufinddbpass}';\"" ${pgsqlrootuser}" />
</exec>
<exec executable="sudo" checkreturn="true">
<arg line="su -c "psql -c \"GRANT ALL ON DATABASE ${vufinddb} TO ${vufinddbuser};\"" ${pgsqlrootuser}" />
</exec>
</else>
</if>
<exec executable="psql" checkreturn="true">
<arg line="-U ${vufinddbuser} -f ${srcdir}/module/VuFind/sql/pgsql.sql ${vufinddb}" />
<env key="PGPASSWORD" value="${vufinddbpass}" />
</exec>
</then>
<else>
<!-- build database -->
<exec executable="mysql" passthru="true">
<arg line="${mysqlconnectionargs} -e "DROP DATABASE IF EXISTS ${vufinddb}"" />
</exec>
<exec executable="mysql" checkreturn="true" passthru="true">
<arg line="${mysqlconnectionargs} -e "CREATE DATABASE ${vufinddb}"" />
</exec>
<exec executable="mysql" passthru="true">
<arg line="${mysqlconnectionargs} -e "DROP USER IF EXISTS '${vufinddbuser}'@'%'"" />
</exec>
<exec executable="mysql" checkreturn="true" passthru="true">
<arg line="${mysqlconnectionargs} -e "CREATE USER '${vufinddbuser}'@'%' IDENTIFIED BY '${vufinddbpass}'"" />
</exec>
<exec executable="mysql" checkreturn="true" passthru="true">
<arg line="${mysqlconnectionargs} -e "GRANT SELECT,INSERT,UPDATE,DELETE ON ${vufinddb}.* TO '${vufinddbuser}'@'%' WITH GRANT OPTION"" />
</exec>
<exec executable="mysql" checkreturn="true" passthru="true">
<arg line="${mysqlconnectionargs} -e "FLUSH PRIVILEGES"" />
</exec>
<exec executable="mysql" checkreturn="true" passthru="true">
<arg line="${mysqlconnectionargs} -D ${vufinddb} < ${srcdir}/module/VuFind/sql/mysql.sql" />
</exec>
</else>
</if>
</target>
<!-- Set up Solr -->
<target name="setup_solr">
<!-- Start Solr using restart in case of old PID files -->
<exec executable="${srcdir}/solr.sh" passthru="true" checkreturn="true">
<arg line="restart" />
<env key="SOLR_PID_DIR" value="${localdir}" />
<env key="VUFIND_HOME" value="${srcdir}" />
<env key="SOLR_ADDITIONAL_JVM_OPTIONS" value="${solr_additional_jvm_options}" />
<env key="SOLR_PORT" value="${solr_port}" />
</exec>
<!-- fail if Solr did not start up successfully: -->
<if>
<not><available file="${solr_pid_file}" /></not>
<then>
<fail>Solr PID file (${solr_pid_file}) not detected. Solr startup failed.</fail>
</then>
</if>
<if>
<equals arg1="0" arg2="${solr_startup_sleep}" />
<then>
<!-- do nothing -->
</then>
<else>
<echo message="Waiting ${solr_startup_sleep} seconds for Solr to be ready..." />
<exec executable="sleep">
<arg line="${solr_startup_sleep}" />
</exec>
</else>
</if>
</target>
<!-- Import test biblio data -->
<target name="import_biblios" description="import all biblio test records">
<foreach param="relfilename" absparam="filename" target="importrec">
<fileset dir="${marc_bib_dir}">
<include name="*.mrc" />
<include name="*.xml" />
</fileset>
</foreach>
</target>
<!-- Import test authority data -->
<target name="import_authorities" description="import all authority test records">
<if>
<available file="${marc_authority_dir}" />
<then>
<foreach param="relfilename" absparam="filename" target="importauthrec">
<fileset dir="${marc_authority_dir}">
<include name="*.mrc" />
</fileset>
</foreach>
</then>
</if>
</target>
<!-- Delete some fake record IDs so we have deleted records to test with -->
<target name="delete_fake_records" description="delete fake records">
<exec executable="php" checkreturn="true" passthru="true">
<arg line="${srcdir}/public/index.php util/deletes ${srcdir}/tests/data/fake-deleted-ids.txt flat" />
<env key="VUFIND_HOME" value="${srcdir}" />
<env key="VUFIND_LOCAL_DIR" value="${localdir}" />
</exec>
</target>
<!-- Build alphabrowse index -->
<target name="build_alphabrowse" description="build the alphabrowse index">
<exec executable="${srcdir}/index-alphabetic-browse.sh" passthru="true">
<env key="VUFIND_HOME" value="${srcdir}" />
<env key="VUFIND_LOCAL_DIR" value="${localdir}" />
</exec>
</target>
<!-- Uninstall and Deactivate VuFind -->
<target name="shutdown" description="deactivate and uninstall demo">
<exec executable="git" outputProperty="git_status">
<arg line="status --porcelain --untracked-files=no" />
</exec>
<if>
<not>
<equals arg1="${git_status}" arg2="" />
</not>
<then>
<fail>
Changes detected in tracked files:
${git_status}
</fail>
</then>
</if>
<!-- Remove Apache settings (if Apache was enabled) -->
<if>
<and>
<not>
<equals arg1="${apachectl}" arg2="" />
</not>
<available file="${apacheconfdir}/vufindtest.conf" />
</and>
<then>
<delete file="${apacheconfdir}/vufindtest.conf" />
<exec executable="${sh}" passthru="true">
<arg line="-c '${apachectl} restart'" />
</exec>
</then>
</if>
<!-- drop database -->
<if>
<equals arg1="${dbtype}" arg2="pgsql" />
<then>
<exec executable="sudo" checkreturn="true">
<arg line="su -c "psql -c \"DROP DATABASE ${vufinddb};\"" ${pgsqlrootuser}" />
</exec>
<exec executable="sudo" checkreturn="true">
<arg line="su -c "psql -c \"DROP USER ${vufinddbuser};\"" ${pgsqlrootuser}" />
</exec>
</then>
<else>
<exec executable="mysql">
<arg line="${mysqlconnectionargs} -e "DROP USER IF EXISTS '${vufinddbuser}'@'%'"" />
</exec>
<exec executable="mysql">
<arg line="${mysqlconnectionargs} -e "DROP DATABASE IF EXISTS ${vufinddb}"" />
</exec>
</else>
</if>
<!-- stop Solr -->
<if>
<available file="${solr_pid_file}" />
<then>
<exec executable="${srcdir}/solr.sh" passthru="true">
<arg line="stop" />
<env key="SOLR_PID_DIR" value="${localdir}" />
<env key="VUFIND_HOME" value="${srcdir}" />
<env key="SOLR_ADDITIONAL_JVM_OPTIONS" value="${solr_additional_jvm_options}" />
<env key="SOLR_PORT" value="${solr_port}" />
</exec>
</then>
</if>
<!-- run extra cleanup action, if any -->
<if>