3 * PEAR_Packager for generating releases
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
22 require_once 'PEAR/Common.php';
23 require_once 'PEAR/PackageFile.php';
24 require_once 'System.php';
27 * Administration class used to make a PEAR release tarball.
31 * @author Greg Beaver <cellog@php.net>
32 * @copyright 1997-2009 The Authors
33 * @license http://opensource.org/licenses/bsd-license.php New BSD License
34 * @version Release: 1.9.4
35 * @link http://pear.php.net/package/PEAR
36 * @since Class available since Release 0.1
38 class PEAR_Packager extends PEAR_Common
45 function package($pkgfile = null, $compress = true, $pkg2 = null)
47 // {{{ validate supplied package.xml file
48 if (empty($pkgfile)) {
49 $pkgfile = 'package.xml';
52 PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
53 $pkg = &new PEAR_PackageFile($this->config, $this->debug);
54 $pf = &$pkg->fromPackageFile($pkgfile, PEAR_VALIDATE_NORMAL);
56 PEAR::staticPopErrorHandling();
57 if (PEAR::isError($pf)) {
58 if (is_array($pf->getUserInfo())) {
59 foreach ($pf->getUserInfo() as $error) {
60 $this->log(0, 'Error: ' . $error['message']);
64 $this->log(0, $pf->getMessage());
65 return $this->raiseError("Cannot package, errors in package file");
68 foreach ($pf->getValidationWarnings() as $warning) {
69 $this->log(1, 'Warning: ' . $warning['message']);
74 $this->log(0, 'Attempting to process the second package file');
75 PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
76 $pf2 = &$pkg->fromPackageFile($pkg2, PEAR_VALIDATE_NORMAL);
77 PEAR::staticPopErrorHandling();
78 if (PEAR::isError($pf2)) {
79 if (is_array($pf2->getUserInfo())) {
80 foreach ($pf2->getUserInfo() as $error) {
81 $this->log(0, 'Error: ' . $error['message']);
84 $this->log(0, $pf2->getMessage());
85 return $this->raiseError("Cannot package, errors in second package file");
88 foreach ($pf2->getValidationWarnings() as $warning) {
89 $this->log(1, 'Warning: ' . $warning['message']);
92 if ($pf2->getPackagexmlVersion() == '2.0' ||
93 $pf2->getPackagexmlVersion() == '2.1'
102 if ($main->getPackagexmlVersion() != '2.0' &&
103 $main->getPackagexmlVersion() != '2.1') {
104 return PEAR::raiseError('Error: cannot package two package.xml version 1.0, can ' .
105 'only package together a package.xml 1.0 and package.xml 2.0');
108 if ($other->getPackagexmlVersion() != '1.0') {
109 return PEAR::raiseError('Error: cannot package two package.xml version 2.0, can ' .
110 'only package together a package.xml 1.0 and package.xml 2.0');
114 $main->setLogger($this);
115 if (!$main->validate(PEAR_VALIDATE_PACKAGING)) {
116 foreach ($main->getValidationWarnings() as $warning) {
117 $this->log(0, 'Error: ' . $warning['message']);
119 return $this->raiseError("Cannot package, errors in package");
122 foreach ($main->getValidationWarnings() as $warning) {
123 $this->log(1, 'Warning: ' . $warning['message']);
127 $other->setLogger($this);
129 if (!$other->validate(PEAR_VALIDATE_NORMAL) || $a = !$main->isEquivalent($other)) {
130 foreach ($other->getValidationWarnings() as $warning) {
131 $this->log(0, 'Error: ' . $warning['message']);
134 foreach ($main->getValidationWarnings() as $warning) {
135 $this->log(0, 'Error: ' . $warning['message']);
139 return $this->raiseError('The two package.xml files are not equivalent!');
142 return $this->raiseError("Cannot package, errors in package");
145 foreach ($other->getValidationWarnings() as $warning) {
146 $this->log(1, 'Warning: ' . $warning['message']);
149 $gen = &$main->getDefaultGenerator();
150 $tgzfile = $gen->toTgz2($this, $other, $compress);
151 if (PEAR::isError($tgzfile)) {
155 $dest_package = basename($tgzfile);
156 $pkgdir = dirname($pkgfile);
158 // TAR the Package -------------------------------------------
159 $this->log(1, "Package $dest_package done");
160 if (file_exists("$pkgdir/CVS/Root")) {
161 $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pf->getVersion());
162 $cvstag = "RELEASE_$cvsversion";
163 $this->log(1, 'Tag the released code with "pear cvstag ' .
164 $main->getPackageFile() . '"');
165 $this->log(1, "(or set the CVS tag $cvstag by hand)");
166 } elseif (file_exists("$pkgdir/.svn")) {
167 $svnversion = preg_replace('/[^a-z0-9]/i', '.', $pf->getVersion());
168 $svntag = $pf->getName() . "-$svnversion";
169 $this->log(1, 'Tag the released code with "pear svntag ' .
170 $main->getPackageFile() . '"');
171 $this->log(1, "(or set the SVN tag $svntag by hand)");
173 } else { // this branch is executed for single packagefile packaging
174 $gen = &$pf->getDefaultGenerator();
175 $tgzfile = $gen->toTgz($this, $compress);
176 if (PEAR::isError($tgzfile)) {
177 $this->log(0, $tgzfile->getMessage());
178 return $this->raiseError("Cannot package, errors in package");
181 $dest_package = basename($tgzfile);
182 $pkgdir = dirname($pkgfile);
184 // TAR the Package -------------------------------------------
185 $this->log(1, "Package $dest_package done");
186 if (file_exists("$pkgdir/CVS/Root")) {
187 $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pf->getVersion());
188 $cvstag = "RELEASE_$cvsversion";
189 $this->log(1, "Tag the released code with `pear cvstag $pkgfile'");
190 $this->log(1, "(or set the CVS tag $cvstag by hand)");
191 } elseif (file_exists("$pkgdir/.svn")) {
192 $svnversion = preg_replace('/[^a-z0-9]/i', '.', $pf->getVersion());
193 $svntag = $pf->getName() . "-$svnversion";
194 $this->log(1, "Tag the released code with `pear svntag $pkgfile'");
195 $this->log(1, "(or set the SVN tag $svntag by hand)");
199 return $dest_package;