$this->output = '';
include_once 'PEAR/Packager.php';
$pkginfofile = isset($params[0]) ? $params[0] : 'package.xml';
- ob_start();
$packager =& new PEAR_Packager($this->config->get('php_dir'),
$this->config->get('ext_dir'),
$this->config->get('doc_dir'));
$packager->debug = $this->config->get('verbose');
$err = $warn = array();
- $packager->validatePackageInfo($pkginfofile, $err, $warn);
- if (!$this->_displayValidationResults($err, $warn, true)) {
- $this->ui->outputData($this->output, $command);
- return;
- }
+ $dir = dirname($pkginfofile);
$compress = empty($options['nocompress']) ? true : false;
- $result = $packager->Package($pkginfofile, $compress);
- $this->output = ob_get_contents();
- ob_end_clean();
+ $result = $packager->package($pkginfofile, $compress);
if (PEAR::isError($result)) {
$this->ui->outputData($this->output, $command);
return $this->raiseError($result);
/**
* Validate XML package definition file.
*
- * @param string Filename of the package archive or of the package definition file
- * @param array Array that will contain the errors
- * @param array Array that will contain the warnings
+ * @param string $info Filename of the package archive or of the
+ * package definition file
+ * @param array $errors Array that will contain the errors
+ * @param array $warnings Array that will contain the warnings
+ * @param string $dir_prefix (optional) directory where source files
+ * may be found, or empty if they are not available
* @access public
* @return boolean
*/
- function validatePackageInfo($info, &$errors, &$warnings)
+ function validatePackageInfo($info, &$errors, &$warnings, $dir_prefix = '')
{
global $_PEAR_Common_maintainer_roles,
$_PEAR_Common_release_states,
} elseif (!in_array($fa['role'], $_PEAR_Common_file_roles)) {
$errors[] = "file $file: invalid role, should be one of: ".implode(' ', $_PEAR_Common_file_roles);
}
- if ($fa['role'] == 'php') {
- $srcinfo = $this->analyzeSourceCode($file);
- $this->buildProvidesArray($srcinfo);
+ if ($fa['role'] == 'php' && $dir_prefix) {
+ $this->log(1, "Analyzing $file");
+ $srcinfo = $this->analyzeSourceCode($dir_prefix . DIRECTORY_SEPARATOR . $file);
+ if ($srcinfo) {
+ $this->buildProvidesArray($srcinfo);
+ }
}
// (ssb) Any checks we can do for baseinstalldir?
// (cox) Perhaps checks that either the target dir and
}
$this->pkginfo['provides'][$key] =
array('type' => 'class', 'name' => $class);
- //var_dump($key, $this->pkginfo['provides'][$key]);
}
foreach ($srcinfo['declared_methods'] as $class => $methods) {
foreach ($methods as $method) {
}
$this->pkginfo['provides'][$key] =
array('type' => 'function', 'name' => $function);
- //var_dump($key, $this->pkginfo['provides'][$key]);
}
}
foreach ($srcinfo['declared_functions'] as $function) {
}
$this->pkginfo['provides'][$key] =
array('type' => 'function', 'name' => $function);
- //var_dump($key, $this->pkginfo['provides'][$key]);
}
}
function PEAR_Packager()
{
- $this->PEAR_Common();
+ parent::PEAR_Common();
}
// }}}
function _PEAR_Packager()
{
- $this->_PEAR_Common();
+ parent::_PEAR_Common();
}
// }}}
if (PEAR::isError($pkginfo)) {
return $this->raiseError($pkginfo);
}
- if (empty($pkginfo['version'])) {
+ if (empty($this->pkginfo['version'])) {
return $this->raiseError("No version info found in $pkgfile");
}
// TMP DIR -------------------------------------------------
// We allow calls like "pear package /home/user/mypack/package.xml"
$oldcwd = getcwd();
- if (!@chdir(dirname($pkgfile))) {
- return $this->raiseError('Could not chdir to '.dirname($pkgfile));
+ $dir = dirname($pkgfile);
+ if (!@chdir($dir)) {
+ return $this->raiseError('Could not chdir to '.$dir);
}
$pkgfile = basename($pkgfile);
- if (@$pkginfo['release_state'] == 'snapshot' && empty($pkginfo['version'])) {
- $pkginfo['version'] = date('Ymd');
+ if (@$this->pkginfo['release_state'] == 'snapshot' && empty($this->pkginfo['version'])) {
+ $this->pkginfo['version'] = date('Ymd');
}
// don't want strange characters
- $pkgname = preg_replace('/[^a-z0-9._]/i', '_', $pkginfo['package']);
- $pkgversion = preg_replace('/[^a-z0-9._-]/i', '_', $pkginfo['version']);
+ $pkgname = preg_replace('/[^a-z0-9._]/i', '_', $this->pkginfo['package']);
+ $pkgversion = preg_replace('/[^a-z0-9._-]/i', '_', $this->pkginfo['version']);
$pkgver = $pkgname . '-' . $pkgversion;
+ $errors = $warnings = array();
+ $this->validatePackageInfo($this->pkginfo, $errors, $warnings, $dir);
+ foreach ($warnings as $w) {
+ $this->log(1, "Warning: $w");
+ }
+ foreach ($errors as $e) {
+ $this->log(0, "Error: $e");
+ }
+ if (sizeof($errors) > 0) {
+ chdir($oldcwd);
+ return $this->raiseError('Errors in package');
+ }
+
// ----- Create the package file list
$filelist = array();
$i = 0;
// Copy files -----------------------------------------------
- foreach ($pkginfo['filelist'] as $fname => $atts) {
+ foreach ($this->pkginfo['filelist'] as $fname => $atts) {
if (!file_exists($fname)) {
chdir($oldcwd);
- return $this->raiseError("File $fname does not exist");
+ return $this->raiseError("File does not exist: $fname");
} else {
$filelist[$i++] = $fname;
- if (empty($pkginfo['filelist'][$fname]['md5sum'])) {
+ if (empty($this->pkginfo['filelist'][$fname]['md5sum'])) {
$md5sum = md5_file($fname);
- $pkginfo['filelist'][$fname]['md5sum'] = $md5sum;
+ $this->pkginfo['filelist'][$fname]['md5sum'] = $md5sum;
}
$this->log(2, "Adding file $fname");
}
}
- $new_xml = $this->xmlFromInfo($pkginfo);
+ $new_xml = $this->xmlFromInfo($this->pkginfo);
if (PEAR::isError($new_xml)) {
chdir($oldcwd);
return $this->raiseError($new_xml);
}
if (!($tmpdir = System::mktemp('-t '.getcwd().' -d'))) {
+ chdir($oldcwd);
return $this->raiseError("PEAR_Packager: mktemp failed");
}
$newpkgfile = $tmpdir . DIRECTORY_SEPARATOR . 'package.xml';
PEAR INSTALLER:
-* Packaging and validation now tokenizes source code (unless
+* Packaging and validation now parses PHP source code (unless
ext/tokenizer is disabled) and does some coding standard conformance
checks. Specifically, the names of classes and functions are
checked to ensure that they are prefixed with the package name. If