PhkPackageTask.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. /**
  3. * $Id: PhkPackageTask.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. require_once 'phing/tasks/ext/phk/PhkPackageWebAccess.php';
  23. /**
  24. * See {@link http://phk.tekwire.net/} for more information about PHK.
  25. *
  26. * @author Alexey Shockov <alexey@shockov.com>
  27. * @package phing.tasks.ext.phk
  28. */
  29. class PhkPackageTask extends Task
  30. {
  31. /**
  32. * @var string
  33. */
  34. private $outputFile;
  35. /**
  36. * @var string
  37. */
  38. private $inputDirectory;
  39. /**
  40. * @var string
  41. */
  42. private $phkCreatorPath;
  43. /**
  44. * @var PhkPackageWebAccess
  45. */
  46. private $webAccess;
  47. /**
  48. * @var array
  49. */
  50. private $modifiers = array();
  51. /**
  52. * @var array
  53. */
  54. private $options = array();
  55. /**
  56. * @return PhkPackageWebAccess
  57. */
  58. public function createWebAccess()
  59. {
  60. return ($this->webAccess = new PhkPackageWebAccess());
  61. }
  62. /**
  63. * @param string $crcCheck
  64. */
  65. public function setCrcCheck($crcCheck)
  66. {
  67. $this->options['crc_check'] = ('true' == $crcCheck ? true : false);
  68. }
  69. /**
  70. * @param string $webRunScript
  71. */
  72. public function setWebRunScript($webRunScript)
  73. {
  74. $this->options['web_run_script'] = $webRunScript;
  75. }
  76. /**
  77. * @param string $cliRunScript
  78. */
  79. public function setCliRunScript($cliRunScript)
  80. {
  81. $this->options['cli_run_script'] = $cliRunScript;
  82. }
  83. /**
  84. * @param string $libRunScript
  85. */
  86. public function setLibRunScript($libRunScript)
  87. {
  88. $this->options['lib_run_script'] = $libRunScript;
  89. }
  90. /**
  91. * @param string $name
  92. */
  93. public function setName($name)
  94. {
  95. $this->options['name'] = $name;
  96. }
  97. /**
  98. * @param string $webMainRedirect
  99. */
  100. public function setWebMainRedirect($webMainRedirect)
  101. {
  102. $this->options['web_main_redirect'] = ('true' == $webMainRedirect ? true : false);
  103. }
  104. /**
  105. * @param string $pluginClass
  106. */
  107. public function setPluginClass($pluginClass)
  108. {
  109. $this->options['plugin_class'] = $pluginClass;
  110. }
  111. /**
  112. * @param string $version
  113. */
  114. public function setVersion($version)
  115. {
  116. $this->options['version'] = $version;
  117. }
  118. /**
  119. * @param string $summary
  120. */
  121. public function setSummary($summary)
  122. {
  123. $this->options['summary'] = $summary;
  124. }
  125. /**
  126. * @param string $inputDirectory
  127. */
  128. public function setInputDirectory($inputDirectory)
  129. {
  130. $this->inputDirectory = $inputDirectory;
  131. }
  132. /**
  133. * @param string $outputFile
  134. */
  135. public function setOutputFile($outputFile)
  136. {
  137. $this->outputFile = $outputFile;
  138. }
  139. /**
  140. * May be none, gzip or bzip2.
  141. *
  142. * @param string $compress
  143. */
  144. public function setCompress($compress)
  145. {
  146. $this->modifiers['compress'] = $compress;
  147. }
  148. /**
  149. * True or false.
  150. *
  151. * @param srting $strip
  152. */
  153. public function setStrip($strip)
  154. {
  155. $this->modifiers['strip'] = $strip;
  156. }
  157. /**
  158. * Path to PHK_Creator.phk file.
  159. *
  160. * @param srting $path
  161. */
  162. public function setPhkCreatorPath($path)
  163. {
  164. $this->phkCreatorPath = $path;
  165. }
  166. /**
  167. *
  168. */
  169. public function init()
  170. {
  171. }
  172. /**
  173. * Main method...
  174. */
  175. public function main()
  176. {
  177. /*
  178. * Check for empty first - speed ;)
  179. */
  180. if (!is_file($this->phkCreatorPath)) {
  181. throw new BuildException('You must specify the "phkcreatorpath" attribute for PHK task.');
  182. }
  183. if (empty($this->inputDirectory)) {
  184. throw new BuildException('You must specify the "inputdirectory" attribute for PHK task.');
  185. }
  186. if (empty($this->outputFile)) {
  187. throw new BuildException('You must specify the "outputfile" attribute for PHK task.');
  188. }
  189. require_once $this->phkCreatorPath;
  190. $mountPoint = PHK_Mgr::mount($this->outputFile, PHK::F_CREATOR);
  191. $phkManager = PHK_Mgr::instance($mountPoint);
  192. /*
  193. * Add files.
  194. */
  195. $phkManager->ftree()->merge_file_tree('/', $this->inputDirectory, $this->modifiers);
  196. /*
  197. * Add web_access to options, if present.
  198. */
  199. if (!is_null($this->webAccess)) {
  200. $webAccessPaths = $this->webAccess->getPaths();
  201. if (!empty($webAccessPaths)) {
  202. $this->options['web_access'] = $webAccessPaths;
  203. }
  204. }
  205. $phkManager->set_options($this->options);
  206. /*
  207. * Intercept output (in PHP we can't intercept stream).
  208. */
  209. ob_start();
  210. /*
  211. * Create file...
  212. */
  213. $phkManager->dump();
  214. /*
  215. * Print with Phing log...
  216. */
  217. $output = trim(ob_get_clean());
  218. $output = split("\n", $output);
  219. foreach ($output as $line) {
  220. /*
  221. * Delete all '--- *' lines. Bluh!
  222. */
  223. /*
  224. * TODO Change preg_math to more faster alternative.
  225. */
  226. if (preg_match('/^---/', $line)) {
  227. continue;
  228. }
  229. $this->log($line);
  230. }
  231. /*
  232. * Set rights for generated file... Don't use umask() - see
  233. * notes in official documentation for this function.
  234. */
  235. chmod($this->outputFile, 0644);
  236. }
  237. }