Subversion Repositories Applications.gtt

Rev

Rev 94 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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