PageRenderTime 55ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/blog/www/system/library/PEAR/PEAR/Packager.php

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