forked from vufind-org/vufind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.xml
883 lines (802 loc) · 39.7 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
<?xml version="1.0" encoding="UTF-8"?>
<project name="vufind" basedir="." default="main">
<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" />
<!--
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="false" /><!-- set to apachectl path to spin up Apache instance -->
<property name="seleniumjar" value="false" /><!-- 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="false" />
<property name="extra_shutdown_cleanup" value="false" />
<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="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" /><!-- if you have issues with segfaults during code coverage generation, try adding -dzend.enable_gc=0 to this (but this fix was probably only needed in PHP 5) -->
<property name="phpunit_extra_params" value="" />
<property name="composer_version" value="2.1.6" />
<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 tests (selenium only) -->
<property name="solr_startup_sleep" value="0" />
<property name="solr_additional_jvm_options" value="-Dlog4j2.formatMsgNoLookups=true" />
<property name="solr_version" value="9.3.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_html_validation_params" value="VUFIND_HTML_VALIDATOR=${html_validator} VUFIND_HTML_VALIDATOR_FAIL_TESTS=${html_validator_fail_tests} VUFIND_HTML_VALIDATOR_LOG_FILE=${html_validator_log_file} VUFIND_HTML_VALIDATOR_QUIET=${html_validator_quiet}" />
<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="version" value="9.0.3" />
<!-- We only need the -p switch if the password is non-blank -->
<if>
<not>
<equals arg1="${mysqlrootpass}" arg2="" />
</not>
<then>
<property name="mysqlpwswitch" value="-p" />
</then>
<else>
<property name="mysqlpwswitch" value="" />
</else>
</if>
<!-- Main Target -->
<target name="main" description="main target">
<phingcall target="startup" />
<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>
<!-- 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"/>
</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"/>
</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"/>
</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>
<!-- Report rule violations with PHPMD (mess detector) -->
<target name="phpmd">
<exec command="${srcdir}/vendor/bin/phpmd ${srcdir}/module xml ${srcdir}/tests/phpmd.xml --exclude ${srcdir}/module/VuFind/tests,${srcdir}/module/VuFindSearch/tests --reportfile ${builddir}/reports/phpmd.xml" />
</target>
<!-- PHP_Depend code analysis -->
<target name="pdepend">
<exec command="${srcdir}/vendor/bin/pdepend --jdepend-xml=${builddir}/reports/jdepend.xml --jdepend-chart=${builddir}/reports/dependencies.svg --overview-pyramid=${builddir}/reports/pdepend-pyramid.svg ${srcdir}/module" />
</target>
<!-- PHP CodeSniffer -->
<target name="phpcbf">
<exec command="${srcdir}/vendor/bin/phpcbf --standard=${srcdir}/tests/phpcs.xml" escape="false" passthru="true" checkreturn="true" />
</target>
<target name="phpcs">
<exec command="${srcdir}/vendor/bin/phpcs --standard=${srcdir}/tests/phpcs.xml --report=checkstyle > ${builddir}/reports/checkstyle.xml" escape="false" />
</target>
<target name="phpcs-console">
<exec command="${srcdir}/vendor/bin/phpcs --standard=${srcdir}/tests/phpcs.xml" escape="false" passthru="true" checkreturn="true" />
</target>
<!-- Phpstan -->
<target name="phpstan-checkstyle">
<exec command="${srcdir}/vendor/bin/phpstan --configuration=${srcdir}/tests/phpstan.neon --memory-limit=2G --error-format=checkstyle analyse > ${builddir}/reports/phpstan-checkstyle.xml" escape="false" passthru="true" checkreturn="true" />
</target>
<target name="phpstan-console">
<exec command="${srcdir}/vendor/bin/phpstan --configuration=${srcdir}/tests/phpstan.neon --memory-limit=2G analyse" escape="false" passthru="true" checkreturn="true" />
</target>
<!-- php-cs-fixer (first task applies fixes, second task simply checks if they are needed) -->
<target name="php-cs-fixer">
<exec command="${srcdir}/vendor/bin/php-cs-fixer fix --config=${srcdir}/tests/vufind.php-cs-fixer.php -vvv" passthru="true" escape="false" />
<exec command="${srcdir}/vendor/bin/php-cs-fixer fix --config=${srcdir}/tests/vufind_templates.php-cs-fixer.php -vvv" passthru="true" escape="false" />
</target>
<target name="php-cs-fixer-dryrun">
<exec command="${srcdir}/vendor/bin/php-cs-fixer fix --config=${srcdir}/tests/vufind.php-cs-fixer.php --dry-run -vvv --diff" passthru="true" escape="false" checkreturn="true" />
<exec command="${srcdir}/vendor/bin/php-cs-fixer fix --config=${srcdir}/tests/vufind_templates.php-cs-fixer.php --dry-run -vvv --diff" passthru="true" escape="false" checkreturn="true" />
</target>
<!-- ESLint -->
<target name="eslint">
<exec command="npx eslint ${srcdir}/themes/**/*.js -c ${srcdir}/.eslintrc.js" escape="false" checkreturn="true" passthru="true" />
</target>
<target name="eslint-fix">
<exec command="npx eslint ${srcdir}/themes/**/*.js -c ${srcdir}/.eslintrc.js --fix" escape="false" passthru="true" />
</target>
<target name="eslint-report">
<exec command="npx eslint ${srcdir}/themes/**/*.js -c ${srcdir}/.eslintrc.js --format checkstyle -o ${builddir}/reports/eslint-checkstyle.xml" escape="false" />
</target>
<!-- JSHint -->
<target name="jshint">
<exec command="npx jshint --config=${srcdir}/tests/jshint.json --exclude=themes/*/js/vendor ${srcdir}/themes" checkreturn="true" passthru="true" />
</target>
<target name="jshint-report">
<exec command="npx jshint --config=${srcdir}/tests/jshint.json --exclude=themes/*/js/vendor --reporter=checkstyle ${srcdir}/themes > ${builddir}/reports/jshint-checkstyle.xml" />
</target>
<!-- Run Sass build, error if it fails -->
<target name="checkSassBuild">
<exec command="npm run check:scss" checkreturn="true" passthru="true" />
</target>
<!-- Run LessToSass, error if there are uncommitted changes (used by continuous integration) -->
<target name="checkLessToSass">
<exec command="npm run lessToSass" checkreturn="true" passthru="true" />
<exec command="git diff --exit-code *.scss" checkreturn="true" passthru="true" />
</target>
<!-- PHP API Documentation -->
<target name="phpdoc">
<!-- Skip the whole phpdoc task when disabled -->
<if>
<not><istrue value="${skip_phpdoc}" /></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 command="php ${srcdir}/vendor/bin/phpDocumentor-${phpdoc_version}.phar --cache-folder=${builddir}/docs_cache --title="VuFind API Documentation" -t ${builddir}/apidocs -d ${srcdir}/module" passthru="true" />
</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="paramCoverageDir" value="VUFIND_REMOTE_COVERAGE_DIR=${coveragedir}/tmp" />
</then>
<else>
<property name="paramCoverageDir" value="" />
</else>
</if>
<exec dir="${srcdir}/module/VuFind/tests" command="XDEBUG_MODE=coverage VUFIND_MINK_DRIVER=${mink_driver} VUFIND_SCREENSHOT_DIR=${screenshot_dir} ${phpunit_html_validation_params} VUFIND_SELENIUM_BROWSER=${selenium_browser} VUFIND_SNOOZE_MULTIPLIER=${snooze_multiplier} VUFIND_LOCAL_DIR=${localdir} VUFIND_URL=${vufindurl} SOLR_PORT=${solr_port} ${paramCoverageDir} ${phpunit_command} --log-junit ${builddir}/reports/phpunit.xml --coverage-php ${coveragedir}/tmp/unit.cov ${phpunit_extra_params}" passthru="true" checkreturn="true" />
<!-- Produce coverage reports -->
<exec command="${srcdir}/vendor/bin/phpcov merge --clover ${coveragedir}/clover.xml --html ${coveragedir} ${coveragedir}/tmp" passthru="true" checkreturn="true" />
<!-- 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" command="VUFIND_MINK_DRIVER=${mink_driver} VUFIND_SCREENSHOT_DIR=${screenshot_dir} ${phpunit_html_validation_params} VUFIND_SELENIUM_BROWSER=${selenium_browser} VUFIND_SNOOZE_MULTIPLIER=${snooze_multiplier} VUFIND_LOCAL_DIR=${localdir} VUFIND_URL=${vufindurl} SOLR_PORT=${solr_port} ${phpunit_command} ${phpunit_extra_params}" passthru="true" checkreturn="true" />
</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" command="VUFIND_MINK_DRIVER=${mink_driver} VUFIND_SCREENSHOT_DIR=${screenshot_dir} ${phpunit_html_validation_params} VUFIND_SELENIUM_BROWSER=${selenium_browser} VUFIND_SNOOZE_MULTIPLIER=${snooze_multiplier} VUFIND_LOCAL_DIR=${localdir} VUFIND_URL=${vufindurl} SOLR_PORT=${solr_port} ${phpunit_command} --stop-on-failure ${phpunit_extra_params}" passthru="true" checkreturn="true" />
</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="${srcdir}/downloads/solr-${solr_version}.tgz" /></not>
<then>
<mkdir dir="${srcdir}/downloads" />
<httpget url="http://archive.apache.org/dist/solr/solr/${solr_version}/solr-${solr_version}.tgz" dir="${srcdir}/downloads" />
</then>
</if>
<!-- unpack the archive into solr/vendor -->
<mkdir dir="${builddir}/solr" />
<untar file="${srcdir}/downloads/solr-${solr_version}.tgz" todir="${builddir}/solr" />
<if>
<available file="${srcdir}/solr/vendor" type="dir" />
<then>
<delete dir="${srcdir}/solr/vendor" includeemptydirs="true" failonerror="false" />
</then>
</if>
<move file="${builddir}/solr/solr-${solr_version}" tofile="${srcdir}/solr/vendor" />
<!-- 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">
<if>
<equals arg1="${composer_version}" arg2="latest-2.x" />
<then>
<httpget url="https://getcomposer.org/composer-2.phar" sslVerifyPeer="false" dir="${srcdir}" filename="composer.phar" />
</then>
<else>
<httpget url="https://getcomposer.org/download/${composer_version}/composer.phar" sslVerifyPeer="false" dir="${srcdir}" />
</else>
</if>
<echo message="Installing dependencies..." />
<exec command="php ${srcdir}/composer.phar install ${composer_extra_params}" passthru="true" checkreturn="true" />
</target>
<!-- Copy files from node modules to themes -->
<target name="copynodemodules">
<!-- autocomplete.js -->
<copy file="${srcdir}/node_modules/autocomplete.js/autocomplete.js" todir="${srcdir}/themes/bootstrap3/js/vendor" overwrite="true" />
<!-- jstree -->
<copy todir="${srcdir}/themes/bootstrap3/js/vendor/jsTree" overwrite="true">
<fileset dir="${srcdir}/node_modules/jstree/dist/" >
<include name="**/**" />
<exclude name="jstree.js" />
<exclude name="themes/default-dark/" />
</fileset>
</copy>
<!-- vanilla-cookieconsent -->
<copy file="${srcdir}/node_modules/vanilla-cookieconsent/dist/cookieconsent.umd.js" todir="${srcdir}/themes/bootstrap3/js/vendor" overwrite="true" />
</target>
<!-- Install and Activate VuFind -->
<target name="startup" description="install and activate demo">
<property name="solr_pid_file" value="${localdir}/solr-${solr_port}.pid" />
<!-- 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" />
<!-- run extra startup action, if any -->
<if>
<istrue value="${extra_startup_command}" />
<then>
<exec command="VUFIND_HOME=${srcdir} VUFIND_LOCAL_DIR=${localdir} ${extra_startup_command}" />
</then>
</if>
<!-- set up appropriate read/write permissions for Apache -->
<exec command="chmod -R a+w ${localdir}/cache" />
<exec command="touch ${srcdir}/vufind-exception.log" />
<exec command="chmod a+w ${srcdir}/vufind-exception.log" />
<phingcall target="configure_install" />
<!-- Activate Selenium (if a path has been provided) -->
<if>
<istrue value="${seleniumjar}" />
<then>
<exec command="xvfb-run --server-args="-screen 0 1024x768x24" java -jar ${seleniumjar}" passthru="true" spawn="true" checkreturn="true" />
</then>
</if>
<!-- Activate Apache (if an apachectl path has been provided) -->
<if>
<istrue value="${apachectl}" />
<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 command="${apachectl} restart" passthru="true" />
</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="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="end(explode('/', '${vufindurl}'))" returnProperty="basepath" />
<exec command="php ${srcdir}/install.php --basepath=/${basepath} --non-interactive --solr-port=${solr_port}" passthru="true" checkreturn="true" />
<!-- 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}/${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 a local translation for tests -->
<if>
<not>
<available file="${localdir}/languages" type="dir" />
</not>
<then>
<mkdir dir="${localdir}/languages" />
</then>
</if>
<append destFile="${localdir}/languages/en.ini" text="location_main = Main Library${line.separator}" />
</target>
<target name="setup_database" description="setup demo database">
<if>
<equals arg1="${dbtype}" arg2="pgsql" />
<then>
<!-- build database -->
<exec command="sudo su -c "psql -c \"DROP DATABASE ${vufinddb};\"" ${pgsqlrootuser}" />
<exec command="sudo su -c "psql -c \"DROP USER ${vufinddbuser};\"" ${pgsqlrootuser}" />
<exec command="sudo su -c "psql -c \"CREATE DATABASE ${vufinddb};\"" ${pgsqlrootuser}" checkreturn="true" />
<exec command="sudo su -c "psql -c \"CREATE USER ${vufinddbuser} PASSWORD '${vufinddbpass}';\"" ${pgsqlrootuser}" checkreturn="true" />
<exec command="sudo su -c "psql -c \"GRANT ALL ON DATABASE ${vufinddb} TO ${vufinddbuser};\"" ${pgsqlrootuser}" checkreturn="true" />
<!--<exec command="sudo su -c "psql -c \"select 'grant SELECT,INSERT,UPDATE,DELETE on '||schemaname||'.'||tablename||' to ${vufinddbuser};' from pg_tables where schemaname in ('${vufinddb}') order by schemaname, tablename;\"" ${pgsqlrootuser}" checkreturn="true" />-->
<exec command="PGPASSWORD=${vufinddbpass} psql -U ${vufinddbuser} -f ${srcdir}/module/VuFind/sql/pgsql.sql ${vufinddb}" checkreturn="true" />
</then>
<else>
<!-- build database -->
<exec command="mysqladmin -f -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} drop ${vufinddb}" />
<exec command="mysqladmin -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} create ${vufinddb}" checkreturn="true" />
<exec command="mysql -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -e "DROP USER '${vufinddbuser}'@'${mysqlhost}'"" />
<exec command="mysql -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -e "CREATE USER '${vufinddbuser}'@'${mysqlhost}' IDENTIFIED BY '${vufinddbpass}'"" checkreturn="true" />
<exec command="mysql -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -e "GRANT SELECT,INSERT,UPDATE,DELETE ON ${vufinddb}.* TO '${vufinddbuser}'@'${mysqlhost}' WITH GRANT OPTION"" checkreturn="true" />
<exec command="mysql -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -e "FLUSH PRIVILEGES"" checkreturn="true" />
<exec command="mysql -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -D ${vufinddb} < ${srcdir}/module/VuFind/sql/mysql.sql" checkreturn="true" />
</else>
</if>
</target>
<!-- Set up Solr -->
<target name="setup_solr">
<!-- Start Solr using restart in case of old PID files -->
<exec command="SOLR_PID_DIR=${localdir} VUFIND_HOME=${srcdir} SOLR_ADDITIONAL_JVM_OPTIONS=${solr_additional_jvm_options} SOLR_PORT=${solr_port} ${srcdir}/solr.sh restart" passthru="true" checkreturn="true" />
<!-- 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 command="sleep ${solr_startup_sleep}" />
</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="${srcdir}/tests/data">
<include name="*.mrc" />
<include name="*.xml" />
</fileset>
</foreach>
</target>
<!-- Import test authority data -->
<target name="import_authorities" description="import all authority test records">
<foreach param="relfilename" absparam="filename" target="importauthrec">
<fileset dir="${srcdir}/tests/data/authority">
<include name="*.mrc" />
</fileset>
</foreach>
</target>
<!-- Build alphabrowse index -->
<target name="build_alphabrowse" description="build the alphabrowse index">
<exec command="VUFIND_HOME=${srcdir} VUFIND_LOCAL_DIR=${localdir} ${srcdir}/index-alphabetic-browse.sh" passthru="true" />
</target>
<!-- Uninstall and Deactivate VuFind -->
<target name="shutdown" description="deactivate and uninstall demo">
<exec command="git status --porcelain --untracked-files=no" outputProperty="git_status" />
<if>
<not>
<equals arg1="${git_status}" arg2="" />
</not>
<then>
<fail>
Changed detected in tracked files:
${git_status}
</fail>
</then>
</if>
<!-- Remove Apache settings (if Apache was enabled) -->
<if>
<istrue value="${apachectl}" />
<then>
<delete file="${apacheconfdir}/vufindtest.conf" />
<exec command="${apachectl} restart" />
</then>
</if>
<!-- drop database -->
<if>
<equals arg1="${dbtype}" arg2="pgsql" />
<then>
<exec command="sudo su -c "psql -c \"DROP DATABASE ${vufinddb};\"" ${pgsqlrootuser}" checkreturn="true" />
<exec command="sudo su -c "psql -c \"DROP USER ${vufinddbuser};\"" ${pgsqlrootuser}" checkreturn="true" />
</then>
<else>
<exec command="mysql -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -e "DROP USER '${vufinddbuser}'@'${mysqlhost}'"" />
<exec command="mysqladmin -f -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} drop ${vufinddb}" />
</else>
</if>
<!-- stop Solr -->
<exec command="SOLR_PID_DIR=${localdir} VUFIND_HOME=${srcdir} SOLR_ADDITIONAL_JVM_OPTIONS=${solr_additional_jvm_options} SOLR_PORT=${solr_port} ${srcdir}/solr.sh stop" passthru="true" />
<!-- run extra cleanup action, if any -->
<if>
<istrue value="${extra_shutdown_cleanup}" />
<then>
<exec command="VUFIND_HOME=${srcdir} VUFIND_LOCAL_DIR=${localdir} ${extra_shutdown_cleanup}" />
</then>
</if>
<!-- shut down selenium if necessary -->
<if>
<istrue value="${seleniumjar}" />
<then>
<exec command="pkill -f xvfb" />
<basename file="${seleniumjar}" property="seleniumbase" />
<exec command="pkill -f "java -jar ${seleniumbase}"" />
</then>
</if>
<!-- delete the configuration, sample index, logs and cache data -->
<if>
<available file="${srcdir}/env.bat" />
<then>
<delete file="${srcdir}/env.bat" failonerror="true" />
</then>
</if>
<if>
<available file="${srcdir}/env.sh" />
<then>
<delete file="${srcdir}/env.sh" failonerror="true" />
</then>
</if>
<if>
<available file="${srcdir}/import/solrmarc.log" />
<then>
<delete file="${srcdir}/import/solrmarc.log" failonerror="true" />
</then>
</if>
<if>
<available file="${srcdir}/solr" type="dir" />
<then>
<delete dir="${srcdir}/solr" includeemptydirs="true" failonerror="true" />
</then>
</if>
<if>
<available file="${srcdir}/composer.phar" />
<then>
<delete file="${srcdir}/composer.phar" failonerror="true" />
</then>
</if>
<if>
<available file="${srcdir}/vufind-exception.log" />
<then>
<filesize file="${srcdir}/vufind-exception.log" propertyname="exception.log.size" />
<if>
<not><equals arg1="${exception.log.size}" arg2="0" /></not>
<then>
<loadfile property="exception.log.contents" file="${srcdir}/vufind-exception.log" />
<echo message="Exception log not empty; contents: ${exception.log.contents}" />
</then>
</if>
<delete file="${srcdir}/vufind-exception.log" failonerror="true" />
</then>
</if>
<delete dir="${srcdir}/vendor" includeemptydirs="true" failonerror="false" />
<if>
<available file="${localdir}" type="dir" />
<then>
<delete dir="${localdir}" includeemptydirs="true" failonerror="true" />
</then>
</if>
<exec command="git reset --hard" passthru="true" />
</target>
<!-- Reset database and configuration of the demo setup -->
<target name="reset_setup" description="reset configuration and database of demo">
<property name="solr_pid_file" value="${localdir}/solr-${solr_port}.pid" />
<!-- fail if the system is not already running -->
<if>
<not><available file="${solr_pid_file}" /></not>
<then>
<fail>Solr PID file (${solr_pid_file}) not detected. Is the demo system not running?</fail>
</then>
</if>
<delete>
<fileset dir="${localdir}/config/vufind">
<patternset>
<include name="*.ini" />
<include name="*.ini.bak" />
<include name="*.json" />
<include name="*.json.bak" />
<include name="*.key" />
<include name="*.key.bak" />
<include name="*.yaml" />
<include name="*.yaml.bak" />
</patternset>
</fileset>
</delete>
<delete>
<fileset dir="${localdir}/cache">
<include name="**/*" />
</fileset>
</delete>
<delete>
<fileset dir="${localdir}/languages">
<include name="*" />
</fileset>
</delete>
<delete file="${srcdir}/env.bat" />
<delete file="${srcdir}/env.sh" />
<delete file="${localdir}/import/import.properties" />
<delete file="${localdir}/import/import_auth.properties" />
<phingcall target="configure_install" />
<phingcall target="setup_database" />
</target>
<!-- Prepare VuFind for distribution -->
<target name="package" description="build VuFind packages for distribution">
<!-- make sure the work area is empty, then rebuild it -->
<delete dir="${builddir}/packages" includeemptydirs="true" failonerror="false" />
<mkdir dir="${builddir}/packages" />
<delete dir="${builddir}/export" includeemptydirs="true" failonerror="false" />
<mkdir dir="${builddir}/export/vufind/usr/local/vufind" />
<!-- load the relevant files into the work area -->
<phingcall target="composer">
<property name="composer_extra_params" value="--no-dev" />
</phingcall>
<exec command="git archive HEAD --format=tar | tar -x -C ${builddir}/export/vufind/usr/local/vufind" />
<copy todir="${builddir}/export/vufind/usr/local/vufind/vendor">
<fileset dir="${srcdir}/vendor" defaultexcludes="false" />
</copy>
<copy todir="${builddir}/export/vufind/usr/local/vufind/solr/vendor">
<fileset dir="${srcdir}/solr/vendor" defaultexcludes="false" />
</copy>
<copy todir="${builddir}/export/vufind/usr/local/vufind/public/swagger-ui">
<fileset dir="${srcdir}/public/swagger-ui" defaultexcludes="false" />
</copy>
<!-- create a version-specific symlink so that tar/zip packages will have
appropriate directory structures. -->
<exec command="ln -s ${builddir}/export/vufind/usr/local/vufind ${builddir}/export/vufind-${version}" />
<!-- build the standard tar.gz archive -->
<echo message="Building .tar.gz...." />
<exec command="cd ${builddir}/export ; tar czfh ${builddir}/packages/vufind-${version}.tar.gz vufind-${version}" checkreturn="true" />
<!-- build the a zip archive -->
<echo message="Building .zip...." />
<exec command="cd ${builddir}/export ; zip -r ${builddir}/packages/vufind-${version}.zip vufind-${version}" checkreturn="true" />
<!-- build the DEB package -->
<echo message="Building .deb...." />
<move file="${builddir}/export/vufind/usr/local/vufind/packages/DEBIAN" todir="${builddir}/export/vufind" includeemptydirs="true"/>
<exec command="chmod 0775 ${builddir}/export/vufind/DEBIAN/postinst" />
<exec command="dpkg-deb -b ${builddir}/export/vufind ${builddir}/packages/vufind_${version}.deb" checkreturn="true" />
<!-- clean up -->
<delete dir="${builddir}/export" includeemptydirs="true" failonerror="true" />
<!-- report success -->
<echo message="Packages successfully generated in ${builddir}/packages" />
</target>
<target name="importauthrec" description="import each of the MARC authority test records">
<!-- perform the import -->
<exec command="VUFIND_HOME=${srcdir} VUFIND_LOCAL_DIR=${localdir} ${srcdir}/import-marc-auth.sh ${filename} marc_auth_ils.properties" passthru="true" checkreturn="true" />
</target>
<target name="importrec" description="import each of the MARC bibliographic test records">
<basename file="${filename}" property="BASENAME" />
<!-- create custom import configurations to load the MARC filename into the building facet to help
test cases to limit searches to within specific collections of test records.
Note: ${localdir}/import/import.properties is created in install.php. -->
<copy file="${srcdir}/import/marc_local.properties" tofile="${localdir}/import/marc-${BASENAME}.properties" overwrite="true" />
<append destFile="${localdir}/import/marc-${BASENAME}.properties" text="building="${BASENAME}"${line.separator}" />
<copy file="${localdir}/import/import.properties" tofile="${localdir}/import/import-${BASENAME}.properties" />
<!-- normalize Unicode to avoid HTML validation warnings -->
<append destFile="${localdir}/import/import-${BASENAME}.properties" text="marc.unicode_normalize = C${line.separator}" />
<reflexive>
<fileset dir="${localdir}/import">
<include pattern="import-${BASENAME}.properties" />
</fileset>
<filterchain>
<replaceregexp>
<regexp pattern="marc_local.properties" replace="marc-${BASENAME}.properties" />
</replaceregexp>
</filterchain>
</reflexive>
<!-- if there is a file-specific import configuration, load it now: -->
<if>
<available file="${filename}.properties" />
<then>
<echo message="Found custom import configs for ${filename}." />
<append file="${filename}.properties" destFile="${localdir}/import/marc-${BASENAME}.properties" />
</then>
</if>
<!-- perform the import -->
<exec command="VUFIND_HOME=${srcdir} VUFIND_LOCAL_DIR=${localdir} ${srcdir}/import-marc.sh -p ${localdir}/import/import-${BASENAME}.properties ${filename}" passthru="true" checkreturn="true" />
<!-- clean up temp files -->
<delete file="${localdir}/import/marc-${BASENAME}.properties" />
<delete file="${localdir}/import/import-${BASENAME}.properties" />
</target>
<target name="patch-dependencies" description="apply fixes to dependencies">
<!-- Fix for PHP 8 incompatibility in chrome-mink-driver 2.8.0: -->
<reflexive>
<fileset dir="vendor/dmore/chrome-mink-driver/src">
<include pattern="ChromeDriver.php" />
</fileset>
<filterchain>
<replaceregexp>
<regexp pattern="\$base_url," replace="\$base_url = ''," />
</replaceregexp>
</filterchain>
</reflexive>
</target>
</project>