Skip to content
This repository
tree: 3d03381e2d
Fetching contributors…

Cannot retrieve contributors at this time

file 1329 lines (1136 sloc) 51.939 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329
<?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.

This is part of the initialization of the build. This target should only be
called from `init` target. -->
  <target name="setup-filesets"
          depends="load-properties">
    <!-- Define pattern sets for future reference -->

    <!-- PHP files -->
    <patternset id="php">
      <include name="**/*.php" />
      <include name="**/*.module" />
      <include name="**/*.install" />
      <include name="**/*.inc" />
      <include name="**/*.profile" />
      <include name="**/*.test" />
    </patternset>

    <!-- Javascript files -->
    <patternset id="js">
      <include name="**/*.js" />
      <!-- Minimized JavaScript files should not be analyzed.
In their optimized state they can not be expexted
to conform to coding standards. -->
      <exclude name="**/*.min.js" />
    </patternset>

    <!-- CSS files -->
    <patternset id="css">
      <include name="**/*.css" />
    </patternset>

    <!-- Directories for community contributed code. We exclude these from
code analysis as we cannot be held responsible for any problems
here. -->
    <patternset id="contrib">
      <exclude name="**/contrib/**/*.*" />
      <exclude name="**/libraries/**/*.*" />
    </patternset>

    <!-- We exclude generated files from We exclude these from code analysis
as we cannot be held responsible for any problems here. -->
    <patternset id="generated">
      <exclude name="**/*.features.*" />
      <exclude name="**/*.field_group.inc" />
      <exclude name="**/*.layouts.inc" />
      <exclude name="**/*.pages_default.inc" />
      <exclude name="**/*.panels_default.inc" />
      <exclude name="**/*.strongarm.inc" />
      <exclude name="**/*.views_default.inc" />
    </patternset>

    <!-- Define file sets for future reference -->

    <!-- All PHP files -->
    <fileset id="src.php" dir="${project.drupal.dir}">
      <patternset refid="php"/>
    </fileset>

    <!-- Custom PHP files -->
    <fileset id="src.php.custom" dir="${project.sitesdir}">
      <patternset refid="php"/>
      <patternset refid="contrib"/>
      <patternset refid="generated"/>
    </fileset>

    <!-- All Javascript files -->
    <fileset id="src.js" dir="${project.drupal.dir}">
      <patternset refid="js" />
    </fileset>

    <!-- Custom Javascript files -->
    <fileset id="src.js.custom" dir="${project.sitesdir}">
      <patternset refid="js" />
      <patternset refid="contrib" />
    </fileset>

    <!-- All CSS files -->
    <fileset id="src.css" dir="${project.basedir}">
      <patternset refid="css" />
    </fileset>

    <!-- Custom CSS files -->
    <fileset id="src.css.custom" dir="${project.sitesdir}">
      <patternset refid="css" />
      <patternset refid="contrib" />
    </fileset>

  </target>

<!-- ### Clean working environment -->
  <target name="clean"
          description="Clean up and create artifact directories"
          depends="setup-dirs"
          unless="project.cleaned">
    <!-- Delete any existing artifacts from a previous build.
Do not delete builddir. It may contain the build file! -->
    <delete dir="${project.toolsdir}"/>
    <delete dir="${project.coveragedir}"/>
    <delete dir="${project.logdir}"/>
    <delete dir="${project.testdir}"/>
    <!-- Verbose. We need to make sure any database is deleted. Reinstalling
the site with an existing database causes the build to fail. -->
    <delete file="${project.drupal.dir}/database.sqlite" verbose="true" />
    <!-- Remove leftover Drupal simpletest databases -->
    <delete>
      <fileset dir="${project.basedir}">
        <include name="database.sqlite-simpletest*"/>
      </fileset>
    </delete>

    <!-- Recreate directories for artifacts -->
    <mkdir dir="${project.toolsdir}"/>
    <mkdir dir="${project.coveragedir}"/>
    <mkdir dir="${project.logdir}"/>
    <mkdir dir="${project.testdir}"/>

    <!-- Set property to prevent target from being executed multiple times -->
    <property name="project.cleaned" value="true"/>
  </target>

