PageRenderTime 62ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/php/PEAR/Packager.php

https://bitbucket.org/adarshj/convenient_website
PHP | 201 lines | 139 code | 24 blank | 38 comment | 25 complexity | 5e553c0ac9530fc8757735675f0837ee MD5 | raw file
Possible License(s): Apache-2.0, MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-2-Clause, GPL-2.0, LGPL-3.0
  1. <?php
  2. /**
  3. * PEAR_Packager for generating releases
  4. *
  5. * PHP versions 4 and 5
  6. *
  7. * @category pear
  8. * @package PEAR
  9. * @author Stig Bakken <ssb@php.net>
  10. * @author Tomas V. V. Cox <cox@idecnet.com>
  11. * @author Greg Beaver <cellog@php.net>
  12. * @copyright 1997-2009 The Authors
  13. * @license http://opensource.org/licenses/bsd-license.php New BSD License
  14. * @version CVS: $Id: Packager.php 313023 2011-07-06 19:17:11Z dufuz $
  15. * @link http://pear.php.net/package/PEAR
  16. * @since File available since Release 0.1
  17. */
  18. /**
  19. * base class
  20. */
  21. require_once 'PEAR/Common.php';
  22. require_once 'PEAR/PackageFile.php';
  23. require_once 'System.php';
  24. /**
  25. * Administration class used to make a PEAR release tarball.
  26. *
  27. * @category pear
  28. * @package PEAR
  29. * @author Greg Beaver <cellog@php.net>
  30. * @copyright 1997-2009 The Authors
  31. * @license http://opensource.org/licenses/bsd-license.php New BSD License
  32. * @version Release: 1.9.4
  33. * @link http://pear.php.net/package/PEAR
  34. * @since Class available since Release 0.1
  35. */
  36. class PEAR_Packager extends PEAR_Common
  37. {
  38. /**
  39. * @var PEAR_Registry
  40. */
  41. var $_registry;
  42. function package($pkgfile = null, $compress = true, $pkg2 = null)
  43. {
  44. // {{{ validate supplied package.xml file
  45. if (empty($pkgfile)) {
  46. $pkgfile = 'package.xml';
  47. }
  48. PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
  49. $pkg = &new PEAR_PackageFile($this->config, $this->debug);
  50. $pf = &$pkg->fromPackageFile($pkgfile, PEAR_VALIDATE_NORMAL);
  51. $main = &$pf;
  52. PEAR::staticPopErrorHandling();
  53. if (PEAR::isError($pf)) {
  54. if (is_array($pf->getUserInfo())) {
  55. foreach ($pf->getUserInfo() as $error) {
  56. $this->log(0, 'Error: ' . $error['message']);
  57. }
  58. }
  59. $this->log(0, $pf->getMessage());
  60. return $this->raiseError("Cannot package, errors in package file");
  61. }
  62. foreach ($pf->getValidationWarnings() as $warning) {
  63. $this->log(1, 'Warning: ' . $warning['message']);
  64. }
  65. // }}}
  66. if ($pkg2) {
  67. $this->log(0, 'Attempting to process the second package file');
  68. PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
  69. $pf2 = &$pkg->fromPackageFile($pkg2, PEAR_VALIDATE_NORMAL);
  70. PEAR::staticPopErrorHandling();
  71. if (PEAR::isError($pf2)) {
  72. if (is_array($pf2->getUserInfo())) {
  73. foreach ($pf2->getUserInfo() as $error) {
  74. $this->log(0, 'Error: ' . $error['message']);
  75. }
  76. }
  77. $this->log(0, $pf2->getMessage());
  78. return $this->raiseError("Cannot package, errors in second package file");
  79. }
  80. foreach ($pf2->getValidationWarnings() as $warning) {
  81. $this->log(1, 'Warning: ' . $warning['message']);
  82. }
  83. if ($pf2->getPackagexmlVersion() == '2.0' ||
  84. $pf2->getPackagexmlVersion() == '2.1'
  85. ) {
  86. $main = &$pf2;
  87. $other = &$pf;
  88. } else {
  89. $main = &$pf;
  90. $other = &$pf2;
  91. }
  92. if ($main->getPackagexmlVersion() != '2.0' &&
  93. $main->getPackagexmlVersion() != '2.1') {
  94. return PEAR::raiseError('Error: cannot package two package.xml version 1.0, can ' .
  95. 'only package together a package.xml 1.0 and package.xml 2.0');
  96. }
  97. if ($other->getPackagexmlVersion() != '1.0') {
  98. return PEAR::raiseError('Error: cannot package two package.xml version 2.0, can ' .
  99. 'only package together a package.xml 1.0 and package.xml 2.0');
  100. }
  101. }
  102. $main->setLogger($this);
  103. if (!$main->validate(PEAR_VALIDATE_PACKAGING)) {
  104. foreach ($main->getValidationWarnings() as $warning) {
  105. $this->log(0, 'Error: ' . $warning['message']);
  106. }
  107. return $this->raiseError("Cannot package, errors in package");
  108. }
  109. foreach ($main->getValidationWarnings() as $warning) {
  110. $this->log(1, 'Warning: ' . $warning['message']);
  111. }
  112. if ($pkg2) {
  113. $other->setLogger($this);
  114. $a = false;
  115. if (!$other->validate(PEAR_VALIDATE_NORMAL) || $a = !$main->isEquivalent($other)) {
  116. foreach ($other->getValidationWarnings() as $warning) {
  117. $this->log(0, 'Error: ' . $warning['message']);
  118. }
  119. foreach ($main->getValidationWarnings() as $warning) {
  120. $this->log(0, 'Error: ' . $warning['message']);
  121. }
  122. if ($a) {
  123. return $this->raiseError('The two package.xml files are not equivalent!');
  124. }
  125. return $this->raiseError("Cannot package, errors in package");
  126. }
  127. foreach ($other->getValidationWarnings() as $warning) {
  128. $this->log(1, 'Warning: ' . $warning['message']);
  129. }
  130. $gen = &$main->getDefaultGenerator();
  131. $tgzfile = $gen->toTgz2($this, $other, $compress);
  132. if (PEAR::isError($tgzfile)) {
  133. return $tgzfile;
  134. }
  135. $dest_package = basename($tgzfile);
  136. $pkgdir = dirname($pkgfile);
  137. // TAR the Package -------------------------------------------
  138. $this->log(1, "Package $dest_package done");
  139. if (file_exists("$pkgdir/CVS/Root")) {
  140. $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pf->getVersion());
  141. $cvstag = "RELEASE_$cvsversion";
  142. $this->log(1, 'Tag the released code with "pear cvstag ' .
  143. $main->getPackageFile() . '"');
  144. $this->log(1, "(or set the CVS tag $cvstag by hand)");
  145. } elseif (file_exists("$pkgdir/.svn")) {
  146. $svnversion = preg_replace('/[^a-z0-9]/i', '.', $pf->getVersion());
  147. $svntag = $pf->getName() . "-$svnversion";
  148. $this->log(1, 'Tag the released code with "pear svntag ' .
  149. $main->getPackageFile() . '"');
  150. $this->log(1, "(or set the SVN tag $svntag by hand)");
  151. }
  152. } else { // this branch is executed for single packagefile packaging
  153. $gen = &$pf->getDefaultGenerator();
  154. $tgzfile = $gen->toTgz($this, $compress);
  155. if (PEAR::isError($tgzfile)) {
  156. $this->log(0, $tgzfile->getMessage());
  157. return $this->raiseError("Cannot package, errors in package");
  158. }
  159. $dest_package = basename($tgzfile);
  160. $pkgdir = dirname($pkgfile);
  161. // TAR the Package -------------------------------------------
  162. $this->log(1, "Package $dest_package done");
  163. if (file_exists("$pkgdir/CVS/Root")) {
  164. $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pf->getVersion());
  165. $cvstag = "RELEASE_$cvsversion";
  166. $this->log(1, "Tag the released code with `pear cvstag $pkgfile'");
  167. $this->log(1, "(or set the CVS tag $cvstag by hand)");
  168. } elseif (file_exists("$pkgdir/.svn")) {
  169. $svnversion = preg_replace('/[^a-z0-9]/i', '.', $pf->getVersion());
  170. $svntag = $pf->getName() . "-$svnversion";
  171. $this->log(1, "Tag the released code with `pear svntag $pkgfile'");
  172. $this->log(1, "(or set the SVN tag $svntag by hand)");
  173. }
  174. }
  175. return $dest_package;
  176. }
  177. }