PageRenderTime 38ms CodeModel.GetById 23ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/php/PEAR/Packager.php

https://bitbucket.org/adarshj/convenient_website
PHP | 201 lines | 139 code | 24 blank | 38 comment | 25 complexity | 5e553c0ac9530fc8757735675f0837ee MD5 | raw file
  1<?php
  2/**
  3 * PEAR_Packager for generating releases
  4 *
  5 * PHP versions 4 and 5
  6 *
  7 * @category   pear
  8 * @package    PEAR
  9 * @author     Stig Bakken <ssb@php.net>
 10 * @author     Tomas V. V. Cox <cox@idecnet.com>
 11 * @author     Greg Beaver <cellog@php.net>
 12 * @copyright  1997-2009 The Authors
 13 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
 14 * @version    CVS: $Id: Packager.php 313023 2011-07-06 19:17:11Z dufuz $
 15 * @link       http://pear.php.net/package/PEAR
 16 * @since      File available since Release 0.1
 17 */
 18
 19/**
 20 * base class
 21 */
 22require_once 'PEAR/Common.php';
 23require_once 'PEAR/PackageFile.php';
 24require_once 'System.php';
 25
 26/**
 27 * Administration class used to make a PEAR release tarball.
 28 *
 29 * @category   pear
 30 * @package    PEAR
 31 * @author     Greg Beaver <cellog@php.net>
 32 * @copyright  1997-2009 The Authors
 33 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
 34 * @version    Release: 1.9.4
 35 * @link       http://pear.php.net/package/PEAR
 36 * @since      Class available since Release 0.1
 37 */
 38class PEAR_Packager extends PEAR_Common
 39{
 40    /**
 41     * @var PEAR_Registry
 42     */
 43    var $_registry;
 44
 45    function package($pkgfile = null, $compress = true, $pkg2 = null)
 46    {
 47        // {{{ validate supplied package.xml file
 48        if (empty($pkgfile)) {
 49            $pkgfile = 'package.xml';
 50        }
 51
 52        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
 53        $pkg  = &new PEAR_PackageFile($this->config, $this->debug);
 54        $pf   = &$pkg->fromPackageFile($pkgfile, PEAR_VALIDATE_NORMAL);
 55        $main = &$pf;
 56        PEAR::staticPopErrorHandling();
 57        if (PEAR::isError($pf)) {
 58            if (is_array($pf->getUserInfo())) {
 59                foreach ($pf->getUserInfo() as $error) {
 60                    $this->log(0, 'Error: ' . $error['message']);
 61                }
 62            }
 63
 64            $this->log(0, $pf->getMessage());
 65            return $this->raiseError("Cannot package, errors in package file");
 66        }
 67
 68        foreach ($pf->getValidationWarnings() as $warning) {
 69            $this->log(1, 'Warning: ' . $warning['message']);
 70        }
 71
 72        // }}}
 73        if ($pkg2) {
 74            $this->log(0, 'Attempting to process the second package file');
 75            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
 76            $pf2 = &$pkg->fromPackageFile($pkg2, PEAR_VALIDATE_NORMAL);
 77            PEAR::staticPopErrorHandling();
 78            if (PEAR::isError($pf2)) {
 79                if (is_array($pf2->getUserInfo())) {
 80                    foreach ($pf2->getUserInfo() as $error) {
 81                        $this->log(0, 'Error: ' . $error['message']);
 82                    }
 83                }
 84                $this->log(0, $pf2->getMessage());
 85                return $this->raiseError("Cannot package, errors in second package file");
 86            }
 87
 88            foreach ($pf2->getValidationWarnings() as $warning) {
 89                $this->log(1, 'Warning: ' . $warning['message']);
 90            }
 91
 92            if ($pf2->getPackagexmlVersion() == '2.0' ||
 93                  $pf2->getPackagexmlVersion() == '2.1'
 94            ) {
 95                $main  = &$pf2;
 96                $other = &$pf;
 97            } else {
 98                $main  = &$pf;
 99                $other = &$pf2;
100            }
101
102            if ($main->getPackagexmlVersion() != '2.0' &&
103                  $main->getPackagexmlVersion() != '2.1') {
104                return PEAR::raiseError('Error: cannot package two package.xml version 1.0, can ' .
105                    'only package together a package.xml 1.0 and package.xml 2.0');
106            }
107
108            if ($other->getPackagexmlVersion() != '1.0') {
109                return PEAR::raiseError('Error: cannot package two package.xml version 2.0, can ' .
110                    'only package together a package.xml 1.0 and package.xml 2.0');
111            }
112        }
113
114        $main->setLogger($this);
115        if (!$main->validate(PEAR_VALIDATE_PACKAGING)) {
116            foreach ($main->getValidationWarnings() as $warning) {
117                $this->log(0, 'Error: ' . $warning['message']);
118            }
119            return $this->raiseError("Cannot package, errors in package");
120        }
121
122        foreach ($main->getValidationWarnings() as $warning) {
123            $this->log(1, 'Warning: ' . $warning['message']);
124        }
125
126        if ($pkg2) {
127            $other->setLogger($this);
128            $a = false;
129            if (!$other->validate(PEAR_VALIDATE_NORMAL) || $a = !$main->isEquivalent($other)) {
130                foreach ($other->getValidationWarnings() as $warning) {
131                    $this->log(0, 'Error: ' . $warning['message']);
132                }
133
134                foreach ($main->getValidationWarnings() as $warning) {
135                    $this->log(0, 'Error: ' . $warning['message']);
136                }
137
138                if ($a) {
139                    return $this->raiseError('The two package.xml files are not equivalent!');
140                }
141
142                return $this->raiseError("Cannot package, errors in package");
143            }
144
145            foreach ($other->getValidationWarnings() as $warning) {
146                $this->log(1, 'Warning: ' . $warning['message']);
147            }
148
149            $gen = &$main->getDefaultGenerator();
150            $tgzfile = $gen->toTgz2($this, $other, $compress);
151            if (PEAR::isError($tgzfile)) {
152                return $tgzfile;
153            }
154
155            $dest_package = basename($tgzfile);
156            $pkgdir       = dirname($pkgfile);
157
158            // TAR the Package -------------------------------------------
159            $this->log(1, "Package $dest_package done");
160            if (file_exists("$pkgdir/CVS/Root")) {
161                $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pf->getVersion());
162                $cvstag = "RELEASE_$cvsversion";
163                $this->log(1, 'Tag the released code with "pear cvstag ' .
164                    $main->getPackageFile() . '"');
165                $this->log(1, "(or set the CVS tag $cvstag by hand)");
166            } elseif (file_exists("$pkgdir/.svn")) {
167                $svnversion = preg_replace('/[^a-z0-9]/i', '.', $pf->getVersion());
168                $svntag = $pf->getName() . "-$svnversion";
169                $this->log(1, 'Tag the released code with "pear svntag ' .
170                    $main->getPackageFile() . '"');
171                $this->log(1, "(or set the SVN tag $svntag by hand)");
172            }
173        } else { // this branch is executed for single packagefile packaging
174            $gen = &$pf->getDefaultGenerator();
175            $tgzfile = $gen->toTgz($this, $compress);
176            if (PEAR::isError($tgzfile)) {
177                $this->log(0, $tgzfile->getMessage());
178                return $this->raiseError("Cannot package, errors in package");
179            }
180
181            $dest_package = basename($tgzfile);
182            $pkgdir       = dirname($pkgfile);
183
184            // TAR the Package -------------------------------------------
185            $this->log(1, "Package $dest_package done");
186            if (file_exists("$pkgdir/CVS/Root")) {
187                $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pf->getVersion());
188                $cvstag = "RELEASE_$cvsversion";
189                $this->log(1, "Tag the released code with `pear cvstag $pkgfile'");
190                $this->log(1, "(or set the CVS tag $cvstag by hand)");
191            } elseif (file_exists("$pkgdir/.svn")) {
192                $svnversion = preg_replace('/[^a-z0-9]/i', '.', $pf->getVersion());
193                $svntag = $pf->getName() . "-$svnversion";
194                $this->log(1, "Tag the released code with `pear svntag $pkgfile'");
195                $this->log(1, "(or set the SVN tag $svntag by hand)");
196            }
197        }
198
199        return $dest_package;
200    }
201}