PageRenderTime 66ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/propel/propel1/generator/pear/BuildPropelGenPEARPackageTask.php

https://gitlab.com/Isaki/le331.fr
PHP | 269 lines | 127 code | 45 blank | 97 comment | 9 complexity | bbd469c2fa2d9a03e5f49c4540cab585 MD5 | raw file
  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. /*
  10. * $Id$
  11. *
  12. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  13. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  14. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  15. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  16. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  17. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  18. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  19. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  20. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  22. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. *
  24. * This software consists of voluntary contributions made by many individuals
  25. * and is licensed under the LGPL. For more information please see
  26. * <http://phing.info>.
  27. */
  28. require_once 'phing/tasks/system/MatchingTask.php';
  29. include_once 'phing/types/FileSet.php';
  30. include_once 'phing/tasks/ext/pearpackage/Fileset.php';
  31. /**
  32. *
  33. * @author Hans Lellelid <hans@xmpl.org>
  34. * @package phing.tasks.ext
  35. * @version $Revision$
  36. */
  37. class BuildPropelGenPEARPackageTask extends MatchingTask
  38. {
  39. /** Base directory for reading files. */
  40. private $dir;
  41. private $version;
  42. private $state = 'stable';
  43. private $notes;
  44. private $filesets = array();
  45. /** Package file */
  46. private $packageFile;
  47. public function init()
  48. {
  49. include_once 'PEAR/PackageFileManager2.php';
  50. if (!class_exists('PEAR_PackageFileManager2')) {
  51. throw new BuildException("You must have installed PEAR_PackageFileManager2 (PEAR_PackageFileManager >= 1.6.0) in order to create a PEAR package.xml file.");
  52. }
  53. }
  54. private function setOptions($pkg)
  55. {
  56. $options['baseinstalldir'] = 'propel';
  57. $options['packagedirectory'] = $this->dir->getAbsolutePath();
  58. if (empty($this->filesets)) {
  59. throw new BuildException("You must use a <fileset> tag to specify the files to include in the package.xml");
  60. }
  61. $options['filelistgenerator'] = 'Fileset';
  62. // Some PHING-specific options needed by our Fileset reader
  63. $options['phing_project'] = $this->getProject();
  64. $options['phing_filesets'] = $this->filesets;
  65. if ($this->packageFile !== null) {
  66. // create one w/ full path
  67. $f = new PhingFile($this->packageFile->getAbsolutePath());
  68. $options['packagefile'] = $f->getName();
  69. // must end in trailing slash
  70. $options['outputdirectory'] = $f->getParent() . DIRECTORY_SEPARATOR;
  71. $this->log("Creating package file: " . $f->getPath(), Project::MSG_INFO);
  72. } else {
  73. $this->log("Creating [default] package.xml file in base directory.", Project::MSG_INFO);
  74. }
  75. // add baseinstalldir exceptions
  76. $options['installexceptions'] = array(
  77. 'pear-propel-gen' => '/',
  78. 'pear-propel-gen.bat' => '/',
  79. );
  80. $options['dir_roles'] = array(
  81. 'lib' => 'data',
  82. 'resources' => 'data'
  83. );
  84. $options['exceptions'] = array(
  85. 'pear-propel-gen.bat' => 'script',
  86. 'pear-propel-gen' => 'script',
  87. );
  88. $pkg->setOptions($options);
  89. }
  90. /**
  91. * Main entry point.
  92. *
  93. * @return void
  94. * @throws BuildException
  95. */
  96. public function main()
  97. {
  98. if ($this->dir === null) {
  99. throw new BuildException("You must specify the \"dir\" attribute for PEAR package task.");
  100. }
  101. if ($this->version === null) {
  102. throw new BuildException("You must specify the \"version\" attribute for PEAR package task.");
  103. }
  104. $package = new PEAR_PackageFileManager2();
  105. $this->setOptions($package);
  106. // the hard-coded stuff
  107. $package->setPackage('propel_generator');
  108. $package->setSummary('Generator component of the Propel PHP object persistence layer');
  109. $package->setDescription('Propel is an object persistence layer for PHP5 based on Apache Torque. This package provides the generator engine that builds PHP classes and SQL DDL based on an XML representation of your data model.');
  110. $package->setChannel('pear.propelorm.org');
  111. $package->setPackageType('php');
  112. $package->setReleaseVersion($this->version);
  113. $package->setAPIVersion($this->version);
  114. $package->setReleaseStability($this->state);
  115. $package->setAPIStability($this->state);
  116. $package->setNotes($this->notes);
  117. $package->setLicense('MIT', 'http://www.opensource.org/licenses/mit-license.php');
  118. // Add package maintainers
  119. $package->addMaintainer('lead', 'hans', 'Hans Lellelid', 'hans@xmpl.org');
  120. $package->addMaintainer('lead', 'david', 'David Zuelke', 'dz@bitxtender.com');
  121. $package->addMaintainer('lead', 'francois', 'Francois Zaninotto', 'fzaninotto@[gmail].com');
  122. $package->addMaintainer('lead', 'couac', 'William Durand', 'william.durand1@[gmail].com');
  123. // creating a sub-section for 'windows'
  124. $package->addRelease();
  125. $package->setOSInstallCondition('windows');
  126. $package->addInstallAs('pear-propel-gen.bat', 'propel-gen.bat');
  127. $package->addIgnoreToRelease('pear-propel-gen');
  128. // creating a sub-section for non-windows
  129. $package->addRelease();
  130. $package->addInstallAs('pear-propel-gen', 'propel-gen');
  131. $package->addIgnoreToRelease('pear-propel-gen.bat');
  132. // "core" dependencies
  133. $package->setPhpDep('5.2.4');
  134. $package->setPearinstallerDep('1.4.0');
  135. // "package" dependencies
  136. $package->addPackageDepWithChannel('required', 'phing', 'pear.phing.info', '2.3.0');
  137. $package->addExtensionDep('required', 'pdo');
  138. $package->addExtensionDep('required', 'xml');
  139. $package->addExtensionDep('required', 'xsl');
  140. // now add the replacements ....
  141. $package->addReplacement('pear-propel-gen.bat', 'pear-config', '@DATA-DIR@', 'data_dir');
  142. $package->addReplacement('pear-propel-gen', 'pear-config', '@DATA-DIR@', 'data_dir');
  143. // now we run this weird generateContents() method that apparently
  144. // is necessary before we can add replacements ... ?
  145. $package->generateContents();
  146. $e = $package->writePackageFile();
  147. if (PEAR::isError($e)) {
  148. throw new BuildException("Unable to write package file.", new Exception($e->getMessage()));
  149. }
  150. }
  151. /**
  152. * Used by the PEAR_PackageFileManager_PhingFileSet lister.
  153. *
  154. * @return array FileSet[]
  155. */
  156. public function getFileSets()
  157. {
  158. return $this->filesets;
  159. }
  160. // -------------------------------
  161. // Set properties from XML
  162. // -------------------------------
  163. /**
  164. * Nested creator, creates a FileSet for this task
  165. *
  166. * @return FileSet The created fileset object
  167. */
  168. public function createFileSet()
  169. {
  170. $num = array_push($this->filesets, new FileSet());
  171. return $this->filesets[$num - 1];
  172. }
  173. /**
  174. * Set the version we are building.
  175. *
  176. * @param string $v
  177. *
  178. * @return void
  179. */
  180. public function setVersion($v)
  181. {
  182. $this->version = $v;
  183. }
  184. /**
  185. * Set the state we are building.
  186. *
  187. * @param string $v
  188. *
  189. * @return void
  190. */
  191. public function setState($v)
  192. {
  193. $this->state = $v;
  194. }
  195. /**
  196. * Sets release notes field.
  197. *
  198. * @param string $v
  199. *
  200. * @return void
  201. */
  202. public function setNotes($v)
  203. {
  204. $this->notes = $v;
  205. }
  206. /**
  207. * Sets "dir" property from XML.
  208. *
  209. * @param PhingFile $f
  210. *
  211. * @return void
  212. */
  213. public function setDir(PhingFile $f)
  214. {
  215. $this->dir = $f;
  216. }
  217. /**
  218. * Sets the file to use for generated package.xml
  219. */
  220. public function setDestFile(PhingFile $f)
  221. {
  222. $this->packageFile = $f;
  223. }
  224. }