3 * PEAR_Command_Pickle (pickle command)
9 * @author Greg Beaver <cellog@php.net>
10 * @copyright 2005-2009 The Authors
11 * @license http://opensource.org/licenses/bsd-license.php New BSD License
12 * @version CVS: $Id: Pickle.php 313023 2011-07-06 19:17:11Z dufuz $
13 * @link http://pear.php.net/package/PEAR
14 * @since File available since Release 1.4.1
20 require_once 'PEAR/Command/Common.php';
23 * PEAR commands for login/logout
27 * @author Greg Beaver <cellog@php.net>
28 * @copyright 2005-2009 The Authors
29 * @license http://opensource.org/licenses/bsd-license.php New BSD License
30 * @version Release: 1.9.4
31 * @link http://pear.php.net/package/PEAR
32 * @since Class available since Release 1.4.1
35 class PEAR_Command_Pickle extends PEAR_Command_Common
37 var $commands = array(
39 'summary' => 'Build PECL Package',
40 'function' => 'doPackage',
43 'nocompress' => array(
45 'doc' => 'Do not gzip the package file'
49 'doc' => 'Print the name of the packaged file.',
53 Creates a PECL package from its package2.xml file.
55 An automatic conversion will be made to a package.xml 1.0 and written out to
56 disk in the current directory as "package.xml". Note that
57 only simple package.xml 2.0 will be converted. package.xml 2.0 with:
59 - dependency types other than required/optional PECL package/ext/php/pearinstaller
60 - more than one extsrcrelease or zendextsrcrelease
61 - zendextbinrelease, extbinrelease, phprelease, or bundle release type
63 - ignore tags in release filelist
64 - tasks other than replace
67 will cause pickle to fail, and output an error message. If your package2.xml
68 uses any of these features, you are best off using PEAR_PackageFileManager to
69 generate both package.xml.
75 * PEAR_Command_Package constructor.
79 function PEAR_Command_Pickle(&$ui, &$config)
81 parent::PEAR_Command_Common($ui, $config);
85 * For unit-testing ease
87 * @return PEAR_Packager
89 function &getPackager()
91 if (!class_exists('PEAR_Packager')) {
92 require_once 'PEAR/Packager.php';
95 $a = &new PEAR_Packager;
100 * For unit-testing ease
102 * @param PEAR_Config $config
104 * @param string|null $tmpdir
105 * @return PEAR_PackageFile
107 function &getPackageFile($config, $debug = false)
109 if (!class_exists('PEAR_Common')) {
110 require_once 'PEAR/Common.php';
113 if (!class_exists('PEAR_PackageFile')) {
114 require_once 'PEAR/PackageFile.php';
117 $a = &new PEAR_PackageFile($config, $debug);
118 $common = new PEAR_Common;
119 $common->ui = $this->ui;
120 $a->setLogger($common);
124 function doPackage($command, $options, $params)
127 $pkginfofile = isset($params[0]) ? $params[0] : 'package2.xml';
128 $packager = &$this->getPackager();
129 if (PEAR::isError($err = $this->_convertPackage($pkginfofile))) {
133 $compress = empty($options['nocompress']) ? true : false;
134 $result = $packager->package($pkginfofile, $compress, 'package.xml');
135 if (PEAR::isError($result)) {
136 return $this->raiseError($result);
139 // Don't want output, only the package file name just created
140 if (isset($options['showname'])) {
141 $this->ui->outputData($result, $command);
147 function _convertPackage($packagexml)
149 $pkg = &$this->getPackageFile($this->config);
150 $pf2 = &$pkg->fromPackageFile($packagexml, PEAR_VALIDATE_NORMAL);
151 if (!is_a($pf2, 'PEAR_PackageFile_v2')) {
152 return $this->raiseError('Cannot process "' .
153 $packagexml . '", is not a package.xml 2.0');
156 require_once 'PEAR/PackageFile/v1.php';
157 $pf = new PEAR_PackageFile_v1;
158 $pf->setConfig($this->config);
159 if ($pf2->getPackageType() != 'extsrc' && $pf2->getPackageType() != 'zendextsrc') {
160 return $this->raiseError('Cannot safely convert "' . $packagexml .
161 '", is not an extension source package. Using a PEAR_PackageFileManager-based ' .
162 'script is an option');
165 if (is_array($pf2->getUsesRole())) {
166 return $this->raiseError('Cannot safely convert "' . $packagexml .
167 '", contains custom roles. Using a PEAR_PackageFileManager-based script or ' .
168 'the convert command is an option');
171 if (is_array($pf2->getUsesTask())) {
172 return $this->raiseError('Cannot safely convert "' . $packagexml .
173 '", contains custom tasks. Using a PEAR_PackageFileManager-based script or ' .
174 'the convert command is an option');
177 $deps = $pf2->getDependencies();
178 if (isset($deps['group'])) {
179 return $this->raiseError('Cannot safely convert "' . $packagexml .
180 '", contains dependency groups. Using a PEAR_PackageFileManager-based script ' .
181 'or the convert command is an option');
184 if (isset($deps['required']['subpackage']) ||
185 isset($deps['optional']['subpackage'])) {
186 return $this->raiseError('Cannot safely convert "' . $packagexml .
187 '", contains subpackage dependencies. Using a PEAR_PackageFileManager-based '.
188 'script is an option');
191 if (isset($deps['required']['os'])) {
192 return $this->raiseError('Cannot safely convert "' . $packagexml .
193 '", contains os dependencies. Using a PEAR_PackageFileManager-based '.
194 'script is an option');
197 if (isset($deps['required']['arch'])) {
198 return $this->raiseError('Cannot safely convert "' . $packagexml .
199 '", contains arch dependencies. Using a PEAR_PackageFileManager-based '.
200 'script is an option');
203 $pf->setPackage($pf2->getPackage());
204 $pf->setSummary($pf2->getSummary());
205 $pf->setDescription($pf2->getDescription());
206 foreach ($pf2->getMaintainers() as $maintainer) {
207 $pf->addMaintainer($maintainer['role'], $maintainer['handle'],
208 $maintainer['name'], $maintainer['email']);
211 $pf->setVersion($pf2->getVersion());
212 $pf->setDate($pf2->getDate());
213 $pf->setLicense($pf2->getLicense());
214 $pf->setState($pf2->getState());
215 $pf->setNotes($pf2->getNotes());
216 $pf->addPhpDep($deps['required']['php']['min'], 'ge');
217 if (isset($deps['required']['php']['max'])) {
218 $pf->addPhpDep($deps['required']['php']['max'], 'le');
221 if (isset($deps['required']['package'])) {
222 if (!isset($deps['required']['package'][0])) {
223 $deps['required']['package'] = array($deps['required']['package']);
226 foreach ($deps['required']['package'] as $dep) {
227 if (!isset($dep['channel'])) {
228 return $this->raiseError('Cannot safely convert "' . $packagexml . '"' .
229 ' contains uri-based dependency on a package. Using a ' .
230 'PEAR_PackageFileManager-based script is an option');
233 if ($dep['channel'] != 'pear.php.net'
234 && $dep['channel'] != 'pecl.php.net'
235 && $dep['channel'] != 'doc.php.net') {
236 return $this->raiseError('Cannot safely convert "' . $packagexml . '"' .
237 ' contains dependency on a non-standard channel package. Using a ' .
238 'PEAR_PackageFileManager-based script is an option');
241 if (isset($dep['conflicts'])) {
242 return $this->raiseError('Cannot safely convert "' . $packagexml . '"' .
243 ' contains conflicts dependency. Using a ' .
244 'PEAR_PackageFileManager-based script is an option');
247 if (isset($dep['exclude'])) {
248 $this->ui->outputData('WARNING: exclude tags are ignored in conversion');
251 if (isset($dep['min'])) {
252 $pf->addPackageDep($dep['name'], $dep['min'], 'ge');
255 if (isset($dep['max'])) {
256 $pf->addPackageDep($dep['name'], $dep['max'], 'le');
261 if (isset($deps['required']['extension'])) {
262 if (!isset($deps['required']['extension'][0])) {
263 $deps['required']['extension'] = array($deps['required']['extension']);
266 foreach ($deps['required']['extension'] as $dep) {
267 if (isset($dep['conflicts'])) {
268 return $this->raiseError('Cannot safely convert "' . $packagexml . '"' .
269 ' contains conflicts dependency. Using a ' .
270 'PEAR_PackageFileManager-based script is an option');
273 if (isset($dep['exclude'])) {
274 $this->ui->outputData('WARNING: exclude tags are ignored in conversion');
277 if (isset($dep['min'])) {
278 $pf->addExtensionDep($dep['name'], $dep['min'], 'ge');
281 if (isset($dep['max'])) {
282 $pf->addExtensionDep($dep['name'], $dep['max'], 'le');
287 if (isset($deps['optional']['package'])) {
288 if (!isset($deps['optional']['package'][0])) {
289 $deps['optional']['package'] = array($deps['optional']['package']);
292 foreach ($deps['optional']['package'] as $dep) {
293 if (!isset($dep['channel'])) {
294 return $this->raiseError('Cannot safely convert "' . $packagexml . '"' .
295 ' contains uri-based dependency on a package. Using a ' .
296 'PEAR_PackageFileManager-based script is an option');
299 if ($dep['channel'] != 'pear.php.net'
300 && $dep['channel'] != 'pecl.php.net'
301 && $dep['channel'] != 'doc.php.net') {
302 return $this->raiseError('Cannot safely convert "' . $packagexml . '"' .
303 ' contains dependency on a non-standard channel package. Using a ' .
304 'PEAR_PackageFileManager-based script is an option');
307 if (isset($dep['exclude'])) {
308 $this->ui->outputData('WARNING: exclude tags are ignored in conversion');
311 if (isset($dep['min'])) {
312 $pf->addPackageDep($dep['name'], $dep['min'], 'ge', 'yes');
315 if (isset($dep['max'])) {
316 $pf->addPackageDep($dep['name'], $dep['max'], 'le', 'yes');
321 if (isset($deps['optional']['extension'])) {
322 if (!isset($deps['optional']['extension'][0])) {
323 $deps['optional']['extension'] = array($deps['optional']['extension']);
326 foreach ($deps['optional']['extension'] as $dep) {
327 if (isset($dep['exclude'])) {
328 $this->ui->outputData('WARNING: exclude tags are ignored in conversion');
331 if (isset($dep['min'])) {
332 $pf->addExtensionDep($dep['name'], $dep['min'], 'ge', 'yes');
335 if (isset($dep['max'])) {
336 $pf->addExtensionDep($dep['name'], $dep['max'], 'le', 'yes');
341 $contents = $pf2->getContents();
342 $release = $pf2->getReleases();
343 if (isset($releases[0])) {
344 return $this->raiseError('Cannot safely process "' . $packagexml . '" contains '
345 . 'multiple extsrcrelease/zendextsrcrelease tags. Using a PEAR_PackageFileManager-based script ' .
346 'or the convert command is an option');
349 if ($configoptions = $pf2->getConfigureOptions()) {
350 foreach ($configoptions as $option) {
351 $default = isset($option['default']) ? $option['default'] : false;
352 $pf->addConfigureOption($option['name'], $option['prompt'], $default);
356 if (isset($release['filelist']['ignore'])) {
357 return $this->raiseError('Cannot safely process "' . $packagexml . '" contains '
358 . 'ignore tags. Using a PEAR_PackageFileManager-based script or the convert' .
359 ' command is an option');
362 if (isset($release['filelist']['install']) &&
363 !isset($release['filelist']['install'][0])) {
364 $release['filelist']['install'] = array($release['filelist']['install']);
367 if (isset($contents['dir']['attribs']['baseinstalldir'])) {
368 $baseinstalldir = $contents['dir']['attribs']['baseinstalldir'];
370 $baseinstalldir = false;
373 if (!isset($contents['dir']['file'][0])) {
374 $contents['dir']['file'] = array($contents['dir']['file']);
377 foreach ($contents['dir']['file'] as $file) {
378 if ($baseinstalldir && !isset($file['attribs']['baseinstalldir'])) {
379 $file['attribs']['baseinstalldir'] = $baseinstalldir;
382 $processFile = $file;
383 unset($processFile['attribs']);
384 if (count($processFile)) {
385 foreach ($processFile as $name => $task) {
386 if ($name != $pf2->getTasksNs() . ':replace') {
387 return $this->raiseError('Cannot safely process "' . $packagexml .
388 '" contains tasks other than replace. Using a ' .
389 'PEAR_PackageFileManager-based script is an option.');
391 $file['attribs']['replace'][] = $task;
395 if (!in_array($file['attribs']['role'], PEAR_Common::getFileRoles())) {
396 return $this->raiseError('Cannot safely convert "' . $packagexml .
397 '", contains custom roles. Using a PEAR_PackageFileManager-based script ' .
398 'or the convert command is an option');
401 if (isset($release['filelist']['install'])) {
402 foreach ($release['filelist']['install'] as $installas) {
403 if ($installas['attribs']['name'] == $file['attribs']['name']) {
404 $file['attribs']['install-as'] = $installas['attribs']['as'];
409 $pf->addFile('/', $file['attribs']['name'], $file['attribs']);
412 if ($pf2->getChangeLog()) {
413 $this->ui->outputData('WARNING: changelog is not translated to package.xml ' .
414 '1.0, use PEAR_PackageFileManager-based script if you need changelog-' .
415 'translation for package.xml 1.0');
418 $gen = &$pf->getDefaultGenerator();
419 $gen->toPackageFile('.');