PhingCallTask.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. /*
  3. * $Id: PhingCallTask.php 905 2010-10-05 16:28:03Z mrook $
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information please see
  19. * <http://phing.info>.
  20. */
  21. require_once 'phing/Task.php';
  22. /**
  23. * Call another target in the same project.
  24. *
  25. * <samp>
  26. * <target name="foo">
  27. * <phingcall target="bar">
  28. * <property name="property1" value="aaaaa" />
  29. * <property name="foo" value="baz" />
  30. * </phingcall>
  31. * </target>
  32. *
  33. * <target name="bar" depends="init">
  34. * <echo message="prop is ${property1} ${foo}" />
  35. * </target>
  36. * </samp>
  37. *
  38. * This only works as expected if neither property1 nor foo are defined in the project itself.
  39. *
  40. * @author Andreas Aderhold <andi@binarycloud.com>
  41. * @copyright 2001,2002 THYRELL. All rights reserved
  42. * @version $Revision: 905 $
  43. * @access public
  44. * @package phing.tasks.system
  45. */
  46. class PhingCallTask extends Task {
  47. /**
  48. * The called Phing task.
  49. *
  50. * @var PhingTask
  51. */
  52. private $callee;
  53. /**
  54. * The target to call.
  55. *
  56. * @var string
  57. */
  58. private $subTarget;
  59. /**
  60. * Whether to inherit all properties from current project.
  61. *
  62. * @var boolean
  63. */
  64. private $inheritAll = true;
  65. /**
  66. * Whether to inherit refs from current project.
  67. *
  68. * @var boolean
  69. */
  70. private $inheritRefs = false;
  71. /**
  72. * If true, pass all properties to the new Phing project.
  73. * Defaults to true. Future use.
  74. * @param boolean new value
  75. */
  76. function setInheritAll($inherit) {
  77. $this->inheritAll = (boolean) $inherit;
  78. }
  79. /**
  80. * If true, pass all references to the new Phing project.
  81. * Defaults to false. Future use.
  82. *
  83. * @param boolean new value
  84. */
  85. function setInheritRefs($inheritRefs) {
  86. $this->inheritRefs = (boolean) $inheritRefs;
  87. }
  88. /**
  89. * Alias for createProperty
  90. * @see createProperty()
  91. */
  92. function createParam() {
  93. if ($this->callee === null) {
  94. $this->init();
  95. }
  96. return $this->callee->createProperty();
  97. }
  98. /**
  99. * Property to pass to the invoked target.
  100. */
  101. function createProperty() {
  102. if ($this->callee === null) {
  103. $this->init();
  104. }
  105. return $this->callee->createProperty();
  106. }
  107. /**
  108. * Target to execute, required.
  109. */
  110. function setTarget($target) {
  111. $this->subTarget = (string) $target;
  112. }
  113. /**
  114. * init this task by creating new instance of the phing task and
  115. * configuring it's by calling its own init method.
  116. */
  117. function init() {
  118. $this->callee = $this->project->createTask("phing");
  119. $this->callee->setOwningTarget($this->getOwningTarget());
  120. $this->callee->setTaskName($this->getTaskName());
  121. $this->callee->setHaltOnFailure(true);
  122. $this->callee->setLocation($this->getLocation());
  123. $this->callee->init();
  124. }
  125. /**
  126. * hand off the work to the phing task of ours, after setting it up
  127. * @throws BuildException on validation failure or if the target didn't
  128. * execute
  129. */
  130. function main() {
  131. $this->log("Running PhingCallTask for target '" . $this->subTarget . "'", Project::MSG_DEBUG);
  132. if ($this->callee === null) {
  133. $this->init();
  134. }
  135. if ($this->subTarget === null) {
  136. throw new BuildException("Attribute target is required.", $this->getLocation());
  137. }
  138. $this->callee->setPhingfile($this->project->getProperty("phing.file"));
  139. $this->callee->setTarget($this->subTarget);
  140. $this->callee->setInheritAll($this->inheritAll);
  141. $this->callee->setInheritRefs($this->inheritRefs);
  142. $this->callee->main();
  143. }
  144. }