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