Skip to content

Commit 0487042

Browse files
committed
* fixed <provides> generation, provides elements are now included for
every non-private class, function and method
1 parent d4dff9e commit 0487042

File tree

4 files changed

+45
-34
lines changed

4 files changed

+45
-34
lines changed

pear/PEAR/Command/Package.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -251,21 +251,14 @@ function doPackage($command, $options, $params)
251251
$this->output = '';
252252
include_once 'PEAR/Packager.php';
253253
$pkginfofile = isset($params[0]) ? $params[0] : 'package.xml';
254-
ob_start();
255254
$packager =& new PEAR_Packager($this->config->get('php_dir'),
256255
$this->config->get('ext_dir'),
257256
$this->config->get('doc_dir'));
258257
$packager->debug = $this->config->get('verbose');
259258
$err = $warn = array();
260-
$packager->validatePackageInfo($pkginfofile, $err, $warn);
261-
if (!$this->_displayValidationResults($err, $warn, true)) {
262-
$this->ui->outputData($this->output, $command);
263-
return;
264-
}
259+
$dir = dirname($pkginfofile);
265260
$compress = empty($options['nocompress']) ? true : false;
266-
$result = $packager->Package($pkginfofile, $compress);
267-
$this->output = ob_get_contents();
268-
ob_end_clean();
261+
$result = $packager->package($pkginfofile, $compress);
269262
if (PEAR::isError($result)) {
270263
$this->ui->outputData($this->output, $command);
271264
return $this->raiseError($result);

pear/PEAR/Common.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -983,13 +983,16 @@ function _makeReleaseXml($pkginfo, $changelog = false)
983983
/**
984984
* Validate XML package definition file.
985985
*
986-
* @param string Filename of the package archive or of the package definition file
987-
* @param array Array that will contain the errors
988-
* @param array Array that will contain the warnings
986+
* @param string $info Filename of the package archive or of the
987+
* package definition file
988+
* @param array $errors Array that will contain the errors
989+
* @param array $warnings Array that will contain the warnings
990+
* @param string $dir_prefix (optional) directory where source files
991+
* may be found, or empty if they are not available
989992
* @access public
990993
* @return boolean
991994
*/
992-
function validatePackageInfo($info, &$errors, &$warnings)
995+
function validatePackageInfo($info, &$errors, &$warnings, $dir_prefix = '')
993996
{
994997
global $_PEAR_Common_maintainer_roles,
995998
$_PEAR_Common_release_states,
@@ -1104,9 +1107,12 @@ function validatePackageInfo($info, &$errors, &$warnings)
11041107
} elseif (!in_array($fa['role'], $_PEAR_Common_file_roles)) {
11051108
$errors[] = "file $file: invalid role, should be one of: ".implode(' ', $_PEAR_Common_file_roles);
11061109
}
1107-
if ($fa['role'] == 'php') {
1108-
$srcinfo = $this->analyzeSourceCode($file);
1109-
$this->buildProvidesArray($srcinfo);
1110+
if ($fa['role'] == 'php' && $dir_prefix) {
1111+
$this->log(1, "Analyzing $file");
1112+
$srcinfo = $this->analyzeSourceCode($dir_prefix . DIRECTORY_SEPARATOR . $file);
1113+
if ($srcinfo) {
1114+
$this->buildProvidesArray($srcinfo);
1115+
}
11101116
}
11111117
// (ssb) Any checks we can do for baseinstalldir?
11121118
// (cox) Perhaps checks that either the target dir and
@@ -1169,7 +1175,6 @@ function buildProvidesArray($srcinfo)
11691175
}
11701176
$this->pkginfo['provides'][$key] =
11711177
array('type' => 'class', 'name' => $class);
1172-
//var_dump($key, $this->pkginfo['provides'][$key]);
11731178
}
11741179
foreach ($srcinfo['declared_methods'] as $class => $methods) {
11751180
foreach ($methods as $method) {
@@ -1181,7 +1186,6 @@ function buildProvidesArray($srcinfo)
11811186
}
11821187
$this->pkginfo['provides'][$key] =
11831188
array('type' => 'function', 'name' => $function);
1184-
//var_dump($key, $this->pkginfo['provides'][$key]);
11851189
}
11861190
}
11871191
foreach ($srcinfo['declared_functions'] as $function) {
@@ -1191,7 +1195,6 @@ function buildProvidesArray($srcinfo)
11911195
}
11921196
$this->pkginfo['provides'][$key] =
11931197
array('type' => 'function', 'name' => $function);
1194-
//var_dump($key, $this->pkginfo['provides'][$key]);
11951198
}
11961199
}
11971200

pear/PEAR/Packager.php

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ class PEAR_Packager extends PEAR_Common
3737

