Subversion Repositories Applications.gtt

Rev

Rev 94 | Details | Compare with Previous | Last modification | View Log | RSS feed

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