This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
/
build.xml
1329 lines (1136 loc) · 50.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
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"?>
<!-- **Phing Drupal Template** is a XML build file for the
**[Phing build system](http://www.phing.info/trac/)** with targets and
configuration designed for **[Drupal](http://drupal.org)** projects.
The aim of the project is to provide a build file which can be used with a
contiuous integration server to ensure clean code - check for compilation
errors, run unit tests, lint code and verify that code standards are upheld.
The template has been developed with the
[Jenkins job template for Drupal projects](http://reload.github.com/jenkins-drupal-template)
and the [Drupal Jenkins demo](http://github.com/kasperg/drupal-jenkins-demo).
It may work with other continuous integration systems.
### Usage
The template can be used in several ways:
* As a starting point for your own build files. Download
[`build.xml`](https://raw.github.com/reload/phing-drupal-template/master/build.xml)
to the root directory of your Drupal project and modify it as needed.
* As the actual build file for your project. You can configure most aspects of
the build according to your project through a properties file. This works
whether you have your entire Drupal project in VCS or use
[drush_make](http://drupal.org/project/drush_make). Download the entire
project and place it in a subfolder or use it as a
[git submodule](http://kernel.org/pub/software/scm/git/docs/git-submodule.html).
Using the `build` subfolder from the root directory is recommended. Copy the
`build.default.properties` file to the root directory, rename it
`build.properties` and modify it according to your project. Leave out
properties where you want to use the default values.
### Requirements
Using the template requires a range of PEAR packages present. They can be
installed as follows:
pear channel-discover pear.phing.info
pear channel-discover pear.pdepend.org
pear channel-discover pear.phpmd.org
pear channel-discover pear.phpunit.de
pear channel-discover components.ez.no
pear channel-discover pear.symfony-project.com
pear install phing/phing
pear install -a phpmd/PHP_PMD
pear install phpunit/phpcpd
pear install phpunit/phploc
pear install PHPDocumentor
pear install PHP_CodeSniffer
pear install HTTP_Request2
pear install -a phpunit/PHP_CodeBrowser
The following must be available from the command line:
* [Drush](http://drupal.org/project/drush): The Drupal shell.
[Installation instructions](http://drupalcode.org/project/drush.git/blob/HEAD:/README.txt).
* PHP 5.2.7 or newer with sqlite extension
* Java Runtime Environment
### Credits
The build file is heavily inspired by Sebastian Bergmans wonderful [template
for Jenkins Jobs for PHP Projects](http://jenkins-php.org/) and began as a
Phing port of his suggested Apache Ant build file.
Many of the same tools are used: [phploc](http://sebastianbergmann.github.com/phploc/),
[phpcpd](https://github.com/sebastianbergmann/phpcpd),
[PHPMD](http://phpmd.org/), [phpDocumentor](http://www.phpdoc.org/) and [PHP_CodeBrowser](https://github.com/Mayflower/PHP_CodeBrowser).
A couple of additional external tools are downloaded and used during the
build process:
* [Phing Drush Task](http://drupal.org/project/phingdrushtask):
A custom task for running drush from Phing
* [Phing PHPLoc](https://github.com/raphaelstolt/phploc-phing): A custom task
for running phploc from Phing
* [jslint4java](http://jslint4java.googlecode.com/): Supports execution of
jslint from the command line
* [jslint´](https://github.com/mikewest/JSLint): A more humane version of
Douglas Crockfords JSLint.
* [csslint](http://csslint.net): A tool to help point out problems with CSS code.
* [Mozilla Rhino](http://www.mozilla.org/rhino/download.html): An implementation of Javascript in Java.
* [Coder](http://drupal.org/project/coder): Drupal module for
performing code reviews.
This documentation has been generated by
[phrocco](https://github.com/oneblackbear/phrocco)
- a PHP port of the literate documentation generator Docco.
### Contributors
The Phing Drupal template is developed by [Reload!](http://reload.dk) - a Drupal development agency located in Copenhagen, Denmark.
Drush Make and Simpletest support has been sponsored by [DBC](http://www.dbc.dk/).
<a href="http://github.com/reload/phing-drupal-template">
<img style="position: absolute; top: 0; right: 0; border: 0;" src="https://a248.e.akamai.net/assets.github.com/img/30f550e0d38ceb6ef5b81500c64d970b7fb0f028/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6f72616e67655f6666373630302e706e67" alt="Fork me on GitHub">
</a>
-->
<project name="phing-drupal" default="build" phingVersion="2.4.11">
<!-- ## Main targets -->
<!-- ### Build project
Do a complete build of the project by verifying code consistency and and
performing static analysis of the code.
This is the default build target.
Do not run `docs` for now. Generating documentation eats up memory and build
time and is largely obsolete when using GitHub. -->
<target name="build" depends="init,
clean,
verify,
analyze" />
<!-- ### Verify code consistency
Make sure that our code is clean and functional. -->
<target name="verify" depends="init,
clean,
lint-php-custom,
lint-js-custom,
lint-css-custom,
check-php-debug,
check-js-debug,
simpletest"/>
<!-- ### Analyze code
Perform static analysis of the code to generate statistics, identify potential
problems and opportunities for refactorings and make sure that the code
complies with coding standards. -->
<target name="analyze" depends="init,
clean,
phploc,
phpmd,
phpcpd">
<!-- Moved inside target to support properties in target name -->
<phingcall target="coder-review-d${drupal.version}">
<!-- Run the target as if it was executed from the Drupal root
directory. -->
<property name="project.basedir" value="${project.drupal.dir}"/>
<!-- We already have a clean environment so avoid further cleaning. -->
<property name="project.cleaned" value="1"/>
<!-- Make will run again as a part of the `init` target. We already have
a working site so skip that. -->
<property name="project.make.skip" value="1"/>
</phingcall>
</target>
<!-- ### Generate documentation
Generate HTML documentation and code browser for the project. -->
<target name="docs" depends="init,
clean,
phpdoc,
phpcb" />
<!-- ## Individual targets
These targets can be executed individually or grouped unless explicitly
stated as a part of the task.
**As a rule targets without descriptions should not be executed directly.** -->
<!-- ### PHP linting
Check files for syntax errors. -->
<target name="lint-php"
description="Check all PHP files for syntax errors using PHPLint"
depends="init">
<phplint haltonfailure="true">
<fileset refid="src.php" />
</phplint>
</target>
<target name="lint-php-custom"
description="Check custom PHP files for syntax errors using PHPLint"
depends="init">
<phplint haltonfailure="true">
<fileset refid="src.php.custom" />
</phplint>
</target>
<!-- ### Javascript linting
Checks code against [jslint](http://www.jslint.com/) to assure a coding
standard is followed and detect potential problems. By default
[jslint´](https://github.com/mikewest/JSLint) is used. -->
<target name="lint-js"
description="Check all Javascript files using JSlint"
depends="init, setup-jslint4java, setup-jslint">
<foreach target="jslint-file" param="filename" absparam="absfilename">
<fileset refid="src.js"/>
</foreach>
</target>
<target name="lint-js-custom"
description="Check custom Javascript files using JSlint"
depends="init, setup-jslint4java, setup-jslint">
<foreach target="jslint-file" param="filename" absparam="absfilename">
<fileset refid="src.js.custom"/>
</foreach>
</target>
<!-- #### jslint a file
No need to run `init` or setup targets here. This target should only be called
from parent `lint-js` targets. -->
<target name="jslint-file">
<echo>Linting file: ${absfilename}</echo>
<!-- Execute jslint4java and return the result in checkstyle format-->
<exec command="java -jar ${jslint4java.file}
--jslint ${jslint.file} --report checkstyle ${absfilename}"
outputProperty="report" />
<!-- Print the result to a file.
Replace / with - in path to create legal filenames in the format
`checkstyle-jslint-dir1-dir2-file.js.xml`. -->
<php function="str_replace" returnProperty="filename.normalized">
<param value="/" />
<param value="-" />
<param value="${filename}" />
</php>
<delete file="${project.logdir}/checkstyle-jslint-${filename.normalized}.xml" />
<append text="${report}" destFile="${project.logdir}/checkstyle-jslint-${filename.normalized}.xml" />
</target>
<!-- #### Setup jslint4java -->
<target name="setup-jslint4java"
depends="init"
unless="project.jslint4java.setup">
<property name="jslint4java.dir"
value="${project.toolsdir}/jslint4java" />
<php function="basename" returnProperty="jslint4java.basename">
<param value="${jslint4java.url}" />
<!-- We assume that the version of jslint4java used is a distribution
where the filename ends in `-dist.zip` -->
<param value="-dist.zip" />
</php>
<!-- Download and unpack jslint4java -->
<mkdir dir="${jslint4java.dir}" />
<php function="basename" returnProperty="jslint4java.zipfile">
<param value="${jslint4java.url}" />
</php>
<httpget url="${jslint4java.url}"
dir="${jslint4java.dir}"
proxy="${phing.httpget.proxy}" />
<unzip file="${jslint4java.dir}/${jslint4java.zipfile}"
todir="${jslint4java.dir}" />
<!-- Other targets use this property to determine the location of the
`jslint4java.jar` file -->
<property name="jslint4java.file"
value="${jslint4java.dir}/${jslint4java.basename}/${jslint4java.basename}.jar"/>
<!-- Set property to prevent unnecessary additional invocations of this
target -->
<property name="project.jslint4java.setup" value="true" />
</target>
<!-- #### Setup jslint -->
<target name="setup-jslint"
depends="init"
unless="project.jslint.setup">
<phingcall target="setup-git-repo">
<property name="repo.dir" value="${project.toolsdir}/jslint"/>
<property name="repo.url" value="${jslint.repository.url}" />
</phingcall>
<!-- Other targets use this property to determine the location of the jslint
file -->
<property name="jslint.file"
value="${project.toolsdir}/jslint/${jslint.file}"
override="true" />
<!-- Set property to prevent unnecessary additional invocations of this
target -->
<property name="project.jslint.setup" value="true" />
</target>
<!-- ### CSS linting
Checks code against [CSS Lint](http://www.csslint.net/) to help point out problems with CSS code. It does basic syntax checking as well as applying a set of rules to the code that look for problematic patterns or signs of inefficiency. -->
<target name="lint-css"
description="Check all CSS files using CSS Lint"
depends="init, setup-rhino, setup-csslint">
<foreach target="csslint-file" param="filename" absparam="absfilename">
<fileset refid="src.css"/>
</foreach>
</target>
<target name="lint-css-custom"
description="Check custom CSS files using CSS Lint"
depends="init, setup-rhino, setup-csslint">
<foreach target="csslint-file" param="filename" absparam="absfilename">
<fileset refid="src.css.custom"/>
</foreach>
</target>
<!-- #### csslint a file
No need to run `init` or setup targets here. This target should only be called
from parent `lint-css` targets. -->
<target name="csslint-file">
<echo>Linting file: ${absfilename}</echo>
<!-- Run csslint through Rhino and return the result in
checkstyle format-->
<exec command="java -jar ${rhino.jar} ${csslint.rhino.file}
--format=checkstyle-xml --rules=${csslint.rules}
${absfilename}"
outputProperty="report" />
<!-- Print the result to a file.
Replace / with - in path to create legal filenames in the format
`checkstyle-csslint-dir1-dir2-file.css.xml`. -->
<php function="str_replace" returnProperty="filename.normalized">
<param value="/" />
<param value="-" />
<param value="${filename}" />
</php>
<property name="csslint.report.file" value="${project.logdir}/checkstyle-csslint-${filename.normalized}.xml" />
<delete file="${csslint.report.file}" />
<append text="${report}" destFile="${csslint.report.file}" />
<!-- Cleanup the break rules property.
Hyphens are removed to support both input and output rule format.
csslint-rule becomes CsslintRule.
Seperators (Commas and multiple whitespace characters) are reduced
to a pipe to be used in a regular expression. -->
<php expression="str_replace('-', '', '${csslint.rules.break}')"
returnProperty="csslint.rules.break"/>
<php expression="preg_replace('/(\s+|\s*,\s*)/', '|', '${csslint.rules.break}')"
returnProperty="csslint.rules.break"/>
<!-- If any rules which require the build to break are defined then
look for them. -->
<if>
<not>
<equals arg1="${csslint.rules.break}" arg2="" />
</not>
<then>
<!-- CSS Lint reports checkstyle errors using the format
net.csslint.RuleName. Load all checkstyle reports and look for
errors with such a source from the provided rules. -->
<loadfile property="csslint.break.errors"
file="${csslint.report.file}">
<filterchain>
<linecontainsregexp>
<regexp pattern="(net\.csslint\.(${csslint.rules.break}))"
ignoreCase="true" />
</linecontainsregexp>
</filterchain>
</loadfile>
<!-- Break if any errors from the provided rules are detected! -->
<if>
<not>
<equals arg1="${csslint.break.errors}" arg2="" />
</not>
<then>
<fail message="CSS error detected in file ${absfilename}" />
</then>
</if>
</then>
</if>
</target>
<!-- #### Setup csslint -->
<target name="setup-csslint"
depends="init"
unless="project.csslint.setup">
<phingcall target="setup-git-repo">
<property name="repo.dir"
value="${project.toolsdir}/csslint"/>
<property name="repo.url"
value="${csslint.repository.url}" />
<property name="repo.revision"
value="${csslint.repository.revision}" />
</phingcall>
<!-- Other targets use this property to determine the location of the
csslint rhino file -->
<property name="csslint.rhino.file"
value="${project.toolsdir}/csslint/release/csslint-rhino.js" />
<!-- Set property to prevent unnecessary additional invocations of this
target -->
<property name="project.csslint.setup" value="true" />
</target>
<!-- ### Debug code detection
Code should not call functions which are usually used for debugging.
This belongs on developer environments - not VCS. This goes for mentioning
them in comments as well. -->
<target name="check-php-debug"
description="Check custom PHP code for debug statements"
depends="init">
<phingcall target="check-debug">
<property name="debug.language" value="PHP" override="true" />
<property name="debug.pattern" value="(var_dump\(|dsm\(|dpm\()"
override="true" />
<property name="debug.fileset" value="src.php.custom"/>
</phingcall>
</target>
<target name="check-js-debug"
description="Check custom Javascript code for debug statements">
<phingcall target="check-debug">
<property name="debug.language" value="Javascript" override="true" />
<property name="debug.pattern" value="(console\.log\()" override="true" />
<property name="debug.fileset" value="src.js.custom"/>
</phingcall>
</target>
<!-- #### Check a fileset for debug code -->
<target name="check-debug"
depends="init">
<php function="strtolower" returnProperty="debug.language.lower">
<param value="${debug.language}" />
</php>
<property name="debug.output"
value="${project.logdir}/debug_${debug.language.lower}.txt"
override="true" />
<delete file="${debug.output}"/>
<append text="" destFile="${debug.output}" />
<foreach target="check-debug-file" param="filename"
absparam="absfilename">
<fileset refid="${debug.fileset}"/>
</foreach>
<loadfile property="debug.lines" file="${debug.output}" />
<!-- Break if debug code is detected! -->
<if>
<not>
<equals arg1="${debug.lines}" arg2="" />
</not>
<then>
<fail message="${debug.language} debug code detected:${line.separator}
${debug.lines}" />
</then>
</if>
</target>
<!-- #### Check an individual file for debug code
No need to run `init` here. This target should only be called through parent
`check-debug` target. -->
<target name="check-debug-file">
<echo>Checking file for debug statements: ${absfilename}</echo>
<loadfile property="debug.lines" file="${absfilename}">
<filterchain>
<linecontainsregexp>
<regexp pattern="${debug.pattern}" />
</linecontainsregexp>
</filterchain>
</loadfile>
<if>
<not>
<equals arg1="${debug.lines}" arg2="" />
</not>
<then>
<append text="${filename}:${line.separator}
${debug.lines}${line.separator}
${line.separator}"
destFile="${debug.output}"/>
</then>
</if>
</target>
<!-- ### Detect code mess
Uses [PHPMD](http://phpmd.org/) to detect code mess and look for potential
problems. -->
<target name="phpmd"
description="Generate pmd.xml using PHPMD"
depends="init">
<!-- We do not use the unusedcode ruleset as Drupal hook implementations
usually are declared with all arguements but may not use them
all. -->
<phpmd rulesets="codesize,naming,design">
<fileset refid="src.php.custom" />
<formatter type="xml" outfile="${project.logdir}/pmd.xml"/>
</phpmd>
</target>
<!-- ### Detect potential copy/pasting
Uses [phpcpd](https://github.com/sebastianbergmann/phpcpd) to detect duplicate
code. This indicates potential refactorings.-->
<target name="phpcpd"
description="Generate pmd-cpd.xml using phpcpd"
depends="init">
<phpcpd>
<fileset refid="src.php.custom" />
<formatter type="pmd" outfile="${project.logdir}/pmd-cpd.xml"/>
</phpcpd>
</target>
<!-- ### Generate code statistics
Measures the size of the project using
[phploc](http://sebastianbergmann.github.com/phploc/) and generates
statistics. -->
<target name="phploc"
description="Generate phploc.csv using phploc"
depends="init, setup-phing-phploc">
<!-- Suffixes should be the same as included in the
src.php filesets -->
<phploc reportType="csv"
reportName="phploc" reportDirectory="${project.logdir}"
suffixes="php,module,inc,install,profile,test" countTests="true">
<fileset refid="src.php.custom" />
</phploc>
</target>
<!-- #### Setup Phing phploc integration -->
<target name="setup-phing-phploc"
depends="init" >
<!-- Clone the project -->
<phingcall target="setup-git-repo">
<property name="repo.dir" value="${project.toolsdir}/phing-phploc"/>
<property name="repo.url" value="${phing.phploc.repository.url}" />
</phingcall>
<!-- Register the custom Phing task -->
<taskdef name="phploc" classname="PHPLocTask"
classpath="${project.toolsdir}/phing-phploc" />
</target>
<!-- ### Drupal Coder review
Review code using [Drupal coder module](http://drupal.org/project/coder).
Configuration of which modules and themes to review is done in
`build.properties`. If your modules use a common prefix such as
`yourproject_module1`, `yourproject_module2` you can add all modules with a
specific prefix. -->
<target name="coder-review-d6"
description="Review code using Drupal 6 Coder module"
depends="init">
<echo level="warning">Coder Review is not supported for Drupal 6 yet.
Check http://drupal.org/node/858330 for
patches/updates.</echo>
</target>
<target name="coder-review-d7"
description="Review code using Drupal 7 Coder module"
depends="init, clean, site-install">
<!-- Setup properties for running Coder Review.
For some reason these properties are not passed correctly through to
subtargets when defining them within the phingcall. -->
<property name="coder.review.command" value="coder-review"/>
<!-- Download and enable the Coder Review module -->
<phingcall target="enable-module">
<property name="project" value="coder"/>
<property name="project.version" value="7.x-1.0"/>
<property name="module" value="coder_review"/>
</phingcall>
<!-- Perform actual coder review for each style -->
<foreach target="coder-review" param="coder.review.type"
list="comment,i18n,security,sql,style" />
</target>
<!-- #### Perform coder review
This target requires properties set by calling targets coder-review-d6 or
coder-review-d7.
No need to run `init` here. This target should only be called from parent
`coder-review-*` targets. -->
<target name="coder-review"
depends="setup-phing-drush">
<!-- Get a list of modules and themes matching the project prefix.
These are the ones we are going to review. -->
<drush command="pm-list" pipe="true" returnProperty="projects" />
<!-- The project list is piped through a file as this seems to be
the only way to handle filtering of values in Phing. -->
<delete file="${project.logdir}/projects.txt" />
<append text="${projects}" destFile="${project.logdir}/projects.txt" />
<!-- Build a regular expression to match modules based on the
set properties. The propery can contain prefixes separated by comma
and/or spaces. The expression should be in the format
`^(prefix1|prefix2|prefix3)_`. -->
<php expression="'^(' . preg_replace('/(\s+|\s*,\s*)/', '|', '${project.code.prefix}') .')_'"
returnProperty="project.code.prefix.regex"/>
<loadfile property="project.code.projects"
file="${project.logdir}/projects.txt">
<filterchain>
<linecontainsregexp>
<regexp pattern="${project.code.prefix.regex}" />
</linecontainsregexp>
<!-- Prefix all lines with a space.
We need the space as separator when we strip line breaks -->
<prefixlines prefix=" " />
<striplinebreaks />
</filterchain>
</loadfile>
<!-- Cleanup the custom code property. Commas and multiple whitespace
characters are reduced to a single space. -->
<php expression="preg_replace('/(\s+|\s*,\s*)/', ' ', '${project.code.custom}')"
returnProperty="project.code.custom"/>
<!-- Execute coder review and output results in XML format-->
<drush command="${coder.review.command}" assume="yes"
pipe="yes" returnProperty="xml">
<param>no-empty</param>
<param>checkstyle</param>
<param>minor</param>
<param>${coder.review.type}</param>
<!-- Review all the modules and themes matching the project prefix -->
<param>${project.code.projects}</param>
<!-- Review additional modules which do not match the prefix -->
<param>${project.code.custom}</param>
</drush>
<!-- Write XML output to file -->
<property name="coderreview.checkstyle.file"
value="${project.logdir}/checkstyle-${coder.review.type}.xml" />
<delete file="${coderreview.checkstyle.file}" />
<append destFile="${coderreview.checkstyle.file}" text="${xml}" />
<!-- Convert source from source extract to Category.Type format -->
<php function="ucwords" returnProperty="type">
<param value="${coder.review.type}"/>
</php>
<reflexive file="${coderreview.checkstyle.file}">
<filterchain>
<replaceregexp>
<regexp pattern='source=".*"'
replace='source="Drupal.CoderReview.${type}"' />
</replaceregexp>
</filterchain>
</reflexive>
</target>
<!-- ### Review code using PHP_CodeSniffer
The purpose and outcome of this target is the same as the coder-review
targets. In general [PHP_CodeSniffer](http://pear.php.net/package/PHP_CodeSniffer/)
is faster to execute but there does not seem to be a complete ruleset which
covers all of the
[Drupal coding standards](http://drupal.org/coding-standards).
Consequently `coder-review-d6/7` and not `phpcs` is used for the main targets.
-->
<target name="phpcs"
description="Generate checkstyle.xml using PHP_CodeSniffer"
depends="init">
<!-- Clone a repository containing Drupal code guidelines for
PHP_CodeSniffer. -->
<phingcall target="setup-git-repo">
<property name="repo.dir" value="${project.toolsdir}/drupalcs"/>
<property name="repo.url" value="${phpcs.drupalcs.repository.url}" />
</phingcall>
<!-- There is no Phing task for PHP Codesniffer in v2.4.6.
It's coming for v2.5. Execute while we wait. -->
<exec command="phpcs --report=checkstyle
--report-file=${project.logdir}/checkstyle-codesniffer.xml
--standard=${project.toolsdir}/drupalcs/ruleset.xml
--extensions=php,inc
--ignore=*/contrib/*,*/*.features.*,*/*.field_group.inc,*/*.layout.*,*/*.pages_default.*,*/*.panels_default.*,*/*strongarm.inc,*/*.views_default.inc
${project.sitesdir}"
logoutput="true" />
</target>
<!-- ### Run simpletests
Execution of this target can be skipped by setting the
`project.simpletest.skip` property from the command line or in other targets.
-->
<target name="simpletest"
description="Run all unit tests"
depends="init, setup-phing-drush, site-install"
unless="project.simpletest.skip">
<!-- Enable simpletest module. If using Drupal 6 the module will be
downloaded as well. -->
<phingcall target="enable-module">
<property name="module" value="simpletest"/>
</phingcall>
<if>
<isset property="drupal.uri" />
<then>
<!-- Get a list of all available test cases -->
<drush command="test-run" uri="${drupal.uri}" root="${project.drupal.dir}" returnProperty="tests" returnGlue="${line.separator}"/>
<!-- The project list is piped through a file as this seems to be
the only way to handle filtering of values in Phing. -->
<delete file="${project.logdir}/tests.txt" />
<append text="${tests}" destFile="${project.logdir}/tests.txt" />
<!-- Build a regular expression to match test groups based on the
set properties. The expression should be in the format
`^\s?(prefix1|prefix2|prefix3)_`. -->
<php expression="'^\s?(' . preg_replace('/(\s+|\s*,\s*)/', '|', '${project.code.prefix}') .').*'"
returnProperty="project.code.prefix.regex"/>
<!-- Load the list of tests but keep only the test groups matching our
prefixes. -->
<loadfile property="project.simpletest.tests"
file="${project.logdir}/tests.txt">
<filterchain>
<linecontainsregexp>
<regexp pattern="${project.code.prefix.regex}" ignoreCase="true"/>
</linecontainsregexp>
</filterchain>
</loadfile>
<!-- Transform the list of filtered test groups in the form
Groupname 1 Groupname 1
Groupname 2 Groupname 2
into a list of comma separated unique group names `Groupname 1,Groupname 2`. -->
<php expression="implode(',', array_unique(preg_split('/(\s{2,}|\r|\n)/', trim('${project.simpletest.tests}', PREG_SPLIT_NO_EMPTY))))"
returnProperty="project.simpletest.tests"/>
<!-- Run the tests and generate JUnit XML reports. This requires
Drush 4.5 or newer or [a patch](http://drupal.org/node/1109408). -->
<drush command="test-run" uri="${drupal.uri}" root="${project.drupal.dir}" haltonerror="false">
<param>${project.simpletest.tests}</param>
<option name="xml">${project.testdir}</option>
</drush>
</then>
<else>
<echo msg="You must set the drupal.uri property to get simpletests working." />
</else>
</if>
</target>
<!-- ### Generate documentation -->
<!-- #### Generate API Documentation
Uses [phpDocumentor](http://www.phpdoc.org/) to generate documentation. -->
<target name="phpdoc"
description="Generate API documentation using phpDocumentor">
<mkdir dir="${project.buildir}/api"/>
<phpdoc title="API Documentation"
destdir="${project.builddir}/api"
sourcecode="php"
output="HTML:Smarty:PHP">
<fileset refid="src.php" />
</phpdoc>
</target>
<!-- #### Generate a code browser
Generate a code browser for PHP files with syntax highlighting and
colored error-sections using
[PHP_CodeBrowser](https://github.com/Mayflower/PHP_CodeBrowser). -->
<target name="phpcb"
description="Aggregate tool output with PHP_CodeBrowser"
depends="init">
<mkdir dir="${project.builddir}/code-browser"/>
<!-- There is no Phing target for PHP CodeBrowser so do a plain
execute. -->
<exec command="phpcb --log ${project.logdir}
--source ${project.basedir}
--output ${project.builddir}/code-browser"
logoutput="true" />
</target>
<!-- ## Helper targets
These targets are used throughout the project and should normally not be
executed directly.-->
<!-- ### Initialization
This target sets up many of the common resources used throughout the build.
All other targets except dependencies for this target should depend on this
unless specifically stated why. -->
<target name="init"
depends="load-properties, setup-dirs, make, setup-filesets"
unless="project.initialized">
<!-- Set property to prevent target from being executed multiple times -->
<property name="project.initialized" value="true"/>
</target>
<!-- ### Load properties
Loads a set of project specific properties from a `.properties` file.
These properties contain information regarding the individual project and/or
environment such as which version of Drupal you are using, how to create a
database and the names of your custom modules.
All available properties are described and set to a default value in
[`build.default.properties`](https://raw.github.com/reload/phing-drupal-template/master/build.default.properties).
You should create your own properties file by copying the
`build.default.properties` file to the root directory, rename it
`build.properties` and modify it according to your project.
Both property files are loaded so your custom `build.properties` file should
only contain properties where you want to override the default value e.g. set
your custom module code prefix or use a special version of one of the build
tools. -->
<target name="load-properties">
<php function="dirname" returnProperty="phing.dir">
<param value="${phing.file}"/>
</php>
<property name="project.basedir" value="${phing.dir}" />
<!-- Use condition instead of unless property as we cannot unset properties in Phing -->
<if>
<or>
<!-- `istrue` evaluates to true is value is not set we need to check
`isset` as well -->
<not><istrue value="${project.properties.loaded}" /></not>
<not><isset property="project.properties.loaded" /></not>
</or>
<then>
<!-- By default Jenkins runs Phing from the directory containing the build
file. If this file is located in a subdirectory - e.g. when using Phing Drupal as a submodule - we need to reset the project basedir and reload properties.
NB: This only works if the subdirectory is directly within the Drupal
root directory. -->
<if>
<!-- If `build.properties` exists then assume we have a
project root directory -->
<available file="${project.basedir}/../build.properties"/>
<then>
<resolvepath propertyName="project.basedir"
file="${project.basedir}/../"/>
</then>
</if>
<!-- By default use default properties file
`build.default.properties` -->
<property name="project.properties.file"
value="${phing.dir}/build.default.properties" />
<!-- Load the default properties.
Override in case `load-properties` are called multiple times. -->
<property file="${project.properties.file}" override="true" />
<!-- Allow override using `build.properties` in build file
directory -->
<available file="${phing.dir}/build.properties"
property="project.properties.file"
value="${phing.dir}/build.properties" />
<!-- Allow override using `build.properties` in project base
directory -->
<available file="${project.basedir}/build.properties"
property="project.properties.file"
value="${project.basedir}/build.properties" />
<!-- Load the overriding properties. -->
<property file="${project.properties.file}" override="true" />
<!-- Set property to prevent unnecessary additional invocations of this target -->
<property name="project.properties.loaded" value="true" />
</then>
</if>
</target>
<!-- ### Setup directories
Define working directories - where the individual parts of the build are and
should be located. These are used in other targets.
This is part of the initialization of the build. This target should only be
called from `init` target. -->
<target name="setup-dirs"
depends="load-properties">
<if>
<isset property="drupal.make.dir"/>
<then>
<property name="project.drupal.dir"
value="${project.basedir}/${drupal.make.dir}" />
</then>
<else>
<property name="project.drupal.dir"
value="${project.basedir}" />
</else>
</if>
<property name="project.sitesdir"
value="${project.drupal.dir}/${project.code.dir}" />
<property name="project.builddir"
value="${project.basedir}/build" />
<property name="project.toolsdir"
value="${project.builddir}/tools" />
<property name="project.coveragedir"
value="${project.builddir}/coverage" />
<property name="project.logdir"
value="${project.builddir}/logs" />
<property name="project.testdir"
value="${project.builddir}/tests" />
</target>
<!-- ### Drush Make
Download and install the source code for the site using Drush Make.
This target is only executed if the project uses make files as configured
in the `build.properties` file. Execution can also be skipped by setting the
`project.make.skip` property from the command line or in other targets.
This is part of the initialization of the build. This target should only be
called from `init` target. -->
<target name="make"
depends="load-properties, setup-phing-drush"
if="drupal.make.file">
<if>
<or>
<not><isset property="project.make.skip"/></not>
<not><istrue value="${project.make.skip}"/></not>
</or>
<then>
<!-- Delete any prexisting builds -->
<delete dir="${project.drupal.dir}"/>
<!-- If the make file does not include a core Drupal project we need
to download one separately. This should be defined in
`build.properties`. -->
<if>
<and>
<isset property="drupal.make.nocore"/>
<istrue value="${drupal.make.nocore}"/>
</and>
<then>
<!-- Download the appropriate version of Drupal -->
<drush command="dl" assume="yes">
<param>drupal-${drupal.version}</param>
<option name="drupal-project-rename">${drupal.make.dir}</option>
</drush>
<!-- Make the project in the project code directory. If using
a directory inside the `sites` folder modules can be tested
faster and easier when using the minimal profile. -->
<drush command="make" assume="yes">
<param>${drupal.make.file}</param>
<option name="contrib-destination">${drupal.make.dir}/${project.code.dir}</option>
<option name="no-core"/>
</drush>
<!-- Copy the install profile bundled with the make file to the
appropriate directory. -->
<copy todir="${project.drupal.dir}/profiles/${drupal.profile}/">
<fileset dir="${project.basedir}">
<include name="${drupal.profile}.*" />
</fileset>
</copy>
</then>
<else>
<drush command="make" assume="yes">
<param>${drupal.make.file}</param>
<param>${drupal.make.dir}</param>
</drush>
</else>
</if>
<if>
<isset property="drupal.make.rewritebase" />
<then>
<reflexive file="${project.drupal.dir}/.htaccess">
<filterchain>
<replaceregexp>
<regexp pattern="# RewriteBase [\w/]*" replace="RewriteBase ${drupal.make.rewritebase}"/>
</replaceregexp>
</filterchain>
</reflexive>
</then>
</if>
<!-- Set property to prevent target from being executed multiple times -->
<property name="project.make.skip" value="true"/>
</then>
<else>
<echo>
Skipping drush make.${line.separator}
drupal.make.skip has been set to ${project.make.skip}.
</echo>
</else>
</if>
</target>
<!-- ### Setup file sets
Setup file sets - patterns for different aspects of the source code.
These are used in other targets.