cvs: pear-core / package-PEAR.xml /PEAR ErrorStack.php /PEAR/PackageFile v2.php /PEAR/PackageFile/Generator v1.php

From: Date: Sat, 11 Sep 2004 04:21:11 +0000
Subject: cvs: pear-core / package-PEAR.xml /PEAR ErrorStack.php /PEAR/PackageFile v2.php /PEAR/PackageFile/Generator v1.php
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-cvs+get-23817@lists.php.net to get a copy of this message
cellog Sat Sep 11 00:21:11 2004 EDT Modified files: /pear-core/PEAR ErrorStack.php /pear-core/PEAR/PackageFile/Generator v1.php /pear-core/PEAR/PackageFile v2.php /pear-core package-PEAR.xml Log: fix PEAR_ErrorStack - exception blows up if code is not an integer add easy generation of package.xml version 2.0 from version 1.0 without need for xsl. in php5: <?php $a = new PEAR_PackageFile; $pf = $a->fromPackageFile('package.xml'); $newxml = $pf->getDefaultGenerator()->toV2()->getDefaultGenerator()->toXml(); ?> fix validation for package.xml version 2.0 fix many small bugs in PEAR_PackageFile*_v2

http://cvs.php.net/diff.php/pear-core/PEAR/ErrorStack.php?r1=1.9&r2=1.10&ty=u Index: pear-core/PEAR/ErrorStack.php diff -u pear-core/PEAR/ErrorStack.php:1.9 pear-core/PEAR/ErrorStack.php:1.10 --- pear-core/PEAR/ErrorStack.php:1.9 Mon Aug 16 22:39:28 2004 +++ pear-core/PEAR/ErrorStack.php Sat Sep 11 00:21:11 2004 @@ -17,7 +17,7 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: ErrorStack.php,v 1.9 2004/08/17 02:39:28 cellog Exp $ +// $Id: ErrorStack.php,v 1.10 2004/09/11 04:21:11 cellog Exp $ /** * Error Stack Implementation @@ -597,7 +597,7 @@ if (is_string($msg) && is_numeric($code)) { $code = $code + 0; } - $ret = new $exception($msg, $code); + $ret = new $exception($msg, (int) $code); $ret->errorData = $err; return $ret; } http://cvs.php.net/diff.php/pear-core/PEAR/PackageFile/Generator/v1.php?r1=1.1&r2=1.2&ty=u Index: pear-core/PEAR/PackageFile/Generator/v1.php diff -u pear-core/PEAR/PackageFile/Generator/v1.php:1.1 pear-core/PEAR/PackageFile/Generator/v1.php:1.2 --- pear-core/PEAR/PackageFile/Generator/v1.php:1.1 Fri Sep 10 12:22:04 2004 +++ pear-core/PEAR/PackageFile/Generator/v1.php Sat Sep 11 00:21:11 2004 @@ -211,6 +211,392 @@ } /** + * Convert a package.xml version 1.0 into version 2.0 + * + * Note that this does a basic conversion, to allow more advanced + * features like bundles and multiple releases + * @return PEAR_PackageFile_v2 + */ + function &toV2() + { + $arr = array( + 'name' => array( + 'attribs' => array( + 'channel' => 'pear', + ), + '_content' => $this->_packagefile->getPackage(), + ) + ); + if ($extends = $this->_packagefile->getExtends()) { + $arr['extends'] = $extends; + } + $arr['summary'] = $this->_packagefile->getSummary(); + $arr['description'] = $this->_packagefile->getDescription(); + $maintainers = $this->_packagefile->getMaintainers(); + foreach ($maintainers as $maintainer) { + if ($maintainer['role'] != 'lead') { + continue; + } + unset($maintainer['role']); + $maintainer['active'] = 'yes'; + $maintainer['user'] = $maintainer['handle']; + unset($maintainer['handle']); + $arr['lead'][] = array('attribs' => $maintainer); + } + if (count($arr['lead']) == 1) { + $arr['lead'] = $arr['lead'][0]; + } + foreach ($maintainers as $maintainer) { + if ($maintainer['role'] == 'lead') { + continue; + } + $maintainer['active'] = 'yes'; + $maintainer['user'] = $maintainer['handle']; + unset($maintainer['handle']); + $arr['maintainer'][] = array('attribs' => $maintainer); + } + if (count($arr['maintainer']) == 1) { + $arr['maintainer'] = $arr['maintainer'][0]; + } + $arr['date'] = $this->_packagefile->getDate(); + $arr['version'] = array( + 'attribs' => + array('api' => $this->_packagefile->getVersion(), + 'package' => $this->_packagefile->getVersion() + ) + ); + $licensemap = + array( + 'php license' => 'http://www.php.net/license/3_0.txt', + 'lgpl' => 'http://www.gnu.org/copyleft/lesser.html', + 'bsd' => 'http://www.opensource.org/licenses/bsd-license.php', + 'mit' => 'http://www.opensource.org/licenses/mit-license.php', + 'gpl' => 'http://www.gnu.org/copyleft/gpl.html', + 'apache' => 'http://www.opensource.org/licenses/apache2.0.php' + ); + if (isset($licensemap[strtolower($this->_packagefile->getLicense())])) { + $uri = $licensemap[strtolower($this->_packagefile->getLicense())]; + } else { + $uri = 'http://www.example.com'; + } + $arr['license'] = array( + 'attribs' => array('uri' => $uri), + '_content' => $this->_packagefile->getLicense() + ); + $arr['stability'] = array( + 'attribs' => + array('api' => $this->_packagefile->getState(), + 'package' => $this->_packagefile->getState() + ) + ); + $arr['notes'] = $this->_packagefile->getNotes(); + $arr['filelist'] = $this->_convertFilelist2_0(); + $release = $this->_packagefile->getConfigureOptions() ? 'extsrc' : 'php'; + $arr[$release] = array(); + $this->_convertRelease2_0($arr[$release]); + if ($cl = $this->_packagefile->getChangelog()) { + foreach ($cl as $release) { + $rel = array(); + $rel['version'] = array( + 'attribs' => + array('api' => $release['version'], + 'package' => $release['version'] + ) + ); + $rel['date'] = $release['release_date']; + if (isset($release['release_license'])) { + if (isset($licensemap[strtolower($release['release_license'])])) { + $uri = $licensemap[strtolower($release['release_license'])]; + } else { + $uri = 'http://www.example.com'; + } + $rel['license'] = array( + 'attribs' => array('uri' => $uri), + '_content' => $release['release_license'] + ); + } else { + $rel['license'] = $arr['license']; + } + $rel['stability'] = array( + 'attribs' => + array('api' => $release['release_state'], + 'package' => $release['release_state'] + ) + ); + $rel['notes'] = $release['release_notes']; + $arr['changelog']['release'][] = $rel; + } + } + include_once 'PEAR/PackageFile/v2.php'; + $ret = new PEAR_PackageFile_v2; + $ret->fromArray($arr); + return $ret; + } + + function _convertFilelist2_0() + { + $ret = array('dir' => + array( + 'attribs' => array('name' => '/'), + 'file' => array() + ) + ); + foreach ($this->_packagefile->getFilelist() as $name => $file) { + $file['name'] = $name; + if (isset($file['replacements'])) { + $repl = $file['replacements']; + unset($file['replacements']); + } else { + unset($repl); + } + $file = array('attribs' => $file); + if (isset($repl)) { + foreach ($repl as $replace ) { + $file['tasks:replace'][] = array('attribs' => $replace); + } + if (count($repl) == 1) { + $file['tasks:replace'] = $file['tasks:replace'][0]; + } + } + $ret['dir']['file'][] = $file; + } + return $ret; + } + + function _convertRelease2_0(&$release) + { + $release['dependencies'] = array(); + $release['dependencies']['pearinstaller'] = + array('attribs' => + array('min' => '@PEAR-VER@')); + if ($this->_packagefile->hasDeps()) { + $deps = array(); + foreach ($this->_packagefile->getDeps() as $dep) { + // organize deps by dependency type and name + if (!isset($deps[$dep['type']])) { + $deps[$dep['type']] = array(); + } + if (isset($dep['name'])) { + $deps[$dep['type']][$dep['name']][] = $dep; + } else { + $deps[$dep['type']][] = $dep; + } + } + do { + if (isset($deps['php'])) { + $php = array(); + if (count($deps['php']) > 1) { + $php = $this->_processMultipleDeps($deps['php']); + } else { + $php = $this->_processDep($deps['php'][0]); + if (!$php) { + break; // poor mans throw + } + } + $release['dependencies']['php'] = $php; + } + } while (false); + do { + if (isset($deps['pkg'])) { + $pkg = array(); + if (count($deps['pkg']) > 1) { + $pkg = $this->_processMultipleDepsName($deps['pkg']); + } else { + $pkg = $this->_processDep($deps['pkg'][0]); + if (!$pkg) { + break; // poor mans throw + } + } + $release['dependencies']['package'] = $pkg; + } + } while (false); + do { + if (isset($deps['ext'])) { + $pkg = array(); + if (count($deps['ext']) > 1) { + $pkg = $this->_processMultipleDepsName($deps['ext']); + } else { + $pkg = $this->_processDep($deps['ext'][0]); + if (!$pkg) { + break; // poor mans throw + } + } + $release['dependencies']['extension'] = $pkg; + } + } while (false); + // skip sapi - it's not supported so nobody will have used it + // skip os - it's not supported in 1.0 + } + } + + function _processDep($dep) + { + if ($dep['type'] == 'php') { + if ($dep['rel'] == 'has') { + // come on - everyone has php! + return false; + } + } + $php = array(); + if ($dep['type'] != 'php') { + $php['attribs']['name'] = $dep['name']; + if ($dep['type'] == 'pkg') { + // no way to guess for extensions, so we'll assume they + // are NOT pecl + $php['attribs']['channel'] = 'pear'; + } + } + if (isset($dep['optional'])) { + $php['attribs']['optional'] = $dep['optional']; + } + switch ($dep['rel']) { + case 'gt' : + $php['exclude']['attribs']['version'] = $dep['version']; + case 'ge' : + $php['attribs']['min'] = $dep['version']; + break; + case 'lt' : + $php['exclude']['attribs']['version'] = $dep['version']; + case 'le' : + $php['attribs']['max'] = $dep['version']; + break; + case 'eq' : + $php['attribs']['max'] = $dep['version']; + $php['attribs']['min'] = $dep['version']; + break; + case 'not' : + $php['exclude']['attribs']['version'] = $dep['version']; + break; + } + return $php; + } + + function _processMultipleDeps($deps) + { + $test = array(); + foreach ($deps as $dep) { + $test[] = $this->_processDep($dep); + } + $min = array(); + $max = array(); + foreach ($test as $dep) { + if (!dep) { + continue; + } + if (isset($dep['attribs']['min'])) { + $min[$dep['attribs']['min']] = count($min); + } + if (isset($dep['attribs']['max'])) { + $max[$dep['attribs']['max']] = count($max); + } + } + if (count($min) > 0) { + uksort($min, 'version_compare'); + } + if (count($max) > 0) { + uksort($max, 'version_compare'); + } + if (count($min)) { + // get the highest minimum + $min = array_pop(array_flip($min)); + } else { + $min = false; + } + if (count($max)) { + // get the lowest maximum + $max = array_shift(array_flip($max)); + } else { + $max = false; + } + if ($min) { + $php['attribs']['min'] = $min; + } + if ($max) { + $php['attribs']['max'] = $max; + } + $exclude = array(); + foreach ($test as $dep) { + if (!isset($dep['exclude'])) { + continue; + } + $exclude[] = $dep['exclude']; + } + if (count($exclude)) { + $php['exclude'] = $exclude; + } + return $php; + } + + function _processMultipleDepsName($deps) + { + $test = array(); + foreach ($deps as $name => $dep) { + foreach ($dep as $d) { + $tests[$name][] = $this->_processDep($d); + } + } + foreach ($tests as $name => $test) { + $php = array(); + $min = array(); + $max = array(); + foreach ($test as $dep) { + if (!$dep) { + continue; + } + if (isset($dep['attribs']['min'])) { + $min[$dep['attribs']['min']] = count($min); + } + if (isset($dep['attribs']['max'])) { + $max[$dep['attribs']['max']] = count($max); + } + } + if (isset($dep['attribs']['channel'])) { + $php['attribs']['channel'] = $dep['attribs']['channel']; + } + if (isset($dep['attribs']['optional'])) { + $php['attribs']['optional'] = $dep['attribs']['optional']; + } + $php['attribs']['name'] = $name; + if (count($min) > 0) { + uksort($min, 'version_compare'); + } + if (count($max) > 0) { + uksort($max, 'version_compare'); + } + if (count($min)) { + // get the highest minimum + $min = array_pop(array_flip($min)); + } else { + $min = false; + } + if (count($max)) { + // get the lowest maximum + $max = array_shift(array_flip($max)); + } else { + $max = false; + } + if ($min) { + $php['attribs']['min'] = $min; + } + if ($max) { + $php['attribs']['max'] = $max; + } + $exclude = array(); + foreach ($test as $dep) { + if (!isset($dep['exclude'])) { + continue; + } + $exclude[] = $dep['exclude']; + } + if (count($exclude)) { + $php['exclude'] = $exclude; + } + $ret[] = $php; + } + return $ret; + } + + /** * Build a "provides" array from data returned by * analyzeSourceCode(). The format of the built array is like * this: @@ -277,4 +663,16 @@ // }}} } +//set_include_path('C:/devel/pear_with_channels'); +//require_once 'PEAR/PackageFile/Parser/v1.php'; +//require_once 'PEAR/Registry.php'; +//$a = new PEAR_PackageFile_Parser_v1; +//$r = new PEAR_Registry('C:\Program Files\php\pear'); +//$a->setRegistry($r); +//$p = &$a->parse(file_get_contents('C:\devel\pear_with_channels\package-PEAR.xml'), PEAR_VALIDATE_NORMAL, +// 'C:\devel\pear_with_channels\package-PEAR.xml'); +//$g = &$p->getDefaultGenerator(); +//$v2 = &$g->toV2(); +//$g = &$v2->getDefaultGenerator(); +//echo $g->toXml(); ?> http://cvs.php.net/diff.php/pear-core/PEAR/PackageFile/v2.php?r1=1.4&r2=1.5&ty=u Index: pear-core/PEAR/PackageFile/v2.php diff -u pear-core/PEAR/PackageFile/v2.php:1.4 pear-core/PEAR/PackageFile/v2.php:1.5 --- pear-core/PEAR/PackageFile/v2.php:1.4 Fri Sep 10 17:56:43 2004 +++ pear-core/PEAR/PackageFile/v2.php Sat Sep 11 00:21:11 2004 @@ -83,11 +83,13 @@ unset($this->_packageInfo['dirtree']); } - function getPackagefile() - { - return $this->_packageFile; - } - + /** + * Directly set the array that defines this packagefile + * + * WARNING: no validation. This should only be performed by internal methods + * inside PEAR or by inputting an array saved from an existing PEAR_PackageFile_v2 + * @param array + */ function fromArray($pinfo) { unset($pinfo['old']); @@ -108,10 +110,14 @@ $this->_packageInfo['old']['release_notes'] = $this->getNotes(); $this->_packageInfo['old']['release_deps'] = $this->getDeps(); $this->_packageInfo['old']['maintainers'] = $this->getMaintainers(); + if ($this->getExtends()) { + $this->_packageInfo['old']['extends'] = $this->getExtends(); + } return $this->_packageInfo; } else { $info = $this->_packageInfo; unset($info['dirtree']); + return $info; } } @@ -362,7 +368,7 @@ $structure = array( 'name->channel', - 'extends?', + '*extends', // can't be multiple, but this works fine 'summary', 'description', '+lead->user->email->name->active', @@ -376,14 +382,16 @@ 'filelist', //special validation needed '+php|+extsrc|+extbin' //special validation needed ); - unset($keys[0]); - foreach ($keys as $key) { + reset($keys); + $key = current($keys); + foreach ($structure as $struc) { $tag = $this->_packageInfo[$key]; - $test = $this->_processStructure(array_shift($structure)); + $test = $this->_processStructure($struc); if (isset($test['choices'])) { foreach ($test['choices'] as $choice) { if ($key == $choice['tag']) { if ($this->_processAttribs($choice, $tag, '<package>')) { + $key = next($keys); continue 2; } return false; @@ -397,9 +405,14 @@ $this->_invalidTagOrder($test['tag'], $key); return false; } + if (!isset($test['multiple'])) { + $this->_invalidTagOrder($test['tag'], $key); + return false; + } continue; } if ($this->_processAttribs($test, $tag, '<package>')) { + $key = next($keys); continue; } return false; @@ -425,7 +438,7 @@ } $this->_validateFilelist(); $this->_validateRelease(); - return $this->_stack->hasErrors(); + return !$this->_stack->hasErrors(); } function _processAttribs($choice, $tag, $context) @@ -584,9 +597,11 @@ } if (isset($list['dir'])) { if ($this->_processDir($list['dir'])) { - foreach ($list['dir'] as $dir) { - $this->_validateFilelist($dir); - return; + if (!isset($list['dir']['attribs'])) { + foreach ($list['dir'] as $dir) { + $this->_validateFilelist($dir); + return; + } } } return $this->_validateFilelist($list['dir'], $allowignorefile); @@ -609,6 +624,7 @@ 'unknown'); } } + return true; } function _validateRelease() @@ -624,10 +640,14 @@ } if (isset($this->_packageInfo[$release][0])) { foreach ($this->_packageInfo[$release] as $rel) { - $this->_validateFilelist($rel['filelist'], true); + if (isset($rel['filelist'])) { + $this->_validateFilelist($rel['filelist'], true); + } } } else { - $this->_validateFilelist($this->_packageInfo[$release]['filelist'], true); + if (isset($this->_packageInfo[$release]['filelist'])) { + $this->_validateFilelist($this->_packageInfo[$release]['filelist'], true); + } } } @@ -644,6 +664,13 @@ function _detectFilelist() { $this->_flatFilelist = isset($this->_filelist); + } + + function _invalidTagOrder($oktags, $actual) + { + $this->_stack->push(__FUNCTION__, 'error', + array('oktags' => $oktags, 'actual' => $actual), + 'Invalid tag order, found <%actual%> expected one of "%oktags%"'); } function _ignorefileNotAllowed() http://cvs.php.net/diff.php/pear-core/package-PEAR.xml?r1=1.116&r2=1.117&ty=u Index: pear-core/package-PEAR.xml diff -u pear-core/package-PEAR.xml:1.116 pear-core/package-PEAR.xml:1.117 --- pear-core/package-PEAR.xml:1.116 Fri Sep 10 12:22:04 2004 +++ pear-core/package-PEAR.xml Sat Sep 11 00:21:11 2004 @@ -125,7 +125,9 @@ </file> <dir name="PackageFile"> <dir name="Generator"> - <file role="php" name="v1.php"/> + <file role="php" name="v1.php"> + <replace from="@PEAR-VER@" to="version" type="package-info"/> + </file> <file role="php" name="v2.php"/> </dir> <dir name="Parser">
« previous php.pear.cvs (#23817) next »