BuildPropelPEARPackageTask.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. /**
  3. * This file is part of the Propel package.
  4. * For the full copyright and license information, please view the LICENSE
  5. * file that was distributed with this source code.
  6. *
  7. * @license MIT License
  8. */
  9. require_once 'phing/tasks/system/MatchingTask.php';
  10. include_once 'phing/types/FileSet.php';
  11. include_once 'phing/tasks/ext/pearpackage/Fileset.php';
  12. /**
  13. *
  14. * @author Hans Lellelid <hans@xmpl.org>
  15. * @package phing.tasks.ext
  16. * @version $Revision: 1681 $
  17. */
  18. class BuildPropelPEARPackageTask extends MatchingTask
  19. {
  20. /** Base directory for reading files. */
  21. private $dir;
  22. private $version;
  23. private $state = 'stable';
  24. private $notes;
  25. private $filesets = array();
  26. /** Package file */
  27. private $packageFile;
  28. public function init()
  29. {
  30. include_once 'PEAR/PackageFileManager2.php';
  31. if (!class_exists('PEAR_PackageFileManager2')) {
  32. throw new BuildException("You must have installed PEAR_PackageFileManager2 (PEAR_PackageFileManager >= 1.6.0) in order to create a PEAR package.xml file.");
  33. }
  34. }
  35. private function setOptions($pkg)
  36. {
  37. $options['baseinstalldir'] = 'propel';
  38. $options['packagedirectory'] = $this->dir->getAbsolutePath();
  39. if (empty($this->filesets)) {
  40. throw new BuildException("You must use a <fileset> tag to specify the files to include in the package.xml");
  41. }
  42. $options['filelistgenerator'] = 'Fileset';
  43. // Some PHING-specific options needed by our Fileset reader
  44. $options['phing_project'] = $this->getProject();
  45. $options['phing_filesets'] = $this->filesets;
  46. if ($this->packageFile !== null) {
  47. // create one w/ full path
  48. $f = new PhingFile($this->packageFile->getAbsolutePath());
  49. $options['packagefile'] = $f->getName();
  50. // must end in trailing slash
  51. $options['outputdirectory'] = $f->getParent() . DIRECTORY_SEPARATOR;
  52. $this->log("Creating package file: " . $f->getPath(), Project::MSG_INFO);
  53. } else {
  54. $this->log("Creating [default] package.xml file in base directory.", Project::MSG_INFO);
  55. }
  56. $pkg->setOptions($options);
  57. }
  58. /**
  59. * Main entry point.
  60. * @return void
  61. */
  62. public function main()
  63. {
  64. if ($this->dir === null) {
  65. throw new BuildException("You must specify the \"dir\" attribute for PEAR package task.");
  66. }
  67. if ($this->version === null) {
  68. throw new BuildException("You must specify the \"version\" attribute for PEAR package task.");
  69. }
  70. $package = new PEAR_PackageFileManager2();
  71. $this->setOptions($package);
  72. // the hard-coded stuff
  73. $package->setPackage('propel_runtime');
  74. $package->setSummary('Runtime component of the Propel PHP object persistence layer');
  75. $package->setDescription('Propel is an object persistence layer for PHP5 based on Apache Torque. This package provides the runtime engine that transparently handles object persistence and retrieval.');
  76. $package->setChannel('pear.propelorm.org');
  77. $package->setPackageType('php');
  78. $package->setReleaseVersion($this->version);
  79. $package->setAPIVersion($this->version);
  80. $package->setReleaseStability($this->state);
  81. $package->setAPIStability($this->state);
  82. $package->setNotes($this->notes);
  83. $package->setLicense('MIT', 'http://www.opensource.org/licenses/mit-license.php');
  84. // Add package maintainers
  85. $package->addMaintainer('lead', 'hans', 'Hans Lellelid', 'hans@xmpl.org');
  86. $package->addMaintainer('lead', 'david', 'David Zuelke', 'dz@bitxtender.com');
  87. $package->addMaintainer('lead', 'francois', 'Francois Zaninotto', 'fzaninotto@[gmail].com');
  88. // "core" dependencies
  89. $package->setPhpDep('5.2.0');
  90. $package->setPearinstallerDep('1.4.0');
  91. // "package" dependencies
  92. $package->addExtensionDep('required', 'pdo');
  93. $package->addExtensionDep('required', 'spl');
  94. // now we run this weird generateContents() method that apparently
  95. // is necessary before we can add replacements ... ?
  96. $package->generateContents();
  97. $e = $package->writePackageFile();
  98. if (PEAR::isError($e)) {
  99. throw new BuildException("Unable to write package file.", new Exception($e->getMessage()));
  100. }
  101. }
  102. /**
  103. * Used by the PEAR_PackageFileManager_PhingFileSet lister.
  104. * @return array FileSet[]
  105. */
  106. public function getFileSets()
  107. {
  108. return $this->filesets;
  109. }
  110. // -------------------------------
  111. // Set properties from XML
  112. // -------------------------------
  113. /**
  114. * Nested creator, creates a FileSet for this task
  115. *
  116. * @return FileSet The created fileset object
  117. */
  118. function createFileSet()
  119. {
  120. $num = array_push($this->filesets, new FileSet());
  121. return $this->filesets[$num-1];
  122. }
  123. /**
  124. * Set the version we are building.
  125. * @param string $v
  126. * @return void
  127. */
  128. public function setVersion($v)
  129. {
  130. $this->version = $v;
  131. }
  132. /**
  133. * Set the state we are building.
  134. * @param string $v
  135. * @return void
  136. */
  137. public function setState($v)
  138. {
  139. $this->state = $v;
  140. }
  141. /**
  142. * Sets release notes field.
  143. * @param string $v
  144. * @return void
  145. */
  146. public function setNotes($v)
  147. {
  148. $this->notes = $v;
  149. }
  150. /**
  151. * Sets "dir" property from XML.
  152. * @param PhingFile $f
  153. * @return void
  154. */
  155. public function setDir(PhingFile $f)
  156. {
  157. $this->dir = $f;
  158. }
  159. /**
  160. * Sets the file to use for generated package.xml
  161. */
  162. public function setDestFile(PhingFile $f)
  163. {
  164. $this->packageFile = $f;
  165. }
  166. }