3838
function PEAR_Packager()
3939
{
40-
$this->PEAR_Common();
40+
parent::PEAR_Common();
4141
}
4242

4343
// }}}
4444
// {{{ destructor
4545

4646
function _PEAR_Packager()
4747
{
48-
$this->_PEAR_Common();
48+
parent::_PEAR_Common();
4949
}
5050

5151
// }}}
@@ -61,48 +61,63 @@ function package($pkgfile = null, $compress = true)
6161
if (PEAR::isError($pkginfo)) {
6262
return $this->raiseError($pkginfo);
6363
}
64-
if (empty($pkginfo['version'])) {
64+
if (empty($this->pkginfo['version'])) {
6565
return $this->raiseError("No version info found in $pkgfile");
6666
}
6767
// TMP DIR -------------------------------------------------
6868
// We allow calls like "pear package /home/user/mypack/package.xml"
6969
$oldcwd = getcwd();
70-
if (!@chdir(dirname($pkgfile))) {
71-
return $this->raiseError('Could not chdir to '.dirname($pkgfile));
70+
$dir = dirname($pkgfile);
71+
if (!@chdir($dir)) {
72+
return $this->raiseError('Could not chdir to '.$dir);
7273
}
7374
$pkgfile = basename($pkgfile);
74-
if (@$pkginfo['release_state'] == 'snapshot' && empty($pkginfo['version'])) {
75-
$pkginfo['version'] = date('Ymd');
75+
if (@$this->pkginfo['release_state'] == 'snapshot' && empty($this->pkginfo['version'])) {
76+
$this->pkginfo['version'] = date('Ymd');
7677
}
7778
// don't want strange characters
78-
$pkgname = preg_replace('/[^a-z0-9._]/i', '_', $pkginfo['package']);
79-
$pkgversion = preg_replace('/[^a-z0-9._-]/i', '_', $pkginfo['version']);
79+
$pkgname = preg_replace('/[^a-z0-9._]/i', '_', $this->pkginfo['package']);
80+
$pkgversion = preg_replace('/[^a-z0-9._-]/i', '_', $this->pkginfo['version']);
8081
$pkgver = $pkgname . '-' . $pkgversion;
8182

83+
$errors = $warnings = array();
84+
$this->validatePackageInfo($this->pkginfo, $errors, $warnings, $dir);
85+
foreach ($warnings as $w) {
86+
$this->log(1, "Warning: $w");
87+
}
88+
foreach ($errors as $e) {
89+
$this->log(0, "Error: $e");
90+
}
91+
if (sizeof($errors) > 0) {
92+
chdir($oldcwd);
93+
return $this->raiseError('Errors in package');
94+
}
95+
8296
// ----- Create the package file list
8397
$filelist = array();
8498
$i = 0;
8599

86100
// Copy files -----------------------------------------------
87-
foreach ($pkginfo['filelist'] as $fname => $atts) {
101+
foreach ($this->pkginfo['filelist'] as $fname => $atts) {
88102
if (!file_exists($fname)) {
89103
chdir($oldcwd);
90-
return $this->raiseError("File $fname does not exist");
104+
return $this->raiseError("File does not exist: $fname");
91105
} else {
92106
$filelist[$i++] = $fname;
93-
if (empty($pkginfo['filelist'][$fname]['md5sum'])) {
107+
if (empty($this->pkginfo['filelist'][$fname]['md5sum'])) {
94108
$md5sum = md5_file($fname);
95-
$pkginfo['filelist'][$fname]['md5sum'] = $md5sum;
109+
$this->pkginfo['filelist'][$fname]['md5sum'] = $md5sum;
96110
}
97111
$this->log(2, "Adding file $fname");
98112
}
99113
}
100-
$new_xml = $this->xmlFromInfo($pkginfo);
114+
$new_xml = $this->xmlFromInfo($this->pkginfo);
101115
if (PEAR::isError($new_xml)) {
102116
chdir($oldcwd);
103117
return $this->raiseError($new_xml);
104118
}
105119
if (!($tmpdir = System::mktemp('-t '.getcwd().' -d'))) {
120+
chdir($oldcwd);
106121
return $this->raiseError("PEAR_Packager: mktemp failed");
107122
}
108123
$newpkgfile = $tmpdir . DIRECTORY_SEPARATOR . 'package.xml';

pear/package-PEAR.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ PEAR BASE CLASS:
4444

4545
PEAR INSTALLER:
4646

47-
* Packaging and validation now tokenizes source code (unless
47+
* Packaging and validation now parses PHP source code (unless
4848
ext/tokenizer is disabled) and does some coding standard conformance
4949
checks. Specifically, the names of classes and functions are
5050
checked to ensure that they are prefixed with the package name. If

0 commit comments

Comments
 (0)