/wp-content/plugins/anthologize/vendor/pear/pear/PEAR/Packager.php

https://github.com/livinglab/openlab · PHP · 200 lines · 139 code · 24 blank · 37 comment · 25 complexity · e45164510b50e6449d750ebe159eaa59 MD5 · raw file

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