cvs: pear-core /PEAR Packager.php /PEAR/PackageFile/Generator v2.php
| From: | Greg Beaver | Date: | Fri, 29 Oct 2004 05:26:43 +0000 |
| Subject: | cvs: pear-core /PEAR Packager.php /PEAR/PackageFile/Generator v2.php | ||
| Groups: | php.pear.cvs php.pear.core | ||
| Request: | Send a blank email to pear-core+get-1196@lists.php.net to get a copy of this message | ||
cellog Fri Oct 29 01:26:43 2004 EDT
Modified files:
/pear-core/PEAR/PackageFile/Generator v2.php
/pear-core/PEAR Packager.php
Log:
complete code making it possible to put both a package.xml 1.0 and
package.xml 2.0 into the same .tgz for full BC and FC
http://cvs.php.net/diff.php/pear-core/PEAR/PackageFile/Generator/v2.php?r1=1.8&r2=1.9&ty=u Index: pear-core/PEAR/PackageFile/Generator/v2.php diff -u pear-core/PEAR/PackageFile/Generator/v2.php:1.8 pear-core/PEAR/PackageFile/Generator/v2.php:1.9 --- pear-core/PEAR/PackageFile/Generator/v2.php:1.8 Thu Sep 30 22:21:20 2004 +++ pear-core/PEAR/PackageFile/Generator/v2.php Fri Oct 29 01:26:43 2004 @@ -18,7 +18,7 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: v2.php,v 1.8 2004/10/01 02:21:20 cellog Exp $ +// $Id: v2.php,v 1.9 2004/10/29 05:26:43 cellog Exp $ /** * This class converts a PEAR_PackageFile_v2 object into any output format. @@ -97,6 +97,12 @@ function toTgz(&$packager, $compress = true, $where = null) { + $a = null; + return $this->toTgz2($packager, $a, $compress, $where); + } + + function toTgz2(&$packager, &$pf1, $compress = true, $where = null) + { include_once 'System.php'; if ($where === null) { if (!($where = System::mktemp(array('-d')))) { @@ -137,7 +143,12 @@ } } // }}} - $packagexml = $this->toPackageFile($where, PEAR_VALIDATE_PACKAGING); + if ($pf1 !== null) { + $name = 'package2.xml'; + } else { + $name = 'package.xml'; + } + $packagexml = $this->toPackageFile($where, PEAR_VALIDATE_PACKAGING, $name); if ($packagexml) { $ext = $compress ? '.tgz' : '.tar'; $dest_package = getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext; @@ -148,12 +159,22 @@ if (PEAR::isError($ok)) { return $packager->raiseError($ok); } elseif (!$ok) { - return $packager->raiseError('PEAR_Packagefile::toTgz(): tarball creation failed'); + return $packager->raiseError('PEAR_Packagefile::toTgz(): adding ' . $name . + ' failed'); } // ----- Add the content of the package if (!$tar->addModify($filelist, $pkgver, $pkgdir)) { return $packager->raiseError('PEAR_Packagefile::toTgz(): tarball creation failed'); } + // add the package.xml version 1.0 + if ($pf1 !== null) { + $pfgen = &$pf1->getDefaultGenerator(); + $packagexml1 = $pfgen->toPackageFile($where, PEAR_VALIDATE_PACKAGING); + if (!$tar->addModify(array($packagexml1), '', $where)) { + return $packager->raiseError('PEAR_Packagefile::toTgz(): adding package.xml ' . + 'failed'); + } + } return $dest_package; } } @@ -736,7 +757,7 @@ // | Authors: Stephan Schmidt <schst@php-tools.net> | // +----------------------------------------------------------------------+ // -// $Id: v2.php,v 1.8 2004/10/01 02:21:20 cellog Exp $ +// $Id: v2.php,v 1.9 2004/10/29 05:26:43 cellog Exp $ /** * error code for invalid chars in XML name http://cvs.php.net/diff.php/pear-core/PEAR/Packager.php?r1=1.59&r2=1.60&ty=u Index: pear-core/PEAR/Packager.php diff -u pear-core/PEAR/Packager.php:1.59 pear-core/PEAR/Packager.php:1.60 --- pear-core/PEAR/Packager.php:1.59 Thu Oct 21 01:09:36 2004 +++ pear-core/PEAR/Packager.php Fri Oct 29 01:26:43 2004 @@ -17,7 +17,7 @@ // | Tomas V.V.Cox <cox@idecnet.com> | // +----------------------------------------------------------------------+ // -// $Id: Packager.php,v 1.59 2004/10/21 05:09:36 cellog Exp $ +// $Id: Packager.php,v 1.60 2004/10/29 05:26:43 cellog Exp $ require_once 'PEAR/Common.php'; require_once 'PEAR/PackageFile.php'; @@ -57,7 +57,7 @@ // {{{ package() - function package($pkgfile = null, $compress = true) + function package($pkgfile = null, $compress = true, $pkg2 = null) { // {{{ validate supplied package.xml file if (empty($pkgfile)) { @@ -75,11 +75,43 @@ return $this->raiseError("Cannot package, errors in package file"); } else { foreach ($pf->getValidationWarnings() as $warning) { - $this->log(1, 'Warning: ' . $warning); + $this->log(1, 'Warning: ' . $warning['message']); } } // }}} + if ($pkg2) { + $this->log(0, 'Attempting to process the second package file'); + PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); + $pf2 = &$pkg->fromPackageFile($pkg2, PEAR_VALIDATE_NORMAL); + PEAR::staticPopErrorHandling(); + if (PEAR::isError($pf2)) { + foreach ($pf2->getUserInfo() as $error) { + $this->log(0, 'Error: ' . $error['message']); + } + $this->log(0, $pf2->getMessage()); + return $this->raiseError("Cannot package, errors in second package file"); + } else { + foreach ($pf2->getValidationWarnings() as $warning) { + $this->log(1, 'Warning: ' . $warning['message']); + } + } + if ($pf2->getPackagexmlVersion() == '2.0') { + $main = &$pf2; + $other = &$pf; + } else { + $main = &$pf; + $other = &$pf2; + } + if ($main->getPackagexmlVersion() != '2.0') { + return PEAR::raiseError('Error: cannot package two package.xml version 1.0, can ' . + 'only package together a package.xml 1.0 and package.xml 2.0'); + } + if ($other->getPackagexmlVersion() != '1.0') { + return PEAR::raiseError('Error: cannot package two package.xml version 2.0, can ' . + 'only package together a package.xml 1.0 and package.xml 2.0'); + } + } $pf->setLogger($this); if (!$pf->validate(PEAR_VALIDATE_PACKAGING)) { foreach ($pf->getValidationWarnings() as $warning) { @@ -91,22 +123,49 @@ $this->log(1, 'Warning: ' . $warning['message']); } } - - $gen = &$pf->getDefaultGenerator(); - $tgzfile = $gen->toTgz($this, $compress); - $dest_package = basename($tgzfile); - $pkgdir = dirname($pkgfile); - - // {{{ TAR the Package ------------------------------------------- - $this->log(1, "Package $dest_package done"); - if (file_exists("$pkgdir/CVS/Root")) { - $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pf->getVersion()); - $cvstag = "RELEASE_$cvsversion"; - $this->log(1, "Tag the released code with `pear cvstag $pkgfile'"); - $this->log(1, "(or set the CVS tag $cvstag by hand)"); + if ($pkg2) { + $pf2->setLogger($this); + if (!$pf2->validate(PEAR_VALIDATE_PACKAGING)) { + foreach ($pf2->getValidationWarnings() as $warning) { + $this->log(0, 'Error: ' . $warning['message']); + } + return $this->raiseError("Cannot package, errors in package"); + } else { + foreach ($pf2->getValidationWarnings() as $warning) { + $this->log(1, 'Warning: ' . $warning['message']); + } + } } - // }}} + if ($pkg2) { + $gen = &$main->getDefaultGenerator(); + $tgzfile = $gen->toTgz2($this, $other, $compress); + $dest_package = basename($tgzfile); + $pkgdir = dirname($pkgfile); + + // TAR the Package ------------------------------------------- + $this->log(1, "Package $dest_package done"); + if (file_exists("$pkgdir/CVS/Root")) { + $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pf->getVersion()); + $cvstag = "RELEASE_$cvsversion"; + $this->log(1, "Tag the released code with `pear cvstag $pkgfile'"); + $this->log(1, "(or set the CVS tag $cvstag by hand)"); + } + } else { + $gen = &$pf->getDefaultGenerator(); + $tgzfile = $gen->toTgz($this, $compress); + $dest_package = basename($tgzfile); + $pkgdir = dirname($pkgfile); + + // TAR the Package ------------------------------------------- + $this->log(1, "Package $dest_package done"); + if (file_exists("$pkgdir/CVS/Root")) { + $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pf->getVersion()); + $cvstag = "RELEASE_$cvsversion"; + $this->log(1, "Tag the released code with `pear cvstag $pkgfile'"); + $this->log(1, "(or set the CVS tag $cvstag by hand)"); + } + } return $dest_package; }
http://cvs.php.net/diff.php/pear-core/PEAR/PackageFile/Generator/v2.php?r1=1.8&r2=1.9&ty=u Index: pear-core/PEAR/PackageFile/Generator/v2.php diff -u pear-core/PEAR/PackageFile/Generator/v2.php:1.8 pear-core/PEAR/PackageFile/Generator/v2.php:1.9 --- pear-core/PEAR/PackageFile/Generator/v2.php:1.8 Thu Sep 30 22:21:20 2004 +++ pear-core/PEAR/PackageFile/Generator/v2.php Fri Oct 29 01:26:43 2004 @@ -18,7 +18,7 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: v2.php,v 1.8 2004/10/01 02:21:20 cellog Exp $ +// $Id: v2.php,v 1.9 2004/10/29 05:26:43 cellog Exp $ /** * This class converts a PEAR_PackageFile_v2 object into any output format. @@ -97,6 +97,12 @@ function toTgz(&$packager, $compress = true, $where = null) { + $a = null; + return $this->toTgz2($packager, $a, $compress, $where); + } + + function toTgz2(&$packager, &$pf1, $compress = true, $where = null) + { include_once 'System.php'; if ($where === null) { if (!($where = System::mktemp(array('-d')))) { @@ -137,7 +143,12 @@ } } // }}} - $packagexml = $this->toPackageFile($where, PEAR_VALIDATE_PACKAGING); + if ($pf1 !== null) { + $name = 'package2.xml'; + } else { + $name = 'package.xml'; + } + $packagexml = $this->toPackageFile($where, PEAR_VALIDATE_PACKAGING, $name); if ($packagexml) { $ext = $compress ? '.tgz' : '.tar'; $dest_package = getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext; @@ -148,12 +159,22 @@ if (PEAR::isError($ok)) { return $packager->raiseError($ok); } elseif (!$ok) { - return $packager->raiseError('PEAR_Packagefile::toTgz(): tarball creation failed'); + return $packager->raiseError('PEAR_Packagefile::toTgz(): adding ' . $name . + ' failed'); } // ----- Add the content of the package if (!$tar->addModify($filelist, $pkgver, $pkgdir)) { return $packager->raiseError('PEAR_Packagefile::toTgz(): tarball creation failed'); } + // add the package.xml version 1.0 + if ($pf1 !== null) { + $pfgen = &$pf1->getDefaultGenerator(); + $packagexml1 = $pfgen->toPackageFile($where, PEAR_VALIDATE_PACKAGING); + if (!$tar->addModify(array($packagexml1), '', $where)) { + return $packager->raiseError('PEAR_Packagefile::toTgz(): adding package.xml ' . + 'failed'); + } + } return $dest_package; } } @@ -736,7 +757,7 @@ // | Authors: Stephan Schmidt <schst@php-tools.net> | // +----------------------------------------------------------------------+ // -// $Id: v2.php,v 1.8 2004/10/01 02:21:20 cellog Exp $ +// $Id: v2.php,v 1.9 2004/10/29 05:26:43 cellog Exp $ /** * error code for invalid chars in XML name http://cvs.php.net/diff.php/pear-core/PEAR/Packager.php?r1=1.59&r2=1.60&ty=u Index: pear-core/PEAR/Packager.php diff -u pear-core/PEAR/Packager.php:1.59 pear-core/PEAR/Packager.php:1.60 --- pear-core/PEAR/Packager.php:1.59 Thu Oct 21 01:09:36 2004 +++ pear-core/PEAR/Packager.php Fri Oct 29 01:26:43 2004 @@ -17,7 +17,7 @@ // | Tomas V.V.Cox <cox@idecnet.com> | // +----------------------------------------------------------------------+ // -// $Id: Packager.php,v 1.59 2004/10/21 05:09:36 cellog Exp $ +// $Id: Packager.php,v 1.60 2004/10/29 05:26:43 cellog Exp $ require_once 'PEAR/Common.php'; require_once 'PEAR/PackageFile.php'; @@ -57,7 +57,7 @@ // {{{ package() - function package($pkgfile = null, $compress = true) + function package($pkgfile = null, $compress = true, $pkg2 = null) { // {{{ validate supplied package.xml file if (empty($pkgfile)) { @@ -75,11 +75,43 @@ return $this->raiseError("Cannot package, errors in package file"); } else { foreach ($pf->getValidationWarnings() as $warning) { - $this->log(1, 'Warning: ' . $warning); + $this->log(1, 'Warning: ' . $warning['message']); } } // }}} + if ($pkg2) { + $this->log(0, 'Attempting to process the second package file'); + PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); + $pf2 = &$pkg->fromPackageFile($pkg2, PEAR_VALIDATE_NORMAL); + PEAR::staticPopErrorHandling(); + if (PEAR::isError($pf2)) { + foreach ($pf2->getUserInfo() as $error) { + $this->log(0, 'Error: ' . $error['message']); + } + $this->log(0, $pf2->getMessage()); + return $this->raiseError("Cannot package, errors in second package file"); + } else { + foreach ($pf2->getValidationWarnings() as $warning) { + $this->log(1, 'Warning: ' . $warning['message']); + } + } + if ($pf2->getPackagexmlVersion() == '2.0') { + $main = &$pf2; + $other = &$pf; + } else { + $main = &$pf; + $other = &$pf2; + } + if ($main->getPackagexmlVersion() != '2.0') { + return PEAR::raiseError('Error: cannot package two package.xml version 1.0, can ' . + 'only package together a package.xml 1.0 and package.xml 2.0'); + } + if ($other->getPackagexmlVersion() != '1.0') { + return PEAR::raiseError('Error: cannot package two package.xml version 2.0, can ' . + 'only package together a package.xml 1.0 and package.xml 2.0'); + } + } $pf->setLogger($this); if (!$pf->validate(PEAR_VALIDATE_PACKAGING)) { foreach ($pf->getValidationWarnings() as $warning) { @@ -91,22 +123,49 @@ $this->log(1, 'Warning: ' . $warning['message']); } } - - $gen = &$pf->getDefaultGenerator(); - $tgzfile = $gen->toTgz($this, $compress); - $dest_package = basename($tgzfile); - $pkgdir = dirname($pkgfile); - - // {{{ TAR the Package ------------------------------------------- - $this->log(1, "Package $dest_package done"); - if (file_exists("$pkgdir/CVS/Root")) { - $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pf->getVersion()); - $cvstag = "RELEASE_$cvsversion"; - $this->log(1, "Tag the released code with `pear cvstag $pkgfile'"); - $this->log(1, "(or set the CVS tag $cvstag by hand)"); + if ($pkg2) { + $pf2->setLogger($this); + if (!$pf2->validate(PEAR_VALIDATE_PACKAGING)) { + foreach ($pf2->getValidationWarnings() as $warning) { + $this->log(0, 'Error: ' . $warning['message']); + } + return $this->raiseError("Cannot package, errors in package"); + } else { + foreach ($pf2->getValidationWarnings() as $warning) { + $this->log(1, 'Warning: ' . $warning['message']); + } + } } - // }}} + if ($pkg2) { + $gen = &$main->getDefaultGenerator(); + $tgzfile = $gen->toTgz2($this, $other, $compress); + $dest_package = basename($tgzfile); + $pkgdir = dirname($pkgfile); + + // TAR the Package ------------------------------------------- + $this->log(1, "Package $dest_package done"); + if (file_exists("$pkgdir/CVS/Root")) { + $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pf->getVersion()); + $cvstag = "RELEASE_$cvsversion"; + $this->log(1, "Tag the released code with `pear cvstag $pkgfile'"); + $this->log(1, "(or set the CVS tag $cvstag by hand)"); + } + } else { + $gen = &$pf->getDefaultGenerator(); + $tgzfile = $gen->toTgz($this, $compress); + $dest_package = basename($tgzfile); + $pkgdir = dirname($pkgfile); + + // TAR the Package ------------------------------------------- + $this->log(1, "Package $dest_package done"); + if (file_exists("$pkgdir/CVS/Root")) { + $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pf->getVersion()); + $cvstag = "RELEASE_$cvsversion"; + $this->log(1, "Tag the released code with `pear cvstag $pkgfile'"); + $this->log(1, "(or set the CVS tag $cvstag by hand)"); + } + } return $dest_package; }