<!-- ### Install a Drupal site

This initializes a Drupal site using a installation profile.

Configuration of which installation profile and database to use in done in
`build.properties`. -->
  <target name="site-install"
          depends="init, setup-phing-drush"
          unless="project.installed">
    <drush command="site-install" assume="yes">
      <option name="db-url">${drupal.db.url}</option>
      <param>${drupal.profile}</param>
    </drush>
    <!-- Fix permissions for the default site directory and settings. The
owner must be able to delete the directories during subsequent
builds. -->
    <chmod file="${project.drupal.dir}/sites/default/"
           mode="0755" failonerror="true"/>
    <chmod file="${project.drupal.dir}/sites/default/default.settings.php"
           mode="0755" failonerror="true"/>

    <!-- Set property to prevent target from being executed multiple times -->
    <property name="project.installed" value="true"/>
  </target>

  <!-- ### Download and enable a project/module -->
  <target name="enable-module"
          depends="setup-phing-drush">
    <!-- If project is not set then we assume that the module name is also
the project name. -->
    <property name="project" value="${module}" override="no"/>

    <!-- If the module is not already available then download it -->
    <drush command="pm-list" returnProperty="modules.available"/>
    <php function="strpos" returnProperty="module.available">
      <param>${modules.available}</param>
      <param>${module}</param>
    </php>
    <if>
      <not><istrue value="${module.available}"/></not>
      <then>
        <!-- Download specific version if specified -->
        <condition property="download" value="${project}-${project.version}">
          <isset property="project.version"/>
        </condition>
        <property name="download" value="${project}" override="false"/>

        <drush command="pm-download" assume="yes">
          <param>${download}</param>
        </drush>
      </then>
    </if>

    <!-- Enable the module -->
    <drush command="pm-enable" assume="yes">
      <param>${module}</param>
    </drush>
  </target>

  <!-- ### Clone a git repository -->
  <target name="setup-git-repo">
    <!-- Only clone if repository does not exist already -->
    <if>
      <not><available file="${repo.dir}" /></not>
      <then>
        <!-- Set revision to HEAD if not already defined -->
        <property name="repo.revision" value="HEAD" override="false"/>

        <echo>Cloning ${repo.url} ${repo.revision} into ${repo.dir}</echo>
        <!-- The [`gitclone` task](http://www.phing.info/docs/guide/stable/chapters/appendixes/AppendixC-OptionalTasks.html#GitCloneTask)
does not seem to work. Use exec instead. -->
        <exec command="git clone ${repo.url} ${repo.dir}" />
        <exec command="git checkout ${repo.revision}" dir="${repo.dir}"/>
      </then>
    </if>
  </target>

  <!-- ### Download and apply a patch -->
  <target name="apply-http-patch">
    <php function="basename" returnProperty="patch.file">
      <param>${patch.url}</param>
    </php>

    <!-- If patch has already been downloaded then we assume it has also been
applied -->
    <if>
      <not><available file="${project.toolsdir}/${patch.file}"/></not>
      <then>
        <httpget url="${patch.url}"
                 dir="${project.toolsdir}"
                 proxy="${phing.httpget.proxy}" />
        <patch patchfile="${project.toolsdir}/${patch.file}"
               dir="${patch.dir}" haltonfailure="true"/>
      </then>
    </if>
  </target>

  <!-- ### Setup Phing Drush integration -->
  <target name="setup-phing-drush"
          depends="setup-dirs" >
    <!-- Clone the project -->
    <phingcall target="setup-git-repo">
      <property name="repo.dir"
                value="${project.toolsdir}/phing-drush"/>
      <property name="repo.url"
                value="${phing.drush.repository.url}" />
      <property name="repo.revision"
                value="${phing.drush.repository.revision}" />
    </phingcall>

    <!-- Register as custom Phing task -->
    <taskdef name="drush" classname="DrushTask"
             classpath="${project.toolsdir}/phing-drush" />

    <!-- Run drush from the project Drupal directory -->
    <property name="drush.root" value="${project.drupal.dir}"/>
  </target>

   <!-- ### Setup Rhino

[Mozilla Rhino](http://www.mozilla.org/rhino/) is an open-source implementation of JavaScript written in Java. -->
   <target name="setup-rhino"
           depends="setup-dirs"
           unless="project.rhino.setup">
     <property name="rhino.dir"
               value="${project.toolsdir}/rhino" />
     <php function="basename" returnProperty="rhino.basename">
       <param value="${rhino.url}" />
       <!-- We assume that the version of Rhino used is a distribution
where the filename ends in `.zip` -->
       <param value=".zip" />
     </php>

     <!-- Other targets use this property to determine the location of the
`js.jar` file -->
     <property name="rhino.jar"
               value="${rhino.dir}/${rhino.basename}/js.jar"/>

     <!-- If the Rhino js.jar file is not available then download and
unpack Rhino -->
     <if>
       <not><available file="${rhino.jar}"/></not>
       <then>
         <mkdir dir="${rhino.dir}" />
         <php function="basename" returnProperty="rhino.zipfile">
           <param value="${rhino.url}" />
         </php>
         <httpget url="${rhino.url}"
                  dir="${rhino.dir}"
                  proxy="${phing.httpget.proxy}"/>
         <unzip file="${rhino.dir}/${rhino.zipfile}"
                todir="${rhino.dir}" />
       </then>
     </if>

     <!-- Set property to prevent unnecessary additional invocations of this
target -->
     <property name="project.rhino.setup" value="true" />
   </target>

   <!-- ### Build documentation using Phrocco

Generate documentation for the build script using [Phrocco](https://github.com/oneblackbear/phrocco) and prepare for pushing changes to [GitHub pages](http://pages.github.com/).

To use this task you mush have a version of Phrocco with support for XML
parsing installed. The task is primarily for template developers. -->
   <target name="phrocco"
           depends="clean">
     <!-- Determine current branch -->
     <exec command="git status --branch --short"
           outputProperty="phrocco.code.status" />
     <php expression="array_shift(explode('...', trim('${phrocco.code.status}', '# '), 2))"
          returnProperty="phrocco.code.branch"/>

     <!-- Generate documentation in the root build directory -->
     <exec command="phrocco -i . -o . -l xml"
           passthru="true" checkreturn="true" />
     <!-- Checkout the GitHub pages branch -->
     <exec command="git checkout gh-pages"
           passthru="true" checkreturn="true"/>
     <!-- We use the documentation for build.xml and root file so rename
it to index.html -->
     <move file="build.html" tofile="index.html" overwrite="true"
           haltonerror="true" />

     <property name="phrocco.commit.mode" value=""/>
     <!-- If the local documentation branch is ahead then we have other
changes which have not been pushed yet. These have probably also
been generated by this script so amend these changes. -->
     <exec command="git status --branch --short"
           outputProperty="phrocco.docs.status" />
     <if>
       <contains string="${phrocco.docs.status}" substring="[ahead"/>
       <then>
         <property name="phrocco.commit.mode" value="--amend"
                   override="true" />
       </then>
     </if>

     <!-- Commit the changes -->
     <exec command="git commit --all -m 'Documentation update' ${phrocco.commit.mode}"
           passthru="true" checkreturn="true"/>

     <!-- Return to the main branch -->
     <exec command="git checkout ${phrocco.code.branch}"
           passthru="true" checkreturn="true"/>
   </target>

</project>
Something went wrong with that request. Please try again.