/mail/mail/PEAR/Packager.php

https://bitbucket.org/squints/greekgeek · PHP · 404 lines · 280 code · 48 blank · 76 comment · 50 complexity · 6bfa0a35dea98d3234e969a66fcb1aa0 MD5 · raw file

  1. <<<<<<< HEAD
  2. <?php
  3. /**
  4. * PEAR_Packager for generating releases
  5. *
  6. * PHP versions 4 and 5
  7. *
  8. * @category pear
  9. * @package PEAR
  10. * @author Stig Bakken <ssb@php.net>
  11. * @author Tomas V. V. Cox <cox@idecnet.com>
  12. * @author Greg Beaver <cellog@php.net>
  13. * @copyright 1997-2009 The Authors
  14. * @license http://opensource.org/licenses/bsd-license.php New BSD License
  15. * @version CVS: $Id: Packager.php 286809 2009-08-04 15:10:26Z dufuz $
  16. * @link http://pear.php.net/package/PEAR
  17. * @since File available since Release 0.1
  18. */
  19. /**
  20. * base class
  21. */
  22. require_once 'PEAR/Common.php';
  23. require_once 'PEAR/PackageFile.php';
  24. require_once 'System.php';
  25. /**
  26. * Administration class used to make a PEAR release tarball.
  27. *
  28. * @category pear
  29. * @package PEAR
  30. * @author Greg Beaver <cellog@php.net>
  31. * @copyright 1997-2009 The Authors
  32. * @license http://opensource.org/licenses/bsd-license.php New BSD License
  33. * @version Release: 1.9.1
  34. * @link http://pear.php.net/package/PEAR
  35. * @since Class available since Release 0.1
  36. */
  37. class PEAR_Packager extends PEAR_Common
  38. {
  39. /**
  40. * @var PEAR_Registry
  41. */
  42. var $_registry;
  43. function package($pkgfile = null, $compress = true, $pkg2 = null)
  44. {
  45. // {{{ validate supplied package.xml file
  46. if (empty($pkgfile)) {
  47. $pkgfile = 'package.xml';
  48. }
  49. PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
  50. $pkg = &new PEAR_PackageFile($this->config, $this->debug);
  51. $pf = &$pkg->fromPackageFile($pkgfile, PEAR_VALIDATE_NORMAL);
  52. $main = &$pf;
  53. PEAR::staticPopErrorHandling();
  54. if (PEAR::isError($pf)) {
  55. if (is_array($pf->getUserInfo())) {
  56. foreach ($pf->getUserInfo() as $error) {
  57. $this->log(0, 'Error: ' . $error['message']);
  58. }
  59. }
  60. $this->log(0, $pf->getMessage());
  61. return $this->raiseError("Cannot package, errors in package file");
  62. }
  63. foreach ($pf->getValidationWarnings() as $warning) {
  64. $this->log(1, 'Warning: ' . $warning['message']);
  65. }
  66. // }}}
  67. if ($pkg2) {
  68. $this->log(0, 'Attempting to process the second package file');
  69. PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
  70. $pf2 = &$pkg->fromPackageFile($pkg2, PEAR_VALIDATE_NORMAL);
  71. PEAR::staticPopErrorHandling();
  72. if (PEAR::isError($pf2)) {
  73. if (is_array($pf2->getUserInfo())) {
  74. foreach ($pf2->getUserInfo() as $error) {
  75. $this->log(0, 'Error: ' . $error['message']);
  76. }
  77. }
  78. $this->log(0, $pf2->getMessage());
  79. return $this->raiseError("Cannot package, errors in second package file");
  80. }
  81. foreach ($pf2->getValidationWarnings() as $warning) {
  82. $this->log(1, 'Warning: ' . $warning['message']);
  83. }
  84. if ($pf2->getPackagexmlVersion() == '2.0' ||
  85. $pf2->getPackagexmlVersion() == '2.1'
  86. ) {
  87. $main = &$pf2;
  88. $other = &$pf;
  89. } else {
  90. $main = &$pf;
  91. $other = &$pf2;
  92. }
  93. if ($main->getPackagexmlVersion() != '2.0' &&
  94. $main->getPackagexmlVersion() != '2.1') {
  95. return PEAR::raiseError('Error: cannot package two package.xml version 1.0, can ' .
  96. 'only package together a package.xml 1.0 and package.xml 2.0');
  97. }
  98. if ($other->getPackagexmlVersion() != '1.0') {
  99. return PEAR::raiseError('Error: cannot package two package.xml version 2.0, can ' .
  100. 'only package together a package.xml 1.0 and package.xml 2.0');
  101. }
  102. }
  103. $main->setLogger($this);
  104. if (!$main->validate(PEAR_VALIDATE_PACKAGING)) {
  105. foreach ($main->getValidationWarnings() as $warning) {
  106. $this->log(0, 'Error: ' . $warning['message']);
  107. }
  108. return $this->raiseError("Cannot package, errors in package");
  109. }
  110. foreach ($main->getValidationWarnings() as $warning) {
  111. $this->log(1, 'Warning: ' . $warning['message']);
  112. }
  113. if ($pkg2) {
  114. $other->setLogger($this);
  115. $a = false;
  116. if (!$other->validate(PEAR_VALIDATE_NORMAL) || $a = !$main->isEquivalent($other)) {
  117. foreach ($other->getValidationWarnings() as $warning) {
  118. $this->log(0, 'Error: ' . $warning['message']);
  119. }
  120. foreach ($main->getValidationWarnings() as $warning) {
  121. $this->log(0, 'Error: ' . $warning['message']);
  122. }
  123. if ($a) {
  124. return $this->raiseError('The two package.xml files are not equivalent!');
  125. }
  126. return $this->raiseError("Cannot package, errors in package");
  127. }
  128. foreach ($other->getValidationWarnings() as $warning) {
  129. $this->log(1, 'Warning: ' . $warning['message']);
  130. }
  131. $gen = &$main->getDefaultGenerator();
  132. $tgzfile = $gen->toTgz2($this, $other, $compress);
  133. if (PEAR::isError($tgzfile)) {
  134. return $tgzfile;
  135. }
  136. $dest_package = basename($tgzfile);
  137. $pkgdir = dirname($pkgfile);
  138. // TAR the Package -------------------------------------------
  139. $this->log(1, "Package $dest_package done");
  140. if (file_exists("$pkgdir/CVS/Root")) {
  141. $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pf->getVersion());
  142. $cvstag = "RELEASE_$cvsversion";
  143. $this->log(1, 'Tag the released code with "pear cvstag ' .
  144. $main->getPackageFile() . '"');
  145. $this->log(1, "(or set the CVS tag $cvstag by hand)");
  146. } elseif (file_exists("$pkgdir/.svn")) {
  147. $svnversion = preg_replace('/[^a-z0-9]/i', '.', $pf->getVersion());
  148. $svntag = $pf->getName() . "-$svnversion";
  149. $this->log(1, 'Tag the released code with "pear svntag ' .
  150. $main->getPackageFile() . '"');
  151. $this->log(1, "(or set the SVN tag $svntag by hand)");
  152. }
  153. } else { // this branch is executed for single packagefile packaging
  154. $gen = &$pf->getDefaultGenerator();
  155. $tgzfile = $gen->toTgz($this, $compress);
  156. if (PEAR::isError($tgzfile)) {
  157. $this->log(0, $tgzfile->getMessage());
  158. return $this->raiseError("Cannot package, errors in package");
  159. }
  160. $dest_package = basename($tgzfile);
  161. $pkgdir = dirname($pkgfile);
  162. // TAR the Package -------------------------------------------
  163. $this->log(1, "Package $dest_package done");
  164. if (file_exists("$pkgdir/CVS/Root")) {
  165. $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pf->getVersion());
  166. $cvstag = "RELEASE_$cvsversion";
  167. $this->log(1, "Tag the released code with `pear cvstag $pkgfile'");
  168. $this->log(1, "(or set the CVS tag $cvstag by hand)");
  169. } elseif (file_exists("$pkgdir/.svn")) {
  170. $svnversion = preg_replace('/[^a-z0-9]/i', '.', $pf->getVersion());
  171. $svntag = $pf->getName() . "-$svnversion";
  172. $this->log(1, "Tag the released code with `pear svntag $pkgfile'");
  173. $this->log(1, "(or set the SVN tag $svntag by hand)");
  174. }
  175. }
  176. return $dest_package;
  177. }
  178. =======
  179. <?php
  180. /**
  181. * PEAR_Packager for generating releases
  182. *
  183. * PHP versions 4 and 5
  184. *
  185. * @category pear
  186. * @package PEAR
  187. * @author Stig Bakken <ssb@php.net>
  188. * @author Tomas V. V. Cox <cox@idecnet.com>
  189. * @author Greg Beaver <cellog@php.net>
  190. * @copyright 1997-2009 The Authors
  191. * @license http://opensource.org/licenses/bsd-license.php New BSD License
  192. * @version CVS: $Id: Packager.php 286809 2009-08-04 15:10:26Z dufuz $
  193. * @link http://pear.php.net/package/PEAR
  194. * @since File available since Release 0.1
  195. */
  196. /**
  197. * base class
  198. */
  199. require_once 'PEAR/Common.php';
  200. require_once 'PEAR/PackageFile.php';
  201. require_once 'System.php';
  202. /**
  203. * Administration class used to make a PEAR release tarball.
  204. *
  205. * @category pear
  206. * @package PEAR
  207. * @author Greg Beaver <cellog@php.net>
  208. * @copyright 1997-2009 The Authors
  209. * @license http://opensource.org/licenses/bsd-license.php New BSD License
  210. * @version Release: 1.9.1
  211. * @link http://pear.php.net/package/PEAR
  212. * @since Class available since Release 0.1
  213. */
  214. class PEAR_Packager extends PEAR_Common
  215. {
  216. /**
  217. * @var PEAR_Registry
  218. */
  219. var $_registry;
  220. function package($pkgfile = null, $compress = true, $pkg2 = null)
  221. {
  222. // {{{ validate supplied package.xml file
  223. if (empty($pkgfile)) {
  224. $pkgfile = 'package.xml';
  225. }
  226. PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
  227. $pkg = &new PEAR_PackageFile($this->config, $this->debug);
  228. $pf = &$pkg->fromPackageFile($pkgfile, PEAR_VALIDATE_NORMAL);
  229. $main = &$pf;
  230. PEAR::staticPopErrorHandling();
  231. if (PEAR::isError($pf)) {
  232. if (is_array($pf->getUserInfo())) {
  233. foreach ($pf->getUserInfo() as $error) {
  234. $this->log(0, 'Error: ' . $error['message']);
  235. }
  236. }
  237. $this->log(0, $pf->getMessage());
  238. return $this->raiseError("Cannot package, errors in package file");
  239. }
  240. foreach ($pf->getValidationWarnings() as $warning) {
  241. $this->log(1, 'Warning: ' . $warning['message']);
  242. }
  243. // }}}
  244. if ($pkg2) {
  245. $this->log(0, 'Attempting to process the second package file');
  246. PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
  247. $pf2 = &$pkg->fromPackageFile($pkg2, PEAR_VALIDATE_NORMAL);
  248. PEAR::staticPopErrorHandling();
  249. if (PEAR::isError($pf2)) {
  250. if (is_array($pf2->getUserInfo())) {
  251. foreach ($pf2->getUserInfo() as $error) {
  252. $this->log(0, 'Error: ' . $error['message']);
  253. }
  254. }
  255. $this->log(0, $pf2->getMessage());
  256. return $this->raiseError("Cannot package, errors in second package file");
  257. }
  258. foreach ($pf2->getValidationWarnings() as $warning) {
  259. $this->log(1, 'Warning: ' . $warning['message']);
  260. }
  261. if ($pf2->getPackagexmlVersion() == '2.0' ||
  262. $pf2->getPackagexmlVersion() == '2.1'
  263. ) {
  264. $main = &$pf2;
  265. $other = &$pf;
  266. } else {
  267. $main = &$pf;
  268. $other = &$pf2;
  269. }
  270. if ($main->getPackagexmlVersion() != '2.0' &&
  271. $main->getPackagexmlVersion() != '2.1') {
  272. return PEAR::raiseError('Error: cannot package two package.xml version 1.0, can ' .
  273. 'only package together a package.xml 1.0 and package.xml 2.0');
  274. }
  275. if ($other->getPackagexmlVersion() != '1.0') {
  276. return PEAR::raiseError('Error: cannot package two package.xml version 2.0, can ' .
  277. 'only package together a package.xml 1.0 and package.xml 2.0');
  278. }
  279. }
  280. $main->setLogger($this);
  281. if (!$main->validate(PEAR_VALIDATE_PACKAGING)) {
  282. foreach ($main->getValidationWarnings() as $warning) {
  283. $this->log(0, 'Error: ' . $warning['message']);
  284. }
  285. return $this->raiseError("Cannot package, errors in package");
  286. }
  287. foreach ($main->getValidationWarnings() as $warning) {
  288. $this->log(1, 'Warning: ' . $warning['message']);
  289. }
  290. if ($pkg2) {
  291. $other->setLogger($this);
  292. $a = false;
  293. if (!$other->validate(PEAR_VALIDATE_NORMAL) || $a = !$main->isEquivalent($other)) {
  294. foreach ($other->getValidationWarnings() as $warning) {
  295. $this->log(0, 'Error: ' . $warning['message']);
  296. }
  297. foreach ($main->getValidationWarnings() as $warning) {
  298. $this->log(0, 'Error: ' . $warning['message']);
  299. }
  300. if ($a) {
  301. return $this->raiseError('The two package.xml files are not equivalent!');
  302. }
  303. return $this->raiseError("Cannot package, errors in package");
  304. }
  305. foreach ($other->getValidationWarnings() as $warning) {
  306. $this->log(1, 'Warning: ' . $warning['message']);
  307. }
  308. $gen = &$main->getDefaultGenerator();
  309. $tgzfile = $gen->toTgz2($this, $other, $compress);
  310. if (PEAR::isError($tgzfile)) {
  311. return $tgzfile;
  312. }
  313. $dest_package = basename($tgzfile);
  314. $pkgdir = dirname($pkgfile);
  315. // TAR the Package -------------------------------------------
  316. $this->log(1, "Package $dest_package done");
  317. if (file_exists("$pkgdir/CVS/Root")) {
  318. $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pf->getVersion());
  319. $cvstag = "RELEASE_$cvsversion";
  320. $this->log(1, 'Tag the released code with "pear cvstag ' .
  321. $main->getPackageFile() . '"');
  322. $this->log(1, "(or set the CVS tag $cvstag by hand)");
  323. } elseif (file_exists("$pkgdir/.svn")) {
  324. $svnversion = preg_replace('/[^a-z0-9]/i', '.', $pf->getVersion());
  325. $svntag = $pf->getName() . "-$svnversion";
  326. $this->log(1, 'Tag the released code with "pear svntag ' .
  327. $main->getPackageFile() . '"');
  328. $this->log(1, "(or set the SVN tag $svntag by hand)");
  329. }
  330. } else { // this branch is executed for single packagefile packaging
  331. $gen = &$pf->getDefaultGenerator();
  332. $tgzfile = $gen->toTgz($this, $compress);
  333. if (PEAR::isError($tgzfile)) {
  334. $this->log(0, $tgzfile->getMessage());
  335. return $this->raiseError("Cannot package, errors in package");
  336. }
  337. $dest_package = basename($tgzfile);
  338. $pkgdir = dirname($pkgfile);
  339. // TAR the Package -------------------------------------------
  340. $this->log(1, "Package $dest_package done");
  341. if (file_exists("$pkgdir/CVS/Root")) {
  342. $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pf->getVersion());
  343. $cvstag = "RELEASE_$cvsversion";
  344. $this->log(1, "Tag the released code with `pear cvstag $pkgfile'");
  345. $this->log(1, "(or set the CVS tag $cvstag by hand)");
  346. } elseif (file_exists("$pkgdir/.svn")) {
  347. $svnversion = preg_replace('/[^a-z0-9]/i', '.', $pf->getVersion());
  348. $svntag = $pf->getName() . "-$svnversion";
  349. $this->log(1, "Tag the released code with `pear svntag $pkgfile'");
  350. $this->log(1, "(or set the SVN tag $svntag by hand)");
  351. }
  352. }
  353. return $dest_package;
  354. }
  355. >>>>>>> b59280b13ce027f89f28f2d12e991e62fe2dd1bd
  356. }