9 require_once
'phing/Task.php';
10 require_once
'PEAR/PackageFileManager2.php';
11 require_once
'PEAR/PackageFileManager/File.php';
12 require_once
'PEAR/Packager.php';
17 private $deploy =
true;
18 private $makephar =
true;
20 private $subpackages = array();
24 $this->version = $str;
29 return $this->version;
34 $this->deploy = (bool) $deploy;
44 $this->makephar = (bool) $makephar;
49 return $this->makephar;
54 private $changelog_release_date;
55 private $changelog_notes =
'-';
59 $this->basedir = $this->getProject()->getBasedir();
61 if (!is_dir((
string) $this->basedir.
'/.subsplit')) {
62 throw new BuildException(
'PEAR packaging requires .subsplit directory');
66 $composer_file = file_get_contents((
string) $this->basedir.
'/.subsplit/composer.json');
67 $this->guzzleinfo = json_decode($composer_file,
true);
70 $pearwork = (string) $this->basedir .
'/build/pearwork';
71 if (!is_dir($pearwork)) {
72 mkdir($pearwork, 0777,
true);
74 $pearlogs = (string) $this->basedir .
'/build/artifacts/logs';
75 if (!is_dir($pearlogs)) {
76 mkdir($pearlogs, 0777,
true);
81 if ($version[0] ==
'2') {
82 $this->log(
'building single PEAR package');
92 $this->log(
"building PHAR");
93 $this->getProject()->executeTarget(
'package-phar');
103 $basedir = (string) $this->basedir;
104 $this->log(
'beginning PEAR/PHAR deployment');
106 chdir($basedir .
'/build/pearwork');
107 if (!is_dir(
'./channel')) {
112 passthru(
'aws s3 sync s3://pear.guzzlephp.org ./channel');
115 foreach (scandir(
'./') as $file) {
116 if (substr($file, -4) ==
'.tgz') {
117 passthru(
'pirum add ./channel ' . $file);
122 if ($this->
getMakephar() && file_exists($basedir .
'/build/artifacts/guzzle.phar')) {
123 rename($basedir .
'/build/artifacts/guzzle.phar',
'./channel/guzzle.phar');
127 chdir($basedir .
'/build/pearwork/channel');
128 passthru(
'aws s3 sync . s3://pear.guzzlephp.org');
134 $apiversion = $v[0] .
'.0.0';
137 'packagedirectory' => (
string) $this->basedir .
'/.subsplit/src/',
138 'filelistgenerator' =>
'file',
139 'ignore' => array(
'*composer.json'),
140 'baseinstalldir' =>
'/',
141 'packagefile' =>
'package.xml'
144 $pfm =
new PEAR_PackageFileManager2();
145 $pfm->setOptions($opts);
146 $pfm->addRole(
'md',
'doc');
147 $pfm->addRole(
'pem',
'php');
148 $pfm->setPackage(
'Guzzle');
149 $pfm->setSummary(
"Object-oriented PHP HTTP Client for PHP 5.3+");
150 $pfm->setDescription($this->guzzleinfo[
'description']);
151 $pfm->setPackageType(
'php');
152 $pfm->setChannel(
'guzzlephp.org/pear');
153 $pfm->setAPIVersion($apiversion);
155 $pfm->setAPIStability(
'stable');
156 $pfm->setReleaseStability(
'stable');
157 $pfm->setNotes($this->changelog_notes);
158 $pfm->setPackageType(
'php');
159 $pfm->setLicense(
'MIT',
'http://github.com/guzzle/guzzle/blob/master/LICENSE');
160 $pfm->addMaintainer(
'lead',
'mtdowling',
'Michael Dowling',
'mtdowling@gmail.com',
'yes');
161 $pfm->setDate($this->changelog_release_date);
162 $pfm->generateContents();
164 $phpdep = $this->guzzleinfo[
'require'][
'php'];
165 $phpdep = str_replace(
'>=',
'', $phpdep);
166 $pfm->setPhpDep($phpdep);
167 $pfm->addExtensionDep(
'required',
'curl');
168 $pfm->setPearinstallerDep(
'1.4.6');
169 $pfm->addPackageDepWithChannel(
'required',
'EventDispatcher',
'pear.symfony.com',
'2.1.0');
170 if (!empty($this->subpackages)) {
171 foreach ($this->subpackages as $package) {
172 $pkg = dirname($package);
173 $pkg = str_replace(
'/',
'_', $pkg);
174 $pfm->addConflictingPackageDepWithChannel($pkg,
'guzzlephp.org/pear',
false, $apiversion);
179 $startdir = getcwd();
180 chdir((
string) $this->basedir .
'/build/pearwork');
182 echo
"DEBUGGING GENERATED PACKAGE FILE\n";
183 $result = $pfm->debugPackageFile();
185 $out = $pfm->writePackageFile();
186 echo
"\n\n\nWRITE PACKAGE FILE RESULT:\n";
189 $packager =
new PEAR_Packager();
190 echo
"\n\n\nBUILDING PACKAGE FROM PACKAGE FILE:\n";
191 $dest_package = $packager->package($opts[
'packagedirectory'].
'package.xml');
192 var_dump($dest_package);
194 echo
"\n\n\nDEBUGGING RESULT:\n";
197 echo
"removing package.xml";
198 unlink($opts[
'packagedirectory'].
'package.xml');
199 $log = ob_get_clean();
200 file_put_contents((
string) $this->basedir .
'/build/artifacts/logs/pear_package.log', $log);
208 foreach ($this->subpackages as $package) {
209 $baseinstalldir = dirname($package);
210 $dir = (string) $this->basedir.
'/.subsplit/src/' . $baseinstalldir;
211 $composer_file = file_get_contents((
string) $this->basedir.
'/.subsplit/src/'. $package);
212 $package_info = json_decode($composer_file,
true);
213 $this->log(
'building ' . $package_info[
'target-dir'] .
' subpackage');
220 $package = str_replace(
'/',
'_', $baseinstalldir);
222 'packagedirectory' => $dir,
223 'filelistgenerator' =>
'file',
224 'ignore' => array(
'*composer.json',
'*package.xml'),
225 'baseinstalldir' =>
'/' . $info[
'target-dir'],
226 'packagefile' =>
'package.xml'
228 $pfm =
new PEAR_PackageFileManager2();
229 $pfm->setOptions($opts);
230 $pfm->setPackage($package);
231 $pfm->setSummary($info[
'description']);
232 $pfm->setDescription($info[
'description']);
233 $pfm->setPackageType(
'php');
234 $pfm->setChannel(
'guzzlephp.org/pear');
235 $pfm->setAPIVersion(
'3.0.0');
237 $pfm->setAPIStability(
'stable');
238 $pfm->setReleaseStability(
'stable');
239 $pfm->setNotes($this->changelog_notes);
240 $pfm->setPackageType(
'php');
241 $pfm->setLicense(
'MIT',
'http://github.com/guzzle/guzzle/blob/master/LICENSE');
242 $pfm->addMaintainer(
'lead',
'mtdowling',
'Michael Dowling',
'mtdowling@gmail.com',
'yes');
243 $pfm->setDate($this->changelog_release_date);
244 $pfm->generateContents();
246 $phpdep = $this->guzzleinfo[
'require'][
'php'];
247 $phpdep = str_replace(
'>=',
'', $phpdep);
248 $pfm->setPhpDep($phpdep);
249 $pfm->setPearinstallerDep(
'1.4.6');
251 foreach ($info[
'require'] as $type => $version) {
252 if ($type ==
'php') {
255 if ($type ==
'symfony/event-dispatcher') {
256 $pfm->addPackageDepWithChannel(
'required',
'EventDispatcher',
'pear.symfony.com',
'2.1.0');
258 if ($type ==
'ext-curl') {
259 $pfm->addExtensionDep(
'required',
'curl');
261 if (substr($type, 0, 6) ==
'guzzle') {
262 $gdep = str_replace(
'/',
' ', $type);
263 $gdep = ucwords($gdep);
264 $gdep = str_replace(
' ',
'_', $gdep);
265 $pfm->addPackageDepWithChannel(
'required', $gdep,
'guzzlephp.org/pear', $this->
getVersion());
270 $pfm->addConflictingPackageDepWithChannel(
'Guzzle',
'guzzlephp.org/pear',
false, $apiversion);
273 $startdir = getcwd();
274 chdir((
string) $this->basedir .
'/build/pearwork');
276 echo
"DEBUGGING GENERATED PACKAGE FILE\n";
277 $result = $pfm->debugPackageFile();
279 $out = $pfm->writePackageFile();
280 echo
"\n\n\nWRITE PACKAGE FILE RESULT:\n";
283 $packager =
new PEAR_Packager();
284 echo
"\n\n\nBUILDING PACKAGE FROM PACKAGE FILE:\n";
285 $dest_package = $packager->package($opts[
'packagedirectory'].
'/package.xml');
286 var_dump($dest_package);
288 echo
"\n\n\nDEBUGGING RESULT:\n";
291 echo
"removing package.xml";
292 unlink($opts[
'packagedirectory'].
'/package.xml');
293 $log = ob_get_clean();
294 file_put_contents((
string) $this->basedir .
'/build/artifacts/logs/pear_package_'.$package.
'.log', $log);
300 $ds =
new DirectoryScanner();
301 $ds->setBasedir((
string) $this->basedir.
'/.subsplit/src');
302 $ds->setIncludes(array(
'**/composer.json'));
304 $files = $ds->getIncludedFiles();
305 $this->subpackages = $files;
310 $cl = file((
string) $this->basedir.
'/.subsplit/CHANGELOG.md');
313 $release_date =
null;
315 foreach ($cl as $line) {
317 if (preg_match(
'/^\* '.$this->
getVersion().
' \(([0-9\-]+)\)$/', $line, $matches)) {
318 $release_date = $matches[1];
322 if ($in_version && empty($line) && empty($notes)) {
325 if ($in_version && ! empty($line)) {
326 $notes .= $line.
"\n";
328 if ($in_version && empty($line) && !empty($notes)) {
332 $this->changelog_release_date = $release_date;
334 if (! empty($notes)) {
335 $this->changelog_notes = $notes;