home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / tmp / PEAR-1.7.1 / PEAR / Command / Pickle.php < prev    next >
Encoding:
PHP Script  |  2008-02-15  |  15.8 KB  |  377 lines

  1. <?php
  2. /**
  3.  * PEAR_Command_Pickle (pickle command)
  4.  *
  5.  * PHP versions 4 and 5
  6.  *
  7.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  8.  * that is available through the world-wide-web at the following URI:
  9.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  10.  * the PHP License and are unable to obtain it through the web, please
  11.  * send a note to license@php.net so we can mail you a copy immediately.
  12.  *
  13.  * @category   pear
  14.  * @package    PEAR
  15.  * @author     Greg Beaver <cellog@php.net>
  16.  * @copyright  2005-2008 The PHP Group
  17.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  18.  * @version    CVS: $Id: Pickle.php,v 1.8 2008/01/29 03:21:01 cellog Exp $
  19.  * @link       http://pear.php.net/package/PEAR
  20.  * @since      File available since Release 1.4.1
  21.  */
  22.  
  23. /**
  24.  * base class
  25.  */
  26. require_once 'PEAR/Command/Common.php';
  27.  
  28. /**
  29.  * PEAR commands for login/logout
  30.  *
  31.  * @category   pear
  32.  * @package    PEAR
  33.  * @author     Greg Beaver <cellog@php.net>
  34.  * @copyright  2005-2008 The PHP Group
  35.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  36.  * @version    Release: 1.7.1
  37.  * @link       http://pear.php.net/package/PEAR
  38.  * @since      Class available since Release 1.4.1
  39.  */
  40.  
  41. class PEAR_Command_Pickle extends PEAR_Command_Common
  42. {
  43.     var $commands = array(
  44.         'pickle' => array(
  45.             'summary' => 'Build PECL Package',
  46.             'function' => 'doPackage',
  47.             'shortcut' => 'pi',
  48.             'options' => array(
  49.                 'nocompress' => array(
  50.                     'shortopt' => 'Z',
  51.                     'doc' => 'Do not gzip the package file'
  52.                     ),
  53.                 'showname' => array(
  54.                     'shortopt' => 'n',
  55.                     'doc' => 'Print the name of the packaged file.',
  56.                     ),
  57.                 ),
  58.             'doc' => '[descfile]
  59. Creates a PECL package from its package2.xml file.
  60.  
  61. An automatic conversion will be made to a package.xml 1.0 and written out to
  62. disk in the current directory as "package.xml".  Note that
  63. only simple package.xml 2.0 will be converted.  package.xml 2.0 with:
  64.  
  65.  - dependency types other than required/optional PECL package/ext/php/pearinstaller
  66.  - more than one extsrcrelease or zendextsrcrelease
  67.  - zendextbinrelease, extbinrelease, phprelease, or bundle release type
  68.  - dependency groups
  69.  - ignore tags in release filelist
  70.  - tasks other than replace
  71.  - custom roles
  72.  
  73. will cause pickle to fail, and output an error message.  If your package2.xml
  74. uses any of these features, you are best off using PEAR_PackageFileManager to
  75. generate both package.xml.
  76. '
  77.             ),
  78.         );
  79.  
  80.     /**
  81.      * PEAR_Command_Package constructor.
  82.      *
  83.      * @access public
  84.      */
  85.     function PEAR_Command_Pickle(&$ui, &$config)
  86.     {
  87.         parent::PEAR_Command_Common($ui, $config);
  88.     }
  89.  
  90.  
  91.     /**
  92.      * For unit-testing ease
  93.      *
  94.      * @return PEAR_Packager
  95.      */
  96.     function &getPackager()
  97.     {
  98.         if (!class_exists('PEAR_Packager')) {
  99.             require_once 'PEAR/Packager.php';
  100.         }
  101.         $a = &new PEAR_Packager;
  102.         return $a;
  103.     }
  104.  
  105.     /**
  106.      * For unit-testing ease
  107.      *
  108.      * @param PEAR_Config $config
  109.      * @param bool $debug
  110.      * @param string|null $tmpdir
  111.      * @return PEAR_PackageFile
  112.      */
  113.     function &getPackageFile($config, $debug = false, $tmpdir = null)
  114.     {
  115.         if (!class_exists('PEAR_Common')) {
  116.             require_once 'PEAR/Common.php';
  117.         }
  118.         if (!class_exists('PEAR_PackageFile')) {
  119.             require_once 'PEAR/PackageFile.php';
  120.         }
  121.         $a = &new PEAR_PackageFile($config, $debug, $tmpdir);
  122.         $common = new PEAR_Common;
  123.         $common->ui = $this->ui;
  124.         $a->setLogger($common);
  125.         return $a;
  126.     }
  127.  
  128.     function doPackage($command, $options, $params)
  129.     {
  130.         $this->output = '';
  131.         $pkginfofile = isset($params[0]) ? $params[0] : 'package2.xml';
  132.         $packager = &$this->getPackager();
  133.         if (PEAR::isError($err = $this->_convertPackage($pkginfofile))) {
  134.             return $err;
  135.         }
  136.         $compress = empty($options['nocompress']) ? true : false;
  137.         $result = $packager->package($pkginfofile, $compress, 'package.xml');
  138.         if (PEAR::isError($result)) {
  139.             return $this->raiseError($result);
  140.         }
  141.         // Don't want output, only the package file name just created
  142.         if (isset($options['showname'])) {
  143.             $this->ui->outputData($result, $command);
  144.         }
  145.         return true;
  146.     }
  147.  
  148.     function _convertPackage($packagexml)
  149.     {
  150.         $pkg = &$this->getPackageFile($this->config);
  151.         $pf2 = &$pkg->fromPackageFile($packagexml, PEAR_VALIDATE_NORMAL);
  152.         if (!is_a($pf2, 'PEAR_PackageFile_v2')) {
  153.             return $this->raiseError('Cannot process "' .
  154.                 $packagexml . '", is not a package.xml 2.0');
  155.         }
  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');
  163.         }
  164.         if (is_array($pf2->getUsesRole())) {
  165.             return $this->raiseError('Cannot safely convert "' . $packagexml .
  166.             '", contains custom roles.  Using a PEAR_PackageFileManager-based script or ' .
  167.             'the convert command is an option');
  168.         }
  169.         if (is_array($pf2->getUsesTask())) {
  170.             return $this->raiseError('Cannot safely convert "' . $packagexml .
  171.             '", contains custom tasks.  Using a PEAR_PackageFileManager-based script or ' .
  172.             'the convert command is an option');
  173.         }
  174.         $deps = $pf2->getDependencies();
  175.         if (isset($deps['group'])) {
  176.             return $this->raiseError('Cannot safely convert "' . $packagexml .
  177.             '", contains dependency groups.  Using a PEAR_PackageFileManager-based script ' .
  178.             'or the convert command is an option');
  179.         }
  180.         if (isset($deps['required']['subpackage']) ||
  181.               isset($deps['optional']['subpackage'])) {
  182.             return $this->raiseError('Cannot safely convert "' . $packagexml .
  183.             '", contains subpackage dependencies.  Using a PEAR_PackageFileManager-based  '.
  184.             'script is an option');
  185.         }
  186.         if (isset($deps['required']['os'])) {
  187.             return $this->raiseError('Cannot safely convert "' . $packagexml .
  188.             '", contains os dependencies.  Using a PEAR_PackageFileManager-based  '.
  189.             'script is an option');
  190.         }
  191.         if (isset($deps['required']['arch'])) {
  192.             return $this->raiseError('Cannot safely convert "' . $packagexml .
  193.             '", contains arch dependencies.  Using a PEAR_PackageFileManager-based  '.
  194.             'script is an option');
  195.         }
  196.         $pf->setPackage($pf2->getPackage());
  197.         $pf->setSummary($pf2->getSummary());
  198.         $pf->setDescription($pf2->getDescription());
  199.         foreach ($pf2->getMaintainers() as $maintainer) {
  200.             $pf->addMaintainer($maintainer['role'], $maintainer['handle'],
  201.                 $maintainer['name'], $maintainer['email']);
  202.         }
  203.         $pf->setVersion($pf2->getVersion());
  204.         $pf->setDate($pf2->getDate());
  205.         $pf->setLicense($pf2->getLicense());
  206.         $pf->setState($pf2->getState());
  207.         $pf->setNotes($pf2->getNotes());
  208.         $pf->addPhpDep($deps['required']['php']['min'], 'ge');
  209.         if (isset($deps['required']['php']['max'])) {
  210.             $pf->addPhpDep($deps['required']['php']['max'], 'le');
  211.         }
  212.         if (isset($deps['required']['package'])) {
  213.             if (!isset($deps['required']['package'][0])) {
  214.                 $deps['required']['package'] = array($deps['required']['package']);
  215.             }
  216.             foreach ($deps['required']['package'] as $dep) {
  217.                 if (!isset($dep['channel'])) {
  218.                     return $this->raiseError('Cannot safely convert "' . $packagexml . '"' .
  219.                     ' contains uri-based dependency on a package.  Using a ' .
  220.                     'PEAR_PackageFileManager-based script is an option');
  221.                 }
  222.                 if ($dep['channel'] != 'pear.php.net' && $dep['channel'] != 'pecl.php.net') {
  223.                     return $this->raiseError('Cannot safely convert "' . $packagexml . '"' .
  224.                     ' contains dependency on a non-standard channel package.  Using a ' .
  225.                     'PEAR_PackageFileManager-based script is an option');
  226.                 }
  227.                 if (isset($dep['conflicts'])) {
  228.                     return $this->raiseError('Cannot safely convert "' . $packagexml . '"' .
  229.                     ' contains conflicts dependency.  Using a ' .
  230.                     'PEAR_PackageFileManager-based script is an option');
  231.                 }
  232.                 if (isset($dep['exclude'])) {
  233.                     $this->ui->outputData('WARNING: exclude tags are ignored in conversion');
  234.                 }
  235.                 if (isset($dep['min'])) {
  236.                     $pf->addPackageDep($dep['name'], $dep['min'], 'ge');
  237.                 }
  238.                 if (isset($dep['max'])) {
  239.                     $pf->addPackageDep($dep['name'], $dep['max'], 'le');
  240.                 }
  241.             }
  242.         }
  243.         if (isset($deps['required']['extension'])) {
  244.             if (!isset($deps['required']['extension'][0])) {
  245.                 $deps['required']['extension'] = array($deps['required']['extension']);
  246.             }
  247.             foreach ($deps['required']['extension'] as $dep) {
  248.                 if (isset($dep['conflicts'])) {
  249.                     return $this->raiseError('Cannot safely convert "' . $packagexml . '"' .
  250.                     ' contains conflicts dependency.  Using a ' .
  251.                     'PEAR_PackageFileManager-based script is an option');
  252.                 }
  253.                 if (isset($dep['exclude'])) {
  254.                     $this->ui->outputData('WARNING: exclude tags are ignored in conversion');
  255.                 }
  256.                 if (isset($dep['min'])) {
  257.                     $pf->addExtensionDep($dep['name'], $dep['min'], 'ge');
  258.                 }
  259.                 if (isset($dep['max'])) {
  260.                     $pf->addExtensionDep($dep['name'], $dep['max'], 'le');
  261.                 }
  262.             }
  263.         }
  264.         if (isset($deps['optional']['package'])) {
  265.             if (!isset($deps['optional']['package'][0])) {
  266.                 $deps['optional']['package'] = array($deps['optional']['package']);
  267.             }
  268.             foreach ($deps['optional']['package'] as $dep) {
  269.                 if (!isset($dep['channel'])) {
  270.                     return $this->raiseError('Cannot safely convert "' . $packagexml . '"' .
  271.                     ' contains uri-based dependency on a package.  Using a ' .
  272.                     'PEAR_PackageFileManager-based script is an option');
  273.                 }
  274.                 if ($dep['channel'] != 'pear.php.net' && $dep['channel'] != 'pecl.php.net') {
  275.                     return $this->raiseError('Cannot safely convert "' . $packagexml . '"' .
  276.                     ' contains dependency on a non-standard channel package.  Using a ' .
  277.                     'PEAR_PackageFileManager-based script is an option');
  278.                 }
  279.                 if (isset($dep['exclude'])) {
  280.                     $this->ui->outputData('WARNING: exclude tags are ignored in conversion');
  281.                 }
  282.                 if (isset($dep['min'])) {
  283.                     $pf->addPackageDep($dep['name'], $dep['min'], 'ge', 'yes');
  284.                 }
  285.                 if (isset($dep['max'])) {
  286.                     $pf->addPackageDep($dep['name'], $dep['max'], 'le', 'yes');
  287.                 }
  288.             }
  289.         }
  290.         if (isset($deps['optional']['extension'])) {
  291.             if (!isset($deps['optional']['extension'][0])) {
  292.                 $deps['optional']['extension'] = array($deps['optional']['extension']);
  293.             }
  294.             foreach ($deps['optional']['extension'] as $dep) {
  295.                 if (isset($dep['exclude'])) {
  296.                     $this->ui->outputData('WARNING: exclude tags are ignored in conversion');
  297.                 }
  298.                 if (isset($dep['min'])) {
  299.                     $pf->addExtensionDep($dep['name'], $dep['min'], 'ge', 'yes');
  300.                 }
  301.                 if (isset($dep['max'])) {
  302.                     $pf->addExtensionDep($dep['name'], $dep['max'], 'le', 'yes');
  303.                 }
  304.             }
  305.         }
  306.         $contents = $pf2->getContents();
  307.         $release = $pf2->getReleases();
  308.         if (isset($releases[0])) {
  309.             return $this->raiseError('Cannot safely process "' . $packagexml . '" contains ' 
  310.             . 'multiple extsrcrelease/zendextsrcrelease tags.  Using a PEAR_PackageFileManager-based script ' .
  311.             'or the convert command is an option');
  312.         }
  313.         if ($configoptions = $pf2->getConfigureOptions()) {
  314.             foreach ($configoptions as $option) {
  315.                 $pf->addConfigureOption($option['name'], $option['prompt'],
  316.                     isset($option['default']) ? $option['default'] : false);
  317.             }
  318.         }
  319.         if (isset($release['filelist']['ignore'])) {
  320.             return $this->raiseError('Cannot safely process "' . $packagexml . '" contains ' 
  321.             . 'ignore tags.  Using a PEAR_PackageFileManager-based script or the convert' .
  322.             ' command is an option');
  323.         }
  324.         if (isset($release['filelist']['install']) &&
  325.               !isset($release['filelist']['install'][0])) {
  326.             $release['filelist']['install'] = array($release['filelist']['install']);
  327.         }
  328.         if (isset($contents['dir']['attribs']['baseinstalldir'])) {
  329.             $baseinstalldir = $contents['dir']['attribs']['baseinstalldir'];
  330.         } else {
  331.             $baseinstalldir = false;
  332.         }
  333.         if (!isset($contents['dir']['file'][0])) {
  334.             $contents['dir']['file'] = array($contents['dir']['file']);
  335.         }
  336.         foreach ($contents['dir']['file'] as $file) {
  337.             if ($baseinstalldir && !isset($file['attribs']['baseinstalldir'])) {
  338.                 $file['attribs']['baseinstalldir'] = $baseinstalldir;
  339.             }
  340.             $processFile = $file;
  341.             unset($processFile['attribs']);
  342.             if (count($processFile)) {
  343.                 foreach ($processFile as $name => $task) {
  344.                     if ($name != $pf2->getTasksNs() . ':replace') {
  345.                         return $this->raiseError('Cannot safely process "' . $packagexml .
  346.                         '" contains tasks other than replace.  Using a ' .
  347.                         'PEAR_PackageFileManager-based script is an option.');
  348.                     }
  349.                     $file['attribs']['replace'][] = $task;
  350.                 }
  351.             }
  352.             if (!in_array($file['attribs']['role'], PEAR_Common::getFileRoles())) {
  353.                 return $this->raiseError('Cannot safely convert "' . $packagexml .
  354.                 '", contains custom roles.  Using a PEAR_PackageFileManager-based script ' .
  355.                 'or the convert command is an option');
  356.             }
  357.             if (isset($release['filelist']['install'])) {
  358.                 foreach ($release['filelist']['install'] as $installas) {
  359.                     if ($installas['attribs']['name'] == $file['attribs']['name']) {
  360.                         $file['attribs']['install-as'] = $installas['attribs']['as'];
  361.                     }
  362.                 }
  363.             }
  364.             $pf->addFile('/', $file['attribs']['name'], $file['attribs']);
  365.         }
  366.         if ($pf2->getChangeLog()) {
  367.             $this->ui->outputData('WARNING: changelog is not translated to package.xml ' .
  368.                 '1.0, use PEAR_PackageFileManager-based script if you need changelog-' .
  369.                 'translation for package.xml 1.0');
  370.         }
  371.         $gen = &$pf->getDefaultGenerator();
  372.         $gen->toPackageFile('.');
  373.     }
  374. }
  375.  
  376. ?>
  377.