1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339:
<?php
require_once 'phing/Task.php';
require_once 'PEAR/PackageFileManager2.php';
require_once 'PEAR/PackageFileManager/File.php';
require_once 'PEAR/Packager.php';
class GuzzlePearPharPackageTask extends Task
{
private $version;
private $deploy = true;
private $makephar = true;
private $subpackages = array();
public function setVersion($str)
{
$this->version = $str;
}
public function getVersion()
{
return $this->version;
}
public function setDeploy($deploy)
{
$this->deploy = (bool) $deploy;
}
public function getDeploy()
{
return $this->deploy;
}
public function setMakephar($makephar)
{
$this->makephar = (bool) $makephar;
}
public function getMakephar()
{
return $this->makephar;
}
private $basedir;
private $guzzleinfo;
private $changelog_release_date;
private $changelog_notes = '-';
public function main()
{
$this->basedir = $this->getProject()->getBasedir();
if (!is_dir((string) $this->basedir.'/.subsplit')) {
throw new BuildException('PEAR packaging requires .subsplit directory');
}
$composer_file = file_get_contents((string) $this->basedir.'/.subsplit/composer.json');
$this->guzzleinfo = json_decode($composer_file, true);
$pearwork = (string) $this->basedir . '/build/pearwork';
if (!is_dir($pearwork)) {
mkdir($pearwork, 0777, true);
}
$pearlogs = (string) $this->basedir . '/build/artifacts/logs';
if (!is_dir($pearlogs)) {
mkdir($pearlogs, 0777, true);
}
$version = $this->getVersion();
$this->grabChangelog();
if ($version[0] == '2') {
$this->log('building single PEAR package');
$this->buildSinglePackage();
} else {
$this->buildSinglePackage();
}
if ($this->getMakephar()) {
$this->log("building PHAR");
$this->getProject()->executeTarget('package-phar');
}
if ($this->getDeploy()) {
$this->doDeployment();
}
}
public function doDeployment()
{
$basedir = (string) $this->basedir;
$this->log('beginning PEAR/PHAR deployment');
chdir($basedir . '/build/pearwork');
if (!is_dir('./channel')) {
mkdir('./channel');
}
passthru('aws s3 sync s3://pear.guzzlephp.org ./channel');
foreach (scandir('./') as $file) {
if (substr($file, -4) == '.tgz') {
passthru('pirum add ./channel ' . $file);
}
}
if ($this->getMakephar() && file_exists($basedir . '/build/artifacts/guzzle.phar')) {
rename($basedir . '/build/artifacts/guzzle.phar', './channel/guzzle.phar');
}
chdir($basedir . '/build/pearwork/channel');
passthru('aws s3 sync . s3://pear.guzzlephp.org');
}
public function buildSinglePackage()
{
$v = $this->getVersion();
$apiversion = $v[0] . '.0.0';
$opts = array(
'packagedirectory' => (string) $this->basedir . '/.subsplit/src/',
'filelistgenerator' => 'file',
'ignore' => array('*composer.json'),
'baseinstalldir' => '/',
'packagefile' => 'package.xml'
);
$pfm = new PEAR_PackageFileManager2();
$pfm->setOptions($opts);
$pfm->addRole('md', 'doc');
$pfm->addRole('pem', 'php');
$pfm->setPackage('Guzzle');
$pfm->setSummary("Object-oriented PHP HTTP Client for PHP 5.3+");
$pfm->setDescription($this->guzzleinfo['description']);
$pfm->setPackageType('php');
$pfm->setChannel('guzzlephp.org/pear');
$pfm->setAPIVersion($apiversion);
$pfm->setReleaseVersion($this->getVersion());
$pfm->setAPIStability('stable');
$pfm->setReleaseStability('stable');
$pfm->setNotes($this->changelog_notes);
$pfm->setPackageType('php');
$pfm->setLicense('MIT', 'http://github.com/guzzle/guzzle/blob/master/LICENSE');
$pfm->addMaintainer('lead', 'mtdowling', 'Michael Dowling', 'mtdowling@gmail.com', 'yes');
$pfm->setDate($this->changelog_release_date);
$pfm->generateContents();
$phpdep = $this->guzzleinfo['require']['php'];
$phpdep = str_replace('>=', '', $phpdep);
$pfm->setPhpDep($phpdep);
$pfm->addExtensionDep('required', 'curl');
$pfm->setPearinstallerDep('1.4.6');
$pfm->addPackageDepWithChannel('required', 'EventDispatcher', 'pear.symfony.com', '2.1.0');
if (!empty($this->subpackages)) {
foreach ($this->subpackages as $package) {
$pkg = dirname($package);
$pkg = str_replace('/', '_', $pkg);
$pfm->addConflictingPackageDepWithChannel($pkg, 'guzzlephp.org/pear', false, $apiversion);
}
}
ob_start();
$startdir = getcwd();
chdir((string) $this->basedir . '/build/pearwork');
echo "DEBUGGING GENERATED PACKAGE FILE\n";
$result = $pfm->debugPackageFile();
if ($result) {
$out = $pfm->writePackageFile();
echo "\n\n\nWRITE PACKAGE FILE RESULT:\n";
var_dump($out);
$packager = new PEAR_Packager();
echo "\n\n\nBUILDING PACKAGE FROM PACKAGE FILE:\n";
$dest_package = $packager->package($opts['packagedirectory'].'package.xml');
var_dump($dest_package);
} else {
echo "\n\n\nDEBUGGING RESULT:\n";
var_dump($result);
}
echo "removing package.xml";
unlink($opts['packagedirectory'].'package.xml');
$log = ob_get_clean();
file_put_contents((string) $this->basedir . '/build/artifacts/logs/pear_package.log', $log);
chdir($startdir);
}
public function createSubPackages()
{
$this->findComponents();
foreach ($this->subpackages as $package) {
$baseinstalldir = dirname($package);
$dir = (string) $this->basedir.'/.subsplit/src/' . $baseinstalldir;
$composer_file = file_get_contents((string) $this->basedir.'/.subsplit/src/'. $package);
$package_info = json_decode($composer_file, true);
$this->log('building ' . $package_info['target-dir'] . ' subpackage');
$this->buildSubPackage($dir, $baseinstalldir, $package_info);
}
}
public function buildSubPackage($dir, $baseinstalldir, $info)
{
$package = str_replace('/', '_', $baseinstalldir);
$opts = array(
'packagedirectory' => $dir,
'filelistgenerator' => 'file',
'ignore' => array('*composer.json', '*package.xml'),
'baseinstalldir' => '/' . $info['target-dir'],
'packagefile' => 'package.xml'
);
$pfm = new PEAR_PackageFileManager2();
$pfm->setOptions($opts);
$pfm->setPackage($package);
$pfm->setSummary($info['description']);
$pfm->setDescription($info['description']);
$pfm->setPackageType('php');
$pfm->setChannel('guzzlephp.org/pear');
$pfm->setAPIVersion('3.0.0');
$pfm->setReleaseVersion($this->getVersion());
$pfm->setAPIStability('stable');
$pfm->setReleaseStability('stable');
$pfm->setNotes($this->changelog_notes);
$pfm->setPackageType('php');
$pfm->setLicense('MIT', 'http://github.com/guzzle/guzzle/blob/master/LICENSE');
$pfm->addMaintainer('lead', 'mtdowling', 'Michael Dowling', 'mtdowling@gmail.com', 'yes');
$pfm->setDate($this->changelog_release_date);
$pfm->generateContents();
$phpdep = $this->guzzleinfo['require']['php'];
$phpdep = str_replace('>=', '', $phpdep);
$pfm->setPhpDep($phpdep);
$pfm->setPearinstallerDep('1.4.6');
foreach ($info['require'] as $type => $version) {
if ($type == 'php') {
continue;
}
if ($type == 'symfony/event-dispatcher') {
$pfm->addPackageDepWithChannel('required', 'EventDispatcher', 'pear.symfony.com', '2.1.0');
}
if ($type == 'ext-curl') {
$pfm->addExtensionDep('required', 'curl');
}
if (substr($type, 0, 6) == 'guzzle') {
$gdep = str_replace('/', ' ', $type);
$gdep = ucwords($gdep);
$gdep = str_replace(' ', '_', $gdep);
$pfm->addPackageDepWithChannel('required', $gdep, 'guzzlephp.org/pear', $this->getVersion());
}
}
$pfm->addConflictingPackageDepWithChannel('Guzzle', 'guzzlephp.org/pear', false, $apiversion);
ob_start();
$startdir = getcwd();
chdir((string) $this->basedir . '/build/pearwork');
echo "DEBUGGING GENERATED PACKAGE FILE\n";
$result = $pfm->debugPackageFile();
if ($result) {
$out = $pfm->writePackageFile();
echo "\n\n\nWRITE PACKAGE FILE RESULT:\n";
var_dump($out);
$packager = new PEAR_Packager();
echo "\n\n\nBUILDING PACKAGE FROM PACKAGE FILE:\n";
$dest_package = $packager->package($opts['packagedirectory'].'/package.xml');
var_dump($dest_package);
} else {
echo "\n\n\nDEBUGGING RESULT:\n";
var_dump($result);
}
echo "removing package.xml";
unlink($opts['packagedirectory'].'/package.xml');
$log = ob_get_clean();
file_put_contents((string) $this->basedir . '/build/artifacts/logs/pear_package_'.$package.'.log', $log);
chdir($startdir);
}
public function findComponents()
{
$ds = new DirectoryScanner();
$ds->setBasedir((string) $this->basedir.'/.subsplit/src');
$ds->setIncludes(array('**/composer.json'));
$ds->scan();
$files = $ds->getIncludedFiles();
$this->subpackages = $files;
}
public function grabChangelog()
{
$cl = file((string) $this->basedir.'/.subsplit/CHANGELOG.md');
$notes = '';
$in_version = false;
$release_date = null;
foreach ($cl as $line) {
$line = trim($line);
if (preg_match('/^\* '.$this->getVersion().' \(([0-9\-]+)\)$/', $line, $matches)) {
$release_date = $matches[1];
$in_version = true;
continue;
}
if ($in_version && empty($line) && empty($notes)) {
continue;
}
if ($in_version && ! empty($line)) {
$notes .= $line."\n";
}
if ($in_version && empty($line) && !empty($notes)) {
$in_version = false;
}
}
$this->changelog_release_date = $release_date;
if (! empty($notes)) {
$this->changelog_notes = $notes;
}
}
}