2001-04-17 01:17:59 +00:00
|
|
|
<?php
|
|
|
|
//
|
|
|
|
// +----------------------------------------------------------------------+
|
2004-01-08 17:33:29 +00:00
|
|
|
// | PHP Version 5 |
|
2001-04-17 01:17:59 +00:00
|
|
|
// +----------------------------------------------------------------------+
|
2004-01-08 17:33:29 +00:00
|
|
|
// | Copyright (c) 1997-2004 The PHP Group |
|
2001-04-17 01:17:59 +00:00
|
|
|
// +----------------------------------------------------------------------+
|
2003-06-10 20:04:29 +00:00
|
|
|
// | This source file is subject to version 3.0 of the PHP license, |
|
2001-04-17 01:17:59 +00:00
|
|
|
// | that is bundled with this package in the file LICENSE, and is |
|
2003-06-10 20:04:29 +00:00
|
|
|
// | available through the world-wide-web at the following url: |
|
|
|
|
// | http://www.php.net/license/3_0.txt. |
|
2001-04-17 01:17:59 +00:00
|
|
|
// | If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
// | obtain it through the world-wide-web, please send a note to |
|
|
|
|
// | license@php.net so we can mail you a copy immediately. |
|
|
|
|
// +----------------------------------------------------------------------+
|
2003-03-18 12:06:09 +00:00
|
|
|
// | Authors: Stig Bakken <ssb@php.net> |
|
2001-07-17 19:21:55 +00:00
|
|
|
// | Tomas V.V.Cox <cox@idecnet.com> |
|
2001-04-17 01:17:59 +00:00
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
//
|
2001-07-17 19:21:55 +00:00
|
|
|
// $Id$
|
2001-04-17 01:17:59 +00:00
|
|
|
|
2001-07-17 19:21:55 +00:00
|
|
|
require_once 'PEAR/Common.php';
|
2002-07-07 20:42:08 +00:00
|
|
|
require_once 'System.php';
|
2001-04-17 01:17:59 +00:00
|
|
|
|
|
|
|
/**
|
2001-04-20 13:04:30 +00:00
|
|
|
* Administration class used to make a PEAR release tarball.
|
2001-04-17 01:17:59 +00:00
|
|
|
*
|
2001-07-18 17:13:38 +00:00
|
|
|
* TODO:
|
|
|
|
* - add an extra param the dir where to place the created package
|
|
|
|
*
|
2001-04-17 01:17:59 +00:00
|
|
|
* @since PHP 4.0.2
|
2003-03-18 12:06:09 +00:00
|
|
|
* @author Stig Bakken <ssb@php.net>
|
2001-04-17 01:17:59 +00:00
|
|
|
*/
|
2001-07-17 19:21:55 +00:00
|
|
|
class PEAR_Packager extends PEAR_Common
|
2001-04-17 01:17:59 +00:00
|
|
|
{
|
|
|
|
// {{{ constructor
|
|
|
|
|
2002-03-21 11:04:56 +00:00
|
|
|
function PEAR_Packager()
|
2001-04-17 01:17:59 +00:00
|
|
|
{
|
2003-02-25 02:44:10 +00:00
|
|
|
parent::PEAR_Common();
|
2001-04-17 01:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
// {{{ destructor
|
|
|
|
|
2001-10-08 16:52:33 +00:00
|
|
|
function _PEAR_Packager()
|
|
|
|
{
|
2003-02-25 02:44:10 +00:00
|
|
|
parent::_PEAR_Common();
|
2001-04-17 01:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
|
2001-05-28 06:31:03 +00:00
|
|
|
// {{{ package()
|
|
|
|
|
2002-04-07 17:07:49 +00:00
|
|
|
function package($pkgfile = null, $compress = true)
|
2001-07-17 19:21:55 +00:00
|
|
|
{
|
2003-10-10 12:22:59 +00:00
|
|
|
// {{{ validate supplied package.xml file
|
2001-08-19 12:53:01 +00:00
|
|
|
if (empty($pkgfile)) {
|
|
|
|
$pkgfile = 'package.xml';
|
|
|
|
}
|
2003-10-10 12:22:59 +00:00
|
|
|
// $this->pkginfo gets populated inside
|
2001-07-17 19:21:55 +00:00
|
|
|
$pkginfo = $this->infoFromDescriptionFile($pkgfile);
|
|
|
|
if (PEAR::isError($pkginfo)) {
|
2002-04-07 17:07:49 +00:00
|
|
|
return $this->raiseError($pkginfo);
|
2001-07-17 19:21:55 +00:00
|
|
|
}
|
2003-10-10 12:22:59 +00:00
|
|
|
|
|
|
|
$pkgdir = dirname(realpath($pkgfile));
|
2001-07-31 13:36:54 +00:00
|
|
|
$pkgfile = basename($pkgfile);
|
2001-10-08 16:52:33 +00:00
|
|
|
|
2003-02-25 02:44:10 +00:00
|
|
|
$errors = $warnings = array();
|
2003-10-10 12:22:59 +00:00
|
|
|
$this->validatePackageInfo($pkginfo, $errors, $warnings, $pkgdir);
|
2003-02-25 02:44:10 +00:00
|
|
|
foreach ($warnings as $w) {
|
|
|
|
$this->log(1, "Warning: $w");
|
|
|
|
}
|
|
|
|
foreach ($errors as $e) {
|
|
|
|
$this->log(0, "Error: $e");
|
|
|
|
}
|
|
|
|
if (sizeof($errors) > 0) {
|
|
|
|
return $this->raiseError('Errors in package');
|
|
|
|
}
|
2003-10-10 12:22:59 +00:00
|
|
|
// }}}
|
2003-02-25 02:44:10 +00:00
|
|
|
|
2003-10-10 12:22:59 +00:00
|
|
|
$pkgver = $pkginfo['package'] . '-' . $pkginfo['version'];
|
|
|
|
|
|
|
|
// {{{ Create the package file list
|
2002-01-26 12:36:30 +00:00
|
|
|
$filelist = array();
|
|
|
|
$i = 0;
|
|
|
|
|
2003-10-10 12:22:59 +00:00
|
|
|
foreach ($pkginfo['filelist'] as $fname => $atts) {
|
|
|
|
$file = $pkgdir . DIRECTORY_SEPARATOR . $fname;
|
|
|
|
if (!file_exists($file)) {
|
2003-02-25 02:44:10 +00:00
|
|
|
return $this->raiseError("File does not exist: $fname");
|
2001-07-17 19:21:55 +00:00
|
|
|
} else {
|
2003-10-10 12:22:59 +00:00
|
|
|
$filelist[$i++] = $file;
|
|
|
|
if (empty($pkginfo['filelist'][$fname]['md5sum'])) {
|
|
|
|
$md5sum = md5_file($file);
|
2004-06-13 14:06:01 +00:00
|
|
|
$pkginfo['filelist'][$fname]['md5sum'] = $md5sum;
|
2002-03-28 23:49:34 +00:00
|
|
|
}
|
2002-03-21 11:04:56 +00:00
|
|
|
$this->log(2, "Adding file $fname");
|
2001-07-17 19:21:55 +00:00
|
|
|
}
|
|
|
|
}
|
2003-10-05 16:42:18 +00:00
|
|
|
// }}}
|
2003-10-10 12:22:59 +00:00
|
|
|
|
|
|
|
// {{{ regenerate package.xml
|
|
|
|
$new_xml = $this->xmlFromInfo($pkginfo);
|
2002-03-28 23:49:34 +00:00
|
|
|
if (PEAR::isError($new_xml)) {
|
2002-04-07 17:07:49 +00:00
|
|
|
return $this->raiseError($new_xml);
|
2002-03-28 23:49:34 +00:00
|
|
|
}
|
2003-10-10 12:22:59 +00:00
|
|
|
if (!($tmpdir = System::mktemp(array('-d')))) {
|
2002-07-07 20:42:08 +00:00
|
|
|
return $this->raiseError("PEAR_Packager: mktemp failed");
|
|
|
|
}
|
2002-04-07 17:07:49 +00:00
|
|
|
$newpkgfile = $tmpdir . DIRECTORY_SEPARATOR . 'package.xml';
|
2003-10-10 12:22:59 +00:00
|
|
|
$np = @fopen($newpkgfile, 'wb');
|
2002-03-28 23:49:34 +00:00
|
|
|
if (!$np) {
|
2002-07-07 20:42:08 +00:00
|
|
|
return $this->raiseError("PEAR_Packager: unable to rewrite $pkgfile as $newpkgfile");
|
2002-03-28 23:49:34 +00:00
|
|
|
}
|
|
|
|
fwrite($np, $new_xml);
|
|
|
|
fclose($np);
|
2003-10-10 12:22:59 +00:00
|
|
|
// }}}
|
2001-07-18 17:13:38 +00:00
|
|
|
|
2003-10-05 16:42:18 +00:00
|
|
|
// {{{ TAR the Package -------------------------------------------
|
2002-04-07 17:07:49 +00:00
|
|
|
$ext = $compress ? '.tgz' : '.tar';
|
2003-10-10 12:22:59 +00:00
|
|
|
$dest_package = getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext;
|
2002-04-07 17:07:49 +00:00
|
|
|
$tar =& new Archive_Tar($dest_package, $compress);
|
2002-03-28 23:49:34 +00:00
|
|
|
$tar->setErrorHandling(PEAR_ERROR_RETURN); // XXX Don't print errors
|
2002-02-22 21:57:04 +00:00
|
|
|
// ----- Creates with the package.xml file
|
2003-08-03 19:32:07 +00:00
|
|
|
$ok = $tar->createModify(array($newpkgfile), '', $tmpdir);
|
2002-03-28 23:49:34 +00:00
|
|
|
if (PEAR::isError($ok)) {
|
2002-04-07 17:07:49 +00:00
|
|
|
return $this->raiseError($ok);
|
2002-03-28 23:49:34 +00:00
|
|
|
} elseif (!$ok) {
|
|
|
|
return $this->raiseError('PEAR_Packager: tarball creation failed');
|
2002-02-22 21:57:04 +00:00
|
|
|
}
|
|
|
|
// ----- Add the content of the package
|
2003-10-10 12:22:59 +00:00
|
|
|
if (!$tar->addModify($filelist, $pkgver, $pkgdir)) {
|
2002-03-28 23:49:34 +00:00
|
|
|
return $this->raiseError('PEAR_Packager: tarball creation failed');
|
2001-10-08 03:29:34 +00:00
|
|
|
}
|
2001-07-31 13:36:54 +00:00
|
|
|
$this->log(1, "Package $dest_package done");
|
2003-10-10 12:22:59 +00:00
|
|
|
if (file_exists("$pkgdir/CVS/Root")) {
|
|
|
|
$cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pkginfo['version']);
|
2002-04-16 05:01:41 +00:00
|
|
|
$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)");
|
|
|
|
}
|
2003-10-05 16:42:18 +00:00
|
|
|
// }}}
|
2003-10-10 12:22:59 +00:00
|
|
|
|
2001-07-31 13:36:54 +00:00
|
|
|
return $dest_package;
|
2001-07-17 19:21:55 +00:00
|
|
|
}
|
|
|
|
|
2001-04-17 01:17:59 +00:00
|
|
|
// }}}
|
|
|
|
}
|
|
|
|
|
2003-10-05 16:42:18 +00:00
|
|
|
// {{{ md5_file() utility function
|
2002-03-31 19:04:26 +00:00
|
|
|
if (!function_exists('md5_file')) {
|
2002-04-01 19:17:59 +00:00
|
|
|
function md5_file($file) {
|
2002-03-31 19:04:26 +00:00
|
|
|
if (!$fd = @fopen($file, 'r')) {
|
|
|
|
return false;
|
|
|
|
}
|
2002-04-01 19:17:59 +00:00
|
|
|
$md5 = md5(fread($fd, filesize($file)));
|
|
|
|
fclose($fd);
|
|
|
|
return $md5;
|
2002-03-31 19:04:26 +00:00
|
|
|
}
|
|
|
|
}
|
2003-10-05 16:42:18 +00:00
|
|
|
// }}}
|
2002-03-31 19:04:26 +00:00
|
|
|
|
2003-06-27 10:46:54 +00:00
|
|
|
?>
|